mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Allow plugins to use different maximum frame lengths.
This commit is contained in:
@@ -7,5 +7,6 @@
|
|||||||
<classpathentry combineaccessrules="false" kind="src" path="/briar-core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/briar-core"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/briar-api"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/briar-api"/>
|
||||||
<classpathentry kind="lib" path="/briar-api/libs/guice-3.0-no_aop.jar"/>
|
<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"/>
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ public interface Plugin {
|
|||||||
/** Returns a label for looking up the plugin's translated name. */
|
/** Returns a label for looking up the plugin's translated name. */
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
/** Returns the transport's maximum frame length in bytes. */
|
||||||
|
int getMaxFrameLength();
|
||||||
|
|
||||||
/** Returns the transport's maximum latency in milliseconds. */
|
/** Returns the transport's maximum latency in milliseconds. */
|
||||||
long getMaxLatency();
|
long getMaxLatency();
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import java.io.OutputStream;
|
|||||||
*/
|
*/
|
||||||
public interface DuplexTransportConnection {
|
public interface DuplexTransportConnection {
|
||||||
|
|
||||||
|
/** Returns the maximum frame length of the transport in bytes. */
|
||||||
|
int getMaxFrameLength();
|
||||||
|
|
||||||
/** Returns the maximum latency of the transport in milliseconds. */
|
/** Returns the maximum latency of the transport in milliseconds. */
|
||||||
long getMaxLatency();
|
long getMaxLatency();
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import java.io.InputStream;
|
|||||||
*/
|
*/
|
||||||
public interface SimplexTransportReader {
|
public interface SimplexTransportReader {
|
||||||
|
|
||||||
|
/** Returns the maximum frame length of the transport in bytes. */
|
||||||
|
int getMaxFrameLength();
|
||||||
|
|
||||||
/** Returns an input stream for reading from the transport. */
|
/** Returns an input stream for reading from the transport. */
|
||||||
InputStream getInputStream() throws IOException;
|
InputStream getInputStream() throws IOException;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ public interface SimplexTransportWriter {
|
|||||||
/** Returns the capacity of the transport in bytes. */
|
/** Returns the capacity of the transport in bytes. */
|
||||||
long getCapacity();
|
long getCapacity();
|
||||||
|
|
||||||
|
/** Returns the maximum frame length of the transport in bytes. */
|
||||||
|
int getMaxFrameLength();
|
||||||
|
|
||||||
/** Returns the maximum latency of the transport in milliseconds. */
|
/** Returns the maximum latency of the transport in milliseconds. */
|
||||||
long getMaxLatency();
|
long getMaxLatency();
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import java.io.InputStream;
|
|||||||
public interface ConnectionReaderFactory {
|
public interface ConnectionReaderFactory {
|
||||||
|
|
||||||
/** Creates a connection reader for one side of a connection. */
|
/** 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);
|
ConnectionContext ctx, boolean incoming, boolean initiator);
|
||||||
|
|
||||||
/** Creates a connection reader for one side of an invitation connection. */
|
/** Creates a connection reader for one side of an invitation connection. */
|
||||||
ConnectionReader createInvitationConnectionReader(InputStream in,
|
ConnectionReader createInvitationConnectionReader(InputStream in,
|
||||||
byte[] secret, boolean alice);
|
int maxFrameLength, byte[] secret, boolean alice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import java.io.OutputStream;
|
|||||||
public interface ConnectionWriterFactory {
|
public interface ConnectionWriterFactory {
|
||||||
|
|
||||||
/** Creates a connection writer for one side of a connection. */
|
/** Creates a connection writer for one side of a connection. */
|
||||||
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
ConnectionWriter createConnectionWriter(OutputStream out,
|
||||||
ConnectionContext ctx, boolean incoming, boolean initiator);
|
int maxFrameLength, long capacity, ConnectionContext ctx,
|
||||||
|
boolean incoming, boolean initiator);
|
||||||
|
|
||||||
/** Creates a connection writer for one side of an invitation connection. */
|
/** Creates a connection writer for one side of an invitation connection. */
|
||||||
ConnectionWriter createInvitationConnectionWriter(OutputStream out,
|
ConnectionWriter createInvitationConnectionWriter(OutputStream out,
|
||||||
byte[] secret, boolean alice);
|
int maxFrameLength, byte[] secret, boolean alice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,13 +135,14 @@ class AliceConnector extends Connector {
|
|||||||
// Confirmation succeeded - upgrade to a secure connection
|
// Confirmation succeeded - upgrade to a secure connection
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info(pluginName + " confirmation succeeded");
|
LOG.info(pluginName + " confirmation succeeded");
|
||||||
|
int maxFrameLength = conn.getMaxFrameLength();
|
||||||
ConnectionReader connectionReader =
|
ConnectionReader connectionReader =
|
||||||
connectionReaderFactory.createInvitationConnectionReader(in,
|
connectionReaderFactory.createInvitationConnectionReader(in,
|
||||||
secret, false);
|
maxFrameLength, secret, false);
|
||||||
r = readerFactory.createReader(connectionReader.getInputStream());
|
r = readerFactory.createReader(connectionReader.getInputStream());
|
||||||
ConnectionWriter connectionWriter =
|
ConnectionWriter connectionWriter =
|
||||||
connectionWriterFactory.createInvitationConnectionWriter(out,
|
connectionWriterFactory.createInvitationConnectionWriter(out,
|
||||||
secret, true);
|
maxFrameLength, secret, true);
|
||||||
w = writerFactory.createWriter(connectionWriter.getOutputStream());
|
w = writerFactory.createWriter(connectionWriter.getOutputStream());
|
||||||
// Derive the invitation nonces
|
// Derive the invitation nonces
|
||||||
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
||||||
|
|||||||
@@ -135,13 +135,14 @@ class BobConnector extends Connector {
|
|||||||
// Confirmation succeeded - upgrade to a secure connection
|
// Confirmation succeeded - upgrade to a secure connection
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info(pluginName + " confirmation succeeded");
|
LOG.info(pluginName + " confirmation succeeded");
|
||||||
|
int maxFrameLength = conn.getMaxFrameLength();
|
||||||
ConnectionReader connectionReader =
|
ConnectionReader connectionReader =
|
||||||
connectionReaderFactory.createInvitationConnectionReader(in,
|
connectionReaderFactory.createInvitationConnectionReader(in,
|
||||||
secret, true);
|
maxFrameLength, secret, true);
|
||||||
r = readerFactory.createReader(connectionReader.getInputStream());
|
r = readerFactory.createReader(connectionReader.getInputStream());
|
||||||
ConnectionWriter connectionWriter =
|
ConnectionWriter connectionWriter =
|
||||||
connectionWriterFactory.createInvitationConnectionWriter(out,
|
connectionWriterFactory.createInvitationConnectionWriter(out,
|
||||||
secret, false);
|
maxFrameLength, secret, false);
|
||||||
w = writerFactory.createWriter(connectionWriter.getOutputStream());
|
w = writerFactory.createWriter(connectionWriter.getOutputStream());
|
||||||
// Derive the nonces
|
// Derive the nonces
|
||||||
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.sf.briar.messaging.duplex;
|
package net.sf.briar.messaging.duplex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
@@ -32,13 +34,17 @@ class IncomingDuplexConnection extends DuplexConnection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionReader createConnectionReader() throws IOException {
|
protected ConnectionReader createConnectionReader() throws IOException {
|
||||||
return connReaderFactory.createConnectionReader(
|
InputStream in = transport.getInputStream();
|
||||||
transport.getInputStream(), ctx, true, true);
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
|
return connReaderFactory.createConnectionReader(in, maxFrameLength,
|
||||||
|
ctx, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionWriter createConnectionWriter() throws IOException {
|
protected ConnectionWriter createConnectionWriter() throws IOException {
|
||||||
return connWriterFactory.createConnectionWriter(
|
OutputStream out = transport.getOutputStream();
|
||||||
transport.getOutputStream(), Long.MAX_VALUE, ctx, true, false);
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
|
return connWriterFactory.createConnectionWriter(out, maxFrameLength,
|
||||||
|
Long.MAX_VALUE, ctx, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.sf.briar.messaging.duplex;
|
package net.sf.briar.messaging.duplex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
@@ -32,13 +34,17 @@ class OutgoingDuplexConnection extends DuplexConnection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionReader createConnectionReader() throws IOException {
|
protected ConnectionReader createConnectionReader() throws IOException {
|
||||||
return connReaderFactory.createConnectionReader(
|
InputStream in = transport.getInputStream();
|
||||||
transport.getInputStream(), ctx, false, false);
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
|
return connReaderFactory.createConnectionReader(in, maxFrameLength,
|
||||||
|
ctx, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionWriter createConnectionWriter() throws IOException {
|
protected ConnectionWriter createConnectionWriter() throws IOException {
|
||||||
return connWriterFactory.createConnectionWriter(
|
OutputStream out = transport.getOutputStream();
|
||||||
transport.getOutputStream(), Long.MAX_VALUE, ctx, false, true);
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
|
return connWriterFactory.createConnectionWriter(out, maxFrameLength,
|
||||||
|
Long.MAX_VALUE, ctx, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,9 +70,11 @@ class IncomingSimplexConnection {
|
|||||||
void read() {
|
void read() {
|
||||||
connRegistry.registerConnection(contactId, transportId);
|
connRegistry.registerConnection(contactId, transportId);
|
||||||
try {
|
try {
|
||||||
ConnectionReader conn = connReaderFactory.createConnectionReader(
|
InputStream in = transport.getInputStream();
|
||||||
transport.getInputStream(), ctx, true, true);
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
InputStream in = conn.getInputStream();
|
ConnectionReader conn = connReaderFactory.createConnectionReader(in,
|
||||||
|
maxFrameLength, ctx, true, true);
|
||||||
|
in = conn.getInputStream();
|
||||||
PacketReader reader = packetReaderFactory.createPacketReader(in);
|
PacketReader reader = packetReaderFactory.createPacketReader(in);
|
||||||
// Read packets until EOF
|
// Read packets until EOF
|
||||||
while(!reader.eof()) {
|
while(!reader.eof()) {
|
||||||
|
|||||||
@@ -63,10 +63,12 @@ class OutgoingSimplexConnection {
|
|||||||
void write() {
|
void write() {
|
||||||
connRegistry.registerConnection(contactId, transportId);
|
connRegistry.registerConnection(contactId, transportId);
|
||||||
try {
|
try {
|
||||||
|
OutputStream out = transport.getOutputStream();
|
||||||
|
long capacity = transport.getCapacity();
|
||||||
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
ConnectionWriter conn = connWriterFactory.createConnectionWriter(
|
ConnectionWriter conn = connWriterFactory.createConnectionWriter(
|
||||||
transport.getOutputStream(), transport.getCapacity(), ctx,
|
out, maxFrameLength, capacity, ctx, false, true);
|
||||||
false, true);
|
out = conn.getOutputStream();
|
||||||
OutputStream out = conn.getOutputStream();
|
|
||||||
if(conn.getRemainingCapacity() < MAX_PACKET_LENGTH)
|
if(conn.getRemainingCapacity() < MAX_PACKET_LENGTH)
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
PacketWriter writer = packetWriterFactory.createPacketWriter(out,
|
PacketWriter writer = packetWriterFactory.createPacketWriter(out,
|
||||||
@@ -79,7 +81,7 @@ class OutgoingSimplexConnection {
|
|||||||
if(hasSpace) hasSpace = writeRetentionAck(conn, writer);
|
if(hasSpace) hasSpace = writeRetentionAck(conn, writer);
|
||||||
if(hasSpace) hasSpace = writeRetentionUpdate(conn, writer);
|
if(hasSpace) hasSpace = writeRetentionUpdate(conn, writer);
|
||||||
// Write acks until you can't write acks no more
|
// Write acks until you can't write acks no more
|
||||||
long capacity = conn.getRemainingCapacity();
|
capacity = conn.getRemainingCapacity();
|
||||||
int maxMessages = writer.getMaxMessagesForAck(capacity);
|
int maxMessages = writer.getMaxMessagesForAck(capacity);
|
||||||
Ack a = db.generateAck(contactId, maxMessages);
|
Ack a = db.generateAck(contactId, maxMessages);
|
||||||
while(a != null) {
|
while(a != null) {
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final SecureRandom secureRandom;
|
private final SecureRandom secureRandom;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
|
private final int maxFrameLength;
|
||||||
private final long maxLatency, pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
private final Semaphore discoverySemaphore = new Semaphore(1);
|
private final Semaphore discoverySemaphore = new Semaphore(1);
|
||||||
|
|
||||||
@@ -58,11 +59,12 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
BluetoothPlugin(Executor pluginExecutor, Clock clock,
|
BluetoothPlugin(Executor pluginExecutor, Clock clock,
|
||||||
SecureRandom secureRandom, DuplexPluginCallback callback,
|
SecureRandom secureRandom, DuplexPluginCallback callback,
|
||||||
long maxLatency, long pollingInterval) {
|
int maxFrameLength, long maxLatency, long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
this.secureRandom = secureRandom;
|
this.secureRandom = secureRandom;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxFrameLength = maxFrameLength;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
}
|
}
|
||||||
@@ -75,6 +77,10 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
return "BLUETOOTH_PLUGIN_NAME";
|
return "BLUETOOTH_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return maxFrameLength;
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return maxLatency;
|
||||||
}
|
}
|
||||||
@@ -159,7 +165,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BluetoothTransportConnection conn =
|
BluetoothTransportConnection conn =
|
||||||
new BluetoothTransportConnection(s, maxLatency);
|
new BluetoothTransportConnection(this, s);
|
||||||
callback.incomingConnectionCreated(conn);
|
callback.incomingConnectionCreated(conn);
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
}
|
}
|
||||||
@@ -205,7 +211,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
private DuplexTransportConnection connect(String url) {
|
private DuplexTransportConnection connect(String url) {
|
||||||
try {
|
try {
|
||||||
StreamConnection s = (StreamConnection) Connector.open(url);
|
StreamConnection s = (StreamConnection) Connector.open(url);
|
||||||
return new BluetoothTransportConnection(s, maxLatency);
|
return new BluetoothTransportConnection(this, s);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
return null;
|
return null;
|
||||||
@@ -303,7 +309,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
|||||||
// Try to accept a connection
|
// Try to accept a connection
|
||||||
try {
|
try {
|
||||||
StreamConnection s = scn.acceptAndOpen();
|
StreamConnection s = scn.acceptAndOpen();
|
||||||
return new BluetoothTransportConnection(s, maxLatency);
|
return new BluetoothTransportConnection(this, s);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
// This is expected when the socket is closed
|
// This is expected when the socket is closed
|
||||||
if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e);
|
if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class BluetoothPluginFactory implements 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 MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
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) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new BluetoothPlugin(pluginExecutor, clock, secureRandom,
|
return new BluetoothPlugin(pluginExecutor, clock, secureRandom,
|
||||||
callback, MAX_LATENCY, POLLING_INTERVAL);
|
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,20 +6,25 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import javax.microedition.io.StreamConnection;
|
import javax.microedition.io.StreamConnection;
|
||||||
|
|
||||||
|
import net.sf.briar.api.plugins.Plugin;
|
||||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
class BluetoothTransportConnection implements DuplexTransportConnection {
|
class BluetoothTransportConnection implements DuplexTransportConnection {
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
private final StreamConnection stream;
|
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.stream = stream;
|
||||||
this.maxLatency = maxLatency;
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return plugin.getMaxFrameLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return plugin.getMaxLatency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final SecureRandom secureRandom;
|
private final SecureRandom secureRandom;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
|
private final int maxFrameLength;
|
||||||
private final long maxLatency, pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
@@ -72,13 +73,14 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
DroidtoothPlugin(Executor pluginExecutor, AndroidExecutor androidExecutor,
|
DroidtoothPlugin(Executor pluginExecutor, AndroidExecutor androidExecutor,
|
||||||
Context appContext, SecureRandom secureRandom,
|
Context appContext, SecureRandom secureRandom,
|
||||||
DuplexPluginCallback callback, long maxLatency,
|
DuplexPluginCallback callback, int maxFrameLength, long maxLatency,
|
||||||
long pollingInterval) {
|
long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.androidExecutor = androidExecutor;
|
this.androidExecutor = androidExecutor;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.secureRandom = secureRandom;
|
this.secureRandom = secureRandom;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxFrameLength = maxFrameLength;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
}
|
}
|
||||||
@@ -92,6 +94,10 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
return "BLUETOOTH_PLUGIN_NAME";
|
return "BLUETOOTH_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return maxFrameLength;
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return maxLatency;
|
||||||
}
|
}
|
||||||
@@ -207,7 +213,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DroidtoothTransportConnection conn =
|
DroidtoothTransportConnection conn =
|
||||||
new DroidtoothTransportConnection(s, maxLatency);
|
new DroidtoothTransportConnection(this, s);
|
||||||
callback.incomingConnectionCreated(conn);
|
callback.incomingConnectionCreated(conn);
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
}
|
}
|
||||||
@@ -296,7 +302,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + address);
|
if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + address);
|
||||||
s.connect();
|
s.connect();
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + address);
|
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + address);
|
||||||
return new DroidtoothTransportConnection(s, maxLatency);
|
return new DroidtoothTransportConnection(this, s);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
tryToClose(s);
|
tryToClose(s);
|
||||||
@@ -375,7 +381,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
|||||||
String address = s.getRemoteDevice().getAddress();
|
String address = s.getRemoteDevice().getAddress();
|
||||||
LOG.info("Incoming connection from " + address);
|
LOG.info("Incoming connection from " + address);
|
||||||
}
|
}
|
||||||
return new DroidtoothTransportConnection(s, maxLatency);
|
return new DroidtoothTransportConnection(this, s);
|
||||||
} catch(SocketTimeoutException e) {
|
} catch(SocketTimeoutException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Invitation timed out");
|
if(LOG.isLoggable(INFO)) LOG.info("Invitation timed out");
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import android.content.Context;
|
|||||||
|
|
||||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
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 MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
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) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new DroidtoothPlugin(pluginExecutor, androidExecutor, appContext,
|
return new DroidtoothPlugin(pluginExecutor, androidExecutor, appContext,
|
||||||
secureRandom, callback, MAX_LATENCY, POLLING_INTERVAL);
|
secureRandom, callback, MAX_FRAME_LENGTH, MAX_LATENCY,
|
||||||
|
POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,21 +4,26 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import net.sf.briar.api.plugins.Plugin;
|
||||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import android.bluetooth.BluetoothSocket;
|
import android.bluetooth.BluetoothSocket;
|
||||||
|
|
||||||
class DroidtoothTransportConnection implements DuplexTransportConnection {
|
class DroidtoothTransportConnection implements DuplexTransportConnection {
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
private final BluetoothSocket socket;
|
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.socket = socket;
|
||||||
this.maxLatency = maxLatency;
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return plugin.getMaxFrameLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return plugin.getMaxLatency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public abstract class FilePlugin implements SimplexPlugin {
|
|||||||
|
|
||||||
protected final Executor pluginExecutor;
|
protected final Executor pluginExecutor;
|
||||||
protected final SimplexPluginCallback callback;
|
protected final SimplexPluginCallback callback;
|
||||||
|
protected final int maxFrameLength;
|
||||||
protected final long maxLatency;
|
protected final long maxLatency;
|
||||||
|
|
||||||
protected volatile boolean running = false;
|
protected volatile boolean running = false;
|
||||||
@@ -37,12 +38,22 @@ public abstract class FilePlugin implements SimplexPlugin {
|
|||||||
protected abstract void readerFinished(File f);
|
protected abstract void readerFinished(File f);
|
||||||
|
|
||||||
protected FilePlugin(Executor pluginExecutor,
|
protected FilePlugin(Executor pluginExecutor,
|
||||||
SimplexPluginCallback callback, long maxLatency) {
|
SimplexPluginCallback callback, int maxFrameLength,
|
||||||
|
long maxLatency) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxFrameLength = maxFrameLength;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return maxFrameLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMaxLatency() {
|
||||||
|
return maxLatency;
|
||||||
|
}
|
||||||
|
|
||||||
public SimplexTransportReader createReader(ContactId c) {
|
public SimplexTransportReader createReader(ContactId c) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -73,7 +84,7 @@ public abstract class FilePlugin implements SimplexPlugin {
|
|||||||
long capacity = getCapacity(dir.getPath());
|
long capacity = getCapacity(dir.getPath());
|
||||||
if(capacity < MIN_CONNECTION_LENGTH) return null;
|
if(capacity < MIN_CONNECTION_LENGTH) return null;
|
||||||
OutputStream out = new FileOutputStream(f);
|
OutputStream out = new FileOutputStream(f);
|
||||||
return new FileTransportWriter(f, out, capacity, maxLatency, this);
|
return new FileTransportWriter(f, out, capacity, this);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
f.delete();
|
f.delete();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
|
|||||||
class FileTransportReader implements SimplexTransportReader {
|
class FileTransportReader implements SimplexTransportReader {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(FileTransportReader.class.getName());
|
Logger.getLogger(FileTransportReader.class.getName());
|
||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
private final InputStream in;
|
private final InputStream in;
|
||||||
@@ -24,6 +24,10 @@ class FileTransportReader implements SimplexTransportReader {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return plugin.getMaxFrameLength();
|
||||||
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
public InputStream getInputStream() {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,19 +12,18 @@ import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
|
|||||||
class FileTransportWriter implements SimplexTransportWriter {
|
class FileTransportWriter implements SimplexTransportWriter {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(FileTransportWriter.class.getName());
|
Logger.getLogger(FileTransportWriter.class.getName());
|
||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
private final OutputStream out;
|
private final OutputStream out;
|
||||||
private final long capacity, maxLatency;
|
private final long capacity;
|
||||||
private final FilePlugin plugin;
|
private final FilePlugin plugin;
|
||||||
|
|
||||||
FileTransportWriter(File file, OutputStream out, long capacity,
|
FileTransportWriter(File file, OutputStream out, long capacity,
|
||||||
long maxLatency, FilePlugin plugin) {
|
FilePlugin plugin) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.out = out;
|
this.out = out;
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
this.maxLatency = maxLatency;
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,8 +31,12 @@ class FileTransportWriter implements SimplexTransportWriter {
|
|||||||
return capacity;
|
return capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return plugin.getMaxFrameLength();
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return plugin.getMaxLatency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OutputStream getOutputStream() {
|
public OutputStream getOutputStream() {
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ implements RemovableDriveMonitor.Callback {
|
|||||||
|
|
||||||
RemovableDrivePlugin(Executor pluginExecutor,
|
RemovableDrivePlugin(Executor pluginExecutor,
|
||||||
SimplexPluginCallback callback, RemovableDriveFinder finder,
|
SimplexPluginCallback callback, RemovableDriveFinder finder,
|
||||||
RemovableDriveMonitor monitor, long maxLatency) {
|
RemovableDriveMonitor monitor, int maxFrameLength,
|
||||||
super(pluginExecutor, callback, maxLatency);
|
long maxLatency) {
|
||||||
|
super(pluginExecutor, callback, maxFrameLength, maxLatency);
|
||||||
this.finder = finder;
|
this.finder = finder;
|
||||||
this.monitor = monitor;
|
this.monitor = monitor;
|
||||||
}
|
}
|
||||||
@@ -47,10 +48,6 @@ implements RemovableDriveMonitor.Callback {
|
|||||||
return "REMOVABLE_DRIVE_PLUGIN_NAME";
|
return "REMOVABLE_DRIVE_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
|
||||||
return maxLatency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean start() throws IOException {
|
public boolean start() throws IOException {
|
||||||
running = true;
|
running = true;
|
||||||
monitor.start(this);
|
monitor.start(this);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.sf.briar.plugins.file;
|
package net.sf.briar.plugins.file;
|
||||||
|
|
||||||
|
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.TransportId;
|
import net.sf.briar.api.TransportId;
|
||||||
@@ -46,6 +48,6 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new RemovableDrivePlugin(pluginExecutor, callback, finder,
|
return new RemovableDrivePlugin(pluginExecutor, callback, finder,
|
||||||
monitor, MAX_LATENCY);
|
monitor, MAX_FRAME_LENGTH, MAX_LATENCY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
private final ModemFactory modemFactory;
|
private final ModemFactory modemFactory;
|
||||||
private final SerialPortList serialPortList;
|
private final SerialPortList serialPortList;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
|
private final int maxFrameLength;
|
||||||
private final long maxLatency, pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
private final boolean shuffle; // Used to disable shuffling for testing
|
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,
|
ModemPlugin(Executor pluginExecutor, ModemFactory modemFactory,
|
||||||
SerialPortList serialPortList, DuplexPluginCallback callback,
|
SerialPortList serialPortList, DuplexPluginCallback callback,
|
||||||
long maxLatency, long pollingInterval, boolean shuffle) {
|
int maxFrameLength, long maxLatency, long pollingInterval,
|
||||||
|
boolean shuffle) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.modemFactory = modemFactory;
|
this.modemFactory = modemFactory;
|
||||||
this.serialPortList = serialPortList;
|
this.serialPortList = serialPortList;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxFrameLength = maxFrameLength;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
this.shuffle = shuffle;
|
this.shuffle = shuffle;
|
||||||
@@ -66,6 +69,10 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
return "MODEM_PLUGIN_NAME";
|
return "MODEM_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return maxFrameLength;
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return maxLatency;
|
||||||
}
|
}
|
||||||
@@ -232,6 +239,10 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
|
|
||||||
private final CountDownLatch finished = new CountDownLatch(1);
|
private final CountDownLatch finished = new CountDownLatch(1);
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return maxFrameLength;
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return maxLatency;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.sf.briar.util.StringUtils;
|
|||||||
|
|
||||||
public class ModemPluginFactory implements DuplexPluginFactory {
|
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 MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
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");
|
String enabled = callback.getConfig().get("enabled");
|
||||||
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
||||||
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
|
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
|
||||||
callback, MAX_LATENCY, POLLING_INTERVAL, true);
|
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL,
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ class DroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
|
||||||
DroidLanTcpPlugin(Executor pluginExecutor, Context appContext, Clock clock,
|
DroidLanTcpPlugin(Executor pluginExecutor, Context appContext, Clock clock,
|
||||||
DuplexPluginCallback callback, long maxLatency,
|
DuplexPluginCallback callback, int maxFrameLength, long maxLatency,
|
||||||
long pollingInterval) {
|
long pollingInterval) {
|
||||||
super(pluginExecutor, clock, callback, maxLatency, pollingInterval);
|
super(pluginExecutor, clock, callback, maxFrameLength, maxLatency,
|
||||||
|
pollingInterval);
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import android.content.Context;
|
|||||||
|
|
||||||
public class DroidLanTcpPluginFactory implements DuplexPluginFactory {
|
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 MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 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) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new DroidLanTcpPlugin(pluginExecutor, appContext, clock,
|
return new DroidLanTcpPlugin(pluginExecutor, appContext, clock,
|
||||||
callback, MAX_LATENCY, POLLING_INTERVAL);
|
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,9 +47,10 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
LanTcpPlugin(Executor pluginExecutor, Clock clock,
|
LanTcpPlugin(Executor pluginExecutor, Clock clock,
|
||||||
DuplexPluginCallback callback, long maxLatency,
|
DuplexPluginCallback callback, int maxFrameLength, long maxLatency,
|
||||||
long pollingInterval) {
|
long pollingInterval) {
|
||||||
super(pluginExecutor, callback, maxLatency, pollingInterval);
|
super(pluginExecutor, callback, maxFrameLength, maxLatency,
|
||||||
|
pollingInterval);
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
// Connect back on the advertised TCP port
|
// Connect back on the advertised TCP port
|
||||||
Socket s = new Socket(packet.getAddress(), port);
|
Socket s = new Socket(packet.getAddress(), port);
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Connected back");
|
if(LOG.isLoggable(INFO)) LOG.info("Connected back");
|
||||||
return new TcpTransportConnection(s, maxLatency);
|
return new TcpTransportConnection(this, s);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING))
|
||||||
LOG.log(WARNING, e.toString(), e);
|
LOG.log(WARNING, e.toString(), e);
|
||||||
@@ -294,7 +295,7 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
Socket s = ss.accept();
|
Socket s = ss.accept();
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info("Received a TCP connection");
|
LOG.info("Received a TCP connection");
|
||||||
return new TcpTransportConnection(s, maxLatency);
|
return new TcpTransportConnection(this, s);
|
||||||
} catch(SocketTimeoutException e) {
|
} catch(SocketTimeoutException e) {
|
||||||
now = clock.currentTimeMillis();
|
now = clock.currentTimeMillis();
|
||||||
if(now < end) {
|
if(now < end) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class LanTcpPluginFactory implements 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 MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 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) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new LanTcpPlugin(pluginExecutor, clock, callback, MAX_LATENCY,
|
return new LanTcpPlugin(pluginExecutor, clock, callback,
|
||||||
POLLING_INTERVAL);
|
MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
|
|
||||||
protected final Executor pluginExecutor;
|
protected final Executor pluginExecutor;
|
||||||
protected final DuplexPluginCallback callback;
|
protected final DuplexPluginCallback callback;
|
||||||
|
protected final int maxFrameLength;
|
||||||
protected final long maxLatency, pollingInterval;
|
protected final long maxLatency, pollingInterval;
|
||||||
|
|
||||||
protected volatile boolean running = false;
|
protected volatile boolean running = false;
|
||||||
@@ -42,13 +43,18 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
protected abstract List<SocketAddress> getLocalSocketAddresses();
|
protected abstract List<SocketAddress> getLocalSocketAddresses();
|
||||||
|
|
||||||
protected TcpPlugin(Executor pluginExecutor, DuplexPluginCallback callback,
|
protected TcpPlugin(Executor pluginExecutor, DuplexPluginCallback callback,
|
||||||
long maxLatency, long pollingInterval) {
|
int maxFrameLength, long maxLatency, long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxFrameLength = maxFrameLength;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return maxFrameLength;
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return maxLatency;
|
||||||
}
|
}
|
||||||
@@ -128,8 +134,8 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
}
|
}
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info("Connection from " + s.getRemoteSocketAddress());
|
LOG.info("Connection from " + s.getRemoteSocketAddress());
|
||||||
callback.incomingConnectionCreated(new TcpTransportConnection(s,
|
TcpTransportConnection conn = new TcpTransportConnection(this, s);
|
||||||
maxLatency));
|
callback.incomingConnectionCreated(conn);
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +181,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + addr);
|
if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + addr);
|
||||||
s.connect(addr);
|
s.connect(addr);
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + addr);
|
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + addr);
|
||||||
return new TcpTransportConnection(s, maxLatency);
|
return new TcpTransportConnection(this, s);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e);
|
if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -5,20 +5,25 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
|
import net.sf.briar.api.plugins.Plugin;
|
||||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
class TcpTransportConnection implements DuplexTransportConnection {
|
class TcpTransportConnection implements DuplexTransportConnection {
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
private final Socket socket;
|
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.socket = socket;
|
||||||
this.maxLatency = maxLatency;
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return plugin.getMaxFrameLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return plugin.getMaxLatency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
|
|||||||
@@ -38,8 +38,10 @@ class WanTcpPlugin extends TcpPlugin {
|
|||||||
private volatile MappingResult mappingResult;
|
private volatile MappingResult mappingResult;
|
||||||
|
|
||||||
WanTcpPlugin(Executor pluginExecutor, DuplexPluginCallback callback,
|
WanTcpPlugin(Executor pluginExecutor, DuplexPluginCallback callback,
|
||||||
long maxLatency, long pollingInterval, PortMapper portMapper) {
|
int maxFrameLength, long maxLatency, long pollingInterval,
|
||||||
super(pluginExecutor, callback, maxLatency, pollingInterval);
|
PortMapper portMapper) {
|
||||||
|
super(pluginExecutor, callback, maxFrameLength, maxLatency,
|
||||||
|
pollingInterval);
|
||||||
this.portMapper = portMapper;
|
this.portMapper = portMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class WanTcpPluginFactory implements 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 MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
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) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new WanTcpPlugin(pluginExecutor, callback, MAX_LATENCY,
|
return new WanTcpPlugin(pluginExecutor, callback, MAX_FRAME_LENGTH,
|
||||||
POLLING_INTERVAL, new PortMapperImpl(shutdownManager));
|
MAX_LATENCY, POLLING_INTERVAL,
|
||||||
|
new PortMapperImpl(shutdownManager));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final ShutdownManager shutdownManager;
|
private final ShutdownManager shutdownManager;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
|
private final int maxFrameLength;
|
||||||
private final long maxLatency, pollingInterval;
|
private final long maxLatency, pollingInterval;
|
||||||
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
|
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
|
||||||
private final File cookieFile, pidFile, hostnameFile;
|
private final File cookieFile, pidFile, hostnameFile;
|
||||||
@@ -78,11 +79,12 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
|
|
||||||
TorPlugin(Executor pluginExecutor, Context appContext,
|
TorPlugin(Executor pluginExecutor, Context appContext,
|
||||||
ShutdownManager shutdownManager, DuplexPluginCallback callback,
|
ShutdownManager shutdownManager, DuplexPluginCallback callback,
|
||||||
long maxLatency, long pollingInterval) {
|
int maxFrameLength, long maxLatency, long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.shutdownManager = shutdownManager;
|
this.shutdownManager = shutdownManager;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.maxFrameLength = maxFrameLength;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
torDirectory = appContext.getDir("tor", MODE_PRIVATE);
|
torDirectory = appContext.getDir("tor", MODE_PRIVATE);
|
||||||
@@ -103,6 +105,10 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
return "TOR_PLUGIN_NAME";
|
return "TOR_PLUGIN_NAME";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return maxFrameLength;
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return maxLatency;
|
||||||
}
|
}
|
||||||
@@ -426,8 +432,8 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Connection received");
|
if(LOG.isLoggable(INFO)) LOG.info("Connection received");
|
||||||
callback.incomingConnectionCreated(new TorTransportConnection(s,
|
TorTransportConnection conn = new TorTransportConnection(this, s);
|
||||||
maxLatency));
|
callback.incomingConnectionCreated(conn);
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,7 +502,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
proxy.resolveAddrLocally(false);
|
proxy.resolveAddrLocally(false);
|
||||||
Socket s = new SocksSocket(proxy, onion, 80);
|
Socket s = new SocksSocket(proxy, onion, 80);
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + onion);
|
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + onion);
|
||||||
return new TorTransportConnection(s, maxLatency);
|
return new TorTransportConnection(this, s);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e);
|
if(LOG.isLoggable(INFO)) LOG.log(INFO, e.toString(), e);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import android.content.Context;
|
|||||||
|
|
||||||
public class TorPluginFactory implements DuplexPluginFactory {
|
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 MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
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) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
return new TorPlugin(pluginExecutor,appContext, shutdownManager,
|
return new TorPlugin(pluginExecutor,appContext, shutdownManager,
|
||||||
callback, MAX_LATENCY, POLLING_INTERVAL);
|
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,20 +5,25 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
|
import net.sf.briar.api.plugins.Plugin;
|
||||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
class TorTransportConnection implements DuplexTransportConnection {
|
class TorTransportConnection implements DuplexTransportConnection {
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
private final Socket socket;
|
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.socket = socket;
|
||||||
this.maxLatency = maxLatency;
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return plugin.getMaxFrameLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return plugin.getMaxLatency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package net.sf.briar.transport;
|
package net.sf.briar.transport;
|
||||||
|
|
||||||
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
@@ -22,7 +20,8 @@ class ConnectionReaderFactoryImpl implements ConnectionReaderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionReader createConnectionReader(InputStream in,
|
public ConnectionReader createConnectionReader(InputStream in,
|
||||||
ConnectionContext ctx, boolean incoming, boolean initiator) {
|
int maxFrameLength, ConnectionContext ctx, boolean incoming,
|
||||||
|
boolean initiator) {
|
||||||
byte[] secret = ctx.getSecret();
|
byte[] secret = ctx.getSecret();
|
||||||
long connection = ctx.getConnectionNumber();
|
long connection = ctx.getConnectionNumber();
|
||||||
boolean weAreAlice = ctx.getAlice();
|
boolean weAreAlice = ctx.getAlice();
|
||||||
@@ -30,15 +29,15 @@ class ConnectionReaderFactoryImpl implements ConnectionReaderFactory {
|
|||||||
ErasableKey frameKey = crypto.deriveFrameKey(secret, connection,
|
ErasableKey frameKey = crypto.deriveFrameKey(secret, connection,
|
||||||
initiatorIsAlice, initiator);
|
initiatorIsAlice, initiator);
|
||||||
FrameReader encryption = new IncomingEncryptionLayer(in,
|
FrameReader encryption = new IncomingEncryptionLayer(in,
|
||||||
crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH);
|
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
||||||
return new ConnectionReaderImpl(encryption, MAX_FRAME_LENGTH);
|
return new ConnectionReaderImpl(encryption, maxFrameLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionReader createInvitationConnectionReader(InputStream in,
|
public ConnectionReader createInvitationConnectionReader(InputStream in,
|
||||||
byte[] secret, boolean alice) {
|
int maxFrameLength, byte[] secret, boolean alice) {
|
||||||
ErasableKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
ErasableKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
||||||
FrameReader encryption = new IncomingEncryptionLayer(in,
|
FrameReader encryption = new IncomingEncryptionLayer(in,
|
||||||
crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH);
|
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
||||||
return new ConnectionReaderImpl(encryption, MAX_FRAME_LENGTH);
|
return new ConnectionReaderImpl(encryption, maxFrameLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.sf.briar.transport;
|
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 static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -25,8 +24,8 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWriter createConnectionWriter(OutputStream out,
|
public ConnectionWriter createConnectionWriter(OutputStream out,
|
||||||
long capacity, ConnectionContext ctx, boolean incoming,
|
int maxFrameLength, long capacity, ConnectionContext ctx,
|
||||||
boolean initiator) {
|
boolean incoming, boolean initiator) {
|
||||||
byte[] secret = ctx.getSecret();
|
byte[] secret = ctx.getSecret();
|
||||||
long connection = ctx.getConnectionNumber();
|
long connection = ctx.getConnectionNumber();
|
||||||
boolean weAreAlice = ctx.getAlice();
|
boolean weAreAlice = ctx.getAlice();
|
||||||
@@ -41,20 +40,20 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
|
|||||||
crypto.encodeTag(tag, tagCipher, tagKey, connection);
|
crypto.encodeTag(tag, tagCipher, tagKey, connection);
|
||||||
tagKey.erase();
|
tagKey.erase();
|
||||||
encryption = new OutgoingEncryptionLayer(out, capacity,
|
encryption = new OutgoingEncryptionLayer(out, capacity,
|
||||||
crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH, tag);
|
crypto.getFrameCipher(), frameKey, maxFrameLength, tag);
|
||||||
} else {
|
} else {
|
||||||
encryption = new OutgoingEncryptionLayer(out, capacity,
|
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,
|
public ConnectionWriter createInvitationConnectionWriter(OutputStream out,
|
||||||
byte[] secret, boolean alice) {
|
int maxFrameLength, byte[] secret, boolean alice) {
|
||||||
ErasableKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
ErasableKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
||||||
FrameWriter encryption = new OutgoingEncryptionLayer(out,
|
FrameWriter encryption = new OutgoingEncryptionLayer(out,
|
||||||
Long.MAX_VALUE, crypto.getFrameCipher(), frameKey,
|
Long.MAX_VALUE, crypto.getFrameCipher(), frameKey,
|
||||||
MAX_FRAME_LENGTH);
|
maxFrameLength);
|
||||||
return new ConnectionWriterImpl(encryption, MAX_FRAME_LENGTH);
|
return new ConnectionWriterImpl(encryption, maxFrameLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +62,9 @@ class TransportConnectionRecogniser {
|
|||||||
db.setConnectionWindow(t.contactId, transportId, t.period,
|
db.setConnectionWindow(t.contactId, transportId, t.period,
|
||||||
t.window.getCentre(), t.window.getBitmap());
|
t.window.getCentre(), t.window.getBitmap());
|
||||||
// Clone the secret - the key manager will erase the original
|
// Clone the secret - the key manager will erase the original
|
||||||
return new ConnectionContext(t.contactId, transportId,
|
byte[] secret = t.secret.clone();
|
||||||
t.secret.clone(), t.connection, t.alice);
|
return new ConnectionContext(t.contactId, transportId, secret,
|
||||||
|
t.connection, t.alice);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void addSecret(TemporarySecret s) {
|
synchronized void addSecret(TemporarySecret s) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.sf.briar;
|
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 net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret.clone(), 0, true);
|
secret.clone(), 0, true);
|
||||||
ConnectionWriter conn = connectionWriterFactory.createConnectionWriter(
|
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();
|
OutputStream out1 = conn.getOutputStream();
|
||||||
PacketWriter writer = packetWriterFactory.createPacketWriter(out1,
|
PacketWriter writer = packetWriterFactory.createPacketWriter(out1,
|
||||||
false);
|
false);
|
||||||
@@ -174,7 +175,7 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret.clone(), 0, false);
|
secret.clone(), 0, false);
|
||||||
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
||||||
in, ctx, true, true);
|
in, MAX_FRAME_LENGTH, ctx, true, true);
|
||||||
InputStream in1 = conn.getInputStream();
|
InputStream in1 = conn.getInputStream();
|
||||||
PacketReader reader = packetReaderFactory.createPacketReader(in1);
|
PacketReader reader = packetReaderFactory.createPacketReader(in1);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.sf.briar.messaging.simplex;
|
package net.sf.briar.messaging.simplex;
|
||||||
|
|
||||||
|
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
|
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
|
||||||
@@ -14,6 +16,10 @@ class TestSimplexTransportReader implements SimplexTransportReader {
|
|||||||
this.in = in;
|
this.in = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return MAX_FRAME_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
public InputStream getInputStream() {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.sf.briar.messaging.simplex;
|
package net.sf.briar.messaging.simplex;
|
||||||
|
|
||||||
|
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
@@ -25,6 +27,10 @@ class TestSimplexTransportWriter implements SimplexTransportWriter {
|
|||||||
return capacity;
|
return capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxFrameLength() {
|
||||||
|
return MAX_FRAME_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
public long getMaxLatency() {
|
public long getMaxLatency() {
|
||||||
return maxLatency;
|
return maxLatency;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class BluetoothClientTest extends DuplexClientTest {
|
|||||||
callback = new ClientCallback(new TransportConfig(),
|
callback = new ClientCallback(new TransportConfig(),
|
||||||
new TransportProperties(), remote);
|
new TransportProperties(), remote);
|
||||||
plugin = new BluetoothPlugin(executor, new SystemClock(),
|
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 {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class BluetoothServerTest extends DuplexServerTest {
|
|||||||
callback = new ServerCallback(new TransportConfig(), local,
|
callback = new ServerCallback(new TransportConfig(), local,
|
||||||
Collections.singletonMap(contactId, new TransportProperties()));
|
Collections.singletonMap(contactId, new TransportProperties()));
|
||||||
plugin = new BluetoothPlugin(executor, new SystemClock(),
|
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 {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.sf.briar.plugins.file;
|
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 static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -41,11 +42,11 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
@@ -54,7 +55,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -73,11 +74,11 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
@@ -89,7 +90,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -110,11 +111,11 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
@@ -126,7 +127,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -149,11 +150,11 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
@@ -165,7 +166,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -188,11 +189,11 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
@@ -204,7 +205,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNotNull(plugin.createWriter(contactId));
|
assertNotNull(plugin.createWriter(contactId));
|
||||||
@@ -230,11 +231,11 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
@@ -247,7 +248,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
||||||
@@ -275,18 +276,18 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
plugin.driveInserted(testDir);
|
plugin.driveInserted(testDir);
|
||||||
@@ -299,14 +300,14 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0);
|
callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||||
|
|
||||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
|
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
|
||||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
|
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
|
||||||
@@ -322,11 +323,11 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
public void testReaderIsCreated() throws Exception {
|
public void testReaderIsCreated() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final SimplexPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(SimplexPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(monitor).start(with(any(Callback.class)));
|
oneOf(monitor).start(with(any(Callback.class)));
|
||||||
@@ -334,7 +335,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
|
||||||
new ImmediateExecutor(), callback, finder, monitor, 0);
|
new ImmediateExecutor(), callback, finder, monitor,
|
||||||
|
MAX_FRAME_LENGTH, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
File f = new File(testDir, "abcdefgh.dat");
|
File f = new File(testDir, "abcdefgh.dat");
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final SerialPortList serialPortList =
|
final SerialPortList serialPortList =
|
||||||
context.mock(SerialPortList.class);
|
context.mock(SerialPortList.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
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);
|
final Modem modem = context.mock(Modem.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(serialPortList).getPortNames();
|
oneOf(serialPortList).getPortNames();
|
||||||
@@ -71,7 +71,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
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 Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -112,7 +112,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
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 Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -153,7 +153,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
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 Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -204,7 +204,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
// Disable shuffling for this test, it confuses jMock
|
// Disable shuffling for this test, it confuses jMock
|
||||||
final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory,
|
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 Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
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.ContactId;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
|
import net.sf.briar.api.clock.Clock;
|
||||||
import net.sf.briar.api.clock.SystemClock;
|
import net.sf.briar.api.clock.SystemClock;
|
||||||
import net.sf.briar.plugins.DuplexClientTest;
|
import net.sf.briar.plugins.DuplexClientTest;
|
||||||
|
|
||||||
@@ -27,7 +28,8 @@ public class LanTcpClientTest extends DuplexClientTest {
|
|||||||
// Create the plugin
|
// Create the plugin
|
||||||
callback = new ClientCallback(new TransportConfig(),
|
callback = new ClientCallback(new TransportConfig(),
|
||||||
new TransportProperties(), remote);
|
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 {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
callback.local.put("port", "0");
|
callback.local.put("port", "0");
|
||||||
Executor executor = Executors.newCachedThreadPool();
|
Executor executor = Executors.newCachedThreadPool();
|
||||||
Clock clock = new SystemClock();
|
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();
|
plugin.start();
|
||||||
// The plugin should have bound a socket and stored the port number
|
// The plugin should have bound a socket and stored the port number
|
||||||
assertTrue(callback.propertiesLatch.await(5, SECONDS));
|
assertTrue(callback.propertiesLatch.await(5, SECONDS));
|
||||||
@@ -62,7 +63,8 @@ public class LanTcpPluginTest extends BriarTestCase {
|
|||||||
Callback callback = new Callback();
|
Callback callback = new Callback();
|
||||||
Executor executor = Executors.newCachedThreadPool();
|
Executor executor = Executors.newCachedThreadPool();
|
||||||
Clock clock = new SystemClock();
|
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();
|
plugin.start();
|
||||||
// Listen on a local port
|
// Listen on a local port
|
||||||
final ServerSocket ss = new ServerSocket();
|
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.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
|
import net.sf.briar.api.clock.Clock;
|
||||||
import net.sf.briar.api.clock.SystemClock;
|
import net.sf.briar.api.clock.SystemClock;
|
||||||
import net.sf.briar.plugins.DuplexServerTest;
|
import net.sf.briar.plugins.DuplexServerTest;
|
||||||
|
|
||||||
@@ -18,7 +19,8 @@ public class LanTcpServerTest extends DuplexServerTest {
|
|||||||
callback = new ServerCallback(new TransportConfig(),
|
callback = new ServerCallback(new TransportConfig(),
|
||||||
new TransportProperties(),
|
new TransportProperties(),
|
||||||
Collections.singletonMap(contactId, 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 {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.transport;
|
package net.sf.briar.transport;
|
||||||
|
|
||||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
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 net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
@@ -129,7 +130,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret, 0, true);
|
secret, 0, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
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
|
// Check that the connection writer thinks there's room for a packet
|
||||||
long capacity = w.getRemainingCapacity();
|
long capacity = w.getRemainingCapacity();
|
||||||
assertTrue(capacity > MAX_PACKET_LENGTH);
|
assertTrue(capacity > MAX_PACKET_LENGTH);
|
||||||
@@ -150,7 +151,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret, 0, true);
|
secret, 0, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
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
|
// Check that the connection writer thinks there's room for a packet
|
||||||
long capacity = w.getRemainingCapacity();
|
long capacity = w.getRemainingCapacity();
|
||||||
assertTrue(capacity > MAX_PACKET_LENGTH);
|
assertTrue(capacity > MAX_PACKET_LENGTH);
|
||||||
|
|||||||
Reference in New Issue
Block a user