mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Expose transport ID through plugin factory so it's available earlier.
This commit is contained in:
@@ -4,11 +4,13 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import android.content.Context;
|
||||
|
||||
public interface DuplexPluginFactory {
|
||||
|
||||
TransportId getId();
|
||||
|
||||
DuplexPlugin createPlugin(Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, DuplexPluginCallback callback);
|
||||
|
||||
@@ -4,11 +4,13 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import android.content.Context;
|
||||
|
||||
public interface SimplexPluginFactory {
|
||||
|
||||
TransportId getId();
|
||||
|
||||
SimplexPlugin createPlugin(Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, SimplexPluginCallback callback);
|
||||
|
||||
@@ -103,7 +103,13 @@ class PluginManagerImpl implements PluginManager {
|
||||
Class<?> c = Class.forName(s);
|
||||
SimplexPluginFactory factory =
|
||||
(SimplexPluginFactory) c.newInstance();
|
||||
SimplexCallback callback = new SimplexCallback();
|
||||
TransportId id = factory.getId();
|
||||
if(!ids.add(id)) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.warning("Duplicate transport ID: " + id);
|
||||
continue;
|
||||
}
|
||||
SimplexCallback callback = new SimplexCallback(id);
|
||||
SimplexPlugin plugin = factory.createPlugin(pluginExecutor,
|
||||
androidExecutor, appContext, shutdownManager, callback);
|
||||
if(plugin == null) {
|
||||
@@ -113,15 +119,13 @@ class PluginManagerImpl implements PluginManager {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
TransportId id = plugin.getId();
|
||||
if(!ids.add(id)) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.warning("Duplicate transport ID: " + id);
|
||||
continue;
|
||||
if(plugin.start()) {
|
||||
simplexPlugins.add(plugin);
|
||||
} else {
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info(plugin.getClass().getSimpleName()
|
||||
+ " did not start");
|
||||
}
|
||||
callback.init(id);
|
||||
plugin.start();
|
||||
simplexPlugins.add(plugin);
|
||||
} catch(ClassCastException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
|
||||
continue;
|
||||
@@ -137,7 +141,13 @@ class PluginManagerImpl implements PluginManager {
|
||||
Class<?> c = Class.forName(s);
|
||||
DuplexPluginFactory factory =
|
||||
(DuplexPluginFactory) c.newInstance();
|
||||
DuplexCallback callback = new DuplexCallback();
|
||||
TransportId id = factory.getId();
|
||||
if(!ids.add(id)) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.warning("Duplicate transport ID: " + id);
|
||||
continue;
|
||||
}
|
||||
DuplexCallback callback = new DuplexCallback(id);
|
||||
DuplexPlugin plugin = factory.createPlugin(pluginExecutor,
|
||||
androidExecutor, appContext, shutdownManager, callback);
|
||||
if(plugin == null) {
|
||||
@@ -147,15 +157,13 @@ class PluginManagerImpl implements PluginManager {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
TransportId id = plugin.getId();
|
||||
if(!ids.add(id)) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.warning("Duplicate transport ID: " + id);
|
||||
continue;
|
||||
if(plugin.start()) {
|
||||
duplexPlugins.add(plugin);
|
||||
} else {
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info(plugin.getClass().getSimpleName()
|
||||
+ " did not start");
|
||||
}
|
||||
callback.init(id);
|
||||
plugin.start();
|
||||
duplexPlugins.add(plugin);
|
||||
} catch(ClassCastException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
|
||||
continue;
|
||||
@@ -174,12 +182,12 @@ class PluginManagerImpl implements PluginManager {
|
||||
return simplexPlugins.size() + duplexPlugins.size();
|
||||
}
|
||||
|
||||
private String[] getSimplexPluginFactoryNames() {
|
||||
private static String[] getSimplexPluginFactoryNames() {
|
||||
if(OsUtils.isAndroid()) return ANDROID_SIMPLEX_FACTORIES;
|
||||
return J2SE_SIMPLEX_FACTORIES;
|
||||
}
|
||||
|
||||
private String[] getDuplexPluginFactoryNames() {
|
||||
private static String[] getDuplexPluginFactoryNames() {
|
||||
if(OsUtils.isAndroid()) return ANDROID_DUPLEX_FACTORIES;
|
||||
return J2SE_DUPLEX_FACTORIES;
|
||||
}
|
||||
@@ -219,27 +227,22 @@ class PluginManagerImpl implements PluginManager {
|
||||
return stopped;
|
||||
}
|
||||
|
||||
public Collection<DuplexPlugin> getInvitationPlugins() {
|
||||
public synchronized Collection<DuplexPlugin> getInvitationPlugins() {
|
||||
Collection<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
||||
synchronized(this) {
|
||||
for(DuplexPlugin d : duplexPlugins) {
|
||||
if(d.supportsInvitations()) supported.add(d);
|
||||
}
|
||||
}
|
||||
for(DuplexPlugin d : duplexPlugins)
|
||||
if(d.supportsInvitations()) supported.add(d);
|
||||
return supported;
|
||||
}
|
||||
|
||||
private abstract class PluginCallbackImpl implements PluginCallback {
|
||||
|
||||
protected volatile TransportId id = null;
|
||||
protected final TransportId id;
|
||||
|
||||
protected void init(TransportId id) {
|
||||
assert this.id == null;
|
||||
protected PluginCallbackImpl(TransportId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public TransportConfig getConfig() {
|
||||
assert id != null;
|
||||
try {
|
||||
return db.getConfig(id);
|
||||
} catch(DbException e) {
|
||||
@@ -249,7 +252,6 @@ class PluginManagerImpl implements PluginManager {
|
||||
}
|
||||
|
||||
public TransportProperties getLocalProperties() {
|
||||
assert id != null;
|
||||
try {
|
||||
TransportProperties p = db.getLocalProperties(id);
|
||||
return p == null ? new TransportProperties() : p;
|
||||
@@ -260,7 +262,6 @@ class PluginManagerImpl implements PluginManager {
|
||||
}
|
||||
|
||||
public Map<ContactId, TransportProperties> getRemoteProperties() {
|
||||
assert id != null;
|
||||
try {
|
||||
return db.getRemoteProperties(id);
|
||||
} catch(DbException e) {
|
||||
@@ -270,7 +271,6 @@ class PluginManagerImpl implements PluginManager {
|
||||
}
|
||||
|
||||
public void mergeConfig(TransportConfig c) {
|
||||
assert id != null;
|
||||
try {
|
||||
db.mergeConfig(id, c);
|
||||
} catch(DbException e) {
|
||||
@@ -279,7 +279,6 @@ class PluginManagerImpl implements PluginManager {
|
||||
}
|
||||
|
||||
public void mergeLocalProperties(TransportProperties p) {
|
||||
assert id != null;
|
||||
try {
|
||||
db.mergeLocalProperties(id, p);
|
||||
} catch(DbException e) {
|
||||
@@ -303,8 +302,11 @@ class PluginManagerImpl implements PluginManager {
|
||||
private class SimplexCallback extends PluginCallbackImpl
|
||||
implements SimplexPluginCallback {
|
||||
|
||||
private SimplexCallback(TransportId id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public void readerCreated(SimplexTransportReader r) {
|
||||
assert id != null;
|
||||
dispatcher.dispatchReader(id, r);
|
||||
}
|
||||
|
||||
@@ -316,8 +318,11 @@ class PluginManagerImpl implements PluginManager {
|
||||
private class DuplexCallback extends PluginCallbackImpl
|
||||
implements DuplexPluginCallback {
|
||||
|
||||
private DuplexCallback(TransportId id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
||||
assert id != null;
|
||||
dispatcher.dispatchIncomingConnection(id, d);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,12 @@ import net.sf.briar.util.StringUtils;
|
||||
class BluetoothPlugin implements DuplexPlugin {
|
||||
|
||||
// Share an ID with the Android Bluetooth plugin
|
||||
private static final byte[] TRANSPORT_ID =
|
||||
static final byte[] TRANSPORT_ID =
|
||||
StringUtils.fromHexString("d99c9313c04417dcf22fc60d12a187ea"
|
||||
+ "00a539fd260f08a13a0d8a900cde5e49"
|
||||
+ "1b4df2ffd42e40c408f2db7868f518aa");
|
||||
private static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BluetoothPlugin.class.getName());
|
||||
|
||||
|
||||
@@ -9,12 +9,17 @@ import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import android.content.Context;
|
||||
|
||||
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 mins
|
||||
|
||||
public TransportId getId() {
|
||||
return BluetoothPlugin.ID;
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, DuplexPluginCallback callback) {
|
||||
|
||||
@@ -44,11 +44,12 @@ import android.content.IntentFilter;
|
||||
class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
// Share an ID with the J2SE Bluetooth plugin
|
||||
private static final byte[] TRANSPORT_ID =
|
||||
static final byte[] TRANSPORT_ID =
|
||||
StringUtils.fromHexString("d99c9313c04417dcf22fc60d12a187ea"
|
||||
+ "00a539fd260f08a13a0d8a900cde5e49"
|
||||
+ "1b4df2ffd42e40c408f2db7868f518aa");
|
||||
private static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(DroidtoothPlugin.class.getName());
|
||||
private static final String FOUND = "android.bluetooth.device.action.FOUND";
|
||||
|
||||
@@ -8,12 +8,17 @@ import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import android.content.Context;
|
||||
|
||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 mins
|
||||
|
||||
public TransportId getId() {
|
||||
return DroidtoothPlugin.ID;
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, DuplexPluginCallback callback) {
|
||||
|
||||
@@ -20,11 +20,12 @@ import net.sf.briar.util.StringUtils;
|
||||
class RemovableDrivePlugin extends FilePlugin
|
||||
implements RemovableDriveMonitor.Callback {
|
||||
|
||||
private static final byte[] TRANSPORT_ID =
|
||||
static final byte[] TRANSPORT_ID =
|
||||
StringUtils.fromHexString("7c81bf5c9b1cd557685548c85f976bbd"
|
||||
+ "e633d2418ea2e230e5710fb43c6f8cc0"
|
||||
+ "68abca3a9d0edb13bcea13b851725c5d");
|
||||
private static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(RemovableDrivePlugin.class.getName());
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexPlugin;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexPluginFactory;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import net.sf.briar.util.OsUtils;
|
||||
import android.content.Context;
|
||||
|
||||
@@ -15,6 +16,10 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 10L * 1000L; // 10 seconds
|
||||
|
||||
public TransportId getId() {
|
||||
return RemovableDrivePlugin.ID;
|
||||
}
|
||||
|
||||
public SimplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, SimplexPluginCallback callback) {
|
||||
|
||||
@@ -16,11 +16,12 @@ import net.sf.briar.util.StringUtils;
|
||||
|
||||
class ModemPlugin implements DuplexPlugin {
|
||||
|
||||
private static final byte[] TRANSPORT_ID =
|
||||
static final byte[] TRANSPORT_ID =
|
||||
StringUtils.fromHexString("8f573867bedf54884b5868ee5d902832" +
|
||||
"ee5e522da84d0d431712bd672fbd2f79" +
|
||||
"262d27b93879b94ee9afbb80e7fc87fb");
|
||||
private static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ModemPlugin.class.getName());
|
||||
|
||||
|
||||
@@ -2,20 +2,26 @@ package net.sf.briar.plugins.modem;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.h2.util.StringUtils;
|
||||
|
||||
import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
|
||||
import org.h2.util.StringUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class ModemPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 60L * 60L * 1000L; // 1 hour
|
||||
|
||||
public TransportId getId() {
|
||||
return ModemPlugin.ID;
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, DuplexPluginCallback callback) {
|
||||
|
||||
@@ -33,11 +33,12 @@ import net.sf.briar.util.StringUtils;
|
||||
/** A socket plugin that supports exchanging invitations over a LAN. */
|
||||
class LanTcpPlugin extends TcpPlugin {
|
||||
|
||||
private static final byte[] TRANSPORT_ID =
|
||||
static final byte[] TRANSPORT_ID =
|
||||
StringUtils.fromHexString("0d79357fd7f74d66c2f6f6ad0f7fff81"
|
||||
+ "d21c53a43b90b0507ed0683872d8e2fc"
|
||||
+ "5a88e8f953638228dc26669639757bbf");
|
||||
private static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(LanTcpPlugin.class.getName());
|
||||
|
||||
|
||||
@@ -8,12 +8,17 @@ import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import android.content.Context;
|
||||
|
||||
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 60L * 1000L; // 1 minute
|
||||
|
||||
public TransportId getId() {
|
||||
return LanTcpPlugin.ID;
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, DuplexPluginCallback callback) {
|
||||
|
||||
@@ -24,11 +24,12 @@ import net.sf.briar.util.StringUtils;
|
||||
|
||||
class WanTcpPlugin extends TcpPlugin {
|
||||
|
||||
private static final byte[] TRANSPORT_ID =
|
||||
static final byte[] TRANSPORT_ID =
|
||||
StringUtils.fromHexString("58c66d999e492b85065924acfd739d80"
|
||||
+ "c65a62f87e5a4fc6c284f95908b9007d"
|
||||
+ "512a93ebf89bf68f50a29e96eebf97b6");
|
||||
private static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(WanTcpPlugin.class.getName());
|
||||
|
||||
|
||||
@@ -8,12 +8,17 @@ import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import android.content.Context;
|
||||
|
||||
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 minutes
|
||||
|
||||
public TransportId getId() {
|
||||
return WanTcpPlugin.ID;
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, DuplexPluginCallback callback) {
|
||||
|
||||
@@ -35,11 +35,12 @@ import org.silvertunnel.netlib.layer.tor.util.RSAKeyPair;
|
||||
|
||||
class TorPlugin implements DuplexPlugin {
|
||||
|
||||
private static final byte[] TRANSPORT_ID =
|
||||
static final byte[] TRANSPORT_ID =
|
||||
StringUtils.fromHexString("f264721575cb7ee710772f35abeb3db4"
|
||||
+ "a91f474e14de346be296c2efc99effdd"
|
||||
+ "f35921e6ed87a25c201f044da4767981");
|
||||
private static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
static final TransportId ID = new TransportId(TRANSPORT_ID);
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(TorPlugin.class.getName());
|
||||
|
||||
|
||||
@@ -2,20 +2,26 @@ package net.sf.briar.plugins.tor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.h2.util.StringUtils;
|
||||
|
||||
import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
|
||||
import org.h2.util.StringUtils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class TorPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long POLLING_INTERVAL = 15L * 60L * 1000L; // 15 mins
|
||||
|
||||
public TransportId getId() {
|
||||
return TorPlugin.ID;
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
ShutdownManager shutdownManager, DuplexPluginCallback callback) {
|
||||
|
||||
Reference in New Issue
Block a user