Use namespaced strings for Transport IDs

This commit is contained in:
Torsten Grote
2016-11-17 17:06:26 -02:00
parent 37e61c97ea
commit e32313c30b
16 changed files with 71 additions and 32 deletions

View File

@@ -29,6 +29,9 @@ import org.briarproject.android.forum.ForumListFragment;
import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
import org.briarproject.android.privategroup.list.GroupListFragment;
import org.briarproject.api.TransportId;
import org.briarproject.api.plugins.BluetoothConstants;
import org.briarproject.api.plugins.LanTcpConstants;
import org.briarproject.api.plugins.TorConstants;
import java.util.ArrayList;
import java.util.List;
@@ -230,21 +233,21 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
transports = new ArrayList<>(3);
Transport tor = new Transport();
tor.id = new TransportId("tor");
tor.id = TorConstants.ID;
tor.enabled = controller.isTransportRunning(tor.id);
tor.iconId = R.drawable.transport_tor;
tor.textId = R.string.transport_tor;
transports.add(tor);
Transport bt = new Transport();
bt.id = new TransportId("bt");
bt.id = BluetoothConstants.ID;
bt.enabled = controller.isTransportRunning(bt.id);
bt.iconId = R.drawable.transport_bt;
bt.textId = R.string.transport_bt;
transports.add(bt);
Transport lan = new Transport();
lan.id = new TransportId("lan");
lan.id = LanTcpConstants.ID;
lan.enabled = controller.isTransportRunning(lan.id);
lan.iconId = R.drawable.transport_lan;
lan.textId = R.string.transport_lan;

View File

@@ -65,26 +65,23 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_BLUETOOTH;
import static org.briarproject.api.plugins.BluetoothConstants.ID;
import static org.briarproject.api.plugins.BluetoothConstants.PROP_ADDRESS;
import static org.briarproject.api.plugins.BluetoothConstants.PROP_UUID;
import static org.briarproject.api.plugins.BluetoothConstants.UUID_BYTES;
import static org.briarproject.util.PrivacyUtils.scrubMacAddress;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
class DroidtoothPlugin implements DuplexPlugin {
// Share an ID with the J2SE Bluetooth plugin
static final TransportId ID = new TransportId("bt");
private static final Logger LOG =
Logger.getLogger(DroidtoothPlugin.class.getName());
private static final int UUID_BYTES = 16;
private static final String FOUND =
"android.bluetooth.device.action.FOUND";
private static final String DISCOVERY_FINISHED =
"android.bluetooth.adapter.action.DISCOVERY_FINISHED";
private static final String PROP_ADDRESS = "address";
private static final String PROP_UUID = "uuid";
private final Executor ioExecutor;
private final AndroidExecutor androidExecutor;
private final Context appContext;
@@ -315,6 +312,7 @@ class DroidtoothPlugin implements DuplexPlugin {
}
}
@Nullable
private BluetoothSocket connect(String address, String uuid) {
// Validate the address
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
@@ -646,7 +644,7 @@ class DroidtoothPlugin implements DuplexPlugin {
private final BluetoothServerSocket ss;
BluetoothKeyAgreementListener(BdfList descriptor,
private BluetoothKeyAgreementListener(BdfList descriptor,
BluetoothServerSocket ss) {
super(descriptor);
this.ss = ss;

View File

@@ -10,7 +10,7 @@ public class TransportId {
/**
* The maximum length of transport identifier in UTF-8 bytes.
*/
public static int MAX_TRANSPORT_ID_LENGTH = 10;
public static int MAX_TRANSPORT_ID_LENGTH = 64;
private final String id;

View File

@@ -0,0 +1,14 @@
package org.briarproject.api.plugins;
import org.briarproject.api.TransportId;
public interface BluetoothConstants {
TransportId ID = new TransportId("org.briarproject.bramble.bluetooth");
int UUID_BYTES = 16;
String PROP_ADDRESS = "address";
String PROP_UUID = "uuid";
}

View File

@@ -0,0 +1,9 @@
package org.briarproject.api.plugins;
import org.briarproject.api.TransportId;
public interface LanTcpConstants {
TransportId ID = new TransportId("org.briarproject.bramble.lan");
}

View File

@@ -4,7 +4,7 @@ import org.briarproject.api.TransportId;
public interface TorConstants {
TransportId ID = new TransportId("tor");
TransportId ID = new TransportId("org.briarproject.bramble.tor");
int SOCKS_PORT = 59050;
int CONTROL_PORT = 59051;

View File

@@ -0,0 +1,9 @@
package org.briarproject.api.plugins;
import org.briarproject.api.TransportId;
public interface WanTcpConstants {
TransportId ID = new TransportId("org.briarproject.bramble.wan");
}

View File

@@ -9,6 +9,8 @@ import org.briarproject.api.keyagreement.Payload;
import org.briarproject.api.keyagreement.PayloadParser;
import org.briarproject.api.keyagreement.TransportDescriptor;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.plugins.BluetoothConstants;
import org.briarproject.api.plugins.TorConstants;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -55,10 +57,10 @@ class PayloadParserImpl implements PayloadParser {
BdfList descriptor = payload.getList(i);
long transportId = descriptor.getLong(0);
if (transportId == TRANSPORT_ID_BLUETOOTH) {
TransportId id = new TransportId("bt");
TransportId id = BluetoothConstants.ID;
recognised.add(new TransportDescriptor(id, descriptor));
} else if (transportId == TRANSPORT_ID_LAN) {
TransportId id = new TransportId("lan");
TransportId id = TorConstants.ID;
recognised.add(new TransportDescriptor(id, descriptor));
}
}

View File

@@ -33,14 +33,13 @@ import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_LAN;
import static org.briarproject.api.plugins.LanTcpConstants.ID;
import static org.briarproject.util.ByteUtils.MAX_16_BIT_UNSIGNED;
import static org.briarproject.util.PrivacyUtils.scrubSocketAddress;
@NotNullByDefault
class LanTcpPlugin extends TcpPlugin {
static final TransportId ID = new TransportId("lan");
private static final Logger LOG =
Logger.getLogger(LanTcpPlugin.class.getName());

View File

@@ -9,6 +9,8 @@ import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
import java.util.concurrent.Executor;
import static org.briarproject.api.plugins.LanTcpConstants.ID;
public class LanTcpPluginFactory implements DuplexPluginFactory {
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
@@ -28,7 +30,7 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
@Override
public TransportId getId() {
return LanTcpPlugin.ID;
return ID;
}
@Override

View File

@@ -16,12 +16,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executor;
import static org.briarproject.api.plugins.WanTcpConstants.ID;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
class WanTcpPlugin extends TcpPlugin {
static final TransportId ID = new TransportId("wan");
private static final String PROP_IP_PORT = "ipPort";
private final PortMapper portMapper;

View File

@@ -10,6 +10,8 @@ import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
import java.util.concurrent.Executor;
import static org.briarproject.api.plugins.WanTcpConstants.ID;
public class WanTcpPluginFactory implements DuplexPluginFactory {
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
@@ -31,7 +33,7 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
@Override
public TransportId getId() {
return WanTcpPlugin.ID;
return ID;
}
@Override

View File

@@ -49,20 +49,17 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static javax.bluetooth.DiscoveryAgent.GIAC;
import static org.briarproject.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_BLUETOOTH;
import static org.briarproject.api.plugins.BluetoothConstants.ID;
import static org.briarproject.api.plugins.BluetoothConstants.PROP_ADDRESS;
import static org.briarproject.api.plugins.BluetoothConstants.PROP_UUID;
import static org.briarproject.api.plugins.BluetoothConstants.UUID_BYTES;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
class BluetoothPlugin implements DuplexPlugin {
// Share an ID with the Android Bluetooth plugin
static final TransportId ID = new TransportId("bt");
private static final Logger LOG =
Logger.getLogger(BluetoothPlugin.class.getName());
private static final int UUID_BYTES = 16;
private static final String PROP_ADDRESS = "address";
private static final String PROP_UUID = "uuid";
private final Executor ioExecutor;
private final SecureRandom secureRandom;
@@ -507,7 +504,7 @@ class BluetoothPlugin implements DuplexPlugin {
private final StreamConnectionNotifier ss;
BluetoothKeyAgreementListener(BdfList descriptor,
private BluetoothKeyAgreementListener(BdfList descriptor,
StreamConnectionNotifier ss) {
super(descriptor);
this.ss = ss;

View File

@@ -10,6 +10,8 @@ import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
import java.security.SecureRandom;
import java.util.concurrent.Executor;
import static org.briarproject.api.plugins.BluetoothConstants.ID;
public class BluetoothPluginFactory implements DuplexPluginFactory {
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
@@ -30,7 +32,7 @@ public class BluetoothPluginFactory implements DuplexPluginFactory {
@Override
public TransportId getId() {
return BluetoothPlugin.ID;
return ID;
}
@Override

View File

@@ -19,7 +19,8 @@ import static java.util.logging.Level.WARNING;
class RemovableDrivePlugin extends FilePlugin
implements RemovableDriveMonitor.Callback {
static final TransportId ID = new TransportId("file");
static final TransportId ID =
new TransportId("org.briarproject.bramble.file");
private static final Logger LOG =
Logger.getLogger(RemovableDrivePlugin.class.getName());

View File

@@ -28,7 +28,8 @@ import static java.util.logging.Level.WARNING;
@ParametersNotNullByDefault
class ModemPlugin implements DuplexPlugin, Modem.Callback {
static final TransportId ID = new TransportId("modem");
static final TransportId ID =
new TransportId("org.briarproject.bramble.modem");
private static final Logger LOG =
Logger.getLogger(ModemPlugin.class.getName());