From 08b11412fb523e838ce850290e65e5adb2eb7032 Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Wed, 5 Jun 2013 14:16:44 +0100 Subject: [PATCH] Allow plugins to use different maximum frame lengths. --- briar-android/.classpath | 1 + .../src/net/sf/briar/api/plugins/Plugin.java | 3 + .../duplex/DuplexTransportConnection.java | 3 + .../simplex/SimplexTransportReader.java | 3 + .../simplex/SimplexTransportWriter.java | 3 + .../transport/ConnectionReaderFactory.java | 4 +- .../transport/ConnectionWriterFactory.java | 7 +- .../sf/briar/invitation/AliceConnector.java | 5 +- .../net/sf/briar/invitation/BobConnector.java | 5 +- .../duplex/IncomingDuplexConnection.java | 14 +++- .../duplex/OutgoingDuplexConnection.java | 14 +++- .../simplex/IncomingSimplexConnection.java | 8 +- .../simplex/OutgoingSimplexConnection.java | 10 ++- .../plugins/bluetooth/BluetoothPlugin.java | 14 +++- .../bluetooth/BluetoothPluginFactory.java | 3 +- .../BluetoothTransportConnection.java | 13 +++- .../plugins/droidtooth/DroidtoothPlugin.java | 14 +++- .../droidtooth/DroidtoothPluginFactory.java | 4 +- .../DroidtoothTransportConnection.java | 13 +++- .../net/sf/briar/plugins/file/FilePlugin.java | 15 +++- .../plugins/file/FileTransportReader.java | 6 +- .../plugins/file/FileTransportWriter.java | 13 ++-- .../plugins/file/RemovableDrivePlugin.java | 9 +-- .../file/RemovableDrivePluginFactory.java | 4 +- .../sf/briar/plugins/modem/ModemPlugin.java | 13 +++- .../plugins/modem/ModemPluginFactory.java | 4 +- .../briar/plugins/tcp/DroidLanTcpPlugin.java | 5 +- .../plugins/tcp/DroidLanTcpPluginFactory.java | 3 +- .../sf/briar/plugins/tcp/LanTcpPlugin.java | 9 ++- .../plugins/tcp/LanTcpPluginFactory.java | 5 +- .../net/sf/briar/plugins/tcp/TcpPlugin.java | 14 +++- .../plugins/tcp/TcpTransportConnection.java | 13 +++- .../sf/briar/plugins/tcp/WanTcpPlugin.java | 6 +- .../plugins/tcp/WanTcpPluginFactory.java | 6 +- .../net/sf/briar/plugins/tor/TorPlugin.java | 14 +++- .../briar/plugins/tor/TorPluginFactory.java | 3 +- .../plugins/tor/TorTransportConnection.java | 13 +++- .../ConnectionReaderFactoryImpl.java | 15 ++-- .../ConnectionWriterFactoryImpl.java | 17 ++--- .../TransportConnectionRecogniser.java | 5 +- .../net/sf/briar/ProtocolIntegrationTest.java | 5 +- .../simplex/TestSimplexTransportReader.java | 6 ++ .../simplex/TestSimplexTransportWriter.java | 6 ++ .../bluetooth/BluetoothClientTest.java | 2 +- .../bluetooth/BluetoothServerTest.java | 2 +- .../file/RemovableDrivePluginTest.java | 74 ++++++++++--------- .../briar/plugins/modem/ModemPluginTest.java | 10 +-- .../briar/plugins/tcp/LanTcpClientTest.java | 4 +- .../briar/plugins/tcp/LanTcpPluginTest.java | 6 +- .../briar/plugins/tcp/LanTcpServerTest.java | 4 +- .../transport/TransportIntegrationTest.java | 5 +- 51 files changed, 298 insertions(+), 159 deletions(-) diff --git a/briar-android/.classpath b/briar-android/.classpath index 33324c4154..591a99a8cc 100644 --- a/briar-android/.classpath +++ b/briar-android/.classpath @@ -7,5 +7,6 @@ <classpathentry combineaccessrules="false" kind="src" path="/briar-core"/> <classpathentry combineaccessrules="false" kind="src" path="/briar-api"/> <classpathentry kind="lib" path="/briar-api/libs/guice-3.0-no_aop.jar"/> + <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> <classpathentry kind="output" path="bin/classes"/> </classpath> diff --git a/briar-api/src/net/sf/briar/api/plugins/Plugin.java b/briar-api/src/net/sf/briar/api/plugins/Plugin.java index a332eb63dc..123dfd0ad1 100644 --- a/briar-api/src/net/sf/briar/api/plugins/Plugin.java +++ b/briar-api/src/net/sf/briar/api/plugins/Plugin.java @@ -14,6 +14,9 @@ public interface Plugin { /** Returns a label for looking up the plugin's translated name. */ String getName(); + /** Returns the transport's maximum frame length in bytes. */ + int getMaxFrameLength(); + /** Returns the transport's maximum latency in milliseconds. */ long getMaxLatency(); diff --git a/briar-api/src/net/sf/briar/api/plugins/duplex/DuplexTransportConnection.java b/briar-api/src/net/sf/briar/api/plugins/duplex/DuplexTransportConnection.java index 06e0f148bf..5d11579538 100644 --- a/briar-api/src/net/sf/briar/api/plugins/duplex/DuplexTransportConnection.java +++ b/briar-api/src/net/sf/briar/api/plugins/duplex/DuplexTransportConnection.java @@ -11,6 +11,9 @@ import java.io.OutputStream; */ public interface DuplexTransportConnection { + /** Returns the maximum frame length of the transport in bytes. */ + int getMaxFrameLength(); + /** Returns the maximum latency of the transport in milliseconds. */ long getMaxLatency(); diff --git a/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportReader.java b/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportReader.java index ffda7ef0d5..00850b12e5 100644 --- a/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportReader.java +++ b/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportReader.java @@ -9,6 +9,9 @@ import java.io.InputStream; */ public interface SimplexTransportReader { + /** Returns the maximum frame length of the transport in bytes. */ + int getMaxFrameLength(); + /** Returns an input stream for reading from the transport. */ InputStream getInputStream() throws IOException; diff --git a/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportWriter.java b/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportWriter.java index facb4769c3..f21aaf032b 100644 --- a/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportWriter.java +++ b/briar-api/src/net/sf/briar/api/plugins/simplex/SimplexTransportWriter.java @@ -12,6 +12,9 @@ public interface SimplexTransportWriter { /** Returns the capacity of the transport in bytes. */ long getCapacity(); + /** Returns the maximum frame length of the transport in bytes. */ + int getMaxFrameLength(); + /** Returns the maximum latency of the transport in milliseconds. */ long getMaxLatency(); diff --git a/briar-api/src/net/sf/briar/api/transport/ConnectionReaderFactory.java b/briar-api/src/net/sf/briar/api/transport/ConnectionReaderFactory.java index 518578c39c..b070b3c63c 100644 --- a/briar-api/src/net/sf/briar/api/transport/ConnectionReaderFactory.java +++ b/briar-api/src/net/sf/briar/api/transport/ConnectionReaderFactory.java @@ -5,10 +5,10 @@ import java.io.InputStream; public interface ConnectionReaderFactory { /** Creates a connection reader for one side of a connection. */ - ConnectionReader createConnectionReader(InputStream in, + ConnectionReader createConnectionReader(InputStream in, int maxFrameLength, ConnectionContext ctx, boolean incoming, boolean initiator); /** Creates a connection reader for one side of an invitation connection. */ ConnectionReader createInvitationConnectionReader(InputStream in, - byte[] secret, boolean alice); + int maxFrameLength, byte[] secret, boolean alice); } diff --git a/briar-api/src/net/sf/briar/api/transport/ConnectionWriterFactory.java b/briar-api/src/net/sf/briar/api/transport/ConnectionWriterFactory.java index 4bff478a34..00d4126030 100644 --- a/briar-api/src/net/sf/briar/api/transport/ConnectionWriterFactory.java +++ b/briar-api/src/net/sf/briar/api/transport/ConnectionWriterFactory.java @@ -5,10 +5,11 @@ import java.io.OutputStream; public interface ConnectionWriterFactory { /** Creates a connection writer for one side of a connection. */ - ConnectionWriter createConnectionWriter(OutputStream out, long capacity, - ConnectionContext ctx, boolean incoming, boolean initiator); + ConnectionWriter createConnectionWriter(OutputStream out, + int maxFrameLength, long capacity, ConnectionContext ctx, + boolean incoming, boolean initiator); /** Creates a connection writer for one side of an invitation connection. */ ConnectionWriter createInvitationConnectionWriter(OutputStream out, - byte[] secret, boolean alice); + int maxFrameLength, byte[] secret, boolean alice); } diff --git a/briar-core/src/net/sf/briar/invitation/AliceConnector.java b/briar-core/src/net/sf/briar/invitation/AliceConnector.java index 6337959617..b4e1b0cdf4 100644 --- a/briar-core/src/net/sf/briar/invitation/AliceConnector.java +++ b/briar-core/src/net/sf/briar/invitation/AliceConnector.java @@ -135,13 +135,14 @@ class AliceConnector extends Connector { // Confirmation succeeded - upgrade to a secure connection if(LOG.isLoggable(INFO)) LOG.info(pluginName + " confirmation succeeded"); + int maxFrameLength = conn.getMaxFrameLength(); ConnectionReader connectionReader = connectionReaderFactory.createInvitationConnectionReader(in, - secret, false); + maxFrameLength, secret, false); r = readerFactory.createReader(connectionReader.getInputStream()); ConnectionWriter connectionWriter = connectionWriterFactory.createInvitationConnectionWriter(out, - secret, true); + maxFrameLength, secret, true); w = writerFactory.createWriter(connectionWriter.getOutputStream()); // Derive the invitation nonces byte[][] nonces = crypto.deriveInvitationNonces(secret); diff --git a/briar-core/src/net/sf/briar/invitation/BobConnector.java b/briar-core/src/net/sf/briar/invitation/BobConnector.java index 3f03a65b61..20bb1b71ee 100644 --- a/briar-core/src/net/sf/briar/invitation/BobConnector.java +++ b/briar-core/src/net/sf/briar/invitation/BobConnector.java @@ -135,13 +135,14 @@ class BobConnector extends Connector { // Confirmation succeeded - upgrade to a secure connection if(LOG.isLoggable(INFO)) LOG.info(pluginName + " confirmation succeeded"); + int maxFrameLength = conn.getMaxFrameLength(); ConnectionReader connectionReader = connectionReaderFactory.createInvitationConnectionReader(in, - secret, true); + maxFrameLength, secret, true); r = readerFactory.createReader(connectionReader.getInputStream()); ConnectionWriter connectionWriter = connectionWriterFactory.createInvitationConnectionWriter(out, - secret, false); + maxFrameLength, secret, false); w = writerFactory.createWriter(connectionWriter.getOutputStream()); // Derive the nonces byte[][] nonces = crypto.deriveInvitationNonces(secret); diff --git a/briar-core/src/net/sf/briar/messaging/duplex/IncomingDuplexConnection.java b/briar-core/src/net/sf/briar/messaging/duplex/IncomingDuplexConnection.java index 1ec9ad384f..03619f6bf7 100644 --- a/briar-core/src/net/sf/briar/messaging/duplex/IncomingDuplexConnection.java +++ b/briar-core/src/net/sf/briar/messaging/duplex/IncomingDuplexConnection.java @@ -1,6 +1,8 @@ package net.sf.briar.messaging.duplex; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.concurrent.Executor; import net.sf.briar.api.db.DatabaseComponent; @@ -32,13 +34,17 @@ class IncomingDuplexConnection extends DuplexConnection { @Override protected ConnectionReader createConnectionReader() throws IOException { - return connReaderFactory.createConnectionReader( - transport.getInputStream(), ctx, true, true); + InputStream in = transport.getInputStream(); + int maxFrameLength = transport.getMaxFrameLength(); + return connReaderFactory.createConnectionReader(in, maxFrameLength, + ctx, true, true); } @Override protected ConnectionWriter createConnectionWriter() throws IOException { - return connWriterFactory.createConnectionWriter( - transport.getOutputStream(), Long.MAX_VALUE, ctx, true, false); + OutputStream out = transport.getOutputStream(); + int maxFrameLength = transport.getMaxFrameLength(); + return connWriterFactory.createConnectionWriter(out, maxFrameLength, + Long.MAX_VALUE, ctx, true, false); } } diff --git a/briar-core/src/net/sf/briar/messaging/duplex/OutgoingDuplexConnection.java b/briar-core/src/net/sf/briar/messaging/duplex/OutgoingDuplexConnection.java index f1767773ce..9a3a86cfd9 100644 --- a/briar-core/src/net/sf/briar/messaging/duplex/OutgoingDuplexConnection.java +++ b/briar-core/src/net/sf/briar/messaging/duplex/OutgoingDuplexConnection.java @@ -1,6 +1,8 @@ package net.sf.briar.messaging.duplex; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.concurrent.Executor; import net.sf.briar.api.db.DatabaseComponent; @@ -32,13 +34,17 @@ class OutgoingDuplexConnection extends DuplexConnection { @Override protected ConnectionReader createConnectionReader() throws IOException { - return connReaderFactory.createConnectionReader( - transport.getInputStream(), ctx, false, false); + InputStream in = transport.getInputStream(); + int maxFrameLength = transport.getMaxFrameLength(); + return connReaderFactory.createConnectionReader(in, maxFrameLength, + ctx, false, false); } @Override protected ConnectionWriter createConnectionWriter() throws IOException { - return connWriterFactory.createConnectionWriter( - transport.getOutputStream(), Long.MAX_VALUE, ctx, false, true); + OutputStream out = transport.getOutputStream(); + int maxFrameLength = transport.getMaxFrameLength(); + return connWriterFactory.createConnectionWriter(out, maxFrameLength, + Long.MAX_VALUE, ctx, false, true); } } diff --git a/briar-core/src/net/sf/briar/messaging/simplex/IncomingSimplexConnection.java b/briar-core/src/net/sf/briar/messaging/simplex/IncomingSimplexConnection.java index 8f829064c9..64b52dd54c 100644 --- a/briar-core/src/net/sf/briar/messaging/simplex/IncomingSimplexConnection.java +++ b/briar-core/src/net/sf/briar/messaging/simplex/IncomingSimplexConnection.java @@ -70,9 +70,11 @@ class IncomingSimplexConnection { void read() { connRegistry.registerConnection(contactId, transportId); try { - ConnectionReader conn = connReaderFactory.createConnectionReader( - transport.getInputStream(), ctx, true, true); - InputStream in = conn.getInputStream(); + InputStream in = transport.getInputStream(); + int maxFrameLength = transport.getMaxFrameLength(); + ConnectionReader conn = connReaderFactory.createConnectionReader(in, + maxFrameLength, ctx, true, true); + in = conn.getInputStream(); PacketReader reader = packetReaderFactory.createPacketReader(in); // Read packets until EOF while(!reader.eof()) { diff --git a/briar-core/src/net/sf/briar/messaging/simplex/OutgoingSimplexConnection.java b/briar-core/src/net/sf/briar/messaging/simplex/OutgoingSimplexConnection.java index 4d30ba9732..8b259c844f 100644 --- a/briar-core/src/net/sf/briar/messaging/simplex/OutgoingSimplexConnection.java +++ b/briar-core/src/net/sf/briar/messaging/simplex/OutgoingSimplexConnection.java @@ -63,10 +63,12 @@ class OutgoingSimplexConnection { void write() { connRegistry.registerConnection(contactId, transportId); try { + OutputStream out = transport.getOutputStream(); + long capacity = transport.getCapacity(); + int maxFrameLength = transport.getMaxFrameLength(); ConnectionWriter conn = connWriterFactory.createConnectionWriter( - transport.getOutputStream(), transport.getCapacity(), ctx, - false, true); - OutputStream out = conn.getOutputStream(); + out, maxFrameLength, capacity, ctx, false, true); + out = conn.getOutputStream(); if(conn.getRemainingCapacity() < MAX_PACKET_LENGTH) throw new EOFException(); PacketWriter writer = packetWriterFactory.createPacketWriter(out, @@ -79,7 +81,7 @@ class OutgoingSimplexConnection { if(hasSpace) hasSpace = writeRetentionAck(conn, writer); if(hasSpace) hasSpace = writeRetentionUpdate(conn, writer); // Write acks until you can't write acks no more - long capacity = conn.getRemainingCapacity(); + capacity = conn.getRemainingCapacity(); int maxMessages = writer.getMaxMessagesForAck(capacity); Ack a = db.generateAck(contactId, maxMessages); while(a != null) { diff --git a/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java b/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java index c07cc1b364..1581db9272 100644 --- a/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java @@ -49,6 +49,7 @@ class BluetoothPlugin implements DuplexPlugin { private final Clock clock; private final SecureRandom secureRandom; private final DuplexPluginCallback callback; + private final int maxFrameLength; private final long maxLatency, pollingInterval; private final Semaphore discoverySemaphore = new Semaphore(1); @@ -58,11 +59,12 @@ class BluetoothPlugin implements DuplexPlugin { BluetoothPlugin(Executor pluginExecutor, Clock clock, SecureRandom secureRandom, DuplexPluginCallback callback, - long maxLatency, long pollingInterval) { + int maxFrameLength, long maxLatency, long pollingInterval) { this.pluginExecutor = pluginExecutor; this.clock = clock; this.secureRandom = secureRandom; this.callback = callback; + this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.pollingInterval = pollingInterval; } @@ -75,6 +77,10 @@ class BluetoothPlugin implements DuplexPlugin { return "BLUETOOTH_PLUGIN_NAME"; } + public int getMaxFrameLength() { + return maxFrameLength; + } + public long getMaxLatency() { return maxLatency; } @@ -159,7 +165,7 @@ class BluetoothPlugin implements DuplexPlugin { return; } BluetoothTransportConnection conn = - new BluetoothTransportConnection(s, maxLatency); + new BluetoothTransportConnection(this, s); callback.incomingConnectionCreated(conn); if(!running) return; } @@ -205,7 +211,7 @@ class BluetoothPlugin implements DuplexPlugin { private DuplexTransportConnection connect(String url) { try { StreamConnection s = (StreamConnection) Connector.open(url); - return new BluetoothTransportConnection(s, maxLatency); + return new BluetoothTransportConnection(this, s); } catch(IOException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); return null; @@ -303,7 +309,7 @@ class BluetoothPlugin implements DuplexPlugin { // Try to accept a connection try { StreamConnection s = scn.acceptAndOpen(); - return new BluetoothTransportConnection(s, maxLatency); + return new BluetoothTransportConnection(this, s); } catch(IOException e) { // This is expected when the socket is closed if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e); diff --git a/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPluginFactory.java b/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPluginFactory.java index 48611f8fd1..88ede376ef 100644 --- a/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothPluginFactory.java @@ -12,6 +12,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory; public class BluetoothPluginFactory implements DuplexPluginFactory { + private static final int MAX_FRAME_LENGTH = 1024; private static final long MAX_LATENCY = 60 * 1000; // 1 minute private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -32,6 +33,6 @@ public class BluetoothPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new BluetoothPlugin(pluginExecutor, clock, secureRandom, - callback, MAX_LATENCY, POLLING_INTERVAL); + callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL); } } diff --git a/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothTransportConnection.java b/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothTransportConnection.java index 5d5fda3b95..7d1a17ab33 100644 --- a/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothTransportConnection.java +++ b/briar-core/src/net/sf/briar/plugins/bluetooth/BluetoothTransportConnection.java @@ -6,20 +6,25 @@ import java.io.OutputStream; import javax.microedition.io.StreamConnection; +import net.sf.briar.api.plugins.Plugin; import net.sf.briar.api.plugins.duplex.DuplexTransportConnection; class BluetoothTransportConnection implements DuplexTransportConnection { + private final Plugin plugin; private final StreamConnection stream; - private final long maxLatency; - BluetoothTransportConnection(StreamConnection stream, long maxLatency) { + BluetoothTransportConnection(Plugin plugin, StreamConnection stream) { + this.plugin = plugin; this.stream = stream; - this.maxLatency = maxLatency; + } + + public int getMaxFrameLength() { + return plugin.getMaxFrameLength(); } public long getMaxLatency() { - return maxLatency; + return plugin.getMaxLatency(); } public InputStream getInputStream() throws IOException { diff --git a/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java b/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java index d978fa74b5..042d672924 100644 --- a/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java @@ -62,6 +62,7 @@ class DroidtoothPlugin implements DuplexPlugin { private final Context appContext; private final SecureRandom secureRandom; private final DuplexPluginCallback callback; + private final int maxFrameLength; private final long maxLatency, pollingInterval; private volatile boolean running = false; @@ -72,13 +73,14 @@ class DroidtoothPlugin implements DuplexPlugin { DroidtoothPlugin(Executor pluginExecutor, AndroidExecutor androidExecutor, Context appContext, SecureRandom secureRandom, - DuplexPluginCallback callback, long maxLatency, + DuplexPluginCallback callback, int maxFrameLength, long maxLatency, long pollingInterval) { this.pluginExecutor = pluginExecutor; this.androidExecutor = androidExecutor; this.appContext = appContext; this.secureRandom = secureRandom; this.callback = callback; + this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.pollingInterval = pollingInterval; } @@ -92,6 +94,10 @@ class DroidtoothPlugin implements DuplexPlugin { return "BLUETOOTH_PLUGIN_NAME"; } + public int getMaxFrameLength() { + return maxFrameLength; + } + public long getMaxLatency() { return maxLatency; } @@ -207,7 +213,7 @@ class DroidtoothPlugin implements DuplexPlugin { return; } DroidtoothTransportConnection conn = - new DroidtoothTransportConnection(s, maxLatency); + new DroidtoothTransportConnection(this, s); callback.incomingConnectionCreated(conn); if(!running) return; } @@ -296,7 +302,7 @@ class DroidtoothPlugin implements DuplexPlugin { if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + address); s.connect(); if(LOG.isLoggable(INFO)) LOG.info("Connected to " + address); - return new DroidtoothTransportConnection(s, maxLatency); + return new DroidtoothTransportConnection(this, s); } catch(IOException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); tryToClose(s); @@ -375,7 +381,7 @@ class DroidtoothPlugin implements DuplexPlugin { String address = s.getRemoteDevice().getAddress(); LOG.info("Incoming connection from " + address); } - return new DroidtoothTransportConnection(s, maxLatency); + return new DroidtoothTransportConnection(this, s); } catch(SocketTimeoutException e) { if(LOG.isLoggable(INFO)) LOG.info("Invitation timed out"); return null; diff --git a/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPluginFactory.java b/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPluginFactory.java index bb884bdd5a..ee6566ed21 100644 --- a/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothPluginFactory.java @@ -12,6 +12,7 @@ import android.content.Context; public class DroidtoothPluginFactory implements DuplexPluginFactory { + private static final int MAX_FRAME_LENGTH = 1024; private static final long MAX_LATENCY = 60 * 1000; // 1 minute private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -35,6 +36,7 @@ public class DroidtoothPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new DroidtoothPlugin(pluginExecutor, androidExecutor, appContext, - secureRandom, callback, MAX_LATENCY, POLLING_INTERVAL); + secureRandom, callback, MAX_FRAME_LENGTH, MAX_LATENCY, + POLLING_INTERVAL); } } diff --git a/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothTransportConnection.java b/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothTransportConnection.java index 2a3238033b..f1cce80c18 100644 --- a/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothTransportConnection.java +++ b/briar-core/src/net/sf/briar/plugins/droidtooth/DroidtoothTransportConnection.java @@ -4,21 +4,26 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import net.sf.briar.api.plugins.Plugin; import net.sf.briar.api.plugins.duplex.DuplexTransportConnection; import android.bluetooth.BluetoothSocket; class DroidtoothTransportConnection implements DuplexTransportConnection { + private final Plugin plugin; private final BluetoothSocket socket; - private final long maxLatency; - DroidtoothTransportConnection(BluetoothSocket socket, long maxLatency) { + DroidtoothTransportConnection(Plugin plugin, BluetoothSocket socket) { + this.plugin = plugin; this.socket = socket; - this.maxLatency = maxLatency; + } + + public int getMaxFrameLength() { + return plugin.getMaxFrameLength(); } public long getMaxLatency() { - return maxLatency; + return plugin.getMaxLatency(); } public InputStream getInputStream() throws IOException { diff --git a/briar-core/src/net/sf/briar/plugins/file/FilePlugin.java b/briar-core/src/net/sf/briar/plugins/file/FilePlugin.java index 8adc969260..2064c377b3 100644 --- a/briar-core/src/net/sf/briar/plugins/file/FilePlugin.java +++ b/briar-core/src/net/sf/briar/plugins/file/FilePlugin.java @@ -27,6 +27,7 @@ public abstract class FilePlugin implements SimplexPlugin { protected final Executor pluginExecutor; protected final SimplexPluginCallback callback; + protected final int maxFrameLength; protected final long maxLatency; protected volatile boolean running = false; @@ -37,12 +38,22 @@ public abstract class FilePlugin implements SimplexPlugin { protected abstract void readerFinished(File f); protected FilePlugin(Executor pluginExecutor, - SimplexPluginCallback callback, long maxLatency) { + SimplexPluginCallback callback, int maxFrameLength, + long maxLatency) { this.pluginExecutor = pluginExecutor; this.callback = callback; + this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; } + public int getMaxFrameLength() { + return maxFrameLength; + } + + public long getMaxLatency() { + return maxLatency; + } + public SimplexTransportReader createReader(ContactId c) { return null; } @@ -73,7 +84,7 @@ public abstract class FilePlugin implements SimplexPlugin { long capacity = getCapacity(dir.getPath()); if(capacity < MIN_CONNECTION_LENGTH) return null; OutputStream out = new FileOutputStream(f); - return new FileTransportWriter(f, out, capacity, maxLatency, this); + return new FileTransportWriter(f, out, capacity, this); } catch(IOException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); f.delete(); diff --git a/briar-core/src/net/sf/briar/plugins/file/FileTransportReader.java b/briar-core/src/net/sf/briar/plugins/file/FileTransportReader.java index e2c7648c95..77d48699f5 100644 --- a/briar-core/src/net/sf/briar/plugins/file/FileTransportReader.java +++ b/briar-core/src/net/sf/briar/plugins/file/FileTransportReader.java @@ -12,7 +12,7 @@ import net.sf.briar.api.plugins.simplex.SimplexTransportReader; class FileTransportReader implements SimplexTransportReader { private static final Logger LOG = - Logger.getLogger(FileTransportReader.class.getName()); + Logger.getLogger(FileTransportReader.class.getName()); private final File file; private final InputStream in; @@ -24,6 +24,10 @@ class FileTransportReader implements SimplexTransportReader { this.plugin = plugin; } + public int getMaxFrameLength() { + return plugin.getMaxFrameLength(); + } + public InputStream getInputStream() { return in; } diff --git a/briar-core/src/net/sf/briar/plugins/file/FileTransportWriter.java b/briar-core/src/net/sf/briar/plugins/file/FileTransportWriter.java index e86b2f8145..921d748ad4 100644 --- a/briar-core/src/net/sf/briar/plugins/file/FileTransportWriter.java +++ b/briar-core/src/net/sf/briar/plugins/file/FileTransportWriter.java @@ -12,19 +12,18 @@ import net.sf.briar.api.plugins.simplex.SimplexTransportWriter; class FileTransportWriter implements SimplexTransportWriter { private static final Logger LOG = - Logger.getLogger(FileTransportWriter.class.getName()); + Logger.getLogger(FileTransportWriter.class.getName()); private final File file; private final OutputStream out; - private final long capacity, maxLatency; + private final long capacity; private final FilePlugin plugin; FileTransportWriter(File file, OutputStream out, long capacity, - long maxLatency, FilePlugin plugin) { + FilePlugin plugin) { this.file = file; this.out = out; this.capacity = capacity; - this.maxLatency = maxLatency; this.plugin = plugin; } @@ -32,8 +31,12 @@ class FileTransportWriter implements SimplexTransportWriter { return capacity; } + public int getMaxFrameLength() { + return plugin.getMaxFrameLength(); + } + public long getMaxLatency() { - return maxLatency; + return plugin.getMaxLatency(); } public OutputStream getOutputStream() { diff --git a/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePlugin.java b/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePlugin.java index f406993c1a..1cc9936eea 100644 --- a/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePlugin.java +++ b/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePlugin.java @@ -33,8 +33,9 @@ implements RemovableDriveMonitor.Callback { RemovableDrivePlugin(Executor pluginExecutor, SimplexPluginCallback callback, RemovableDriveFinder finder, - RemovableDriveMonitor monitor, long maxLatency) { - super(pluginExecutor, callback, maxLatency); + RemovableDriveMonitor monitor, int maxFrameLength, + long maxLatency) { + super(pluginExecutor, callback, maxFrameLength, maxLatency); this.finder = finder; this.monitor = monitor; } @@ -47,10 +48,6 @@ implements RemovableDriveMonitor.Callback { return "REMOVABLE_DRIVE_PLUGIN_NAME"; } - public long getMaxLatency() { - return maxLatency; - } - public boolean start() throws IOException { running = true; monitor.start(this); diff --git a/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java b/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java index 0823a13d31..1ed88d03b6 100644 --- a/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/file/RemovableDrivePluginFactory.java @@ -1,5 +1,7 @@ package net.sf.briar.plugins.file; +import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; + import java.util.concurrent.Executor; import net.sf.briar.api.TransportId; @@ -46,6 +48,6 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory { return null; } return new RemovableDrivePlugin(pluginExecutor, callback, finder, - monitor, MAX_LATENCY); + monitor, MAX_FRAME_LENGTH, MAX_LATENCY); } } diff --git a/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java b/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java index 5cf653eed4..893205225c 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/modem/ModemPlugin.java @@ -40,6 +40,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { private final ModemFactory modemFactory; private final SerialPortList serialPortList; private final DuplexPluginCallback callback; + private final int maxFrameLength; private final long maxLatency, pollingInterval; private final boolean shuffle; // Used to disable shuffling for testing @@ -48,11 +49,13 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { ModemPlugin(Executor pluginExecutor, ModemFactory modemFactory, SerialPortList serialPortList, DuplexPluginCallback callback, - long maxLatency, long pollingInterval, boolean shuffle) { + int maxFrameLength, long maxLatency, long pollingInterval, + boolean shuffle) { this.pluginExecutor = pluginExecutor; this.modemFactory = modemFactory; this.serialPortList = serialPortList; this.callback = callback; + this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.pollingInterval = pollingInterval; this.shuffle = shuffle; @@ -66,6 +69,10 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { return "MODEM_PLUGIN_NAME"; } + public int getMaxFrameLength() { + return maxFrameLength; + } + public long getMaxLatency() { return maxLatency; } @@ -232,6 +239,10 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { private final CountDownLatch finished = new CountDownLatch(1); + public int getMaxFrameLength() { + return maxFrameLength; + } + public long getMaxLatency() { return maxLatency; } diff --git a/briar-core/src/net/sf/briar/plugins/modem/ModemPluginFactory.java b/briar-core/src/net/sf/briar/plugins/modem/ModemPluginFactory.java index c09e67d6f2..f9270db561 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/ModemPluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/modem/ModemPluginFactory.java @@ -11,6 +11,7 @@ import net.sf.briar.util.StringUtils; public class ModemPluginFactory implements DuplexPluginFactory { + private static final int MAX_FRAME_LENGTH = 1024; private static final long MAX_LATENCY = 60 * 1000; // 1 minute private static final long POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour @@ -34,6 +35,7 @@ public class ModemPluginFactory implements DuplexPluginFactory { String enabled = callback.getConfig().get("enabled"); if(StringUtils.isNullOrEmpty(enabled)) return null; return new ModemPlugin(pluginExecutor, modemFactory, serialPortList, - callback, MAX_LATENCY, POLLING_INTERVAL, true); + callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL, + true); } } diff --git a/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPlugin.java b/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPlugin.java index 818472cbd7..067984e1df 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPlugin.java @@ -17,9 +17,10 @@ class DroidLanTcpPlugin extends LanTcpPlugin { private final Context appContext; DroidLanTcpPlugin(Executor pluginExecutor, Context appContext, Clock clock, - DuplexPluginCallback callback, long maxLatency, + DuplexPluginCallback callback, int maxFrameLength, long maxLatency, long pollingInterval) { - super(pluginExecutor, clock, callback, maxLatency, pollingInterval); + super(pluginExecutor, clock, callback, maxFrameLength, maxLatency, + pollingInterval); this.appContext = appContext; } diff --git a/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPluginFactory.java b/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPluginFactory.java index 44d4881658..32ca3261a7 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/DroidLanTcpPluginFactory.java @@ -12,6 +12,7 @@ import android.content.Context; public class DroidLanTcpPluginFactory implements DuplexPluginFactory { + private static final int MAX_FRAME_LENGTH = 1024; private static final long MAX_LATENCY = 60 * 1000; // 1 minute private static final long POLLING_INTERVAL = 60 * 1000; // 1 minute @@ -32,6 +33,6 @@ public class DroidLanTcpPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new DroidLanTcpPlugin(pluginExecutor, appContext, clock, - callback, MAX_LATENCY, POLLING_INTERVAL); + callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL); } } diff --git a/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java b/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java index b81250fd13..b5fdc5e6b5 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java @@ -47,9 +47,10 @@ class LanTcpPlugin extends TcpPlugin { private final Clock clock; LanTcpPlugin(Executor pluginExecutor, Clock clock, - DuplexPluginCallback callback, long maxLatency, + DuplexPluginCallback callback, int maxFrameLength, long maxLatency, long pollingInterval) { - super(pluginExecutor, callback, maxLatency, pollingInterval); + super(pluginExecutor, callback, maxFrameLength, maxLatency, + pollingInterval); this.clock = clock; } @@ -160,7 +161,7 @@ class LanTcpPlugin extends TcpPlugin { // Connect back on the advertised TCP port Socket s = new Socket(packet.getAddress(), port); if(LOG.isLoggable(INFO)) LOG.info("Connected back"); - return new TcpTransportConnection(s, maxLatency); + return new TcpTransportConnection(this, s); } catch(IOException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); @@ -294,7 +295,7 @@ class LanTcpPlugin extends TcpPlugin { Socket s = ss.accept(); if(LOG.isLoggable(INFO)) LOG.info("Received a TCP connection"); - return new TcpTransportConnection(s, maxLatency); + return new TcpTransportConnection(this, s); } catch(SocketTimeoutException e) { now = clock.currentTimeMillis(); if(now < end) { diff --git a/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPluginFactory.java b/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPluginFactory.java index 73e0b21685..d3339b3b3f 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/LanTcpPluginFactory.java @@ -11,6 +11,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory; public class LanTcpPluginFactory implements DuplexPluginFactory { + private static final int MAX_FRAME_LENGTH = 1024; private static final long MAX_LATENCY = 60 * 1000; // 1 minute private static final long POLLING_INTERVAL = 60 * 1000; // 1 minute @@ -27,7 +28,7 @@ public class LanTcpPluginFactory implements DuplexPluginFactory { } public DuplexPlugin createPlugin(DuplexPluginCallback callback) { - return new LanTcpPlugin(pluginExecutor, clock, callback, MAX_LATENCY, - POLLING_INTERVAL); + return new LanTcpPlugin(pluginExecutor, clock, callback, + MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL); } } diff --git a/briar-core/src/net/sf/briar/plugins/tcp/TcpPlugin.java b/briar-core/src/net/sf/briar/plugins/tcp/TcpPlugin.java index 5f8fb8195f..49eb023e2f 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/TcpPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/TcpPlugin.java @@ -30,6 +30,7 @@ abstract class TcpPlugin implements DuplexPlugin { protected final Executor pluginExecutor; protected final DuplexPluginCallback callback; + protected final int maxFrameLength; protected final long maxLatency, pollingInterval; protected volatile boolean running = false; @@ -42,13 +43,18 @@ abstract class TcpPlugin implements DuplexPlugin { protected abstract List<SocketAddress> getLocalSocketAddresses(); protected TcpPlugin(Executor pluginExecutor, DuplexPluginCallback callback, - long maxLatency, long pollingInterval) { + int maxFrameLength, long maxLatency, long pollingInterval) { this.pluginExecutor = pluginExecutor; this.callback = callback; + this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.pollingInterval = pollingInterval; } + public int getMaxFrameLength() { + return maxFrameLength; + } + public long getMaxLatency() { return maxLatency; } @@ -128,8 +134,8 @@ abstract class TcpPlugin implements DuplexPlugin { } if(LOG.isLoggable(INFO)) LOG.info("Connection from " + s.getRemoteSocketAddress()); - callback.incomingConnectionCreated(new TcpTransportConnection(s, - maxLatency)); + TcpTransportConnection conn = new TcpTransportConnection(this, s); + callback.incomingConnectionCreated(conn); if(!running) return; } } @@ -175,7 +181,7 @@ abstract class TcpPlugin implements DuplexPlugin { if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + addr); s.connect(addr); if(LOG.isLoggable(INFO)) LOG.info("Connected to " + addr); - return new TcpTransportConnection(s, maxLatency); + return new TcpTransportConnection(this, s); } catch(IOException e) { if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e); return null; diff --git a/briar-core/src/net/sf/briar/plugins/tcp/TcpTransportConnection.java b/briar-core/src/net/sf/briar/plugins/tcp/TcpTransportConnection.java index ee27cf22a6..9cc129b503 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/TcpTransportConnection.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/TcpTransportConnection.java @@ -5,20 +5,25 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; +import net.sf.briar.api.plugins.Plugin; import net.sf.briar.api.plugins.duplex.DuplexTransportConnection; class TcpTransportConnection implements DuplexTransportConnection { + private final Plugin plugin; private final Socket socket; - private final long maxLatency; - TcpTransportConnection(Socket socket, long maxLatency) { + TcpTransportConnection(Plugin plugin, Socket socket) { + this.plugin = plugin; this.socket = socket; - this.maxLatency = maxLatency; + } + + public int getMaxFrameLength() { + return plugin.getMaxFrameLength(); } public long getMaxLatency() { - return maxLatency; + return plugin.getMaxLatency(); } public InputStream getInputStream() throws IOException { diff --git a/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPlugin.java b/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPlugin.java index 962d52ccc5..770f2f7a56 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPlugin.java @@ -38,8 +38,10 @@ class WanTcpPlugin extends TcpPlugin { private volatile MappingResult mappingResult; WanTcpPlugin(Executor pluginExecutor, DuplexPluginCallback callback, - long maxLatency, long pollingInterval, PortMapper portMapper) { - super(pluginExecutor, callback, maxLatency, pollingInterval); + int maxFrameLength, long maxLatency, long pollingInterval, + PortMapper portMapper) { + super(pluginExecutor, callback, maxFrameLength, maxLatency, + pollingInterval); this.portMapper = portMapper; } diff --git a/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPluginFactory.java b/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPluginFactory.java index 23bf0dc0ae..7540f20971 100644 --- a/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/tcp/WanTcpPluginFactory.java @@ -10,6 +10,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory; public class WanTcpPluginFactory implements DuplexPluginFactory { + private static final int MAX_FRAME_LENGTH = 1024; private static final long MAX_LATENCY = 60 * 1000; // 1 minute private static final long POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes @@ -27,7 +28,8 @@ public class WanTcpPluginFactory implements DuplexPluginFactory { } public DuplexPlugin createPlugin(DuplexPluginCallback callback) { - return new WanTcpPlugin(pluginExecutor, callback, MAX_LATENCY, - POLLING_INTERVAL, new PortMapperImpl(shutdownManager)); + return new WanTcpPlugin(pluginExecutor, callback, MAX_FRAME_LENGTH, + MAX_LATENCY, POLLING_INTERVAL, + new PortMapperImpl(shutdownManager)); } } diff --git a/briar-core/src/net/sf/briar/plugins/tor/TorPlugin.java b/briar-core/src/net/sf/briar/plugins/tor/TorPlugin.java index 14e63cf70b..2b1eacee34 100644 --- a/briar-core/src/net/sf/briar/plugins/tor/TorPlugin.java +++ b/briar-core/src/net/sf/briar/plugins/tor/TorPlugin.java @@ -65,6 +65,7 @@ class TorPlugin implements DuplexPlugin, EventHandler { private final Context appContext; private final ShutdownManager shutdownManager; private final DuplexPluginCallback callback; + private final int maxFrameLength; private final long maxLatency, pollingInterval; private final File torDirectory, torFile, geoIpFile, configFile, doneFile; private final File cookieFile, pidFile, hostnameFile; @@ -78,11 +79,12 @@ class TorPlugin implements DuplexPlugin, EventHandler { TorPlugin(Executor pluginExecutor, Context appContext, ShutdownManager shutdownManager, DuplexPluginCallback callback, - long maxLatency, long pollingInterval) { + int maxFrameLength, long maxLatency, long pollingInterval) { this.pluginExecutor = pluginExecutor; this.appContext = appContext; this.shutdownManager = shutdownManager; this.callback = callback; + this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.pollingInterval = pollingInterval; torDirectory = appContext.getDir("tor", MODE_PRIVATE); @@ -103,6 +105,10 @@ class TorPlugin implements DuplexPlugin, EventHandler { return "TOR_PLUGIN_NAME"; } + public int getMaxFrameLength() { + return maxFrameLength; + } + public long getMaxLatency() { return maxLatency; } @@ -426,8 +432,8 @@ class TorPlugin implements DuplexPlugin, EventHandler { return; } if(LOG.isLoggable(INFO)) LOG.info("Connection received"); - callback.incomingConnectionCreated(new TorTransportConnection(s, - maxLatency)); + TorTransportConnection conn = new TorTransportConnection(this, s); + callback.incomingConnectionCreated(conn); if(!running) return; } } @@ -496,7 +502,7 @@ class TorPlugin implements DuplexPlugin, EventHandler { proxy.resolveAddrLocally(false); Socket s = new SocksSocket(proxy, onion, 80); if(LOG.isLoggable(INFO)) LOG.info("Connected to " + onion); - return new TorTransportConnection(s, maxLatency); + return new TorTransportConnection(this, s); } catch(IOException e) { if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e); return null; diff --git a/briar-core/src/net/sf/briar/plugins/tor/TorPluginFactory.java b/briar-core/src/net/sf/briar/plugins/tor/TorPluginFactory.java index 59ca7c4525..494edc0e11 100644 --- a/briar-core/src/net/sf/briar/plugins/tor/TorPluginFactory.java +++ b/briar-core/src/net/sf/briar/plugins/tor/TorPluginFactory.java @@ -11,6 +11,7 @@ import android.content.Context; public class TorPluginFactory implements DuplexPluginFactory { + private static final int MAX_FRAME_LENGTH = 1024; private static final long MAX_LATENCY = 60 * 1000; // 1 minute private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -31,6 +32,6 @@ public class TorPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new TorPlugin(pluginExecutor,appContext, shutdownManager, - callback, MAX_LATENCY, POLLING_INTERVAL); + callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL); } } diff --git a/briar-core/src/net/sf/briar/plugins/tor/TorTransportConnection.java b/briar-core/src/net/sf/briar/plugins/tor/TorTransportConnection.java index 9e897aacb2..2965b36afb 100644 --- a/briar-core/src/net/sf/briar/plugins/tor/TorTransportConnection.java +++ b/briar-core/src/net/sf/briar/plugins/tor/TorTransportConnection.java @@ -5,20 +5,25 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; +import net.sf.briar.api.plugins.Plugin; import net.sf.briar.api.plugins.duplex.DuplexTransportConnection; class TorTransportConnection implements DuplexTransportConnection { + private final Plugin plugin; private final Socket socket; - private final long maxLatency; - TorTransportConnection(Socket socket, long maxLatency) { + TorTransportConnection(Plugin plugin, Socket socket) { + this.plugin = plugin; this.socket = socket; - this.maxLatency = maxLatency; + } + + public int getMaxFrameLength() { + return plugin.getMaxFrameLength(); } public long getMaxLatency() { - return maxLatency; + return plugin.getMaxLatency(); } public InputStream getInputStream() throws IOException { diff --git a/briar-core/src/net/sf/briar/transport/ConnectionReaderFactoryImpl.java b/briar-core/src/net/sf/briar/transport/ConnectionReaderFactoryImpl.java index 1af211a532..ae4aefb064 100644 --- a/briar-core/src/net/sf/briar/transport/ConnectionReaderFactoryImpl.java +++ b/briar-core/src/net/sf/briar/transport/ConnectionReaderFactoryImpl.java @@ -1,7 +1,5 @@ package net.sf.briar.transport; -import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; - import java.io.InputStream; import net.sf.briar.api.crypto.CryptoComponent; @@ -22,7 +20,8 @@ class ConnectionReaderFactoryImpl implements ConnectionReaderFactory { } public ConnectionReader createConnectionReader(InputStream in, - ConnectionContext ctx, boolean incoming, boolean initiator) { + int maxFrameLength, ConnectionContext ctx, boolean incoming, + boolean initiator) { byte[] secret = ctx.getSecret(); long connection = ctx.getConnectionNumber(); boolean weAreAlice = ctx.getAlice(); @@ -30,15 +29,15 @@ class ConnectionReaderFactoryImpl implements ConnectionReaderFactory { ErasableKey frameKey = crypto.deriveFrameKey(secret, connection, initiatorIsAlice, initiator); FrameReader encryption = new IncomingEncryptionLayer(in, - crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH); - return new ConnectionReaderImpl(encryption, MAX_FRAME_LENGTH); + crypto.getFrameCipher(), frameKey, maxFrameLength); + return new ConnectionReaderImpl(encryption, maxFrameLength); } public ConnectionReader createInvitationConnectionReader(InputStream in, - byte[] secret, boolean alice) { + int maxFrameLength, byte[] secret, boolean alice) { ErasableKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice); FrameReader encryption = new IncomingEncryptionLayer(in, - crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH); - return new ConnectionReaderImpl(encryption, MAX_FRAME_LENGTH); + crypto.getFrameCipher(), frameKey, maxFrameLength); + return new ConnectionReaderImpl(encryption, maxFrameLength); } } diff --git a/briar-core/src/net/sf/briar/transport/ConnectionWriterFactoryImpl.java b/briar-core/src/net/sf/briar/transport/ConnectionWriterFactoryImpl.java index daf99021e3..dbfe989cf0 100644 --- a/briar-core/src/net/sf/briar/transport/ConnectionWriterFactoryImpl.java +++ b/briar-core/src/net/sf/briar/transport/ConnectionWriterFactoryImpl.java @@ -1,6 +1,5 @@ package net.sf.briar.transport; -import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH; import java.io.OutputStream; @@ -25,8 +24,8 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory { } public ConnectionWriter createConnectionWriter(OutputStream out, - long capacity, ConnectionContext ctx, boolean incoming, - boolean initiator) { + int maxFrameLength, long capacity, ConnectionContext ctx, + boolean incoming, boolean initiator) { byte[] secret = ctx.getSecret(); long connection = ctx.getConnectionNumber(); boolean weAreAlice = ctx.getAlice(); @@ -41,20 +40,20 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory { crypto.encodeTag(tag, tagCipher, tagKey, connection); tagKey.erase(); encryption = new OutgoingEncryptionLayer(out, capacity, - crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH, tag); + crypto.getFrameCipher(), frameKey, maxFrameLength, tag); } else { encryption = new OutgoingEncryptionLayer(out, capacity, - crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH); + crypto.getFrameCipher(), frameKey, maxFrameLength); } - return new ConnectionWriterImpl(encryption, MAX_FRAME_LENGTH); + return new ConnectionWriterImpl(encryption, maxFrameLength); } public ConnectionWriter createInvitationConnectionWriter(OutputStream out, - byte[] secret, boolean alice) { + int maxFrameLength, byte[] secret, boolean alice) { ErasableKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice); FrameWriter encryption = new OutgoingEncryptionLayer(out, Long.MAX_VALUE, crypto.getFrameCipher(), frameKey, - MAX_FRAME_LENGTH); - return new ConnectionWriterImpl(encryption, MAX_FRAME_LENGTH); + maxFrameLength); + return new ConnectionWriterImpl(encryption, maxFrameLength); } } \ No newline at end of file diff --git a/briar-core/src/net/sf/briar/transport/TransportConnectionRecogniser.java b/briar-core/src/net/sf/briar/transport/TransportConnectionRecogniser.java index 9b9c177ede..4557cc17cb 100644 --- a/briar-core/src/net/sf/briar/transport/TransportConnectionRecogniser.java +++ b/briar-core/src/net/sf/briar/transport/TransportConnectionRecogniser.java @@ -62,8 +62,9 @@ class TransportConnectionRecogniser { db.setConnectionWindow(t.contactId, transportId, t.period, t.window.getCentre(), t.window.getBitmap()); // Clone the secret - the key manager will erase the original - return new ConnectionContext(t.contactId, transportId, - t.secret.clone(), t.connection, t.alice); + byte[] secret = t.secret.clone(); + return new ConnectionContext(t.contactId, transportId, secret, + t.connection, t.alice); } synchronized void addSecret(TemporarySecret s) { diff --git a/briar-tests/src/net/sf/briar/ProtocolIntegrationTest.java b/briar-tests/src/net/sf/briar/ProtocolIntegrationTest.java index 2eaed41474..e535ff331e 100644 --- a/briar-tests/src/net/sf/briar/ProtocolIntegrationTest.java +++ b/briar-tests/src/net/sf/briar/ProtocolIntegrationTest.java @@ -1,5 +1,6 @@ package net.sf.briar; +import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH; import static org.junit.Assert.assertArrayEquals; @@ -135,7 +136,7 @@ public class ProtocolIntegrationTest extends BriarTestCase { ConnectionContext ctx = new ConnectionContext(contactId, transportId, secret.clone(), 0, true); ConnectionWriter conn = connectionWriterFactory.createConnectionWriter( - out, Long.MAX_VALUE, ctx, false, true); + out, MAX_FRAME_LENGTH, Long.MAX_VALUE, ctx, false, true); OutputStream out1 = conn.getOutputStream(); PacketWriter writer = packetWriterFactory.createPacketWriter(out1, false); @@ -174,7 +175,7 @@ public class ProtocolIntegrationTest extends BriarTestCase { ConnectionContext ctx = new ConnectionContext(contactId, transportId, secret.clone(), 0, false); ConnectionReader conn = connectionReaderFactory.createConnectionReader( - in, ctx, true, true); + in, MAX_FRAME_LENGTH, ctx, true, true); InputStream in1 = conn.getInputStream(); PacketReader reader = packetReaderFactory.createPacketReader(in1); diff --git a/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportReader.java b/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportReader.java index dafa494f07..b8f075c120 100644 --- a/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportReader.java +++ b/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportReader.java @@ -1,5 +1,7 @@ package net.sf.briar.messaging.simplex; +import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; + import java.io.InputStream; import net.sf.briar.api.plugins.simplex.SimplexTransportReader; @@ -14,6 +16,10 @@ class TestSimplexTransportReader implements SimplexTransportReader { this.in = in; } + public int getMaxFrameLength() { + return MAX_FRAME_LENGTH; + } + public InputStream getInputStream() { return in; } diff --git a/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportWriter.java b/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportWriter.java index e2fc34ed26..691a4bd211 100644 --- a/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportWriter.java +++ b/briar-tests/src/net/sf/briar/messaging/simplex/TestSimplexTransportWriter.java @@ -1,5 +1,7 @@ package net.sf.briar.messaging.simplex; +import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; + import java.io.ByteArrayOutputStream; import java.io.OutputStream; @@ -25,6 +27,10 @@ class TestSimplexTransportWriter implements SimplexTransportWriter { return capacity; } + public int getMaxFrameLength() { + return MAX_FRAME_LENGTH; + } + public long getMaxLatency() { return maxLatency; } diff --git a/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothClientTest.java b/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothClientTest.java index d137c2481f..18be16bfd1 100644 --- a/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothClientTest.java +++ b/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothClientTest.java @@ -28,7 +28,7 @@ public class BluetoothClientTest extends DuplexClientTest { callback = new ClientCallback(new TransportConfig(), new TransportProperties(), remote); plugin = new BluetoothPlugin(executor, new SystemClock(), - new SecureRandom(), callback, 0, 0); + new SecureRandom(), callback, 0, 0, 0); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothServerTest.java b/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothServerTest.java index d60d2dda90..08ade2b39e 100644 --- a/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothServerTest.java +++ b/briar-tests/src/net/sf/briar/plugins/bluetooth/BluetoothServerTest.java @@ -23,7 +23,7 @@ public class BluetoothServerTest extends DuplexServerTest { callback = new ServerCallback(new TransportConfig(), local, Collections.singletonMap(contactId, new TransportProperties())); plugin = new BluetoothPlugin(executor, new SystemClock(), - new SecureRandom(), callback, 0, 0); + new SecureRandom(), callback, 0, 0, 0); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/net/sf/briar/plugins/file/RemovableDrivePluginTest.java b/briar-tests/src/net/sf/briar/plugins/file/RemovableDrivePluginTest.java index 27d8220c4f..6a83e1dae1 100644 --- a/briar-tests/src/net/sf/briar/plugins/file/RemovableDrivePluginTest.java +++ b/briar-tests/src/net/sf/briar/plugins/file/RemovableDrivePluginTest.java @@ -1,5 +1,6 @@ package net.sf.briar.plugins.file; +import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; import java.io.File; @@ -41,11 +42,11 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); @@ -54,7 +55,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -73,11 +74,11 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); @@ -89,7 +90,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -110,11 +111,11 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); @@ -126,7 +127,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -149,11 +150,11 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); @@ -165,7 +166,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -188,11 +189,11 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); @@ -204,7 +205,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); plugin.start(); assertNotNull(plugin.createWriter(contactId)); @@ -230,11 +231,11 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); @@ -247,7 +248,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); plugin.start(); SimplexTransportWriter writer = plugin.createWriter(contactId); @@ -275,18 +276,18 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); plugin.start(); plugin.driveInserted(testDir); @@ -299,14 +300,14 @@ public class RemovableDrivePluginTest extends BriarTestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - callback, finder, monitor, 0); + callback, finder, monitor, MAX_FRAME_LENGTH, 0); assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat")); assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat")); @@ -322,11 +323,11 @@ public class RemovableDrivePluginTest extends BriarTestCase { public void testReaderIsCreated() throws Exception { Mockery context = new Mockery(); final SimplexPluginCallback callback = - context.mock(SimplexPluginCallback.class); + context.mock(SimplexPluginCallback.class); final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); + context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); + context.mock(RemovableDriveMonitor.class); context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); @@ -334,7 +335,8 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin( - new ImmediateExecutor(), callback, finder, monitor, 0); + new ImmediateExecutor(), callback, finder, monitor, + MAX_FRAME_LENGTH, 0); plugin.start(); File f = new File(testDir, "abcdefgh.dat"); diff --git a/briar-tests/src/net/sf/briar/plugins/modem/ModemPluginTest.java b/briar-tests/src/net/sf/briar/plugins/modem/ModemPluginTest.java index 7707760015..fadaa044a6 100644 --- a/briar-tests/src/net/sf/briar/plugins/modem/ModemPluginTest.java +++ b/briar-tests/src/net/sf/briar/plugins/modem/ModemPluginTest.java @@ -37,7 +37,7 @@ public class ModemPluginTest extends BriarTestCase { final SerialPortList serialPortList = context.mock(SerialPortList.class); final ModemPlugin plugin = new ModemPlugin(null, modemFactory, - serialPortList, null, 0, 0, true); + serialPortList, null, 0, 0, 0, true); final Modem modem = context.mock(Modem.class); context.checking(new Expectations() {{ oneOf(serialPortList).getPortNames(); @@ -71,7 +71,7 @@ public class ModemPluginTest extends BriarTestCase { final DuplexPluginCallback callback = context.mock(DuplexPluginCallback.class); final ModemPlugin plugin = new ModemPlugin(null, modemFactory, - serialPortList, callback, 0, 0, true); + serialPortList, callback, 0, 0, 0, true); final Modem modem = context.mock(Modem.class); final TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); @@ -112,7 +112,7 @@ public class ModemPluginTest extends BriarTestCase { final DuplexPluginCallback callback = context.mock(DuplexPluginCallback.class); final ModemPlugin plugin = new ModemPlugin(null, modemFactory, - serialPortList, callback, 0, 0, true); + serialPortList, callback, 0, 0, 0, true); final Modem modem = context.mock(Modem.class); final TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); @@ -153,7 +153,7 @@ public class ModemPluginTest extends BriarTestCase { final DuplexPluginCallback callback = context.mock(DuplexPluginCallback.class); final ModemPlugin plugin = new ModemPlugin(null, modemFactory, - serialPortList, callback, 0, 0, true); + serialPortList, callback, 0, 0, 0, true); final Modem modem = context.mock(Modem.class); final TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); @@ -204,7 +204,7 @@ public class ModemPluginTest extends BriarTestCase { context.mock(DuplexPluginCallback.class); // Disable shuffling for this test, it confuses jMock final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory, - serialPortList, callback, 0, 0, false); + serialPortList, callback, 0, 0, 0, false); final Modem modem = context.mock(Modem.class); final TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); diff --git a/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpClientTest.java b/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpClientTest.java index c3ba14c384..9472213b13 100644 --- a/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpClientTest.java +++ b/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpClientTest.java @@ -9,6 +9,7 @@ import java.util.concurrent.Executors; import net.sf.briar.api.ContactId; import net.sf.briar.api.TransportConfig; import net.sf.briar.api.TransportProperties; +import net.sf.briar.api.clock.Clock; import net.sf.briar.api.clock.SystemClock; import net.sf.briar.plugins.DuplexClientTest; @@ -27,7 +28,8 @@ public class LanTcpClientTest extends DuplexClientTest { // Create the plugin callback = new ClientCallback(new TransportConfig(), new TransportProperties(), remote); - plugin = new LanTcpPlugin(executor, new SystemClock(), callback, 0, 0); + Clock clock = new SystemClock(); + plugin = new LanTcpPlugin(executor, clock, callback, 0, 0, 0); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpPluginTest.java b/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpPluginTest.java index 61d563c34d..a335a908d6 100644 --- a/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpPluginTest.java +++ b/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpPluginTest.java @@ -36,7 +36,8 @@ public class LanTcpPluginTest extends BriarTestCase { callback.local.put("port", "0"); Executor executor = Executors.newCachedThreadPool(); Clock clock = new SystemClock(); - DuplexPlugin plugin = new LanTcpPlugin(executor, clock, callback, 0, 0); + DuplexPlugin plugin = + new LanTcpPlugin(executor, clock, callback, 0, 0, 0); plugin.start(); // The plugin should have bound a socket and stored the port number assertTrue(callback.propertiesLatch.await(5, SECONDS)); @@ -62,7 +63,8 @@ public class LanTcpPluginTest extends BriarTestCase { Callback callback = new Callback(); Executor executor = Executors.newCachedThreadPool(); Clock clock = new SystemClock(); - DuplexPlugin plugin = new LanTcpPlugin(executor, clock, callback, 0, 0); + DuplexPlugin plugin = + new LanTcpPlugin(executor, clock, callback, 0, 0, 0); plugin.start(); // Listen on a local port final ServerSocket ss = new ServerSocket(); diff --git a/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpServerTest.java b/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpServerTest.java index f62573d84c..16d7d73f65 100644 --- a/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpServerTest.java +++ b/briar-tests/src/net/sf/briar/plugins/tcp/LanTcpServerTest.java @@ -7,6 +7,7 @@ import java.util.concurrent.Executors; import net.sf.briar.api.TransportConfig; import net.sf.briar.api.TransportProperties; +import net.sf.briar.api.clock.Clock; import net.sf.briar.api.clock.SystemClock; import net.sf.briar.plugins.DuplexServerTest; @@ -18,7 +19,8 @@ public class LanTcpServerTest extends DuplexServerTest { callback = new ServerCallback(new TransportConfig(), new TransportProperties(), Collections.singletonMap(contactId, new TransportProperties())); - plugin = new LanTcpPlugin(executor, new SystemClock(), callback, 0, 0); + Clock clock = new SystemClock(); + plugin = new LanTcpPlugin(executor, clock, callback, 0, 0, 0); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/net/sf/briar/transport/TransportIntegrationTest.java b/briar-tests/src/net/sf/briar/transport/TransportIntegrationTest.java index 8ef8c3b5dc..dd6d5adbcf 100644 --- a/briar-tests/src/net/sf/briar/transport/TransportIntegrationTest.java +++ b/briar-tests/src/net/sf/briar/transport/TransportIntegrationTest.java @@ -1,6 +1,7 @@ package net.sf.briar.transport; import static net.sf.briar.api.messaging.MessagingConstants.MAX_PACKET_LENGTH; +import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; import static org.junit.Assert.assertArrayEquals; @@ -129,7 +130,7 @@ public class TransportIntegrationTest extends BriarTestCase { ConnectionContext ctx = new ConnectionContext(contactId, transportId, secret, 0, true); ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out, - MIN_CONNECTION_LENGTH, ctx, false, true); + MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, true); // Check that the connection writer thinks there's room for a packet long capacity = w.getRemainingCapacity(); assertTrue(capacity > MAX_PACKET_LENGTH); @@ -150,7 +151,7 @@ public class TransportIntegrationTest extends BriarTestCase { ConnectionContext ctx = new ConnectionContext(contactId, transportId, secret, 0, true); ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out, - MIN_CONNECTION_LENGTH, ctx, false, false); + MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, false); // Check that the connection writer thinks there's room for a packet long capacity = w.getRemainingCapacity(); assertTrue(capacity > MAX_PACKET_LENGTH); -- GitLab