mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Allow plugins to use different maximum frame lengths.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user