Merge branch '1147-only-alice-performs-discovery' into 'master'

Only Alice should perform Bluetooth discovery

See merge request briar/briar!1291
This commit is contained in:
Torsten Grote
2020-10-28 11:11:34 +00:00
8 changed files with 26 additions and 15 deletions

View File

@@ -41,10 +41,12 @@ public interface DuplexPlugin extends Plugin {
/** /**
* Attempts to connect to the remote peer specified in the given descriptor. * Attempts to connect to the remote peer specified in the given descriptor.
* Returns null if no connection can be established. * Returns null if no connection can be established.
*
* @param alice True if the local party is Alice
*/ */
@Nullable @Nullable
DuplexTransportConnection createKeyAgreementConnection( DuplexTransportConnection createKeyAgreementConnection(
byte[] remoteCommitment, BdfList descriptor); byte[] remoteCommitment, BdfList descriptor, boolean alice);
/** /**
* Returns true if the plugin supports rendezvous connections. * Returns true if the plugin supports rendezvous connections.

View File

@@ -118,8 +118,8 @@ class KeyAgreementConnector {
DuplexPlugin plugin = (DuplexPlugin) p; DuplexPlugin plugin = (DuplexPlugin) p;
byte[] commitment = remotePayload.getCommitment(); byte[] commitment = remotePayload.getCommitment();
BdfList descriptor = d.getDescriptor(); BdfList descriptor = d.getDescriptor();
connectionChooser.submit(new ReadableTask( connectionChooser.submit(new ReadableTask(new ConnectorTask(
new ConnectorTask(plugin, commitment, descriptor))); plugin, commitment, descriptor, alice)));
} }
} }
@@ -148,15 +148,17 @@ class KeyAgreementConnector {
private class ConnectorTask implements Callable<KeyAgreementConnection> { private class ConnectorTask implements Callable<KeyAgreementConnection> {
private final DuplexPlugin plugin;
private final byte[] commitment; private final byte[] commitment;
private final BdfList descriptor; private final BdfList descriptor;
private final DuplexPlugin plugin; private final boolean alice;
private ConnectorTask(DuplexPlugin plugin, byte[] commitment, private ConnectorTask(DuplexPlugin plugin, byte[] commitment,
BdfList descriptor) { BdfList descriptor, boolean alice) {
this.plugin = plugin; this.plugin = plugin;
this.commitment = commitment; this.commitment = commitment;
this.descriptor = descriptor; this.descriptor = descriptor;
this.alice = alice;
} }
@Nullable @Nullable
@@ -166,7 +168,7 @@ class KeyAgreementConnector {
while (!stopped) { while (!stopped) {
DuplexTransportConnection conn = DuplexTransportConnection conn =
plugin.createKeyAgreementConnection(commitment, plugin.createKeyAgreementConnection(commitment,
descriptor); descriptor, alice);
if (conn != null) { if (conn != null) {
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info(plugin.getId() + ": Outgoing connection"); LOG.info(plugin.getId() + ": Outgoing connection");

View File

@@ -430,15 +430,22 @@ abstract class BluetoothPlugin<S, SS> implements DuplexPlugin, EventListener {
@Override @Override
public DuplexTransportConnection createKeyAgreementConnection( public DuplexTransportConnection createKeyAgreementConnection(
byte[] commitment, BdfList descriptor) { byte[] commitment, BdfList descriptor, boolean alice) {
if (getState() != ACTIVE) return null; if (getState() != ACTIVE) return null;
// No truncation necessary because COMMIT_LENGTH = 16 // No truncation necessary because COMMIT_LENGTH = 16
String uuid = UUID.nameUUIDFromBytes(commitment).toString(); String uuid = UUID.nameUUIDFromBytes(commitment).toString();
DuplexTransportConnection conn; DuplexTransportConnection conn;
if (descriptor.size() == 1) { if (descriptor.size() == 1) {
if (LOG.isLoggable(INFO)) if (alice) {
LOG.info("Discovering address for key agreement UUID " + uuid); if (LOG.isLoggable(INFO)) {
conn = discoverAndConnect(uuid); LOG.info("Discovering address for key agreement UUID " +
uuid);
}
conn = discoverAndConnect(uuid);
} else {
LOG.info("No address in key agreement descriptor");
return null;
}
} else { } else {
String address; String address;
try { try {

View File

@@ -376,7 +376,7 @@ class LanTcpPlugin extends TcpPlugin {
@Override @Override
public DuplexTransportConnection createKeyAgreementConnection( public DuplexTransportConnection createKeyAgreementConnection(
byte[] commitment, BdfList descriptor) { byte[] commitment, BdfList descriptor, boolean alice) {
ServerSocket ss = state.getServerSocket(true); ServerSocket ss = state.getServerSocket(true);
if (ss == null) return null; if (ss == null) return null;
InterfaceAddress local = getLocalInterfaceAddress(ss.getInetAddress()); InterfaceAddress local = getLocalInterfaceAddress(ss.getInetAddress());

View File

@@ -367,7 +367,7 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
@Override @Override
public DuplexTransportConnection createKeyAgreementConnection( public DuplexTransportConnection createKeyAgreementConnection(
byte[] commitment, BdfList descriptor) { byte[] commitment, BdfList descriptor, boolean alice) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@@ -708,7 +708,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
@Override @Override
public DuplexTransportConnection createKeyAgreementConnection( public DuplexTransportConnection createKeyAgreementConnection(
byte[] commitment, BdfList descriptor) { byte[] commitment, BdfList descriptor, boolean alice) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@@ -276,7 +276,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
descriptor.add(local.getPort()); descriptor.add(local.getPort());
// Connect to the port // Connect to the port
DuplexTransportConnection d = plugin.createKeyAgreementConnection( DuplexTransportConnection d = plugin.createKeyAgreementConnection(
new byte[COMMIT_LENGTH], descriptor); new byte[COMMIT_LENGTH], descriptor, true);
assertNotNull(d); assertNotNull(d);
// Check that the connection was accepted // Check that the connection was accepted
assertTrue(latch.await(5, SECONDS)); assertTrue(latch.await(5, SECONDS));

View File

@@ -198,7 +198,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
@Override @Override
public DuplexTransportConnection createKeyAgreementConnection( public DuplexTransportConnection createKeyAgreementConnection(
byte[] commitment, BdfList descriptor) { byte[] commitment, BdfList descriptor, boolean alice) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }