From b24f153704e3dde58479fa5e0e47ded715d12d5d Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Wed, 8 Oct 2014 16:18:33 +0100 Subject: [PATCH] Renamed a load of things from 'connection' to 'stream'. --- .../briarproject/android/TestingActivity.java | 4 ++ .../briarproject/system/AndroidFileUtils.java | 2 + .../system/AndroidSeedProvider.java | 1 + .../api/crypto/CryptoComponent.java | 11 ++- .../briarproject/api/crypto/KeyManager.java | 15 ++-- .../api/db/DatabaseComponent.java | 14 ++-- .../api/messaging/MessagingConstants.java | 8 +-- .../duplex/DuplexConnectionFactory.java | 4 +- .../simplex/SimplexConnectionFactory.java | 4 +- .../api/transport/ConnectionDispatcher.java | 8 +-- .../transport/ConnectionReaderFactory.java | 14 ---- .../api/transport/ConnectionRecogniser.java | 29 -------- .../transport/ConnectionWriterFactory.java | 15 ---- ...nectionContext.java => StreamContext.java} | 14 ++-- ...onnectionReader.java => StreamReader.java} | 4 +- .../api/transport/StreamReaderFactory.java | 14 ++++ ...onnectionWriter.java => StreamWriter.java} | 9 ++- .../api/transport/StreamWriterFactory.java | 15 ++++ .../api/transport/TagRecogniser.java | 25 +++++++ .../api/transport/TemporarySecret.java | 11 +-- .../api/transport/TransportConstants.java | 14 ++-- .../crypto/CryptoComponentImpl.java | 18 ++--- .../org/briarproject/crypto/DoubleDigest.java | 1 - .../briarproject/crypto/Sec1PrivateKey.java | 1 - .../src/org/briarproject/db/Database.java | 16 ++--- .../db/DatabaseComponentImpl.java | 8 +-- .../src/org/briarproject/db/JdbcDatabase.java | 14 ++-- .../invitation/AliceConnector.java | 30 ++++---- .../briarproject/invitation/BobConnector.java | 30 ++++---- .../briarproject/invitation/Connector.java | 16 ++--- .../invitation/ConnectorGroup.java | 24 +++---- .../invitation/InvitationTaskFactoryImpl.java | 18 ++--- .../briarproject/messaging/MessageImpl.java | 1 + .../messaging/duplex/DuplexConnection.java | 32 ++++----- .../duplex/DuplexConnectionFactoryImpl.java | 20 +++--- .../duplex/IncomingDuplexConnection.java | 24 +++---- .../duplex/OutgoingDuplexConnection.java | 24 +++---- .../simplex/IncomingSimplexConnection.java | 16 ++--- .../simplex/OutgoingSimplexConnection.java | 28 ++++---- .../simplex/SimplexConnectionFactoryImpl.java | 18 ++--- .../plugins/PluginManagerImpl.java | 4 +- .../briarproject/plugins/file/FilePlugin.java | 4 +- .../plugins/tcp/PortMapperImpl.java | 3 +- .../transport/ConnectionDispatcherImpl.java | 29 ++++---- .../briarproject/transport/FrameEncoder.java | 1 + .../transport/KeyManagerImpl.java | 18 ++--- ...ctionWindow.java => ReorderingWindow.java} | 48 ++++++------- ...Impl.java => StreamReaderFactoryImpl.java} | 24 +++---- ...nReaderImpl.java => StreamReaderImpl.java} | 6 +- ...Impl.java => StreamWriterFactoryImpl.java} | 26 +++---- ...nWriterImpl.java => StreamWriterImpl.java} | 11 +-- ...gniserImpl.java => TagRecogniserImpl.java} | 28 ++++---- .../transport/TransportModule.java | 18 ++--- ...niser.java => TransportTagRecogniser.java} | 62 ++++++++-------- .../briarproject/plugins/modem/ModemImpl.java | 1 + briar-tests/build.xml | 8 +-- .../briarproject/ProtocolIntegrationTest.java | 26 +++---- .../crypto/KeyDerivationTest.java | 2 +- .../crypto/KeyEncodingAndParsingTest.java | 1 - .../crypto/SecretKeyImplTest.java | 1 - .../src/org/briarproject/db/BasicH2Test.java | 1 - .../db/DatabaseComponentTest.java | 8 +-- .../db/ExponentialBackoffTest.java | 1 - .../org/briarproject/db/H2DatabaseTest.java | 52 +++++++------- .../lifecycle/ShutdownManagerImplTest.java | 1 - .../WindowsShutdownManagerImplTest.java | 1 - .../briarproject/messaging/ConsumersTest.java | 1 - .../messaging/PacketReaderImplTest.java | 1 - .../OutgoingSimplexConnectionTest.java | 20 +++--- .../SimplexMessagingIntegrationTest.java | 24 +++---- .../file/LinuxRemovableDriveFinderTest.java | 1 - .../file/MacRemovableDriveFinderTest.java | 1 - .../PollingRemovableDriveMonitorTest.java | 1 - .../file/RemovableDrivePluginTest.java | 7 +- .../plugins/modem/CountryCodesTest.java | 1 - .../transport/KeyManagerImplTest.java | 72 +++++++++---------- .../transport/KeyRotationIntegrationTest.java | 59 ++++++++------- ...dowTest.java => ReorderingWindowTest.java} | 27 ++++--- ...mplTest.java => StreamReaderImplTest.java} | 46 ++++++------ ...mplTest.java => StreamWriterImplTest.java} | 38 +++++----- .../transport/TransportIntegrationTest.java | 45 ++++++------ ...t.java => TransportTagRecogniserTest.java} | 36 +++++----- .../org/briarproject/util/ByteUtilsTest.java | 1 - .../briarproject/util/StringUtilsTest.java | 2 +- 84 files changed, 671 insertions(+), 671 deletions(-) delete mode 100644 briar-api/src/org/briarproject/api/transport/ConnectionReaderFactory.java delete mode 100644 briar-api/src/org/briarproject/api/transport/ConnectionRecogniser.java delete mode 100644 briar-api/src/org/briarproject/api/transport/ConnectionWriterFactory.java rename briar-api/src/org/briarproject/api/transport/{ConnectionContext.java => StreamContext.java} (68%) rename briar-api/src/org/briarproject/api/transport/{ConnectionReader.java => StreamReader.java} (64%) create mode 100644 briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java rename briar-api/src/org/briarproject/api/transport/{ConnectionWriter.java => StreamWriter.java} (53%) create mode 100644 briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java create mode 100644 briar-api/src/org/briarproject/api/transport/TagRecogniser.java rename briar-core/src/org/briarproject/transport/{ConnectionWindow.java => ReorderingWindow.java} (62%) rename briar-core/src/org/briarproject/transport/{ConnectionReaderFactoryImpl.java => StreamReaderFactoryImpl.java} (52%) rename briar-core/src/org/briarproject/transport/{ConnectionReaderImpl.java => StreamReaderImpl.java} (86%) rename briar-core/src/org/briarproject/transport/{ConnectionWriterFactoryImpl.java => StreamWriterFactoryImpl.java} (61%) rename briar-core/src/org/briarproject/transport/{ConnectionWriterImpl.java => StreamWriterImpl.java} (82%) rename briar-core/src/org/briarproject/transport/{ConnectionRecogniserImpl.java => TagRecogniserImpl.java} (61%) rename briar-core/src/org/briarproject/transport/{TransportConnectionRecogniser.java => TransportTagRecogniser.java} (75%) rename briar-tests/src/org/briarproject/transport/{ConnectionWindowTest.java => ReorderingWindowTest.java} (85%) rename briar-tests/src/org/briarproject/transport/{ConnectionReaderImplTest.java => StreamReaderImplTest.java} (75%) rename briar-tests/src/org/briarproject/transport/{ConnectionWriterImplTest.java => StreamWriterImplTest.java} (83%) rename briar-tests/src/org/briarproject/transport/{TransportConnectionRecogniserTest.java => TransportTagRecogniserTest.java} (80%) diff --git a/briar-android/src/org/briarproject/android/TestingActivity.java b/briar-android/src/org/briarproject/android/TestingActivity.java index 7fcc1b3579..80f0d8fd73 100644 --- a/briar-android/src/org/briarproject/android/TestingActivity.java +++ b/briar-android/src/org/briarproject/android/TestingActivity.java @@ -19,6 +19,7 @@ import static java.util.logging.Level.WARNING; import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -34,7 +35,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.logging.Logger; import java.util.regex.Pattern; + import javax.inject.Inject; + import org.briarproject.R; import org.briarproject.android.util.ElasticHorizontalSpace; import org.briarproject.android.util.HorizontalBorder; @@ -50,6 +53,7 @@ import org.briarproject.api.plugins.Plugin; import org.briarproject.api.plugins.PluginManager; import org.briarproject.api.system.FileUtils; import org.briarproject.util.StringUtils; + import android.annotation.SuppressLint; import android.app.ActivityManager; import android.bluetooth.BluetoothAdapter; diff --git a/briar-android/src/org/briarproject/system/AndroidFileUtils.java b/briar-android/src/org/briarproject/system/AndroidFileUtils.java index 8291687667..62d60102d0 100644 --- a/briar-android/src/org/briarproject/system/AndroidFileUtils.java +++ b/briar-android/src/org/briarproject/system/AndroidFileUtils.java @@ -2,7 +2,9 @@ package org.briarproject.system; import java.io.File; import java.io.IOException; + import org.briarproject.api.system.FileUtils; + import android.annotation.SuppressLint; import android.os.Build; import android.os.StatFs; diff --git a/briar-android/src/org/briarproject/system/AndroidSeedProvider.java b/briar-android/src/org/briarproject/system/AndroidSeedProvider.java index f53b1fea54..2cc9ac48d5 100644 --- a/briar-android/src/org/briarproject/system/AndroidSeedProvider.java +++ b/briar-android/src/org/briarproject/system/AndroidSeedProvider.java @@ -2,6 +2,7 @@ package org.briarproject.system; import java.io.DataOutputStream; import java.io.IOException; + import android.annotation.SuppressLint; import android.os.Build; diff --git a/briar-api/src/org/briarproject/api/crypto/CryptoComponent.java b/briar-api/src/org/briarproject/api/crypto/CryptoComponent.java index e40614efc6..b946f57606 100644 --- a/briar-api/src/org/briarproject/api/crypto/CryptoComponent.java +++ b/briar-api/src/org/briarproject/api/crypto/CryptoComponent.java @@ -71,21 +71,20 @@ public interface CryptoComponent { SecretKey deriveTagKey(byte[] secret, boolean alice); /** - * Derives a frame key from the given temporary secret and connection - * number. + * Derives a frame key from the given temporary secret and stream number. * @param alice indicates whether the key is for a connection initiated by * Alice or Bob. * @param initiator indicates whether the key is for the initiator's or the * responder's side of the connection. */ - SecretKey deriveFrameKey(byte[] secret, long connection, boolean alice, + SecretKey deriveFrameKey(byte[] secret, long streamNumber, boolean alice, boolean initiator); - /** Returns a cipher for encrypting and authenticating connections. */ + /** Returns a cipher for encrypting and authenticating frames. */ AuthenticatedCipher getFrameCipher(); - /** Encodes the pseudo-random tag that is used to recognise a connection. */ - void encodeTag(byte[] tag, SecretKey tagKey, long connection); + /** Encodes the pseudo-random tag that is used to recognise a stream. */ + void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber); /** * Encrypts and authenticates the given plaintext so it can be written to diff --git a/briar-api/src/org/briarproject/api/crypto/KeyManager.java b/briar-api/src/org/briarproject/api/crypto/KeyManager.java index 94bc503a13..59e4d7af30 100644 --- a/briar-api/src/org/briarproject/api/crypto/KeyManager.java +++ b/briar-api/src/org/briarproject/api/crypto/KeyManager.java @@ -3,21 +3,22 @@ package org.briarproject.api.crypto; import org.briarproject.api.ContactId; import org.briarproject.api.TransportId; import org.briarproject.api.lifecycle.Service; -import org.briarproject.api.transport.ConnectionContext; import org.briarproject.api.transport.Endpoint; +import org.briarproject.api.transport.StreamContext; public interface KeyManager extends Service { /** - * Returns a connection context for connecting to the given contact over - * the given transport, or null if an error occurs or the contact does not - * support the transport. + * Returns a {@link org.briarproject.api.transport.StreamContext + * StreamContext} for sending data to the given contact over the given + * transport, or null if an error occurs or the contact does not support + * the transport. */ - ConnectionContext getConnectionContext(ContactId c, TransportId t); + StreamContext getStreamContext(ContactId c, TransportId t); /** - * Called whenever an endpoint has been added. The initial secret - * is erased before returning. + * Called whenever an endpoint has been added. The initial secret is erased + * before returning. */ void endpointAdded(Endpoint ep, long maxLatency, byte[] initialSecret); } diff --git a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java index 751ef78c9a..e7b55dd6d2 100644 --- a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java +++ b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java @@ -237,11 +237,11 @@ public interface DatabaseComponent { Collection<ContactId> getVisibility(GroupId g) throws DbException; /** - * Increments the outgoing connection counter for the given endpoint - * in the given rotation period and returns the old value, or -1 if the - * counter does not exist. + * Increments the outgoing stream counter for the given endpoint in the + * given rotation period and returns the old value, or -1 if the counter + * does not exist. */ - long incrementConnectionCounter(ContactId c, TransportId t, long period) + long incrementStreamCounter(ContactId c, TransportId t, long period) throws DbException; /** @@ -315,10 +315,10 @@ public interface DatabaseComponent { void removeTransport(TransportId t) throws DbException; /** - * Sets the connection reordering window for the given endpoint in the - * given rotation period. + * Sets the reordering window for the given endpoint in the given rotation + * period. */ - void setConnectionWindow(ContactId c, TransportId t, long period, + void setReorderingWindow(ContactId c, TransportId t, long period, long centre, byte[] bitmap) throws DbException; /** diff --git a/briar-api/src/org/briarproject/api/messaging/MessagingConstants.java b/briar-api/src/org/briarproject/api/messaging/MessagingConstants.java index a30881eca6..0f52b49010 100644 --- a/briar-api/src/org/briarproject/api/messaging/MessagingConstants.java +++ b/briar-api/src/org/briarproject/api/messaging/MessagingConstants.java @@ -1,15 +1,15 @@ package org.briarproject.api.messaging; -import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; +import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH; public interface MessagingConstants { /** * The maximum length of a serialised packet in bytes. To allow for future - * changes in the protocol, this is smaller than the minimum connection - * length minus the maximum encryption and authentication overhead. + * changes in the protocol, this is smaller than the minimum stream length + * minus the maximum encryption and authentication overhead. */ - int MAX_PACKET_LENGTH = MIN_CONNECTION_LENGTH / 2; + int MAX_PACKET_LENGTH = MIN_STREAM_LENGTH / 2; /** The maximum number of public groups a user may subscribe to. */ int MAX_SUBSCRIPTIONS = 3000; diff --git a/briar-api/src/org/briarproject/api/messaging/duplex/DuplexConnectionFactory.java b/briar-api/src/org/briarproject/api/messaging/duplex/DuplexConnectionFactory.java index b0c8e313ea..977df2176f 100644 --- a/briar-api/src/org/briarproject/api/messaging/duplex/DuplexConnectionFactory.java +++ b/briar-api/src/org/briarproject/api/messaging/duplex/DuplexConnectionFactory.java @@ -3,11 +3,11 @@ package org.briarproject.api.messaging.duplex; import org.briarproject.api.ContactId; import org.briarproject.api.TransportId; import org.briarproject.api.plugins.duplex.DuplexTransportConnection; -import org.briarproject.api.transport.ConnectionContext; +import org.briarproject.api.transport.StreamContext; public interface DuplexConnectionFactory { - void createIncomingConnection(ConnectionContext ctx, + void createIncomingConnection(StreamContext ctx, DuplexTransportConnection d); void createOutgoingConnection(ContactId c, TransportId t, diff --git a/briar-api/src/org/briarproject/api/messaging/simplex/SimplexConnectionFactory.java b/briar-api/src/org/briarproject/api/messaging/simplex/SimplexConnectionFactory.java index 8ecd4978bd..61f75a084a 100644 --- a/briar-api/src/org/briarproject/api/messaging/simplex/SimplexConnectionFactory.java +++ b/briar-api/src/org/briarproject/api/messaging/simplex/SimplexConnectionFactory.java @@ -4,11 +4,11 @@ import org.briarproject.api.ContactId; import org.briarproject.api.TransportId; import org.briarproject.api.plugins.simplex.SimplexTransportReader; import org.briarproject.api.plugins.simplex.SimplexTransportWriter; -import org.briarproject.api.transport.ConnectionContext; +import org.briarproject.api.transport.StreamContext; public interface SimplexConnectionFactory { - void createIncomingConnection(ConnectionContext ctx, + void createIncomingConnection(StreamContext ctx, SimplexTransportReader r); void createOutgoingConnection(ContactId c, TransportId t, diff --git a/briar-api/src/org/briarproject/api/transport/ConnectionDispatcher.java b/briar-api/src/org/briarproject/api/transport/ConnectionDispatcher.java index eb81685ec7..27f41ce3fa 100644 --- a/briar-api/src/org/briarproject/api/transport/ConnectionDispatcher.java +++ b/briar-api/src/org/briarproject/api/transport/ConnectionDispatcher.java @@ -8,13 +8,13 @@ import org.briarproject.api.plugins.simplex.SimplexTransportWriter; public interface ConnectionDispatcher { - void dispatchReader(TransportId t, SimplexTransportReader r); - - void dispatchWriter(ContactId c, TransportId t, - SimplexTransportWriter w); + void dispatchIncomingConnection(TransportId t, SimplexTransportReader r); void dispatchIncomingConnection(TransportId t, DuplexTransportConnection d); + void dispatchOutgoingConnection(ContactId c, TransportId t, + SimplexTransportWriter w); + void dispatchOutgoingConnection(ContactId c, TransportId t, DuplexTransportConnection d); } diff --git a/briar-api/src/org/briarproject/api/transport/ConnectionReaderFactory.java b/briar-api/src/org/briarproject/api/transport/ConnectionReaderFactory.java deleted file mode 100644 index 2757e43180..0000000000 --- a/briar-api/src/org/briarproject/api/transport/ConnectionReaderFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.briarproject.api.transport; - -import java.io.InputStream; - -public interface ConnectionReaderFactory { - - /** Creates a connection reader for one side of a connection. */ - ConnectionReader createConnectionReader(InputStream in, int maxFrameLength, - ConnectionContext ctx, boolean incoming, boolean initiator); - - /** Creates a connection reader for one side of an invitation connection. */ - ConnectionReader createInvitationConnectionReader(InputStream in, - int maxFrameLength, byte[] secret, boolean alice); -} diff --git a/briar-api/src/org/briarproject/api/transport/ConnectionRecogniser.java b/briar-api/src/org/briarproject/api/transport/ConnectionRecogniser.java deleted file mode 100644 index 39ec863005..0000000000 --- a/briar-api/src/org/briarproject/api/transport/ConnectionRecogniser.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.briarproject.api.transport; - -import org.briarproject.api.ContactId; -import org.briarproject.api.TransportId; -import org.briarproject.api.db.DbException; - -/** - * Maintains the connection reordering windows and decides whether incoming - * connections should be accepted or rejected. - */ -public interface ConnectionRecogniser { - - /** - * Returns the context for the given connection if the connection was - * expected, or null if the connection was not expected. - */ - ConnectionContext acceptConnection(TransportId t, byte[] tag) - throws DbException; - - void addSecret(TemporarySecret s); - - void removeSecret(ContactId c, TransportId t, long period); - - void removeSecrets(ContactId c); - - void removeSecrets(TransportId t); - - void removeSecrets(); -} diff --git a/briar-api/src/org/briarproject/api/transport/ConnectionWriterFactory.java b/briar-api/src/org/briarproject/api/transport/ConnectionWriterFactory.java deleted file mode 100644 index 017ca9fdae..0000000000 --- a/briar-api/src/org/briarproject/api/transport/ConnectionWriterFactory.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.briarproject.api.transport; - -import java.io.OutputStream; - -public interface ConnectionWriterFactory { - - /** Creates a connection writer for one side of a connection. */ - ConnectionWriter createConnectionWriter(OutputStream out, - int maxFrameLength, long capacity, ConnectionContext ctx, - boolean incoming, boolean initiator); - - /** Creates a connection writer for one side of an invitation connection. */ - ConnectionWriter createInvitationConnectionWriter(OutputStream out, - int maxFrameLength, byte[] secret, boolean alice); -} diff --git a/briar-api/src/org/briarproject/api/transport/ConnectionContext.java b/briar-api/src/org/briarproject/api/transport/StreamContext.java similarity index 68% rename from briar-api/src/org/briarproject/api/transport/ConnectionContext.java rename to briar-api/src/org/briarproject/api/transport/StreamContext.java index 16434bdc53..61554c0ace 100644 --- a/briar-api/src/org/briarproject/api/transport/ConnectionContext.java +++ b/briar-api/src/org/briarproject/api/transport/StreamContext.java @@ -3,20 +3,20 @@ package org.briarproject.api.transport; import org.briarproject.api.ContactId; import org.briarproject.api.TransportId; -public class ConnectionContext { +public class StreamContext { private final ContactId contactId; private final TransportId transportId; private final byte[] secret; - private final long connection; + private final long streamNumber; private final boolean alice; - public ConnectionContext(ContactId contactId, TransportId transportId, - byte[] secret, long connection, boolean alice) { + public StreamContext(ContactId contactId, TransportId transportId, + byte[] secret, long streamNumber, boolean alice) { this.contactId = contactId; this.transportId = transportId; this.secret = secret; - this.connection = connection; + this.streamNumber = streamNumber; this.alice = alice; } @@ -32,8 +32,8 @@ public class ConnectionContext { return secret; } - public long getConnectionNumber() { - return connection; + public long getStreamNumber() { + return streamNumber; } public boolean getAlice() { diff --git a/briar-api/src/org/briarproject/api/transport/ConnectionReader.java b/briar-api/src/org/briarproject/api/transport/StreamReader.java similarity index 64% rename from briar-api/src/org/briarproject/api/transport/ConnectionReader.java rename to briar-api/src/org/briarproject/api/transport/StreamReader.java index a4dc40b152..2fef7b4df0 100644 --- a/briar-api/src/org/briarproject/api/transport/ConnectionReader.java +++ b/briar-api/src/org/briarproject/api/transport/StreamReader.java @@ -2,8 +2,8 @@ package org.briarproject.api.transport; import java.io.InputStream; -/** Decrypts and authenticates data received over a connection. */ -public interface ConnectionReader { +/** Decrypts and authenticates data received over an underlying transport. */ +public interface StreamReader { /** * Returns an input stream from which the decrypted, authenticated data can diff --git a/briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java b/briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java new file mode 100644 index 0000000000..8c43c30eb5 --- /dev/null +++ b/briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java @@ -0,0 +1,14 @@ +package org.briarproject.api.transport; + +import java.io.InputStream; + +public interface StreamReaderFactory { + + /** Creates a {@link StreamReader} for a transport connection. */ + StreamReader createStreamReader(InputStream in, int maxFrameLength, + StreamContext ctx, boolean incoming, boolean initiator); + + /** Creates a {@link StreamReader} for an invitation connection. */ + StreamReader createInvitationStreamReader(InputStream in, + int maxFrameLength, byte[] secret, boolean alice); +} diff --git a/briar-api/src/org/briarproject/api/transport/ConnectionWriter.java b/briar-api/src/org/briarproject/api/transport/StreamWriter.java similarity index 53% rename from briar-api/src/org/briarproject/api/transport/ConnectionWriter.java rename to briar-api/src/org/briarproject/api/transport/StreamWriter.java index b195785991..e5f50ecce8 100644 --- a/briar-api/src/org/briarproject/api/transport/ConnectionWriter.java +++ b/briar-api/src/org/briarproject/api/transport/StreamWriter.java @@ -2,8 +2,8 @@ package org.briarproject.api.transport; import java.io.OutputStream; -/** Encrypts and authenticates data to be sent over a connection. */ -public interface ConnectionWriter { +/** Encrypts and authenticates data to be sent over an underlying transport. */ +public interface StreamWriter { /** * Returns an output stream to which unencrypted, unauthenticated data can @@ -11,6 +11,9 @@ public interface ConnectionWriter { */ OutputStream getOutputStream(); - /** Returns the maximum number of bytes that can be written. */ + /** + * Returns the maximum number of bytes that can be written to the output + * stream. + */ long getRemainingCapacity(); } diff --git a/briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java b/briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java new file mode 100644 index 0000000000..f3b8e1c2f8 --- /dev/null +++ b/briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java @@ -0,0 +1,15 @@ +package org.briarproject.api.transport; + +import java.io.OutputStream; + +public interface StreamWriterFactory { + + /** Creates a {@link StreamWriter} for a transport connection. */ + StreamWriter createStreamWriter(OutputStream out, int maxFrameLength, + long capacity, StreamContext ctx, boolean incoming, + boolean initiator); + + /** Creates a {@link StreamWriter} for an invitation connection. */ + StreamWriter createInvitationStreamWriter(OutputStream out, + int maxFrameLength, byte[] secret, boolean alice); +} diff --git a/briar-api/src/org/briarproject/api/transport/TagRecogniser.java b/briar-api/src/org/briarproject/api/transport/TagRecogniser.java new file mode 100644 index 0000000000..a6823a2e93 --- /dev/null +++ b/briar-api/src/org/briarproject/api/transport/TagRecogniser.java @@ -0,0 +1,25 @@ +package org.briarproject.api.transport; + +import org.briarproject.api.ContactId; +import org.briarproject.api.TransportId; +import org.briarproject.api.db.DbException; + +/** Maintains the table of expected tags for recognising incoming streams. */ +public interface TagRecogniser { + + /** + * Returns a {@link StreamContext} for reading from the stream with the + * given tag if the tag was expected, or null if the tag was unexpected. + */ + StreamContext recogniseTag(TransportId t, byte[] tag) throws DbException; + + void addSecret(TemporarySecret s); + + void removeSecret(ContactId c, TransportId t, long period); + + void removeSecrets(ContactId c); + + void removeSecrets(TransportId t); + + void removeSecrets(); +} diff --git a/briar-api/src/org/briarproject/api/transport/TemporarySecret.java b/briar-api/src/org/briarproject/api/transport/TemporarySecret.java index f3a858425e..37ed630e46 100644 --- a/briar-api/src/org/briarproject/api/transport/TemporarySecret.java +++ b/briar-api/src/org/briarproject/api/transport/TemporarySecret.java @@ -1,6 +1,7 @@ package org.briarproject.api.transport; -import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE; +import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE; + import org.briarproject.api.ContactId; import org.briarproject.api.TransportId; @@ -9,7 +10,7 @@ public class TemporarySecret extends Endpoint { private final long period, outgoing, centre; private final byte[] secret, bitmap; - /** Creates a temporary secret with the given connection window. */ + /** Creates a temporary secret with the given reordering window. */ public TemporarySecret(ContactId contactId, TransportId transportId, long epoch, boolean alice, long period, byte[] secret, long outgoing, long centre, byte[] bitmap) { @@ -21,11 +22,11 @@ public class TemporarySecret extends Endpoint { this.bitmap = bitmap; } - /** Creates a temporary secret with a new connection window. */ + /** Creates a temporary secret with a new reordering window. */ public TemporarySecret(ContactId contactId, TransportId transportId, long epoch, boolean alice, long period, byte[] secret) { this(contactId, transportId, epoch, alice, period, secret, 0, 0, - new byte[CONNECTION_WINDOW_SIZE / 8]); + new byte[REORDERING_WINDOW_SIZE / 8]); } /** Creates a temporary secret derived from the given endpoint. */ @@ -42,7 +43,7 @@ public class TemporarySecret extends Endpoint { return secret; } - public long getOutgoingConnectionCounter() { + public long getOutgoingStreamCounter() { return outgoing; } diff --git a/briar-api/src/org/briarproject/api/transport/TransportConstants.java b/briar-api/src/org/briarproject/api/transport/TransportConstants.java index da5eff390f..666d74e964 100644 --- a/briar-api/src/org/briarproject/api/transport/TransportConstants.java +++ b/briar-api/src/org/briarproject/api/transport/TransportConstants.java @@ -2,7 +2,7 @@ package org.briarproject.api.transport; public interface TransportConstants { - /** The length of the connection tag in bytes. */ + /** The length of the pseudo-random tag in bytes. */ int TAG_LENGTH = 16; /** The maximum length of a frame in bytes, including the header and MAC. */ @@ -21,15 +21,15 @@ public interface TransportConstants { int MAC_LENGTH = 16; /** - * The minimum connection length in bytes that all transport plugins must - * support. Connections may be shorter than this length, but all transport - * plugins must support connections of at least this length. + * The minimum stream length in bytes that all transport plugins must + * support. Streams may be shorter than this length, but all transport + * plugins must support streams of at least this length. */ - int MIN_CONNECTION_LENGTH = 1024 * 1024; // 2^20, 1 MiB + int MIN_STREAM_LENGTH = 1024 * 1024; // 2^20, 1 MiB /** The maximum difference between two communicating devices' clocks. */ int MAX_CLOCK_DIFFERENCE = 60 * 60 * 1000; // 1 hour - /** The size of the connection reordering window. */ - int CONNECTION_WINDOW_SIZE = 32; + /** The size of the reordering window. */ + int REORDERING_WINDOW_SIZE = 32; } diff --git a/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java b/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java index 167fb84f33..dc4dbba95c 100644 --- a/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java +++ b/briar-core/src/org/briarproject/crypto/CryptoComponentImpl.java @@ -287,20 +287,20 @@ class CryptoComponentImpl implements CryptoComponent { else return deriveKey(secret, B_TAG, 0); } - public SecretKey deriveFrameKey(byte[] secret, long connection, + public SecretKey deriveFrameKey(byte[] secret, long streamNumber, boolean alice, boolean initiator) { if(secret.length != CIPHER_KEY_BYTES) throw new IllegalArgumentException(); if(Arrays.equals(secret, BLANK_SECRET)) throw new IllegalArgumentException(); - if(connection < 0 || connection > MAX_32_BIT_UNSIGNED) + if(streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException(); if(alice) { - if(initiator) return deriveKey(secret, A_FRAME_A, connection); - else return deriveKey(secret, A_FRAME_B, connection); + if(initiator) return deriveKey(secret, A_FRAME_A, streamNumber); + else return deriveKey(secret, A_FRAME_B, streamNumber); } else { - if(initiator) return deriveKey(secret, B_FRAME_A, connection); - else return deriveKey(secret, B_FRAME_B, connection); + if(initiator) return deriveKey(secret, B_FRAME_A, streamNumber); + else return deriveKey(secret, B_FRAME_B, streamNumber); } } @@ -318,12 +318,12 @@ class CryptoComponentImpl implements CryptoComponent { return new AuthenticatedCipherImpl(a, MAC_BYTES); } - public void encodeTag(byte[] tag, SecretKey tagKey, long connection) { + public void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber) { if(tag.length < TAG_LENGTH) throw new IllegalArgumentException(); - if(connection < 0 || connection > MAX_32_BIT_UNSIGNED) + if(streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException(); for(int i = 0; i < TAG_LENGTH; i++) tag[i] = 0; - ByteUtils.writeUint32(connection, tag, 0); + ByteUtils.writeUint32(streamNumber, tag, 0); BlockCipher cipher = new AESLightEngine(); assert cipher.getBlockSize() == TAG_LENGTH; KeyParameter k = new KeyParameter(tagKey.getEncoded()); diff --git a/briar-core/src/org/briarproject/crypto/DoubleDigest.java b/briar-core/src/org/briarproject/crypto/DoubleDigest.java index c6186596f1..1d1fdd99d1 100644 --- a/briar-core/src/org/briarproject/crypto/DoubleDigest.java +++ b/briar-core/src/org/briarproject/crypto/DoubleDigest.java @@ -1,7 +1,6 @@ package org.briarproject.crypto; import org.briarproject.api.crypto.MessageDigest; - import org.spongycastle.crypto.Digest; /** diff --git a/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java b/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java index 256001dbaf..ff38772074 100644 --- a/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java +++ b/briar-core/src/org/briarproject/crypto/Sec1PrivateKey.java @@ -1,7 +1,6 @@ package org.briarproject.crypto; import org.briarproject.api.crypto.PrivateKey; - import org.spongycastle.crypto.params.ECPrivateKeyParameters; class Sec1PrivateKey implements PrivateKey { diff --git a/briar-core/src/org/briarproject/db/Database.java b/briar-core/src/org/briarproject/db/Database.java index ad0fb223e0..5bce51798e 100644 --- a/briar-core/src/org/briarproject/db/Database.java +++ b/briar-core/src/org/briarproject/db/Database.java @@ -542,14 +542,14 @@ interface Database<T> { Collection<ContactId> getVisibility(T txn, GroupId g) throws DbException; /** - * Increments the outgoing connection counter for the given endpoint - * in the given rotation period and returns the old value, or -1 if the - * counter does not exist. + * Increments the outgoing stream counter for the given endpoint in the + * given rotation period and returns the old value, or -1 if the counter + * does not exist. * <p> * Locking: write. */ - long incrementConnectionCounter(T txn, ContactId c, TransportId t, - long period) throws DbException; + long incrementStreamCounter(T txn, ContactId c, TransportId t, long period) + throws DbException; /** * Increments the retention time versions for all contacts to indicate that @@ -694,12 +694,12 @@ interface Database<T> { void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException; /** - * Sets the connection reordering window for the given endpoint in the - * given rotation period. + * Sets the reordering window for the given endpoint in the given rotation + * period. * <p> * Locking: write. */ - void setConnectionWindow(T txn, ContactId c, TransportId t, long period, + void setReorderingWindow(T txn, ContactId c, TransportId t, long period, long centre, byte[] bitmap) throws DbException; /** diff --git a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java index 6683d36702..c22643f0be 100644 --- a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java +++ b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java @@ -986,7 +986,7 @@ DatabaseCleaner.Callback { } } - public long incrementConnectionCounter(ContactId c, TransportId t, + public long incrementStreamCounter(ContactId c, TransportId t, long period) throws DbException { lock.writeLock().lock(); try { @@ -996,7 +996,7 @@ DatabaseCleaner.Callback { throw new NoSuchContactException(); if(!db.containsTransport(txn, t)) throw new NoSuchTransportException(); - long counter = db.incrementConnectionCounter(txn, c, t, period); + long counter = db.incrementStreamCounter(txn, c, t, period); db.commitTransaction(txn); return counter; } catch(DbException e) { @@ -1401,7 +1401,7 @@ DatabaseCleaner.Callback { eventBus.broadcast(new TransportRemovedEvent(t)); } - public void setConnectionWindow(ContactId c, TransportId t, long period, + public void setReorderingWindow(ContactId c, TransportId t, long period, long centre, byte[] bitmap) throws DbException { lock.writeLock().lock(); try { @@ -1411,7 +1411,7 @@ DatabaseCleaner.Callback { throw new NoSuchContactException(); if(!db.containsTransport(txn, t)) throw new NoSuchTransportException(); - db.setConnectionWindow(txn, c, t, period, centre, bitmap); + db.setReorderingWindow(txn, c, t, period, centre, bitmap); db.commitTransaction(txn); } catch(DbException e) { db.abortTransaction(txn); diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java index 5d51ad1049..fdeab4e543 100644 --- a/briar-core/src/org/briarproject/db/JdbcDatabase.java +++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java @@ -813,7 +813,7 @@ abstract class JdbcDatabase implements Database<Connection> { ps.setString(2, s.getTransportId().getString()); ps.setLong(3, s.getPeriod()); ps.setBytes(4, s.getSecret()); - ps.setLong(5, s.getOutgoingConnectionCounter()); + ps.setLong(5, s.getOutgoingStreamCounter()); ps.setLong(6, s.getWindowCentre()); ps.setBytes(7, s.getWindowBitmap()); ps.addBatch(); @@ -2433,12 +2433,12 @@ abstract class JdbcDatabase implements Database<Connection> { } } - public long incrementConnectionCounter(Connection txn, ContactId c, + public long incrementStreamCounter(Connection txn, ContactId c, TransportId t, long period) throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { - // Get the current connection counter + // Get the current stream counter String sql = "SELECT outgoing FROM secrets" + " WHERE contactId = ? AND transportId = ? AND period = ?"; ps = txn.prepareStatement(sql); @@ -2451,11 +2451,11 @@ abstract class JdbcDatabase implements Database<Connection> { ps.close(); return -1; } - long connection = rs.getLong(1); + long streamNumber = rs.getLong(1); if(rs.next()) throw new DbStateException(); rs.close(); ps.close(); - // Increment the connection counter + // Increment the stream counter sql = "UPDATE secrets SET outgoing = outgoing + 1" + " WHERE contactId = ? AND transportId = ? AND period = ?"; ps = txn.prepareStatement(sql); @@ -2465,7 +2465,7 @@ abstract class JdbcDatabase implements Database<Connection> { int affected = ps.executeUpdate(); if(affected != 1) throw new DbStateException(); ps.close(); - return connection; + return streamNumber; } catch(SQLException e) { tryToClose(ps); tryToClose(rs); @@ -2907,7 +2907,7 @@ abstract class JdbcDatabase implements Database<Connection> { throw new DbException(e); } } - public void setConnectionWindow(Connection txn, ContactId c, TransportId t, + public void setReorderingWindow(Connection txn, ContactId c, TransportId t, long period, long centre, byte[] bitmap) throws DbException { PreparedStatement ps = null; try { diff --git a/briar-core/src/org/briarproject/invitation/AliceConnector.java b/briar-core/src/org/briarproject/invitation/AliceConnector.java index 18d603ba00..455e1a6bda 100644 --- a/briar-core/src/org/briarproject/invitation/AliceConnector.java +++ b/briar-core/src/org/briarproject/invitation/AliceConnector.java @@ -29,10 +29,10 @@ import org.briarproject.api.serial.Writer; import org.briarproject.api.serial.WriterFactory; import org.briarproject.api.system.Clock; import org.briarproject.api.transport.ConnectionDispatcher; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; /** A connection thread for the peer being Alice in the invitation protocol. */ class AliceConnector extends Connector { @@ -42,16 +42,16 @@ class AliceConnector extends Connector { AliceConnector(CryptoComponent crypto, DatabaseComponent db, ReaderFactory readerFactory, WriterFactory writerFactory, - ConnectionReaderFactory connectionReaderFactory, - ConnectionWriterFactory connectionWriterFactory, + StreamReaderFactory streamReaderFactory, + StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, KeyManager keyManager, ConnectionDispatcher connectionDispatcher, Clock clock, boolean reuseConnection, ConnectorGroup group, DuplexPlugin plugin, LocalAuthor localAuthor, Map<TransportId, TransportProperties> localProps, PseudoRandom random) { - super(crypto, db, readerFactory, writerFactory, connectionReaderFactory, - connectionWriterFactory, authorFactory, groupFactory, + super(crypto, db, readerFactory, writerFactory, streamReaderFactory, + streamWriterFactory, authorFactory, groupFactory, keyManager, connectionDispatcher, clock, reuseConnection, group, plugin, localAuthor, localProps, random); } @@ -131,14 +131,14 @@ class AliceConnector extends Connector { if(LOG.isLoggable(INFO)) LOG.info(pluginName + " confirmation succeeded"); int maxFrameLength = conn.getMaxFrameLength(); - ConnectionReader connectionReader = - connectionReaderFactory.createInvitationConnectionReader(in, + StreamReader streamReader = + streamReaderFactory.createInvitationStreamReader(in, maxFrameLength, secret, false); - r = readerFactory.createReader(connectionReader.getInputStream()); - ConnectionWriter connectionWriter = - connectionWriterFactory.createInvitationConnectionWriter(out, + r = readerFactory.createReader(streamReader.getInputStream()); + StreamWriter streamWriter = + streamWriterFactory.createInvitationStreamWriter(out, maxFrameLength, secret, true); - w = writerFactory.createWriter(connectionWriter.getOutputStream()); + w = writerFactory.createWriter(streamWriter.getOutputStream()); // Derive the invitation nonces byte[][] nonces = crypto.deriveInvitationNonces(secret); byte[] aliceNonce = nonces[0], bobNonce = nonces[1]; @@ -179,7 +179,7 @@ class AliceConnector extends Connector { if(LOG.isLoggable(INFO)) LOG.info(pluginName + " pseudonym exchange succeeded"); group.pseudonymExchangeSucceeded(remoteAuthor); - // Reuse the connection as an outgoing BTP connection + // Reuse the connection as an outgoing transport connection if(reuseConnection) reuseConnection(conn, true); else tryToClose(conn, false); } diff --git a/briar-core/src/org/briarproject/invitation/BobConnector.java b/briar-core/src/org/briarproject/invitation/BobConnector.java index c51dec4e22..584f5b81f9 100644 --- a/briar-core/src/org/briarproject/invitation/BobConnector.java +++ b/briar-core/src/org/briarproject/invitation/BobConnector.java @@ -29,10 +29,10 @@ import org.briarproject.api.serial.Writer; import org.briarproject.api.serial.WriterFactory; import org.briarproject.api.system.Clock; import org.briarproject.api.transport.ConnectionDispatcher; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; /** A connection thread for the peer being Bob in the invitation protocol. */ class BobConnector extends Connector { @@ -42,16 +42,16 @@ class BobConnector extends Connector { BobConnector(CryptoComponent crypto, DatabaseComponent db, ReaderFactory readerFactory, WriterFactory writerFactory, - ConnectionReaderFactory connectionReaderFactory, - ConnectionWriterFactory connectionWriterFactory, + StreamReaderFactory streamReaderFactory, + StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, KeyManager keyManager, ConnectionDispatcher connectionDispatcher, Clock clock, boolean reuseConnection, ConnectorGroup group, DuplexPlugin plugin, LocalAuthor localAuthor, Map<TransportId, TransportProperties> localProps, PseudoRandom random) { - super(crypto, db, readerFactory, writerFactory, connectionReaderFactory, - connectionWriterFactory, authorFactory, groupFactory, + super(crypto, db, readerFactory, writerFactory, streamReaderFactory, + streamWriterFactory, authorFactory, groupFactory, keyManager, connectionDispatcher, clock, reuseConnection, group, plugin, localAuthor, localProps, random); } @@ -131,14 +131,14 @@ class BobConnector extends Connector { if(LOG.isLoggable(INFO)) LOG.info(pluginName + " confirmation succeeded"); int maxFrameLength = conn.getMaxFrameLength(); - ConnectionReader connectionReader = - connectionReaderFactory.createInvitationConnectionReader(in, + StreamReader streamReader = + streamReaderFactory.createInvitationStreamReader(in, maxFrameLength, secret, true); - r = readerFactory.createReader(connectionReader.getInputStream()); - ConnectionWriter connectionWriter = - connectionWriterFactory.createInvitationConnectionWriter(out, + r = readerFactory.createReader(streamReader.getInputStream()); + StreamWriter streamWriter = + streamWriterFactory.createInvitationStreamWriter(out, maxFrameLength, secret, false); - w = writerFactory.createWriter(connectionWriter.getOutputStream()); + w = writerFactory.createWriter(streamWriter.getOutputStream()); // Derive the nonces byte[][] nonces = crypto.deriveInvitationNonces(secret); byte[] aliceNonce = nonces[0], bobNonce = nonces[1]; @@ -179,7 +179,7 @@ class BobConnector extends Connector { if(LOG.isLoggable(INFO)) LOG.info(pluginName + " pseudonym exchange succeeded"); group.pseudonymExchangeSucceeded(remoteAuthor); - // Reuse the connection as an incoming BTP connection + // Reuse the connection as an incoming transport connection if(reuseConnection) reuseConnection(conn, false); else tryToClose(conn, false); } diff --git a/briar-core/src/org/briarproject/invitation/Connector.java b/briar-core/src/org/briarproject/invitation/Connector.java index 74d88dac0f..36b84860f5 100644 --- a/briar-core/src/org/briarproject/invitation/Connector.java +++ b/briar-core/src/org/briarproject/invitation/Connector.java @@ -51,9 +51,9 @@ import org.briarproject.api.serial.Writer; import org.briarproject.api.serial.WriterFactory; import org.briarproject.api.system.Clock; import org.briarproject.api.transport.ConnectionDispatcher; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionWriterFactory; import org.briarproject.api.transport.Endpoint; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriterFactory; abstract class Connector extends Thread { @@ -64,8 +64,8 @@ abstract class Connector extends Thread { protected final DatabaseComponent db; protected final ReaderFactory readerFactory; protected final WriterFactory writerFactory; - protected final ConnectionReaderFactory connectionReaderFactory; - protected final ConnectionWriterFactory connectionWriterFactory; + protected final StreamReaderFactory streamReaderFactory; + protected final StreamWriterFactory streamWriterFactory; protected final AuthorFactory authorFactory; protected final GroupFactory groupFactory; protected final KeyManager keyManager; @@ -87,8 +87,8 @@ abstract class Connector extends Thread { Connector(CryptoComponent crypto, DatabaseComponent db, ReaderFactory readerFactory, WriterFactory writerFactory, - ConnectionReaderFactory connectionReaderFactory, - ConnectionWriterFactory connectionWriterFactory, + StreamReaderFactory streamReaderFactory, + StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, KeyManager keyManager, ConnectionDispatcher connectionDispatcher, Clock clock, boolean reuseConnection, ConnectorGroup group, @@ -100,8 +100,8 @@ abstract class Connector extends Thread { this.db = db; this.readerFactory = readerFactory; this.writerFactory = writerFactory; - this.connectionReaderFactory = connectionReaderFactory; - this.connectionWriterFactory = connectionWriterFactory; + this.streamReaderFactory = streamReaderFactory; + this.streamWriterFactory = streamWriterFactory; this.authorFactory = authorFactory; this.groupFactory = groupFactory; this.keyManager = keyManager; diff --git a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java index 7ce73fcc85..7473c27b7e 100644 --- a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java +++ b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java @@ -33,8 +33,8 @@ import org.briarproject.api.serial.ReaderFactory; import org.briarproject.api.serial.WriterFactory; import org.briarproject.api.system.Clock; import org.briarproject.api.transport.ConnectionDispatcher; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriterFactory; /** A task consisting of one or more parallel connection attempts. */ class ConnectorGroup extends Thread implements InvitationTask { @@ -46,8 +46,8 @@ class ConnectorGroup extends Thread implements InvitationTask { private final DatabaseComponent db; private final ReaderFactory readerFactory; private final WriterFactory writerFactory; - private final ConnectionReaderFactory connectionReaderFactory; - private final ConnectionWriterFactory connectionWriterFactory; + private final StreamReaderFactory streamReaderFactory; + private final StreamWriterFactory streamWriterFactory; private final AuthorFactory authorFactory; private final GroupFactory groupFactory; private final KeyManager keyManager; @@ -64,8 +64,8 @@ class ConnectorGroup extends Thread implements InvitationTask { /* * All of the following require locking: this. We don't want to call the * listeners with a lock held, but we need to avoid a race condition in - * addListener(), so the state that's accessed there after calling - * listeners.add() must be guarded by a lock. + * addListener(), so the state that's accessed in addListener() after + * calling listeners.add() must be guarded by a lock. */ private int localConfirmationCode = -1, remoteConfirmationCode = -1; private boolean connectionFailed = false; @@ -75,8 +75,8 @@ class ConnectorGroup extends Thread implements InvitationTask { ConnectorGroup(CryptoComponent crypto, DatabaseComponent db, ReaderFactory readerFactory, WriterFactory writerFactory, - ConnectionReaderFactory connectionReaderFactory, - ConnectionWriterFactory connectionWriterFactory, + StreamReaderFactory streamReaderFactory, + StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, KeyManager keyManager, ConnectionDispatcher connectionDispatcher, Clock clock, PluginManager pluginManager, AuthorId localAuthorId, @@ -87,8 +87,8 @@ class ConnectorGroup extends Thread implements InvitationTask { this.db = db; this.readerFactory = readerFactory; this.writerFactory = writerFactory; - this.connectionReaderFactory = connectionReaderFactory; - this.connectionWriterFactory = connectionWriterFactory; + this.streamReaderFactory = streamReaderFactory; + this.streamWriterFactory = streamWriterFactory; this.authorFactory = authorFactory; this.groupFactory = groupFactory; this.keyManager = keyManager; @@ -176,7 +176,7 @@ class ConnectorGroup extends Thread implements InvitationTask { PseudoRandom random = crypto.getPseudoRandom(localInvitationCode, remoteInvitationCode); return new AliceConnector(crypto, db, readerFactory, writerFactory, - connectionReaderFactory, connectionWriterFactory, authorFactory, + streamReaderFactory, streamWriterFactory, authorFactory, groupFactory, keyManager, connectionDispatcher, clock, reuseConnection, this, plugin, localAuthor, localProps, random); } @@ -187,7 +187,7 @@ class ConnectorGroup extends Thread implements InvitationTask { PseudoRandom random = crypto.getPseudoRandom(remoteInvitationCode, localInvitationCode); return new BobConnector(crypto, db, readerFactory, writerFactory, - connectionReaderFactory, connectionWriterFactory, authorFactory, + streamReaderFactory, streamWriterFactory, authorFactory, groupFactory, keyManager, connectionDispatcher, clock, reuseConnection, this, plugin, localAuthor, localProps, random); } diff --git a/briar-core/src/org/briarproject/invitation/InvitationTaskFactoryImpl.java b/briar-core/src/org/briarproject/invitation/InvitationTaskFactoryImpl.java index c0b0487204..e847269f70 100644 --- a/briar-core/src/org/briarproject/invitation/InvitationTaskFactoryImpl.java +++ b/briar-core/src/org/briarproject/invitation/InvitationTaskFactoryImpl.java @@ -15,8 +15,8 @@ import org.briarproject.api.serial.ReaderFactory; import org.briarproject.api.serial.WriterFactory; import org.briarproject.api.system.Clock; import org.briarproject.api.transport.ConnectionDispatcher; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriterFactory; class InvitationTaskFactoryImpl implements InvitationTaskFactory { @@ -24,8 +24,8 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory { private final DatabaseComponent db; private final ReaderFactory readerFactory; private final WriterFactory writerFactory; - private final ConnectionReaderFactory connectionReaderFactory; - private final ConnectionWriterFactory connectionWriterFactory; + private final StreamReaderFactory streamReaderFactory; + private final StreamWriterFactory streamWriterFactory; private final AuthorFactory authorFactory; private final GroupFactory groupFactory; private final KeyManager keyManager; @@ -36,8 +36,8 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory { @Inject InvitationTaskFactoryImpl(CryptoComponent crypto, DatabaseComponent db, ReaderFactory readerFactory, WriterFactory writerFactory, - ConnectionReaderFactory connectionReaderFactory, - ConnectionWriterFactory connectionWriterFactory, + StreamReaderFactory streamReaderFactory, + StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, KeyManager keyManager, ConnectionDispatcher connectionDispatcher, Clock clock, PluginManager pluginManager) { @@ -45,8 +45,8 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory { this.db = db; this.readerFactory = readerFactory; this.writerFactory = writerFactory; - this.connectionReaderFactory = connectionReaderFactory; - this.connectionWriterFactory = connectionWriterFactory; + this.streamReaderFactory = streamReaderFactory; + this.streamWriterFactory = streamWriterFactory; this.authorFactory = authorFactory; this.groupFactory = groupFactory; this.keyManager = keyManager; @@ -58,7 +58,7 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory { public InvitationTask createTask(AuthorId localAuthorId, int localCode, int remoteCode, boolean reuseConnection) { return new ConnectorGroup(crypto, db, readerFactory, writerFactory, - connectionReaderFactory, connectionWriterFactory, + streamReaderFactory, streamWriterFactory, authorFactory, groupFactory, keyManager, connectionDispatcher, clock, pluginManager, localAuthorId, localCode, remoteCode, reuseConnection); diff --git a/briar-core/src/org/briarproject/messaging/MessageImpl.java b/briar-core/src/org/briarproject/messaging/MessageImpl.java index e967a97077..3ac77ef5bf 100644 --- a/briar-core/src/org/briarproject/messaging/MessageImpl.java +++ b/briar-core/src/org/briarproject/messaging/MessageImpl.java @@ -1,6 +1,7 @@ package org.briarproject.messaging; import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH; + import org.briarproject.api.Author; import org.briarproject.api.messaging.Group; import org.briarproject.api.messaging.Message; diff --git a/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java b/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java index 88c7fbbe82..0ba89f29fd 100644 --- a/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java +++ b/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java @@ -51,12 +51,12 @@ import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.messaging.UnverifiedMessage; import org.briarproject.api.plugins.duplex.DuplexTransportConnection; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; import org.briarproject.util.ByteUtils; abstract class DuplexConnection implements EventListener { @@ -75,11 +75,11 @@ abstract class DuplexConnection implements EventListener { protected final DatabaseComponent db; protected final EventBus eventBus; protected final ConnectionRegistry connRegistry; - protected final ConnectionReaderFactory connReaderFactory; - protected final ConnectionWriterFactory connWriterFactory; + protected final StreamReaderFactory connReaderFactory; + protected final StreamWriterFactory connWriterFactory; protected final PacketReaderFactory packetReaderFactory; protected final PacketWriterFactory packetWriterFactory; - protected final ConnectionContext ctx; + protected final StreamContext ctx; protected final DuplexTransportConnection transport; protected final ContactId contactId; protected final TransportId transportId; @@ -95,10 +95,10 @@ abstract class DuplexConnection implements EventListener { DuplexConnection(Executor dbExecutor, Executor cryptoExecutor, MessageVerifier messageVerifier, DatabaseComponent db, EventBus eventBus, ConnectionRegistry connRegistry, - ConnectionReaderFactory connReaderFactory, - ConnectionWriterFactory connWriterFactory, + StreamReaderFactory connReaderFactory, + StreamWriterFactory connWriterFactory, PacketReaderFactory packetReaderFactory, - PacketWriterFactory packetWriterFactory, ConnectionContext ctx, + PacketWriterFactory packetWriterFactory, StreamContext ctx, DuplexTransportConnection transport) { this.dbExecutor = dbExecutor; this.cryptoExecutor = cryptoExecutor; @@ -119,11 +119,9 @@ abstract class DuplexConnection implements EventListener { writerTasks = new LinkedBlockingQueue<Runnable>(); } - protected abstract ConnectionReader createConnectionReader() - throws IOException; + protected abstract StreamReader createStreamReader() throws IOException; - protected abstract ConnectionWriter createConnectionWriter() - throws IOException; + protected abstract StreamWriter createStreamWriter() throws IOException; public void eventOccurred(Event e) { if(e instanceof ContactRemovedEvent) { @@ -163,7 +161,7 @@ abstract class DuplexConnection implements EventListener { void read() { try { - InputStream in = createConnectionReader().getInputStream(); + InputStream in = createStreamReader().getInputStream(); PacketReader reader = packetReaderFactory.createPacketReader(in); LOG.info("Starting to read"); while(!reader.eof()) { @@ -223,7 +221,7 @@ abstract class DuplexConnection implements EventListener { connRegistry.registerConnection(contactId, transportId); eventBus.addListener(this); try { - OutputStream out = createConnectionWriter().getOutputStream(); + OutputStream out = createStreamWriter().getOutputStream(); writer = packetWriterFactory.createPacketWriter(out, true); LOG.info("Starting to write"); // Ensure the tag is sent diff --git a/briar-core/src/org/briarproject/messaging/duplex/DuplexConnectionFactoryImpl.java b/briar-core/src/org/briarproject/messaging/duplex/DuplexConnectionFactoryImpl.java index dfb71541dc..f8affa8dde 100644 --- a/briar-core/src/org/briarproject/messaging/duplex/DuplexConnectionFactoryImpl.java +++ b/briar-core/src/org/briarproject/messaging/duplex/DuplexConnectionFactoryImpl.java @@ -17,10 +17,10 @@ import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.messaging.duplex.DuplexConnectionFactory; import org.briarproject.api.plugins.duplex.DuplexTransportConnection; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReaderFactory; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriterFactory; class DuplexConnectionFactoryImpl implements DuplexConnectionFactory { @@ -33,8 +33,8 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory { private final EventBus eventBus; private final KeyManager keyManager; private final ConnectionRegistry connRegistry; - private final ConnectionReaderFactory connReaderFactory; - private final ConnectionWriterFactory connWriterFactory; + private final StreamReaderFactory connReaderFactory; + private final StreamWriterFactory connWriterFactory; private final PacketReaderFactory packetReaderFactory; private final PacketWriterFactory packetWriterFactory; @@ -44,8 +44,8 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory { MessageVerifier messageVerifier, DatabaseComponent db, EventBus eventBus, KeyManager keyManager, ConnectionRegistry connRegistry, - ConnectionReaderFactory connReaderFactory, - ConnectionWriterFactory connWriterFactory, + StreamReaderFactory connReaderFactory, + StreamWriterFactory connWriterFactory, PacketReaderFactory packetReaderFactory, PacketWriterFactory packetWriterFactory) { this.dbExecutor = dbExecutor; @@ -61,7 +61,7 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory { this.packetWriterFactory = packetWriterFactory; } - public void createIncomingConnection(ConnectionContext ctx, + public void createIncomingConnection(StreamContext ctx, DuplexTransportConnection transport) { final DuplexConnection conn = new IncomingDuplexConnection(dbExecutor, cryptoExecutor, messageVerifier, db, eventBus, connRegistry, @@ -83,9 +83,9 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory { public void createOutgoingConnection(ContactId c, TransportId t, DuplexTransportConnection transport) { - ConnectionContext ctx = keyManager.getConnectionContext(c, t); + StreamContext ctx = keyManager.getStreamContext(c, t); if(ctx == null) { - LOG.warning("Could not create outgoing connection context"); + LOG.warning("Could not create outgoing stream context"); return; } final DuplexConnection conn = new OutgoingDuplexConnection(dbExecutor, diff --git a/briar-core/src/org/briarproject/messaging/duplex/IncomingDuplexConnection.java b/briar-core/src/org/briarproject/messaging/duplex/IncomingDuplexConnection.java index ed63fe015f..52e4e93181 100644 --- a/briar-core/src/org/briarproject/messaging/duplex/IncomingDuplexConnection.java +++ b/briar-core/src/org/briarproject/messaging/duplex/IncomingDuplexConnection.java @@ -11,41 +11,41 @@ import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.plugins.duplex.DuplexTransportConnection; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; class IncomingDuplexConnection extends DuplexConnection { IncomingDuplexConnection(Executor dbExecutor, Executor cryptoExecutor, MessageVerifier messageVerifier, DatabaseComponent db, EventBus eventBus, ConnectionRegistry connRegistry, - ConnectionReaderFactory connReaderFactory, - ConnectionWriterFactory connWriterFactory, + StreamReaderFactory connReaderFactory, + StreamWriterFactory connWriterFactory, PacketReaderFactory packetReaderFactory, PacketWriterFactory packetWriterFactory, - ConnectionContext ctx, DuplexTransportConnection transport) { + StreamContext ctx, DuplexTransportConnection transport) { super(dbExecutor, cryptoExecutor, messageVerifier, db, eventBus, connRegistry, connReaderFactory, connWriterFactory, packetReaderFactory, packetWriterFactory, ctx, transport); } @Override - protected ConnectionReader createConnectionReader() throws IOException { + protected StreamReader createStreamReader() throws IOException { InputStream in = transport.getInputStream(); int maxFrameLength = transport.getMaxFrameLength(); - return connReaderFactory.createConnectionReader(in, maxFrameLength, + return connReaderFactory.createStreamReader(in, maxFrameLength, ctx, true, true); } @Override - protected ConnectionWriter createConnectionWriter() throws IOException { + protected StreamWriter createStreamWriter() throws IOException { OutputStream out = transport.getOutputStream(); int maxFrameLength = transport.getMaxFrameLength(); - return connWriterFactory.createConnectionWriter(out, maxFrameLength, + return connWriterFactory.createStreamWriter(out, maxFrameLength, Long.MAX_VALUE, ctx, true, false); } } diff --git a/briar-core/src/org/briarproject/messaging/duplex/OutgoingDuplexConnection.java b/briar-core/src/org/briarproject/messaging/duplex/OutgoingDuplexConnection.java index 4305674c16..7eab0226d9 100644 --- a/briar-core/src/org/briarproject/messaging/duplex/OutgoingDuplexConnection.java +++ b/briar-core/src/org/briarproject/messaging/duplex/OutgoingDuplexConnection.java @@ -11,22 +11,22 @@ import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.plugins.duplex.DuplexTransportConnection; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; class OutgoingDuplexConnection extends DuplexConnection { OutgoingDuplexConnection(Executor dbExecutor, Executor cryptoExecutor, MessageVerifier messageVerifier, DatabaseComponent db, EventBus eventBus, ConnectionRegistry connRegistry, - ConnectionReaderFactory connReaderFactory, - ConnectionWriterFactory connWriterFactory, + StreamReaderFactory connReaderFactory, + StreamWriterFactory connWriterFactory, PacketReaderFactory packetReaderFactory, - PacketWriterFactory packetWriterFactory, ConnectionContext ctx, + PacketWriterFactory packetWriterFactory, StreamContext ctx, DuplexTransportConnection transport) { super(dbExecutor, cryptoExecutor, messageVerifier, db, eventBus, connRegistry, connReaderFactory, connWriterFactory, @@ -34,18 +34,18 @@ class OutgoingDuplexConnection extends DuplexConnection { } @Override - protected ConnectionReader createConnectionReader() throws IOException { + protected StreamReader createStreamReader() throws IOException { InputStream in = transport.getInputStream(); int maxFrameLength = transport.getMaxFrameLength(); - return connReaderFactory.createConnectionReader(in, maxFrameLength, + return connReaderFactory.createStreamReader(in, maxFrameLength, ctx, false, false); } @Override - protected ConnectionWriter createConnectionWriter() throws IOException { + protected StreamWriter createStreamWriter() throws IOException { OutputStream out = transport.getOutputStream(); int maxFrameLength = transport.getMaxFrameLength(); - return connWriterFactory.createConnectionWriter(out, maxFrameLength, + return connWriterFactory.createStreamWriter(out, maxFrameLength, Long.MAX_VALUE, ctx, false, true); } } diff --git a/briar-core/src/org/briarproject/messaging/simplex/IncomingSimplexConnection.java b/briar-core/src/org/briarproject/messaging/simplex/IncomingSimplexConnection.java index ac997916f8..72162747c2 100644 --- a/briar-core/src/org/briarproject/messaging/simplex/IncomingSimplexConnection.java +++ b/briar-core/src/org/briarproject/messaging/simplex/IncomingSimplexConnection.java @@ -26,10 +26,10 @@ import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.messaging.UnverifiedMessage; import org.briarproject.api.plugins.simplex.SimplexTransportReader; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; import org.briarproject.api.transport.ConnectionRegistry; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.util.ByteUtils; class IncomingSimplexConnection { @@ -41,9 +41,9 @@ class IncomingSimplexConnection { private final MessageVerifier messageVerifier; private final DatabaseComponent db; private final ConnectionRegistry connRegistry; - private final ConnectionReaderFactory connReaderFactory; + private final StreamReaderFactory connReaderFactory; private final PacketReaderFactory packetReaderFactory; - private final ConnectionContext ctx; + private final StreamContext ctx; private final SimplexTransportReader transport; private final ContactId contactId; private final TransportId transportId; @@ -51,8 +51,8 @@ class IncomingSimplexConnection { IncomingSimplexConnection(Executor dbExecutor, Executor cryptoExecutor, MessageVerifier messageVerifier, DatabaseComponent db, ConnectionRegistry connRegistry, - ConnectionReaderFactory connReaderFactory, - PacketReaderFactory packetReaderFactory, ConnectionContext ctx, + StreamReaderFactory connReaderFactory, + PacketReaderFactory packetReaderFactory, StreamContext ctx, SimplexTransportReader transport) { this.dbExecutor = dbExecutor; this.cryptoExecutor = cryptoExecutor; @@ -72,7 +72,7 @@ class IncomingSimplexConnection { try { InputStream in = transport.getInputStream(); int maxFrameLength = transport.getMaxFrameLength(); - ConnectionReader conn = connReaderFactory.createConnectionReader(in, + StreamReader conn = connReaderFactory.createStreamReader(in, maxFrameLength, ctx, true, true); in = conn.getInputStream(); PacketReader reader = packetReaderFactory.createPacketReader(in); diff --git a/briar-core/src/org/briarproject/messaging/simplex/OutgoingSimplexConnection.java b/briar-core/src/org/briarproject/messaging/simplex/OutgoingSimplexConnection.java index 1f1b205fd8..94fd128ff7 100644 --- a/briar-core/src/org/briarproject/messaging/simplex/OutgoingSimplexConnection.java +++ b/briar-core/src/org/briarproject/messaging/simplex/OutgoingSimplexConnection.java @@ -23,10 +23,10 @@ import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.plugins.simplex.SimplexTransportWriter; -import org.briarproject.api.transport.ConnectionContext; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; import org.briarproject.util.ByteUtils; class OutgoingSimplexConnection { @@ -36,9 +36,9 @@ class OutgoingSimplexConnection { private final DatabaseComponent db; private final ConnectionRegistry connRegistry; - private final ConnectionWriterFactory connWriterFactory; + private final StreamWriterFactory connWriterFactory; private final PacketWriterFactory packetWriterFactory; - private final ConnectionContext ctx; + private final StreamContext ctx; private final SimplexTransportWriter transport; private final ContactId contactId; private final TransportId transportId; @@ -46,8 +46,8 @@ class OutgoingSimplexConnection { OutgoingSimplexConnection(DatabaseComponent db, ConnectionRegistry connRegistry, - ConnectionWriterFactory connWriterFactory, - PacketWriterFactory packetWriterFactory, ConnectionContext ctx, + StreamWriterFactory connWriterFactory, + PacketWriterFactory packetWriterFactory, StreamContext ctx, SimplexTransportWriter transport) { this.db = db; this.connRegistry = connRegistry; @@ -66,7 +66,7 @@ class OutgoingSimplexConnection { OutputStream out = transport.getOutputStream(); long capacity = transport.getCapacity(); int maxFrameLength = transport.getMaxFrameLength(); - ConnectionWriter conn = connWriterFactory.createConnectionWriter( + StreamWriter conn = connWriterFactory.createStreamWriter( out, maxFrameLength, capacity, ctx, false, true); out = conn.getOutputStream(); if(conn.getRemainingCapacity() < MAX_PACKET_LENGTH) @@ -114,7 +114,7 @@ class OutgoingSimplexConnection { connRegistry.unregisterConnection(contactId, transportId); } - private boolean writeTransportAcks(ConnectionWriter conn, + private boolean writeTransportAcks(StreamWriter conn, PacketWriter writer) throws DbException, IOException { assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; Collection<TransportAck> acks = db.generateTransportAcks(contactId); @@ -126,7 +126,7 @@ class OutgoingSimplexConnection { return true; } - private boolean writeTransportUpdates(ConnectionWriter conn, + private boolean writeTransportUpdates(StreamWriter conn, PacketWriter writer) throws DbException, IOException { assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; Collection<TransportUpdate> updates = @@ -139,7 +139,7 @@ class OutgoingSimplexConnection { return true; } - private boolean writeSubscriptionAck(ConnectionWriter conn, + private boolean writeSubscriptionAck(StreamWriter conn, PacketWriter writer) throws DbException, IOException { assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; SubscriptionAck a = db.generateSubscriptionAck(contactId); @@ -148,7 +148,7 @@ class OutgoingSimplexConnection { return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; } - private boolean writeSubscriptionUpdate(ConnectionWriter conn, + private boolean writeSubscriptionUpdate(StreamWriter conn, PacketWriter writer) throws DbException, IOException { assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; SubscriptionUpdate u = @@ -158,7 +158,7 @@ class OutgoingSimplexConnection { return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; } - private boolean writeRetentionAck(ConnectionWriter conn, + private boolean writeRetentionAck(StreamWriter conn, PacketWriter writer) throws DbException, IOException { assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; RetentionAck a = db.generateRetentionAck(contactId); @@ -167,7 +167,7 @@ class OutgoingSimplexConnection { return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; } - private boolean writeRetentionUpdate(ConnectionWriter conn, + private boolean writeRetentionUpdate(StreamWriter conn, PacketWriter writer) throws DbException, IOException { assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH; RetentionUpdate u = db.generateRetentionUpdate(contactId, maxLatency); diff --git a/briar-core/src/org/briarproject/messaging/simplex/SimplexConnectionFactoryImpl.java b/briar-core/src/org/briarproject/messaging/simplex/SimplexConnectionFactoryImpl.java index aeff21e837..f202d061eb 100644 --- a/briar-core/src/org/briarproject/messaging/simplex/SimplexConnectionFactoryImpl.java +++ b/briar-core/src/org/briarproject/messaging/simplex/SimplexConnectionFactoryImpl.java @@ -17,10 +17,10 @@ import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.messaging.simplex.SimplexConnectionFactory; import org.briarproject.api.plugins.simplex.SimplexTransportReader; import org.briarproject.api.plugins.simplex.SimplexTransportWriter; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReaderFactory; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriterFactory; class SimplexConnectionFactoryImpl implements SimplexConnectionFactory { @@ -32,8 +32,8 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory { private final DatabaseComponent db; private final KeyManager keyManager; private final ConnectionRegistry connRegistry; - private final ConnectionReaderFactory connReaderFactory; - private final ConnectionWriterFactory connWriterFactory; + private final StreamReaderFactory connReaderFactory; + private final StreamWriterFactory connWriterFactory; private final PacketReaderFactory packetReaderFactory; private final PacketWriterFactory packetWriterFactory; @@ -42,8 +42,8 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory { @CryptoExecutor Executor cryptoExecutor, MessageVerifier messageVerifier, DatabaseComponent db, KeyManager keyManager, ConnectionRegistry connRegistry, - ConnectionReaderFactory connReaderFactory, - ConnectionWriterFactory connWriterFactory, + StreamReaderFactory connReaderFactory, + StreamWriterFactory connWriterFactory, PacketReaderFactory packetReaderFactory, PacketWriterFactory packetWriterFactory) { this.dbExecutor = dbExecutor; @@ -58,7 +58,7 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory { this.packetWriterFactory = packetWriterFactory; } - public void createIncomingConnection(ConnectionContext ctx, + public void createIncomingConnection(StreamContext ctx, SimplexTransportReader r) { final IncomingSimplexConnection conn = new IncomingSimplexConnection( dbExecutor, cryptoExecutor, messageVerifier, db, connRegistry, @@ -73,7 +73,7 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory { public void createOutgoingConnection(ContactId c, TransportId t, SimplexTransportWriter w) { - ConnectionContext ctx = keyManager.getConnectionContext(c, t); + StreamContext ctx = keyManager.getStreamContext(c, t); if(ctx == null) { LOG.warning("Could not create outgoing connection context"); return; diff --git a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java index 722897476e..1e14f9c72c 100644 --- a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java +++ b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java @@ -378,11 +378,11 @@ class PluginManagerImpl implements PluginManager { } public void readerCreated(SimplexTransportReader r) { - dispatcher.dispatchReader(id, r); + dispatcher.dispatchIncomingConnection(id, r); } public void writerCreated(ContactId c, SimplexTransportWriter w) { - dispatcher.dispatchWriter(c, id, w); + dispatcher.dispatchOutgoingConnection(c, id, w); } } diff --git a/briar-core/src/org/briarproject/plugins/file/FilePlugin.java b/briar-core/src/org/briarproject/plugins/file/FilePlugin.java index 60628f33e0..0302037366 100644 --- a/briar-core/src/org/briarproject/plugins/file/FilePlugin.java +++ b/briar-core/src/org/briarproject/plugins/file/FilePlugin.java @@ -1,7 +1,7 @@ package org.briarproject.plugins.file; import static java.util.logging.Level.WARNING; -import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; +import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH; import java.io.File; import java.io.FileInputStream; @@ -88,7 +88,7 @@ public abstract class FilePlugin implements SimplexPlugin { File f = new File(dir, filename); try { long capacity = fileUtils.getFreeSpace(dir); - if(capacity < MIN_CONNECTION_LENGTH) return null; + if(capacity < MIN_STREAM_LENGTH) return null; OutputStream out = new FileOutputStream(f); return new FileTransportWriter(f, out, capacity, this); } catch(IOException e) { diff --git a/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java b/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java index 648fbaa5ee..5ac8251fc7 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java +++ b/briar-core/src/org/briarproject/plugins/tcp/PortMapperImpl.java @@ -10,10 +10,9 @@ import java.util.logging.Logger; import javax.xml.parsers.ParserConfigurationException; -import org.briarproject.api.lifecycle.ShutdownManager; - import org.bitlet.weupnp.GatewayDevice; import org.bitlet.weupnp.GatewayDiscover; +import org.briarproject.api.lifecycle.ShutdownManager; import org.xml.sax.SAXException; class PortMapperImpl implements PortMapper { diff --git a/briar-core/src/org/briarproject/transport/ConnectionDispatcherImpl.java b/briar-core/src/org/briarproject/transport/ConnectionDispatcherImpl.java index 9844ad30e3..adda06a560 100644 --- a/briar-core/src/org/briarproject/transport/ConnectionDispatcherImpl.java +++ b/briar-core/src/org/briarproject/transport/ConnectionDispatcherImpl.java @@ -20,9 +20,9 @@ import org.briarproject.api.messaging.simplex.SimplexConnectionFactory; import org.briarproject.api.plugins.duplex.DuplexTransportConnection; import org.briarproject.api.plugins.simplex.SimplexTransportReader; import org.briarproject.api.plugins.simplex.SimplexTransportWriter; -import org.briarproject.api.transport.ConnectionContext; import org.briarproject.api.transport.ConnectionDispatcher; -import org.briarproject.api.transport.ConnectionRecogniser; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.TagRecogniser; class ConnectionDispatcherImpl implements ConnectionDispatcher { @@ -30,35 +30,36 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher { Logger.getLogger(ConnectionDispatcherImpl.class.getName()); private final Executor ioExecutor; - private final ConnectionRecogniser recogniser; + private final TagRecogniser tagRecogniser; private final SimplexConnectionFactory simplexConnFactory; private final DuplexConnectionFactory duplexConnFactory; @Inject ConnectionDispatcherImpl(@IoExecutor Executor ioExecutor, - ConnectionRecogniser recogniser, + TagRecogniser tagRecogniser, SimplexConnectionFactory simplexConnFactory, DuplexConnectionFactory duplexConnFactory) { this.ioExecutor = ioExecutor; - this.recogniser = recogniser; + this.tagRecogniser = tagRecogniser; this.simplexConnFactory = simplexConnFactory; this.duplexConnFactory = duplexConnFactory; } - public void dispatchReader(TransportId t, SimplexTransportReader r) { + public void dispatchIncomingConnection(TransportId t, + SimplexTransportReader r) { ioExecutor.execute(new DispatchSimplexConnection(t, r)); } - public void dispatchWriter(ContactId c, TransportId t, - SimplexTransportWriter w) { - simplexConnFactory.createOutgoingConnection(c, t, w); - } - public void dispatchIncomingConnection(TransportId t, DuplexTransportConnection d) { ioExecutor.execute(new DispatchDuplexConnection(t, d)); } + public void dispatchOutgoingConnection(ContactId c, TransportId t, + SimplexTransportWriter w) { + simplexConnFactory.createOutgoingConnection(c, t, w); + } + public void dispatchOutgoingConnection(ContactId c, TransportId t, DuplexTransportConnection d) { duplexConnFactory.createOutgoingConnection(c, t, d); @@ -89,7 +90,7 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher { public void run() { try { byte[] tag = readTag(transport.getInputStream()); - ConnectionContext ctx = recogniser.acceptConnection(transportId, + StreamContext ctx = tagRecogniser.recogniseTag(transportId, tag); if(ctx == null) { transport.dispose(false, false); @@ -137,9 +138,9 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher { dispose(true, false); return; } - ConnectionContext ctx = null; + StreamContext ctx = null; try { - ctx = recogniser.acceptConnection(transportId, tag); + ctx = tagRecogniser.recogniseTag(transportId, tag); } catch(DbException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); dispose(true, false); diff --git a/briar-core/src/org/briarproject/transport/FrameEncoder.java b/briar-core/src/org/briarproject/transport/FrameEncoder.java index 53f8994124..684b875424 100644 --- a/briar-core/src/org/briarproject/transport/FrameEncoder.java +++ b/briar-core/src/org/briarproject/transport/FrameEncoder.java @@ -6,6 +6,7 @@ import static org.briarproject.api.transport.TransportConstants.IV_LENGTH; import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH; import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED; + import org.briarproject.util.ByteUtils; class FrameEncoder { diff --git a/briar-core/src/org/briarproject/transport/KeyManagerImpl.java b/briar-core/src/org/briarproject/transport/KeyManagerImpl.java index 3b0ff81c89..c6617da8bc 100644 --- a/briar-core/src/org/briarproject/transport/KeyManagerImpl.java +++ b/briar-core/src/org/briarproject/transport/KeyManagerImpl.java @@ -29,9 +29,9 @@ import org.briarproject.api.event.TransportAddedEvent; import org.briarproject.api.event.TransportRemovedEvent; import org.briarproject.api.system.Clock; import org.briarproject.api.system.Timer; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionRecogniser; import org.briarproject.api.transport.Endpoint; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.TagRecogniser; import org.briarproject.api.transport.TemporarySecret; import org.briarproject.util.ByteUtils; @@ -46,7 +46,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener { private final CryptoComponent crypto; private final DatabaseComponent db; private final EventBus eventBus; - private final ConnectionRecogniser connectionRecogniser; + private final TagRecogniser connectionRecogniser; private final Clock clock; private final Timer timer; @@ -58,7 +58,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener { @Inject KeyManagerImpl(CryptoComponent crypto, DatabaseComponent db, - EventBus eventBus, ConnectionRecogniser connectionRecogniser, + EventBus eventBus, TagRecogniser connectionRecogniser, Clock clock, Timer timer) { this.crypto = crypto; this.db = db; @@ -232,17 +232,17 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener { m.clear(); } - public synchronized ConnectionContext getConnectionContext(ContactId c, + public synchronized StreamContext getStreamContext(ContactId c, TransportId t) { TemporarySecret s = currentSecrets.get(new EndpointKey(c, t)); if(s == null) { LOG.info("No secret for endpoint"); return null; } - long connection; + long streamNumber; try { - connection = db.incrementConnectionCounter(c, t, s.getPeriod()); - if(connection == -1) { + streamNumber = db.incrementStreamCounter(c, t, s.getPeriod()); + if(streamNumber == -1) { LOG.info("No counter for period"); return null; } @@ -252,7 +252,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener { } // Clone the secret - the original will be erased byte[] secret = s.getSecret().clone(); - return new ConnectionContext(c, t, secret, connection, s.getAlice()); + return new StreamContext(c, t, secret, streamNumber, s.getAlice()); } public synchronized void endpointAdded(Endpoint ep, long maxLatency, diff --git a/briar-core/src/org/briarproject/transport/ConnectionWindow.java b/briar-core/src/org/briarproject/transport/ReorderingWindow.java similarity index 62% rename from briar-core/src/org/briarproject/transport/ConnectionWindow.java rename to briar-core/src/org/briarproject/transport/ReorderingWindow.java index 13cdcb5e3a..951319ddfa 100644 --- a/briar-core/src/org/briarproject/transport/ConnectionWindow.java +++ b/briar-core/src/org/briarproject/transport/ReorderingWindow.java @@ -1,6 +1,6 @@ package org.briarproject.transport; -import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE; +import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE; import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED; import java.util.ArrayList; @@ -9,51 +9,51 @@ import java.util.HashSet; import java.util.Set; // This class is not thread-safe -class ConnectionWindow { +class ReorderingWindow { private final Set<Long> unseen; private long centre; - ConnectionWindow() { + ReorderingWindow() { unseen = new HashSet<Long>(); - for(long l = 0; l < CONNECTION_WINDOW_SIZE / 2; l++) unseen.add(l); + for(long l = 0; l < REORDERING_WINDOW_SIZE / 2; l++) unseen.add(l); centre = 0; } - ConnectionWindow(long centre, byte[] bitmap) { + ReorderingWindow(long centre, byte[] bitmap) { if(centre < 0 || centre > MAX_32_BIT_UNSIGNED + 1) throw new IllegalArgumentException(); - if(bitmap.length != CONNECTION_WINDOW_SIZE / 8) + if(bitmap.length != REORDERING_WINDOW_SIZE / 8) throw new IllegalArgumentException(); this.centre = centre; unseen = new HashSet<Long>(); - long bitmapBottom = centre - CONNECTION_WINDOW_SIZE / 2; + long bitmapBottom = centre - REORDERING_WINDOW_SIZE / 2; for(int bytes = 0; bytes < bitmap.length; bytes++) { for(int bits = 0; bits < 8; bits++) { - long connection = bitmapBottom + bytes * 8 + bits; - if(connection >= 0 && connection <= MAX_32_BIT_UNSIGNED) { + long streamNumber = bitmapBottom + bytes * 8 + bits; + if(streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) { if((bitmap[bytes] & (128 >> bits)) == 0) - unseen.add(connection); + unseen.add(streamNumber); } } } } - boolean isSeen(long connection) { - return !unseen.contains(connection); + boolean isSeen(long streamNumber) { + return !unseen.contains(streamNumber); } - Collection<Long> setSeen(long connection) { + Collection<Long> setSeen(long streamNumber) { long bottom = getBottom(centre); long top = getTop(centre); - if(connection < bottom || connection > top) + if(streamNumber < bottom || streamNumber > top) throw new IllegalArgumentException(); - if(!unseen.remove(connection)) + if(!unseen.remove(streamNumber)) throw new IllegalArgumentException(); Collection<Long> changed = new ArrayList<Long>(); - if(connection >= centre) { - centre = connection + 1; + if(streamNumber >= centre) { + centre = streamNumber + 1; long newBottom = getBottom(centre); long newTop = getTop(centre); for(long l = bottom; l < newBottom; l++) { @@ -71,13 +71,13 @@ class ConnectionWindow { } byte[] getBitmap() { - byte[] bitmap = new byte[CONNECTION_WINDOW_SIZE / 8]; - long bitmapBottom = centre - CONNECTION_WINDOW_SIZE / 2; + byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8]; + long bitmapBottom = centre - REORDERING_WINDOW_SIZE / 2; for(int bytes = 0; bytes < bitmap.length; bytes++) { for(int bits = 0; bits < 8; bits++) { - long connection = bitmapBottom + bytes * 8 + bits; - if(connection >= 0 && connection <= MAX_32_BIT_UNSIGNED) { - if(!unseen.contains(connection)) + long streamNumber = bitmapBottom + bytes * 8 + bits; + if(streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) { + if(!unseen.contains(streamNumber)) bitmap[bytes] |= 128 >> bits; } } @@ -87,13 +87,13 @@ class ConnectionWindow { // Returns the lowest value contained in a window with the given centre private static long getBottom(long centre) { - return Math.max(0, centre - CONNECTION_WINDOW_SIZE / 2); + return Math.max(0, centre - REORDERING_WINDOW_SIZE / 2); } // Returns the highest value contained in a window with the given centre private static long getTop(long centre) { return Math.min(MAX_32_BIT_UNSIGNED, - centre + CONNECTION_WINDOW_SIZE / 2 - 1); + centre + REORDERING_WINDOW_SIZE / 2 - 1); } public Collection<Long> getUnseen() { diff --git a/briar-core/src/org/briarproject/transport/ConnectionReaderFactoryImpl.java b/briar-core/src/org/briarproject/transport/StreamReaderFactoryImpl.java similarity index 52% rename from briar-core/src/org/briarproject/transport/ConnectionReaderFactoryImpl.java rename to briar-core/src/org/briarproject/transport/StreamReaderFactoryImpl.java index fca67c69e2..d2997b3663 100644 --- a/briar-core/src/org/briarproject/transport/ConnectionReaderFactoryImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamReaderFactoryImpl.java @@ -6,38 +6,38 @@ import javax.inject.Inject; import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.SecretKey; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; -class ConnectionReaderFactoryImpl implements ConnectionReaderFactory { +class StreamReaderFactoryImpl implements StreamReaderFactory { private final CryptoComponent crypto; @Inject - ConnectionReaderFactoryImpl(CryptoComponent crypto) { + StreamReaderFactoryImpl(CryptoComponent crypto) { this.crypto = crypto; } - public ConnectionReader createConnectionReader(InputStream in, - int maxFrameLength, ConnectionContext ctx, boolean incoming, + public StreamReader createStreamReader(InputStream in, + int maxFrameLength, StreamContext ctx, boolean incoming, boolean initiator) { byte[] secret = ctx.getSecret(); - long connection = ctx.getConnectionNumber(); + long streamNumber = ctx.getStreamNumber(); boolean weAreAlice = ctx.getAlice(); boolean initiatorIsAlice = incoming ? !weAreAlice : weAreAlice; - SecretKey frameKey = crypto.deriveFrameKey(secret, connection, + SecretKey frameKey = crypto.deriveFrameKey(secret, streamNumber, initiatorIsAlice, initiator); FrameReader encryption = new IncomingEncryptionLayer(in, crypto.getFrameCipher(), frameKey, maxFrameLength); - return new ConnectionReaderImpl(encryption, maxFrameLength); + return new StreamReaderImpl(encryption, maxFrameLength); } - public ConnectionReader createInvitationConnectionReader(InputStream in, + public StreamReader createInvitationStreamReader(InputStream in, int maxFrameLength, byte[] secret, boolean alice) { SecretKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice); FrameReader encryption = new IncomingEncryptionLayer(in, crypto.getFrameCipher(), frameKey, maxFrameLength); - return new ConnectionReaderImpl(encryption, maxFrameLength); + return new StreamReaderImpl(encryption, maxFrameLength); } } diff --git a/briar-core/src/org/briarproject/transport/ConnectionReaderImpl.java b/briar-core/src/org/briarproject/transport/StreamReaderImpl.java similarity index 86% rename from briar-core/src/org/briarproject/transport/ConnectionReaderImpl.java rename to briar-core/src/org/briarproject/transport/StreamReaderImpl.java index f1a7e43285..0de048a6fa 100644 --- a/briar-core/src/org/briarproject/transport/ConnectionReaderImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamReaderImpl.java @@ -6,16 +6,16 @@ import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH; import java.io.IOException; import java.io.InputStream; -import org.briarproject.api.transport.ConnectionReader; +import org.briarproject.api.transport.StreamReader; -class ConnectionReaderImpl extends InputStream implements ConnectionReader { +class StreamReaderImpl extends InputStream implements StreamReader { private final FrameReader in; private final byte[] frame; private int offset = 0, length = 0; - ConnectionReaderImpl(FrameReader in, int frameLength) { + StreamReaderImpl(FrameReader in, int frameLength) { this.in = in; frame = new byte[frameLength - MAC_LENGTH]; } diff --git a/briar-core/src/org/briarproject/transport/ConnectionWriterFactoryImpl.java b/briar-core/src/org/briarproject/transport/StreamWriterFactoryImpl.java similarity index 61% rename from briar-core/src/org/briarproject/transport/ConnectionWriterFactoryImpl.java rename to briar-core/src/org/briarproject/transport/StreamWriterFactoryImpl.java index 7ad0ec06e3..1935fea1be 100644 --- a/briar-core/src/org/briarproject/transport/ConnectionWriterFactoryImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamWriterFactoryImpl.java @@ -8,33 +8,33 @@ import javax.inject.Inject; import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.SecretKey; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; -class ConnectionWriterFactoryImpl implements ConnectionWriterFactory { +class StreamWriterFactoryImpl implements StreamWriterFactory { private final CryptoComponent crypto; @Inject - ConnectionWriterFactoryImpl(CryptoComponent crypto) { + StreamWriterFactoryImpl(CryptoComponent crypto) { this.crypto = crypto; } - public ConnectionWriter createConnectionWriter(OutputStream out, - int maxFrameLength, long capacity, ConnectionContext ctx, + public StreamWriter createStreamWriter(OutputStream out, + int maxFrameLength, long capacity, StreamContext ctx, boolean incoming, boolean initiator) { byte[] secret = ctx.getSecret(); - long connection = ctx.getConnectionNumber(); + long streamNumber = ctx.getStreamNumber(); boolean weAreAlice = ctx.getAlice(); boolean initiatorIsAlice = incoming ? !weAreAlice : weAreAlice; - SecretKey frameKey = crypto.deriveFrameKey(secret, connection, + SecretKey frameKey = crypto.deriveFrameKey(secret, streamNumber, initiatorIsAlice, initiator); FrameWriter encryption; if(initiator) { byte[] tag = new byte[TAG_LENGTH]; SecretKey tagKey = crypto.deriveTagKey(secret, initiatorIsAlice); - crypto.encodeTag(tag, tagKey, connection); + crypto.encodeTag(tag, tagKey, streamNumber); tagKey.erase(); encryption = new OutgoingEncryptionLayer(out, capacity, crypto.getFrameCipher(), frameKey, maxFrameLength, tag); @@ -42,15 +42,15 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory { encryption = new OutgoingEncryptionLayer(out, capacity, crypto.getFrameCipher(), frameKey, maxFrameLength); } - return new ConnectionWriterImpl(encryption, maxFrameLength); + return new StreamWriterImpl(encryption, maxFrameLength); } - public ConnectionWriter createInvitationConnectionWriter(OutputStream out, + public StreamWriter createInvitationStreamWriter(OutputStream out, int maxFrameLength, byte[] secret, boolean alice) { SecretKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice); FrameWriter encryption = new OutgoingEncryptionLayer(out, Long.MAX_VALUE, crypto.getFrameCipher(), frameKey, maxFrameLength); - return new ConnectionWriterImpl(encryption, maxFrameLength); + return new StreamWriterImpl(encryption, maxFrameLength); } } \ No newline at end of file diff --git a/briar-core/src/org/briarproject/transport/ConnectionWriterImpl.java b/briar-core/src/org/briarproject/transport/StreamWriterImpl.java similarity index 82% rename from briar-core/src/org/briarproject/transport/ConnectionWriterImpl.java rename to briar-core/src/org/briarproject/transport/StreamWriterImpl.java index 0274b7b392..82de19e1e0 100644 --- a/briar-core/src/org/briarproject/transport/ConnectionWriterImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamWriterImpl.java @@ -6,15 +6,16 @@ import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH; import java.io.IOException; import java.io.OutputStream; -import org.briarproject.api.transport.ConnectionWriter; +import org.briarproject.api.transport.StreamWriter; /** - * A ConnectionWriter that buffers its input and writes a frame whenever there - * is a full frame to write or the {@link #flush()} method is called. + * A {@link org.briarproject.api.transport.StreamWriter StreamWriter} that + * buffers its input and writes a frame whenever there is a full frame to write + * or the {@link #flush()} method is called. * <p> * This class is not thread-safe. */ -class ConnectionWriterImpl extends OutputStream implements ConnectionWriter { +class StreamWriterImpl extends OutputStream implements StreamWriter { private final FrameWriter out; private final byte[] frame; @@ -22,7 +23,7 @@ class ConnectionWriterImpl extends OutputStream implements ConnectionWriter { private int length = 0; - ConnectionWriterImpl(FrameWriter out, int frameLength) { + StreamWriterImpl(FrameWriter out, int frameLength) { this.out = out; this.frameLength = frameLength; frame = new byte[frameLength - MAC_LENGTH]; diff --git a/briar-core/src/org/briarproject/transport/ConnectionRecogniserImpl.java b/briar-core/src/org/briarproject/transport/TagRecogniserImpl.java similarity index 61% rename from briar-core/src/org/briarproject/transport/ConnectionRecogniserImpl.java rename to briar-core/src/org/briarproject/transport/TagRecogniserImpl.java index 421791317a..a929bc2d98 100644 --- a/briar-core/src/org/briarproject/transport/ConnectionRecogniserImpl.java +++ b/briar-core/src/org/briarproject/transport/TagRecogniserImpl.java @@ -10,41 +10,41 @@ import org.briarproject.api.TransportId; import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DbException; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionRecogniser; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.TagRecogniser; import org.briarproject.api.transport.TemporarySecret; -class ConnectionRecogniserImpl implements ConnectionRecogniser { +class TagRecogniserImpl implements TagRecogniser { private final CryptoComponent crypto; private final DatabaseComponent db; // Locking: this - private final Map<TransportId, TransportConnectionRecogniser> recognisers; + private final Map<TransportId, TransportTagRecogniser> recognisers; @Inject - ConnectionRecogniserImpl(CryptoComponent crypto, DatabaseComponent db) { + TagRecogniserImpl(CryptoComponent crypto, DatabaseComponent db) { this.crypto = crypto; this.db = db; - recognisers = new HashMap<TransportId, TransportConnectionRecogniser>(); + recognisers = new HashMap<TransportId, TransportTagRecogniser>(); } - public ConnectionContext acceptConnection(TransportId t, byte[] tag) + public StreamContext recogniseTag(TransportId t, byte[] tag) throws DbException { - TransportConnectionRecogniser r; + TransportTagRecogniser r; synchronized(this) { r = recognisers.get(t); } if(r == null) return null; - return r.acceptConnection(tag); + return r.recogniseTag(tag); } public void addSecret(TemporarySecret s) { TransportId t = s.getTransportId(); - TransportConnectionRecogniser r; + TransportTagRecogniser r; synchronized(this) { r = recognisers.get(t); if(r == null) { - r = new TransportConnectionRecogniser(crypto, db, t); + r = new TransportTagRecogniser(crypto, db, t); recognisers.put(t, r); } } @@ -52,7 +52,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser { } public void removeSecret(ContactId c, TransportId t, long period) { - TransportConnectionRecogniser r; + TransportTagRecogniser r; synchronized(this) { r = recognisers.get(t); } @@ -60,7 +60,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser { } public synchronized void removeSecrets(ContactId c) { - for(TransportConnectionRecogniser r : recognisers.values()) + for(TransportTagRecogniser r : recognisers.values()) r.removeSecrets(c); } @@ -69,7 +69,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser { } public synchronized void removeSecrets() { - for(TransportConnectionRecogniser r : recognisers.values()) + for(TransportTagRecogniser r : recognisers.values()) r.removeSecrets(); } } diff --git a/briar-core/src/org/briarproject/transport/TransportModule.java b/briar-core/src/org/briarproject/transport/TransportModule.java index 6ac7a15c93..3567b45fb4 100644 --- a/briar-core/src/org/briarproject/transport/TransportModule.java +++ b/briar-core/src/org/briarproject/transport/TransportModule.java @@ -5,10 +5,10 @@ import javax.inject.Singleton; import org.briarproject.api.crypto.KeyManager; import org.briarproject.api.lifecycle.LifecycleManager; import org.briarproject.api.transport.ConnectionDispatcher; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionRecogniser; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriterFactory; +import org.briarproject.api.transport.TagRecogniser; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -18,14 +18,14 @@ public class TransportModule extends AbstractModule { @Override protected void configure() { bind(ConnectionDispatcher.class).to(ConnectionDispatcherImpl.class); - bind(ConnectionReaderFactory.class).to( - ConnectionReaderFactoryImpl.class); - bind(ConnectionRecogniser.class).to( - ConnectionRecogniserImpl.class).in(Singleton.class); + bind(StreamReaderFactory.class).to( + StreamReaderFactoryImpl.class); + bind(TagRecogniser.class).to( + TagRecogniserImpl.class).in(Singleton.class); bind(ConnectionRegistry.class).to( ConnectionRegistryImpl.class).in(Singleton.class);; - bind(ConnectionWriterFactory.class).to( - ConnectionWriterFactoryImpl.class); + bind(StreamWriterFactory.class).to( + StreamWriterFactoryImpl.class); } @Provides @Singleton diff --git a/briar-core/src/org/briarproject/transport/TransportConnectionRecogniser.java b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java similarity index 75% rename from briar-core/src/org/briarproject/transport/TransportConnectionRecogniser.java rename to briar-core/src/org/briarproject/transport/TransportTagRecogniser.java index 75f1a57a8d..3c9508397c 100644 --- a/briar-core/src/org/briarproject/transport/TransportConnectionRecogniser.java +++ b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java @@ -14,12 +14,15 @@ import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DbException; -import org.briarproject.api.transport.ConnectionContext; +import org.briarproject.api.transport.StreamContext; import org.briarproject.api.transport.TemporarySecret; // FIXME: Don't make alien calls with a lock held -/** A connection recogniser for a specific transport. */ -class TransportConnectionRecogniser { +/** + * A {@link org.briarproject.api.transport.TagRecogniser TagRecogniser} for a + * specific transport. + */ +class TransportTagRecogniser { private final CryptoComponent crypto; private final DatabaseComponent db; @@ -27,7 +30,7 @@ class TransportConnectionRecogniser { private final Map<Bytes, TagContext> tagMap; // Locking: this private final Map<RemovalKey, RemovalContext> removalMap; // Locking: this - TransportConnectionRecogniser(CryptoComponent crypto, DatabaseComponent db, + TransportTagRecogniser(CryptoComponent crypto, DatabaseComponent db, TransportId transportId) { this.crypto = crypto; this.db = db; @@ -36,32 +39,31 @@ class TransportConnectionRecogniser { removalMap = new HashMap<RemovalKey, RemovalContext>(); } - synchronized ConnectionContext acceptConnection(byte[] tag) - throws DbException { + synchronized StreamContext recogniseTag(byte[] tag) throws DbException { TagContext t = tagMap.remove(new Bytes(tag)); if(t == null) return null; // The tag was not expected - // Update the connection window and the expected tags + // Update the reordering window and the expected tags SecretKey key = crypto.deriveTagKey(t.secret, !t.alice); - for(long connection : t.window.setSeen(t.connection)) { + for(long streamNumber : t.window.setSeen(t.streamNumber)) { byte[] tag1 = new byte[TAG_LENGTH]; - crypto.encodeTag(tag1, key, connection); - if(connection < t.connection) { + crypto.encodeTag(tag1, key, streamNumber); + if(streamNumber < t.streamNumber) { TagContext removed = tagMap.remove(new Bytes(tag1)); assert removed != null; } else { - TagContext added = new TagContext(t, connection); + TagContext added = new TagContext(t, streamNumber); TagContext duplicate = tagMap.put(new Bytes(tag1), added); assert duplicate == null; } } key.erase(); - // Store the updated connection window in the DB - db.setConnectionWindow(t.contactId, transportId, t.period, + // Store the updated reordering window in the DB + db.setReorderingWindow(t.contactId, transportId, t.period, t.window.getCentre(), t.window.getBitmap()); // Clone the secret - the key manager will erase the original byte[] secret = t.secret.clone(); - return new ConnectionContext(t.contactId, transportId, secret, - t.connection, t.alice); + return new StreamContext(t.contactId, transportId, secret, + t.streamNumber, t.alice); } synchronized void addSecret(TemporarySecret s) { @@ -71,14 +73,14 @@ class TransportConnectionRecogniser { byte[] secret = s.getSecret(); long centre = s.getWindowCentre(); byte[] bitmap = s.getWindowBitmap(); - // Create the connection window and the expected tags + // Create the reordering window and the expected tags SecretKey key = crypto.deriveTagKey(secret, !alice); - ConnectionWindow window = new ConnectionWindow(centre, bitmap); - for(long connection : window.getUnseen()) { + ReorderingWindow window = new ReorderingWindow(centre, bitmap); + for(long streamNumber : window.getUnseen()) { byte[] tag = new byte[TAG_LENGTH]; - crypto.encodeTag(tag, key, connection); + crypto.encodeTag(tag, key, streamNumber); TagContext added = new TagContext(contactId, alice, period, - secret, window, connection); + secret, window, streamNumber); TagContext duplicate = tagMap.put(new Bytes(tag), added); assert duplicate == null; } @@ -100,8 +102,8 @@ class TransportConnectionRecogniser { // Remove the expected tags SecretKey key = crypto.deriveTagKey(r.secret, !r.alice); byte[] tag = new byte[TAG_LENGTH]; - for(long connection : r.window.getUnseen()) { - crypto.encodeTag(tag, key, connection); + for(long streamNumber : r.window.getUnseen()) { + crypto.encodeTag(tag, key, streamNumber); TagContext removed = tagMap.remove(new Bytes(tag)); assert removed != null; } @@ -127,22 +129,22 @@ class TransportConnectionRecogniser { private final boolean alice; private final long period; private final byte[] secret; - private final ConnectionWindow window; - private final long connection; + private final ReorderingWindow window; + private final long streamNumber; private TagContext(ContactId contactId, boolean alice, long period, - byte[] secret, ConnectionWindow window, long connection) { + byte[] secret, ReorderingWindow window, long streamNumber) { this.contactId = contactId; this.alice = alice; this.period = period; this.secret = secret; this.window = window; - this.connection = connection; + this.streamNumber = streamNumber; } - private TagContext(TagContext t, long connection) { + private TagContext(TagContext t, long streamNumber) { this(t.contactId, t.alice, t.period, t.secret, t.window, - connection); + streamNumber); } } @@ -173,11 +175,11 @@ class TransportConnectionRecogniser { private static class RemovalContext { - private final ConnectionWindow window; + private final ReorderingWindow window; private final byte[] secret; private final boolean alice; - private RemovalContext(ConnectionWindow window, byte[] secret, + private RemovalContext(ReorderingWindow window, byte[] secret, boolean alice) { this.window = window; this.secret = secret; diff --git a/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java b/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java index 5cabb5cf0c..ea0af1c425 100644 --- a/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java +++ b/briar-desktop/src/org/briarproject/plugins/modem/ModemImpl.java @@ -14,6 +14,7 @@ import java.util.logging.Logger; import jssc.SerialPortEvent; import jssc.SerialPortEventListener; + import org.briarproject.api.reliability.ReliabilityLayer; import org.briarproject.api.reliability.ReliabilityLayerFactory; import org.briarproject.api.reliability.WriteHandler; diff --git a/briar-tests/build.xml b/briar-tests/build.xml index a93657ab50..e126d2dceb 100644 --- a/briar-tests/build.xml +++ b/briar-tests/build.xml @@ -125,16 +125,16 @@ <test name='org.briarproject.serial.ReaderImplTest'/> <test name='org.briarproject.serial.WriterImplTest'/> <test name='org.briarproject.system.LinuxSeedProviderTest'/> - <test name='org.briarproject.transport.ConnectionReaderImplTest'/> <test name='org.briarproject.transport.ConnectionRegistryImplTest'/> - <test name='org.briarproject.transport.ConnectionWindowTest'/> - <test name='org.briarproject.transport.ConnectionWriterImplTest'/> <test name='org.briarproject.transport.IncomingEncryptionLayerTest'/> <test name='org.briarproject.transport.KeyManagerImplTest'/> <test name='org.briarproject.transport.KeyRotationIntegrationTest'/> <test name='org.briarproject.transport.OutgoingEncryptionLayerTest'/> + <test name='org.briarproject.transport.ReorderingWindowTest'/> + <test name='org.briarproject.transport.StreamReaderImplTest'/> + <test name='org.briarproject.transport.StreamWriterImplTest'/> <test name='org.briarproject.transport.TransportIntegrationTest'/> - <test name='org.briarproject.transport.TransportConnectionRecogniserTest'/> + <test name='org.briarproject.transport.TransportTagRecogniserTest'/> <test name='org.briarproject.util.ByteUtilsTest'/> <test name='org.briarproject.util.StringUtilsTest'/> </junit> diff --git a/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java b/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java index 6441b83e41..9e1b190adf 100644 --- a/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java +++ b/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java @@ -36,11 +36,11 @@ import org.briarproject.api.messaging.Request; import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.messaging.UnverifiedMessage; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReader; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReader; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; import org.briarproject.crypto.CryptoModule; import org.briarproject.db.DatabaseModule; import org.briarproject.event.EventModule; @@ -57,8 +57,8 @@ import com.google.inject.Injector; public class ProtocolIntegrationTest extends BriarTestCase { - private final ConnectionReaderFactory connectionReaderFactory; - private final ConnectionWriterFactory connectionWriterFactory; + private final StreamReaderFactory streamReaderFactory; + private final StreamWriterFactory streamWriterFactory; private final PacketReaderFactory packetReaderFactory; private final PacketWriterFactory packetWriterFactory; private final MessageVerifier messageVerifier; @@ -84,8 +84,8 @@ public class ProtocolIntegrationTest extends BriarTestCase { new DuplexMessagingModule(), new SimplexMessagingModule(), new ReliabilityModule(), new SerialModule(), new TransportModule()); - connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class); - connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class); + streamReaderFactory = i.getInstance(StreamReaderFactory.class); + streamWriterFactory = i.getInstance(StreamWriterFactory.class); packetReaderFactory = i.getInstance(PacketReaderFactory.class); packetWriterFactory = i.getInstance(PacketWriterFactory.class); messageVerifier = i.getInstance(MessageVerifier.class); @@ -123,9 +123,9 @@ public class ProtocolIntegrationTest extends BriarTestCase { private byte[] write() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); - ConnectionContext ctx = new ConnectionContext(contactId, transportId, + StreamContext ctx = new StreamContext(contactId, transportId, secret.clone(), 0, true); - ConnectionWriter conn = connectionWriterFactory.createConnectionWriter( + StreamWriter conn = streamWriterFactory.createStreamWriter( out, MAX_FRAME_LENGTH, Long.MAX_VALUE, ctx, false, true); OutputStream out1 = conn.getOutputStream(); PacketWriter writer = packetWriterFactory.createPacketWriter(out1, @@ -156,9 +156,9 @@ public class ProtocolIntegrationTest extends BriarTestCase { byte[] tag = new byte[TAG_LENGTH]; assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH)); // FIXME: Check that the expected tag was received - ConnectionContext ctx = new ConnectionContext(contactId, transportId, + StreamContext ctx = new StreamContext(contactId, transportId, secret.clone(), 0, false); - ConnectionReader conn = connectionReaderFactory.createConnectionReader( + StreamReader conn = streamReaderFactory.createStreamReader( in, MAX_FRAME_LENGTH, ctx, true, true); InputStream in1 = conn.getInputStream(); PacketReader reader = packetReaderFactory.createPacketReader(in1); diff --git a/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java b/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java index d2c02c078a..4b27522e84 100644 --- a/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java +++ b/briar-tests/src/org/briarproject/crypto/KeyDerivationTest.java @@ -59,7 +59,7 @@ public class KeyDerivationTest extends BriarTestCase { } @Test - public void testConnectionNumberAffectsDerivation() { + public void testStreamNumberAffectsDerivation() { List<byte[]> secrets = new ArrayList<byte[]>(); for(int i = 0; i < 20; i++) { secrets.add(crypto.deriveNextSecret(secret.clone(), i)); diff --git a/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java b/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java index a4d8e7b78f..44b4d3a9fc 100644 --- a/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java +++ b/briar-tests/src/org/briarproject/crypto/KeyEncodingAndParsingTest.java @@ -11,7 +11,6 @@ import org.briarproject.api.crypto.KeyPair; import org.briarproject.api.crypto.KeyParser; import org.briarproject.api.crypto.PrivateKey; import org.briarproject.api.crypto.PublicKey; - import org.junit.Test; public class KeyEncodingAndParsingTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/crypto/SecretKeyImplTest.java b/briar-tests/src/org/briarproject/crypto/SecretKeyImplTest.java index b56b73900a..20ee3605bf 100644 --- a/briar-tests/src/org/briarproject/crypto/SecretKeyImplTest.java +++ b/briar-tests/src/org/briarproject/crypto/SecretKeyImplTest.java @@ -6,7 +6,6 @@ import java.util.Random; import org.briarproject.BriarTestCase; import org.briarproject.api.crypto.SecretKey; - import org.junit.Test; public class SecretKeyImplTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/db/BasicH2Test.java b/briar-tests/src/org/briarproject/db/BasicH2Test.java index fc5b1434c9..bf490af013 100644 --- a/briar-tests/src/org/briarproject/db/BasicH2Test.java +++ b/briar-tests/src/org/briarproject/db/BasicH2Test.java @@ -15,7 +15,6 @@ import java.util.Random; import org.briarproject.BriarTestCase; import org.briarproject.TestUtils; - import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java b/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java index 7bb0c12ce7..57855cfb6f 100644 --- a/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java +++ b/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java @@ -388,7 +388,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase { } catch(NoSuchContactException expected) {} try { - db.incrementConnectionCounter(contactId, transportId, 0); + db.incrementStreamCounter(contactId, transportId, 0); fail(); } catch(NoSuchContactException expected) {} @@ -453,7 +453,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase { } catch(NoSuchContactException expected) {} try { - db.setConnectionWindow(contactId, transportId, 0, 0, new byte[4]); + db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]); fail(); } catch(NoSuchContactException expected) {} @@ -624,7 +624,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase { } catch(NoSuchTransportException expected) {} try { - db.incrementConnectionCounter(contactId, transportId, 0); + db.incrementStreamCounter(contactId, transportId, 0); fail(); } catch(NoSuchTransportException expected) {} @@ -634,7 +634,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase { } catch(NoSuchTransportException expected) {} try { - db.setConnectionWindow(contactId, transportId, 0, 0, new byte[4]); + db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]); fail(); } catch(NoSuchTransportException expected) {} diff --git a/briar-tests/src/org/briarproject/db/ExponentialBackoffTest.java b/briar-tests/src/org/briarproject/db/ExponentialBackoffTest.java index 06ab48e615..923939e304 100644 --- a/briar-tests/src/org/briarproject/db/ExponentialBackoffTest.java +++ b/briar-tests/src/org/briarproject/db/ExponentialBackoffTest.java @@ -1,7 +1,6 @@ package org.briarproject.db; import org.briarproject.BriarTestCase; - import org.junit.Test; public class ExponentialBackoffTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java index 40658bf428..3ecaf692a1 100644 --- a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java +++ b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java @@ -88,6 +88,7 @@ public class H2DatabaseTest extends BriarTestCase { contactId = new ContactId(1); } + @Override @Before public void setUp() { testDir.mkdirs(); @@ -465,6 +466,7 @@ public class H2DatabaseTest extends BriarTestCase { Connection txn = db.startTransaction(); // In another thread, close the database Thread close = new Thread() { + @Override public void run() { try { closing.countDown(); @@ -501,6 +503,7 @@ public class H2DatabaseTest extends BriarTestCase { Connection txn = db.startTransaction(); // In another thread, close the database Thread close = new Thread() { + @Override public void run() { try { closing.countDown(); @@ -1160,19 +1163,19 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(alice, s.getAlice()); if(s.getPeriod() == 0) { assertArrayEquals(secret1, s.getSecret()); - assertEquals(outgoing1, s.getOutgoingConnectionCounter()); + assertEquals(outgoing1, s.getOutgoingStreamCounter()); assertEquals(centre1, s.getWindowCentre()); assertArrayEquals(bitmap1, s.getWindowBitmap()); foundFirst = true; } else if(s.getPeriod() == 1) { assertArrayEquals(secret2, s.getSecret()); - assertEquals(outgoing2, s.getOutgoingConnectionCounter()); + assertEquals(outgoing2, s.getOutgoingStreamCounter()); assertEquals(centre2, s.getWindowCentre()); assertArrayEquals(bitmap2, s.getWindowBitmap()); foundSecond = true; } else if(s.getPeriod() == 2) { assertArrayEquals(secret3, s.getSecret()); - assertEquals(outgoing3, s.getOutgoingConnectionCounter()); + assertEquals(outgoing3, s.getOutgoingStreamCounter()); assertEquals(centre3, s.getWindowCentre()); assertArrayEquals(bitmap3, s.getWindowBitmap()); foundThird = true; @@ -1197,19 +1200,19 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(alice, s.getAlice()); if(s.getPeriod() == 1) { assertArrayEquals(secret2, s.getSecret()); - assertEquals(outgoing2, s.getOutgoingConnectionCounter()); + assertEquals(outgoing2, s.getOutgoingStreamCounter()); assertEquals(centre2, s.getWindowCentre()); assertArrayEquals(bitmap2, s.getWindowBitmap()); foundSecond = true; } else if(s.getPeriod() == 2) { assertArrayEquals(secret3, s.getSecret()); - assertEquals(outgoing3, s.getOutgoingConnectionCounter()); + assertEquals(outgoing3, s.getOutgoingStreamCounter()); assertEquals(centre3, s.getWindowCentre()); assertArrayEquals(bitmap3, s.getWindowBitmap()); foundThird = true; } else if(s.getPeriod() == 3) { assertArrayEquals(secret4, s.getSecret()); - assertEquals(outgoing4, s.getOutgoingConnectionCounter()); + assertEquals(outgoing4, s.getOutgoingStreamCounter()); assertEquals(centre4, s.getWindowCentre()); assertArrayEquals(bitmap4, s.getWindowBitmap()); foundFourth = true; @@ -1230,7 +1233,7 @@ public class H2DatabaseTest extends BriarTestCase { } @Test - public void testIncrementConnectionCounter() throws Exception { + public void testIncrementStreamCounter() throws Exception { // Create an endpoint and a temporary secret long epoch = 123, latency = 234; boolean alice = false; @@ -1245,7 +1248,7 @@ public class H2DatabaseTest extends BriarTestCase { Database<Connection> db = open(false); Connection txn = db.startTransaction(); - // Add the contact, the transport, the endpoint and the temporary secret + // Add the contact, transport, endpoint and temporary secret db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId)); db.addTransport(txn, transportId, latency); @@ -1260,14 +1263,14 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(transportId, s.getTransportId()); assertEquals(period, s.getPeriod()); assertArrayEquals(secret, s.getSecret()); - assertEquals(outgoing, s.getOutgoingConnectionCounter()); + assertEquals(outgoing, s.getOutgoingStreamCounter()); assertEquals(centre, s.getWindowCentre()); assertArrayEquals(bitmap, s.getWindowBitmap()); - // Increment the connection counter twice and retrieve the secret again - assertEquals(outgoing, db.incrementConnectionCounter(txn, + // Increment the stream counter twice and retrieve the secret again + assertEquals(outgoing, db.incrementStreamCounter(txn, s.getContactId(), s.getTransportId(), s.getPeriod())); - assertEquals(outgoing + 1, db.incrementConnectionCounter(txn, + assertEquals(outgoing + 1, db.incrementStreamCounter(txn, s.getContactId(), s.getTransportId(), s.getPeriod())); secrets = db.getSecrets(txn); assertEquals(1, secrets.size()); @@ -1276,7 +1279,7 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(transportId, s.getTransportId()); assertEquals(period, s.getPeriod()); assertArrayEquals(secret, s.getSecret()); - assertEquals(outgoing + 2, s.getOutgoingConnectionCounter()); + assertEquals(outgoing + 2, s.getOutgoingStreamCounter()); assertEquals(centre, s.getWindowCentre()); assertArrayEquals(bitmap, s.getWindowBitmap()); @@ -1285,7 +1288,7 @@ public class H2DatabaseTest extends BriarTestCase { } @Test - public void testSetConnectionWindow() throws Exception { + public void testSetReorderingWindow() throws Exception { // Create an endpoint and a temporary secret long epoch = 123, latency = 234; boolean alice = false; @@ -1300,7 +1303,7 @@ public class H2DatabaseTest extends BriarTestCase { Database<Connection> db = open(false); Connection txn = db.startTransaction(); - // Add the contact, the transport, the endpoint and the temporary secret + // Add the contact, transport, endpoint and temporary secret db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId)); db.addTransport(txn, transportId, latency); @@ -1315,13 +1318,13 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(transportId, s.getTransportId()); assertEquals(period, s.getPeriod()); assertArrayEquals(secret, s.getSecret()); - assertEquals(outgoing, s.getOutgoingConnectionCounter()); + assertEquals(outgoing, s.getOutgoingStreamCounter()); assertEquals(centre, s.getWindowCentre()); assertArrayEquals(bitmap, s.getWindowBitmap()); - // Update the connection window and retrieve the secret again + // Update the reordering window and retrieve the secret again random.nextBytes(bitmap); - db.setConnectionWindow(txn, contactId, transportId, period, centre, + db.setReorderingWindow(txn, contactId, transportId, period, centre, bitmap); secrets = db.getSecrets(txn); assertEquals(1, secrets.size()); @@ -1330,12 +1333,12 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(transportId, s.getTransportId()); assertEquals(period, s.getPeriod()); assertArrayEquals(secret, s.getSecret()); - assertEquals(outgoing, s.getOutgoingConnectionCounter()); + assertEquals(outgoing, s.getOutgoingStreamCounter()); assertEquals(centre, s.getWindowCentre()); assertArrayEquals(bitmap, s.getWindowBitmap()); // Updating a nonexistent window should not throw an exception - db.setConnectionWindow(txn, contactId, transportId, period + 1, 1, + db.setReorderingWindow(txn, contactId, transportId, period + 1, 1, bitmap); // The nonexistent window should not have been created secrets = db.getSecrets(txn); @@ -1345,7 +1348,7 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(transportId, s.getTransportId()); assertEquals(period, s.getPeriod()); assertArrayEquals(secret, s.getSecret()); - assertEquals(outgoing, s.getOutgoingConnectionCounter()); + assertEquals(outgoing, s.getOutgoingStreamCounter()); assertEquals(centre, s.getWindowCentre()); assertArrayEquals(bitmap, s.getWindowBitmap()); @@ -1354,7 +1357,7 @@ public class H2DatabaseTest extends BriarTestCase { } @Test - public void testContactTransports() throws Exception { + public void testEndpoints() throws Exception { // Create some endpoints long epoch1 = 123, latency1 = 234; long epoch2 = 345, latency2 = 456; @@ -1378,7 +1381,7 @@ public class H2DatabaseTest extends BriarTestCase { db.addEndpoint(txn, ep1); db.addEndpoint(txn, ep2); - // Retrieve the contact transports + // Retrieve the endpoints Collection<Endpoint> endpoints = db.getEndpoints(txn); assertEquals(2, endpoints.size()); boolean foundFirst = false, foundSecond = false; @@ -1399,7 +1402,7 @@ public class H2DatabaseTest extends BriarTestCase { assertTrue(foundFirst); assertTrue(foundSecond); - // Removing the contact should remove the contact transports + // Removing the contact should remove the endpoints db.removeContact(txn, contactId); assertEquals(Collections.emptyList(), db.getEndpoints(txn)); @@ -1646,6 +1649,7 @@ public class H2DatabaseTest extends BriarTestCase { return db; } + @Override @After public void tearDown() { TestUtils.deleteTestDirectory(testDir); diff --git a/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java b/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java index 9bc3c222d3..8243cd4641 100644 --- a/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java +++ b/briar-tests/src/org/briarproject/lifecycle/ShutdownManagerImplTest.java @@ -5,7 +5,6 @@ import java.util.Set; import org.briarproject.BriarTestCase; import org.briarproject.api.lifecycle.ShutdownManager; - import org.junit.Test; public class ShutdownManagerImplTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java b/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java index ad02647623..d93f42d05b 100644 --- a/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java +++ b/briar-tests/src/org/briarproject/lifecycle/WindowsShutdownManagerImplTest.java @@ -1,7 +1,6 @@ package org.briarproject.lifecycle; import org.briarproject.api.lifecycle.ShutdownManager; - import org.junit.Test; public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest { diff --git a/briar-tests/src/org/briarproject/messaging/ConsumersTest.java b/briar-tests/src/org/briarproject/messaging/ConsumersTest.java index daf7559ff3..ccf1038d22 100644 --- a/briar-tests/src/org/briarproject/messaging/ConsumersTest.java +++ b/briar-tests/src/org/briarproject/messaging/ConsumersTest.java @@ -11,7 +11,6 @@ import org.briarproject.api.crypto.MessageDigest; import org.briarproject.api.serial.CopyingConsumer; import org.briarproject.api.serial.CountingConsumer; import org.briarproject.api.serial.DigestingConsumer; - import org.junit.Test; public class ConsumersTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java b/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java index e3b1af5141..097f2dab19 100644 --- a/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java +++ b/briar-tests/src/org/briarproject/messaging/PacketReaderImplTest.java @@ -16,7 +16,6 @@ import org.briarproject.api.serial.SerialComponent; import org.briarproject.api.serial.Writer; import org.briarproject.api.serial.WriterFactory; import org.briarproject.serial.SerialModule; - import org.junit.Test; import com.google.inject.Guice; diff --git a/briar-tests/src/org/briarproject/messaging/simplex/OutgoingSimplexConnectionTest.java b/briar-tests/src/org/briarproject/messaging/simplex/OutgoingSimplexConnectionTest.java index 4f421c6127..3de41423c4 100644 --- a/briar-tests/src/org/briarproject/messaging/simplex/OutgoingSimplexConnectionTest.java +++ b/briar-tests/src/org/briarproject/messaging/simplex/OutgoingSimplexConnectionTest.java @@ -3,7 +3,7 @@ package org.briarproject.messaging.simplex; import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH; import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH; import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH; -import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; +import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH; import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH; import java.io.ByteArrayOutputStream; @@ -24,9 +24,9 @@ import org.briarproject.api.db.DatabaseExecutor; import org.briarproject.api.messaging.Ack; import org.briarproject.api.messaging.MessageId; import org.briarproject.api.messaging.PacketWriterFactory; -import org.briarproject.api.transport.ConnectionContext; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamWriterFactory; import org.briarproject.crypto.CryptoModule; import org.briarproject.event.EventModule; import org.briarproject.messaging.MessagingModule; @@ -49,7 +49,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase { private final Mockery context; private final DatabaseComponent db; private final ConnectionRegistry connRegistry; - private final ConnectionWriterFactory connWriterFactory; + private final StreamWriterFactory connWriterFactory; private final PacketWriterFactory packetWriterFactory; private final ContactId contactId; private final MessageId messageId; @@ -74,7 +74,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase { new DuplexMessagingModule(), new SimplexMessagingModule(), new SerialModule(), new TransportModule()); connRegistry = i.getInstance(ConnectionRegistry.class); - connWriterFactory = i.getInstance(ConnectionWriterFactory.class); + connWriterFactory = i.getInstance(StreamWriterFactory.class); packetWriterFactory = i.getInstance(PacketWriterFactory.class); contactId = new ContactId(234); messageId = new MessageId(TestUtils.getRandomId()); @@ -88,7 +88,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); TestSimplexTransportWriter transport = new TestSimplexTransportWriter( out, MAX_PACKET_LENGTH, Long.MAX_VALUE); - ConnectionContext ctx = new ConnectionContext(contactId, transportId, + StreamContext ctx = new StreamContext(contactId, transportId, secret, 0, true); OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db, connRegistry, connWriterFactory, packetWriterFactory, ctx, @@ -105,8 +105,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase { public void testNothingToSend() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); TestSimplexTransportWriter transport = new TestSimplexTransportWriter( - out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE); - ConnectionContext ctx = new ConnectionContext(contactId, transportId, + out, MIN_STREAM_LENGTH, Long.MAX_VALUE); + StreamContext ctx = new StreamContext(contactId, transportId, secret, 0, true); OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db, connRegistry, connWriterFactory, packetWriterFactory, ctx, @@ -154,8 +154,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase { public void testSomethingToSend() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); TestSimplexTransportWriter transport = new TestSimplexTransportWriter( - out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE); - ConnectionContext ctx = new ConnectionContext(contactId, transportId, + out, MIN_STREAM_LENGTH, Long.MAX_VALUE); + StreamContext ctx = new StreamContext(contactId, transportId, secret, 0, true); OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db, connRegistry, connWriterFactory, packetWriterFactory, ctx, diff --git a/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java b/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java index 659d4d8412..e26b4be884 100644 --- a/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java +++ b/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java @@ -32,12 +32,12 @@ import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.messaging.PacketWriterFactory; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionReaderFactory; -import org.briarproject.api.transport.ConnectionRecogniser; import org.briarproject.api.transport.ConnectionRegistry; -import org.briarproject.api.transport.ConnectionWriterFactory; import org.briarproject.api.transport.Endpoint; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamReaderFactory; +import org.briarproject.api.transport.StreamWriterFactory; +import org.briarproject.api.transport.TagRecogniser; import org.briarproject.crypto.CryptoModule; import org.briarproject.db.DatabaseModule; import org.briarproject.event.EventModule; @@ -144,13 +144,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); ConnectionRegistry connRegistry = alice.getInstance(ConnectionRegistry.class); - ConnectionWriterFactory connWriterFactory = - alice.getInstance(ConnectionWriterFactory.class); + StreamWriterFactory connWriterFactory = + alice.getInstance(StreamWriterFactory.class); PacketWriterFactory packetWriterFactory = alice.getInstance(PacketWriterFactory.class); TestSimplexTransportWriter transport = new TestSimplexTransportWriter( out, Long.MAX_VALUE, Long.MAX_VALUE); - ConnectionContext ctx = km.getConnectionContext(contactId, transportId); + StreamContext ctx = km.getStreamContext(contactId, transportId); assertNotNull(ctx); OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db, connRegistry, connWriterFactory, packetWriterFactory, ctx, @@ -196,21 +196,21 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { // Set up an event listener MessageListener listener = new MessageListener(); bob.getInstance(EventBus.class).addListener(listener); - // Create a connection recogniser and recognise the connection + // Create a tag recogniser and recognise the tag ByteArrayInputStream in = new ByteArrayInputStream(b); - ConnectionRecogniser rec = bob.getInstance(ConnectionRecogniser.class); + TagRecogniser rec = bob.getInstance(TagRecogniser.class); byte[] tag = new byte[TAG_LENGTH]; int read = in.read(tag); assertEquals(tag.length, read); - ConnectionContext ctx = rec.acceptConnection(transportId, tag); + StreamContext ctx = rec.recogniseTag(transportId, tag); assertNotNull(ctx); // Create an incoming simplex connection MessageVerifier messageVerifier = bob.getInstance(MessageVerifier.class); ConnectionRegistry connRegistry = bob.getInstance(ConnectionRegistry.class); - ConnectionReaderFactory connWriterFactory = - bob.getInstance(ConnectionReaderFactory.class); + StreamReaderFactory connWriterFactory = + bob.getInstance(StreamReaderFactory.class); PacketReaderFactory packetWriterFactory = bob.getInstance(PacketReaderFactory.class); TestSimplexTransportReader transport = diff --git a/briar-tests/src/org/briarproject/plugins/file/LinuxRemovableDriveFinderTest.java b/briar-tests/src/org/briarproject/plugins/file/LinuxRemovableDriveFinderTest.java index a9c4bc5bb6..d79fad795e 100644 --- a/briar-tests/src/org/briarproject/plugins/file/LinuxRemovableDriveFinderTest.java +++ b/briar-tests/src/org/briarproject/plugins/file/LinuxRemovableDriveFinderTest.java @@ -1,7 +1,6 @@ package org.briarproject.plugins.file; import org.briarproject.BriarTestCase; - import org.junit.Test; public class LinuxRemovableDriveFinderTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/plugins/file/MacRemovableDriveFinderTest.java b/briar-tests/src/org/briarproject/plugins/file/MacRemovableDriveFinderTest.java index 87ad6f655c..f9156c9136 100644 --- a/briar-tests/src/org/briarproject/plugins/file/MacRemovableDriveFinderTest.java +++ b/briar-tests/src/org/briarproject/plugins/file/MacRemovableDriveFinderTest.java @@ -1,7 +1,6 @@ package org.briarproject.plugins.file; import org.briarproject.BriarTestCase; - import org.junit.Test; public class MacRemovableDriveFinderTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java b/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java index b34b826137..061d6d007e 100644 --- a/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java +++ b/briar-tests/src/org/briarproject/plugins/file/PollingRemovableDriveMonitorTest.java @@ -15,7 +15,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.briarproject.BriarTestCase; import org.briarproject.plugins.file.RemovableDriveMonitor.Callback; - import org.junit.Test; public class PollingRemovableDriveMonitorTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java b/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java index 3875c1f702..b799262185 100644 --- a/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java +++ b/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java @@ -1,7 +1,7 @@ package org.briarproject.plugins.file; import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; -import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; +import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH; import java.io.File; import java.io.FileOutputStream; @@ -20,7 +20,6 @@ import org.briarproject.api.plugins.simplex.SimplexTransportWriter; import org.briarproject.api.system.FileUtils; import org.briarproject.plugins.ImmediateExecutor; import org.briarproject.plugins.file.RemovableDriveMonitor.Callback; - import org.jmock.Expectations; import org.jmock.Mockery; import org.junit.After; @@ -344,10 +343,10 @@ public class RemovableDrivePluginTest extends BriarTestCase { File f = new File(testDir, "abcdefgh.dat"); OutputStream out = new FileOutputStream(f); - out.write(new byte[MIN_CONNECTION_LENGTH]); + out.write(new byte[MIN_STREAM_LENGTH]); out.flush(); out.close(); - assertEquals(MIN_CONNECTION_LENGTH, f.length()); + assertEquals(MIN_STREAM_LENGTH, f.length()); plugin.driveInserted(testDir); context.assertIsSatisfied(); diff --git a/briar-tests/src/org/briarproject/plugins/modem/CountryCodesTest.java b/briar-tests/src/org/briarproject/plugins/modem/CountryCodesTest.java index da85b94bb4..29786b4432 100644 --- a/briar-tests/src/org/briarproject/plugins/modem/CountryCodesTest.java +++ b/briar-tests/src/org/briarproject/plugins/modem/CountryCodesTest.java @@ -1,7 +1,6 @@ package org.briarproject.plugins.modem; import org.briarproject.BriarTestCase; - import org.junit.Test; public class CountryCodesTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java b/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java index 08b05a38e0..85a8ce4b4c 100644 --- a/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java +++ b/briar-tests/src/org/briarproject/transport/KeyManagerImplTest.java @@ -15,9 +15,9 @@ import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventListener; import org.briarproject.api.system.Clock; import org.briarproject.api.system.Timer; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionRecogniser; import org.briarproject.api.transport.Endpoint; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.TagRecogniser; import org.briarproject.api.transport.TemporarySecret; import org.jmock.Expectations; import org.jmock.Mockery; @@ -58,8 +58,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -95,8 +95,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -154,8 +154,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -195,7 +195,7 @@ public class KeyManagerImplTest extends BriarTestCase { oneOf(connectionRecogniser).addSecret(s1); oneOf(connectionRecogniser).addSecret(s2); // getConnectionContext() - oneOf(db).incrementConnectionCounter(contactId, transportId, 1); + oneOf(db).incrementStreamCounter(contactId, transportId, 1); will(returnValue(0L)); // stop() oneOf(eventBus).removeListener(with(any(EventListener.class))); @@ -205,13 +205,13 @@ public class KeyManagerImplTest extends BriarTestCase { assertTrue(keyManager.start()); keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone()); - ConnectionContext ctx = - keyManager.getConnectionContext(contactId, transportId); + StreamContext ctx = + keyManager.getStreamContext(contactId, transportId); assertNotNull(ctx); assertEquals(contactId, ctx.getContactId()); assertEquals(transportId, ctx.getTransportId()); assertArrayEquals(secret1, ctx.getSecret()); - assertEquals(0, ctx.getConnectionNumber()); + assertEquals(0, ctx.getStreamNumber()); assertEquals(true, ctx.getAlice()); keyManager.stop(); @@ -224,8 +224,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -273,8 +273,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -332,8 +332,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -393,8 +393,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -428,7 +428,7 @@ public class KeyManagerImplTest extends BriarTestCase { oneOf(clock).currentTimeMillis(); will(returnValue(EPOCH + 1)); // getConnectionContext() - oneOf(db).incrementConnectionCounter(contactId, transportId, 1); + oneOf(db).incrementStreamCounter(contactId, transportId, 1); will(returnValue(0L)); // stop() oneOf(eventBus).removeListener(with(any(EventListener.class))); @@ -438,13 +438,13 @@ public class KeyManagerImplTest extends BriarTestCase { assertTrue(keyManager.start()); keyManager.run(); - ConnectionContext ctx = - keyManager.getConnectionContext(contactId, transportId); + StreamContext ctx = + keyManager.getStreamContext(contactId, transportId); assertNotNull(ctx); assertEquals(contactId, ctx.getContactId()); assertEquals(transportId, ctx.getTransportId()); assertArrayEquals(secret1, ctx.getSecret()); - assertEquals(0, ctx.getConnectionNumber()); + assertEquals(0, ctx.getStreamNumber()); assertEquals(true, ctx.getAlice()); keyManager.stop(); @@ -457,8 +457,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -503,7 +503,7 @@ public class KeyManagerImplTest extends BriarTestCase { oneOf(db).addSecrets(Arrays.asList(s3)); oneOf(connectionRecogniser).addSecret(s3); // getConnectionContext() - oneOf(db).incrementConnectionCounter(contactId, transportId, 2); + oneOf(db).incrementStreamCounter(contactId, transportId, 2); will(returnValue(0L)); // stop() oneOf(eventBus).removeListener(with(any(EventListener.class))); @@ -513,13 +513,13 @@ public class KeyManagerImplTest extends BriarTestCase { assertTrue(keyManager.start()); keyManager.run(); - ConnectionContext ctx = - keyManager.getConnectionContext(contactId, transportId); + StreamContext ctx = + keyManager.getStreamContext(contactId, transportId); assertNotNull(ctx); assertEquals(contactId, ctx.getContactId()); assertEquals(transportId, ctx.getTransportId()); assertArrayEquals(secret2, ctx.getSecret()); - assertEquals(0, ctx.getConnectionNumber()); + assertEquals(0, ctx.getStreamNumber()); assertEquals(true, ctx.getAlice()); keyManager.stop(); @@ -532,8 +532,8 @@ public class KeyManagerImplTest extends BriarTestCase { final CryptoComponent crypto = context.mock(CryptoComponent.class); final DatabaseComponent db = context.mock(DatabaseComponent.class); final EventBus eventBus = context.mock(EventBus.class); - final ConnectionRecogniser connectionRecogniser = - context.mock(ConnectionRecogniser.class); + final TagRecogniser connectionRecogniser = + context.mock(TagRecogniser.class); final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); @@ -581,7 +581,7 @@ public class KeyManagerImplTest extends BriarTestCase { oneOf(connectionRecogniser).addSecret(s3); oneOf(connectionRecogniser).addSecret(s4); // getConnectionContext() - oneOf(db).incrementConnectionCounter(contactId, transportId, 3); + oneOf(db).incrementStreamCounter(contactId, transportId, 3); will(returnValue(0L)); // stop() oneOf(eventBus).removeListener(with(any(EventListener.class))); @@ -591,13 +591,13 @@ public class KeyManagerImplTest extends BriarTestCase { assertTrue(keyManager.start()); keyManager.run(); - ConnectionContext ctx = - keyManager.getConnectionContext(contactId, transportId); + StreamContext ctx = + keyManager.getStreamContext(contactId, transportId); assertNotNull(ctx); assertEquals(contactId, ctx.getContactId()); assertEquals(transportId, ctx.getTransportId()); assertArrayEquals(secret3, ctx.getSecret()); - assertEquals(0, ctx.getConnectionNumber()); + assertEquals(0, ctx.getStreamNumber()); assertEquals(true, ctx.getAlice()); keyManager.stop(); diff --git a/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java b/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java index 6969f67df5..d7beae54dd 100644 --- a/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java +++ b/briar-tests/src/org/briarproject/transport/KeyRotationIntegrationTest.java @@ -17,9 +17,9 @@ import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventListener; import org.briarproject.api.system.Clock; import org.briarproject.api.system.Timer; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionRecogniser; import org.briarproject.api.transport.Endpoint; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.TagRecogniser; import org.briarproject.api.transport.TemporarySecret; import org.briarproject.util.ByteUtils; import org.hamcrest.Description; @@ -78,8 +78,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase { final Clock clock = context.mock(Clock.class); final Timer timer = context.mock(Timer.class); - final ConnectionRecogniser connectionRecogniser = - new ConnectionRecogniserImpl(crypto, db); + final TagRecogniser connectionRecogniser = + new TagRecogniserImpl(crypto, db); final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db, eventBus, connectionRecogniser, clock, timer); @@ -117,8 +117,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase { final SecretKey k1 = context.mock(SecretKey.class, "k1"); final SecretKey k2 = context.mock(SecretKey.class, "k2"); - final ConnectionRecogniser connectionRecogniser = - new ConnectionRecogniserImpl(crypto, db); + final TagRecogniser connectionRecogniser = + new TagRecogniserImpl(crypto, db); final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db, eventBus, connectionRecogniser, clock, timer); @@ -241,8 +241,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase { final SecretKey k1 = context.mock(SecretKey.class, "k1"); final SecretKey k2 = context.mock(SecretKey.class, "k2"); - final ConnectionRecogniser connectionRecogniser = - new ConnectionRecogniserImpl(crypto, db); + final TagRecogniser connectionRecogniser = + new TagRecogniserImpl(crypto, db); final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db, eventBus, connectionRecogniser, clock, timer); @@ -308,7 +308,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase { } oneOf(k2).erase(); // getConnectionContext() - oneOf(db).incrementConnectionCounter(contactId, transportId, 1); + oneOf(db).incrementStreamCounter(contactId, transportId, 1); will(returnValue(0L)); // stop() // The recogniser should derive the tags for period 0 @@ -351,13 +351,13 @@ public class KeyRotationIntegrationTest extends BriarTestCase { assertTrue(keyManager.start()); keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone()); - ConnectionContext ctx = - keyManager.getConnectionContext(contactId, transportId); + StreamContext ctx = + keyManager.getStreamContext(contactId, transportId); assertNotNull(ctx); assertEquals(contactId, ctx.getContactId()); assertEquals(transportId, ctx.getTransportId()); assertArrayEquals(secret1, ctx.getSecret()); - assertEquals(0, ctx.getConnectionNumber()); + assertEquals(0, ctx.getStreamNumber()); assertEquals(true, ctx.getAlice()); keyManager.stop(); @@ -376,10 +376,10 @@ public class KeyRotationIntegrationTest extends BriarTestCase { final SecretKey k1 = context.mock(SecretKey.class, "k1"); final SecretKey k2 = context.mock(SecretKey.class, "k2"); - final ConnectionRecogniser connectionRecogniser = - new ConnectionRecogniserImpl(crypto, db); + final TagRecogniser tagRecogniser = + new TagRecogniserImpl(crypto, db); final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db, - eventBus, connectionRecogniser, clock, timer); + eventBus, tagRecogniser, clock, timer); // The secrets for periods 0 - 2 should be derived Endpoint ep = new Endpoint(contactId, transportId, EPOCH, true); @@ -450,7 +450,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase { will(new EncodeTagAction()); oneOf(k2).getEncoded(); will(returnValue(key2)); - oneOf(db).setConnectionWindow(contactId, transportId, 2, 1, + oneOf(db).setReorderingWindow(contactId, transportId, 2, 1, new byte[] {0, 1, 0, 0}); oneOf(k2).erase(); // stop() @@ -497,13 +497,12 @@ public class KeyRotationIntegrationTest extends BriarTestCase { // Recognise the tag for connection 0 in period 2 byte[] tag = new byte[TAG_LENGTH]; encodeTag(tag, key2, 0); - ConnectionContext ctx = - connectionRecogniser.acceptConnection(transportId, tag); + StreamContext ctx = tagRecogniser.recogniseTag(transportId, tag); assertNotNull(ctx); assertEquals(contactId, ctx.getContactId()); assertEquals(transportId, ctx.getTransportId()); assertArrayEquals(secret2, ctx.getSecret()); - assertEquals(0, ctx.getConnectionNumber()); + assertEquals(0, ctx.getStreamNumber()); assertEquals(true, ctx.getAlice()); keyManager.stop(); @@ -522,8 +521,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase { final SecretKey k1 = context.mock(SecretKey.class, "k1"); final SecretKey k2 = context.mock(SecretKey.class, "k2"); - final ConnectionRecogniser connectionRecogniser = - new ConnectionRecogniserImpl(crypto, db); + final TagRecogniser connectionRecogniser = + new TagRecogniserImpl(crypto, db); final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db, eventBus, connectionRecogniser, clock, timer); @@ -637,8 +636,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase { final SecretKey k2 = context.mock(SecretKey.class, "k2"); final SecretKey k3 = context.mock(SecretKey.class, "k3"); - final ConnectionRecogniser connectionRecogniser = - new ConnectionRecogniserImpl(crypto, db); + final TagRecogniser connectionRecogniser = + new TagRecogniserImpl(crypto, db); final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db, eventBus, connectionRecogniser, clock, timer); @@ -762,8 +761,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase { final SecretKey k3 = context.mock(SecretKey.class, "k3"); final SecretKey k4 = context.mock(SecretKey.class, "k4"); - final ConnectionRecogniser connectionRecogniser = - new ConnectionRecogniserImpl(crypto, db); + final TagRecogniser connectionRecogniser = + new TagRecogniserImpl(crypto, db); final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db, eventBus, connectionRecogniser, clock, timer); @@ -877,10 +876,10 @@ public class KeyRotationIntegrationTest extends BriarTestCase { context.assertIsSatisfied(); } - private void encodeTag(byte[] tag, byte[] rawKey, long connection) { - // Encode a fake tag based on the key and connection number + private void encodeTag(byte[] tag, byte[] rawKey, long streamNumber) { + // Encode a fake tag based on the key and stream number System.arraycopy(rawKey, 0, tag, 0, tag.length); - ByteUtils.writeUint32(connection, tag, 0); + ByteUtils.writeUint32(streamNumber, tag, 0); } private class EncodeTagAction implements Action { @@ -892,8 +891,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase { public Object invoke(Invocation invocation) throws Throwable { byte[] tag = (byte[]) invocation.getParameter(0); SecretKey key = (SecretKey) invocation.getParameter(1); - long connection = (Long) invocation.getParameter(2); - encodeTag(tag, key.getEncoded(), connection); + long streamNumber = (Long) invocation.getParameter(2); + encodeTag(tag, key.getEncoded(), streamNumber); return null; } } diff --git a/briar-tests/src/org/briarproject/transport/ConnectionWindowTest.java b/briar-tests/src/org/briarproject/transport/ReorderingWindowTest.java similarity index 85% rename from briar-tests/src/org/briarproject/transport/ConnectionWindowTest.java rename to briar-tests/src/org/briarproject/transport/ReorderingWindowTest.java index 2d60c037f7..f2b9f5837b 100644 --- a/briar-tests/src/org/briarproject/transport/ConnectionWindowTest.java +++ b/briar-tests/src/org/briarproject/transport/ReorderingWindowTest.java @@ -1,20 +1,19 @@ package org.briarproject.transport; -import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE; +import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE; import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED; import static org.junit.Assert.assertArrayEquals; import java.util.Collection; import org.briarproject.BriarTestCase; - import org.junit.Test; -public class ConnectionWindowTest extends BriarTestCase { +public class ReorderingWindowTest extends BriarTestCase { @Test public void testWindowSliding() { - ConnectionWindow w = new ConnectionWindow(); + ReorderingWindow w = new ReorderingWindow(); for(int i = 0; i < 100; i++) { assertFalse(w.isSeen(i)); w.setSeen(i); @@ -24,7 +23,7 @@ public class ConnectionWindowTest extends BriarTestCase { @Test public void testWindowJumping() { - ConnectionWindow w = new ConnectionWindow(); + ReorderingWindow w = new ReorderingWindow(); for(int i = 0; i < 100; i += 13) { assertFalse(w.isSeen(i)); w.setSeen(i); @@ -34,7 +33,7 @@ public class ConnectionWindowTest extends BriarTestCase { @Test public void testWindowUpperLimit() { - ConnectionWindow w = new ConnectionWindow(); + ReorderingWindow w = new ReorderingWindow(); // Centre is 0, highest value in window is 15 w.setSeen(15); // Centre is 16, highest value in window is 31 @@ -45,8 +44,8 @@ public class ConnectionWindowTest extends BriarTestCase { fail(); } catch(IllegalArgumentException expected) {} // Centre is max - 1, highest value in window is max - byte[] bitmap = new byte[CONNECTION_WINDOW_SIZE / 8]; - w = new ConnectionWindow(MAX_32_BIT_UNSIGNED - 1, bitmap); + byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8]; + w = new ReorderingWindow(MAX_32_BIT_UNSIGNED - 1, bitmap); assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED - 1)); assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED)); // Values greater than max should never be allowed @@ -59,7 +58,7 @@ public class ConnectionWindowTest extends BriarTestCase { // Centre should have moved to max + 1 assertEquals(MAX_32_BIT_UNSIGNED + 1, w.getCentre()); // The bit corresponding to max should be set - byte[] expectedBitmap = new byte[CONNECTION_WINDOW_SIZE / 8]; + byte[] expectedBitmap = new byte[REORDERING_WINDOW_SIZE / 8]; expectedBitmap[expectedBitmap.length / 2 - 1] = 1; // 00000001 assertArrayEquals(expectedBitmap, w.getBitmap()); // Values greater than max should never be allowed even if centre > max @@ -71,7 +70,7 @@ public class ConnectionWindowTest extends BriarTestCase { @Test public void testWindowLowerLimit() { - ConnectionWindow w = new ConnectionWindow(); + ReorderingWindow w = new ReorderingWindow(); // Centre is 0, negative values should never be allowed try { w.setSeen(-1); @@ -100,7 +99,7 @@ public class ConnectionWindowTest extends BriarTestCase { // Centre should still be 26 assertEquals(26, w.getCentre()); // The bits corresponding to 10, 15, 16 and 25 should be set - byte[] expectedBitmap = new byte[CONNECTION_WINDOW_SIZE / 8]; + byte[] expectedBitmap = new byte[REORDERING_WINDOW_SIZE / 8]; expectedBitmap[0] = (byte) 134; // 10000110 expectedBitmap[1] = 1; // 00000001 assertArrayEquals(expectedBitmap, w.getBitmap()); @@ -108,7 +107,7 @@ public class ConnectionWindowTest extends BriarTestCase { @Test public void testCannotSetSeenTwice() { - ConnectionWindow w = new ConnectionWindow(); + ReorderingWindow w = new ReorderingWindow(); w.setSeen(15); try { w.setSeen(15); @@ -117,8 +116,8 @@ public class ConnectionWindowTest extends BriarTestCase { } @Test - public void testGetUnseenConnectionNumbers() { - ConnectionWindow w = new ConnectionWindow(); + public void testGetUnseenStreamNumbers() { + ReorderingWindow w = new ReorderingWindow(); // Centre is 0; window should cover 0 to 15, inclusive, with none seen Collection<Long> unseen = w.getUnseen(); assertEquals(16, unseen.size()); diff --git a/briar-tests/src/org/briarproject/transport/ConnectionReaderImplTest.java b/briar-tests/src/org/briarproject/transport/StreamReaderImplTest.java similarity index 75% rename from briar-tests/src/org/briarproject/transport/ConnectionReaderImplTest.java rename to briar-tests/src/org/briarproject/transport/StreamReaderImplTest.java index 72650e2e22..67337a50ca 100644 --- a/briar-tests/src/org/briarproject/transport/ConnectionReaderImplTest.java +++ b/briar-tests/src/org/briarproject/transport/StreamReaderImplTest.java @@ -2,13 +2,13 @@ package org.briarproject.transport; import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH; import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH; -import org.briarproject.BriarTestCase; +import org.briarproject.BriarTestCase; import org.jmock.Expectations; import org.jmock.Mockery; import org.junit.Test; -public class ConnectionReaderImplTest extends BriarTestCase { +public class StreamReaderImplTest extends BriarTestCase { private static final int FRAME_LENGTH = 1024; private static final int MAX_PAYLOAD_LENGTH = @@ -28,13 +28,13 @@ public class ConnectionReaderImplTest extends BriarTestCase { oneOf(reader).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH); - assertEquals(0, c.read()); // Skip the first empty frame, read a byte - assertEquals(0, c.read()); // Read another byte - assertEquals(-1, c.read()); // Skip the second empty frame, reach EOF - assertEquals(-1, c.read()); // Still at EOF + StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH); + assertEquals(0, r.read()); // Skip the first empty frame, read a byte + assertEquals(0, r.read()); // Read another byte + assertEquals(-1, r.read()); // Skip the second empty frame, reach EOF + assertEquals(-1, r.read()); // Still at EOF context.assertIsSatisfied(); - c.close(); + r.close(); } @Test @@ -51,16 +51,16 @@ public class ConnectionReaderImplTest extends BriarTestCase { oneOf(reader).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH); + StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH); byte[] buf = new byte[MAX_PAYLOAD_LENGTH]; // Skip the first empty frame, read the two payload bytes - assertEquals(2, c.read(buf)); + assertEquals(2, r.read(buf)); // Skip the second empty frame, reach EOF - assertEquals(-1, c.read(buf)); + assertEquals(-1, r.read(buf)); // Still at EOF - assertEquals(-1, c.read(buf)); + assertEquals(-1, r.read(buf)); context.assertIsSatisfied(); - c.close(); + r.close(); } @Test @@ -73,16 +73,16 @@ public class ConnectionReaderImplTest extends BriarTestCase { oneOf(reader).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH); + StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH); byte[] buf = new byte[MAX_PAYLOAD_LENGTH / 2]; // Read the first half of the payload - assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf)); + assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf)); // Read the second half of the payload - assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf)); + assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf)); // Reach EOF - assertEquals(-1, c.read(buf, 0, buf.length)); + assertEquals(-1, r.read(buf, 0, buf.length)); context.assertIsSatisfied(); - c.close(); + r.close(); } @Test @@ -95,17 +95,17 @@ public class ConnectionReaderImplTest extends BriarTestCase { oneOf(reader).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH); + StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH); byte[] buf = new byte[MAX_PAYLOAD_LENGTH]; // Read the first half of the payload - assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf, MAX_PAYLOAD_LENGTH / 2, + assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, MAX_PAYLOAD_LENGTH / 2, MAX_PAYLOAD_LENGTH / 2)); // Read the second half of the payload - assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf, 123, + assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, 123, MAX_PAYLOAD_LENGTH / 2)); // Reach EOF - assertEquals(-1, c.read(buf, 0, buf.length)); + assertEquals(-1, r.read(buf, 0, buf.length)); context.assertIsSatisfied(); - c.close(); + r.close(); } } diff --git a/briar-tests/src/org/briarproject/transport/ConnectionWriterImplTest.java b/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java similarity index 83% rename from briar-tests/src/org/briarproject/transport/ConnectionWriterImplTest.java rename to briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java index 8ac7d795b6..8fc9cd6f1a 100644 --- a/briar-tests/src/org/briarproject/transport/ConnectionWriterImplTest.java +++ b/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java @@ -2,13 +2,13 @@ package org.briarproject.transport; import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH; import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH; -import org.briarproject.BriarTestCase; +import org.briarproject.BriarTestCase; import org.jmock.Expectations; import org.jmock.Mockery; import org.junit.Test; -public class ConnectionWriterImplTest extends BriarTestCase { +public class StreamWriterImplTest extends BriarTestCase { private static final int FRAME_LENGTH = 1024; private static final int MAX_PAYLOAD_LENGTH = @@ -25,8 +25,8 @@ public class ConnectionWriterImplTest extends BriarTestCase { // Flush the stream oneOf(writer).flush(); }}); - ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH); - c.close(); + StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH); + w.close(); context.assertIsSatisfied(); } @@ -34,12 +34,12 @@ public class ConnectionWriterImplTest extends BriarTestCase { public void testFlushWithoutBufferedDataWritesFrame() throws Exception { Mockery context = new Mockery(); final FrameWriter writer = context.mock(FrameWriter.class); - ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH); context.checking(new Expectations() {{ // Flush the stream oneOf(writer).flush(); }}); - c.flush(); + w.flush(); context.assertIsSatisfied(); } @@ -48,7 +48,7 @@ public class ConnectionWriterImplTest extends BriarTestCase { throws Exception { Mockery context = new Mockery(); final FrameWriter writer = context.mock(FrameWriter.class); - ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH); context.checking(new Expectations() {{ // Write a non-final frame with one payload byte oneOf(writer).writeFrame(with(any(byte[].class)), with(1), @@ -56,8 +56,8 @@ public class ConnectionWriterImplTest extends BriarTestCase { // Flush the stream oneOf(writer).flush(); }}); - c.write(0); - c.flush(); + w.write(0); + w.flush(); context.assertIsSatisfied(); } @@ -65,14 +65,14 @@ public class ConnectionWriterImplTest extends BriarTestCase { public void testSingleByteWritesWriteFullFrame() throws Exception { Mockery context = new Mockery(); final FrameWriter writer = context.mock(FrameWriter.class); - ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH); context.checking(new Expectations() {{ // Write a full non-final frame oneOf(writer).writeFrame(with(any(byte[].class)), with(MAX_PAYLOAD_LENGTH), with(false)); }}); for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) { - c.write(0); + w.write(0); } context.assertIsSatisfied(); } @@ -81,7 +81,7 @@ public class ConnectionWriterImplTest extends BriarTestCase { public void testMultiByteWritesWriteFullFrames() throws Exception { Mockery context = new Mockery(); final FrameWriter writer = context.mock(FrameWriter.class); - ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH); context.checking(new Expectations() {{ // Write two full non-final frames exactly(2).of(writer).writeFrame(with(any(byte[].class)), @@ -91,10 +91,10 @@ public class ConnectionWriterImplTest extends BriarTestCase { assertEquals(0, MAX_PAYLOAD_LENGTH % 2); // Write two full payloads using four multi-byte writes byte[] b = new byte[MAX_PAYLOAD_LENGTH / 2]; - c.write(b); - c.write(b); - c.write(b); - c.write(b); + w.write(b); + w.write(b); + w.write(b); + w.write(b); context.assertIsSatisfied(); } @@ -102,7 +102,7 @@ public class ConnectionWriterImplTest extends BriarTestCase { public void testLargeMultiByteWriteWritesFullFrames() throws Exception { Mockery context = new Mockery(); final FrameWriter writer = context.mock(FrameWriter.class); - ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH); context.checking(new Expectations() {{ // Write two full non-final frames exactly(2).of(writer).writeFrame(with(any(byte[].class)), @@ -115,9 +115,9 @@ public class ConnectionWriterImplTest extends BriarTestCase { }}); // Write two full payloads using one large multi-byte write byte[] b = new byte[MAX_PAYLOAD_LENGTH * 2 + 1]; - c.write(b); + w.write(b); // There should be one byte left in the buffer - c.close(); + w.close(); context.assertIsSatisfied(); } } diff --git a/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java b/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java index baf7b000c1..742e207412 100644 --- a/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java +++ b/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java @@ -2,7 +2,7 @@ package org.briarproject.transport; import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH; import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; -import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; +import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH; import static org.junit.Assert.assertArrayEquals; import java.io.ByteArrayInputStream; @@ -19,9 +19,9 @@ import org.briarproject.api.TransportId; import org.briarproject.api.crypto.AuthenticatedCipher; import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.SecretKey; -import org.briarproject.api.transport.ConnectionContext; -import org.briarproject.api.transport.ConnectionWriter; -import org.briarproject.api.transport.ConnectionWriterFactory; +import org.briarproject.api.transport.StreamContext; +import org.briarproject.api.transport.StreamWriter; +import org.briarproject.api.transport.StreamWriterFactory; import org.briarproject.crypto.CryptoModule; import org.junit.Test; @@ -35,7 +35,7 @@ public class TransportIntegrationTest extends BriarTestCase { private final int FRAME_LENGTH = 2048; private final CryptoComponent crypto; - private final ConnectionWriterFactory connectionWriterFactory; + private final StreamWriterFactory streamWriterFactory; private final ContactId contactId; private final TransportId transportId; private final AuthenticatedCipher frameCipher; @@ -45,15 +45,16 @@ public class TransportIntegrationTest extends BriarTestCase { public TransportIntegrationTest() { Module testModule = new AbstractModule() { + @Override public void configure() { - bind(ConnectionWriterFactory.class).to( - ConnectionWriterFactoryImpl.class); + bind(StreamWriterFactory.class).to( + StreamWriterFactoryImpl.class); } }; Injector i = Guice.createInjector(testModule, new CryptoModule(), new TestLifecycleModule(), new TestSystemModule()); crypto = i.getInstance(CryptoComponent.class); - connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class); + streamWriterFactory = i.getInstance(StreamWriterFactory.class); contactId = new ContactId(234); transportId = new TransportId("id"); frameCipher = crypto.getFrameCipher(); @@ -86,7 +87,7 @@ public class TransportIntegrationTest extends BriarTestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); FrameWriter encryptionOut = new OutgoingEncryptionLayer(out, Long.MAX_VALUE, frameCipher, frameCopy, FRAME_LENGTH); - ConnectionWriterImpl writer = new ConnectionWriterImpl(encryptionOut, + StreamWriterImpl writer = new StreamWriterImpl(encryptionOut, FRAME_LENGTH); OutputStream out1 = writer.getOutputStream(); out1.write(frame); @@ -99,7 +100,7 @@ public class TransportIntegrationTest extends BriarTestCase { ByteArrayInputStream in = new ByteArrayInputStream(output); FrameReader encryptionIn = new IncomingEncryptionLayer(in, frameCipher, frameKey, FRAME_LENGTH); - ConnectionReaderImpl reader = new ConnectionReaderImpl(encryptionIn, + StreamReaderImpl reader = new StreamReaderImpl(encryptionIn, FRAME_LENGTH); InputStream in1 = reader.getInputStream(); byte[] recovered = new byte[frame.length]; @@ -127,42 +128,42 @@ public class TransportIntegrationTest extends BriarTestCase { @Test public void testOverheadWithTag() throws Exception { ByteArrayOutputStream out = - new ByteArrayOutputStream(MIN_CONNECTION_LENGTH); - ConnectionContext ctx = new ConnectionContext(contactId, transportId, + new ByteArrayOutputStream(MIN_STREAM_LENGTH); + StreamContext ctx = new StreamContext(contactId, transportId, secret, 0, true); - ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out, - MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, true); + StreamWriter w = streamWriterFactory.createStreamWriter(out, + MAX_FRAME_LENGTH, MIN_STREAM_LENGTH, ctx, false, true); // Check that the connection writer thinks there's room for a packet long capacity = w.getRemainingCapacity(); assertTrue(capacity > MAX_PACKET_LENGTH); - assertTrue(capacity < MIN_CONNECTION_LENGTH); + assertTrue(capacity < MIN_STREAM_LENGTH); // Check that there really is room for a packet byte[] payload = new byte[MAX_PACKET_LENGTH]; w.getOutputStream().write(payload); w.getOutputStream().close(); long used = out.size(); assertTrue(used > MAX_PACKET_LENGTH); - assertTrue(used <= MIN_CONNECTION_LENGTH); + assertTrue(used <= MIN_STREAM_LENGTH); } @Test public void testOverheadWithoutTag() throws Exception { ByteArrayOutputStream out = - new ByteArrayOutputStream(MIN_CONNECTION_LENGTH); - ConnectionContext ctx = new ConnectionContext(contactId, transportId, + new ByteArrayOutputStream(MIN_STREAM_LENGTH); + StreamContext ctx = new StreamContext(contactId, transportId, secret, 0, true); - ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out, - MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, false); + StreamWriter w = streamWriterFactory.createStreamWriter(out, + MAX_FRAME_LENGTH, MIN_STREAM_LENGTH, ctx, false, false); // Check that the connection writer thinks there's room for a packet long capacity = w.getRemainingCapacity(); assertTrue(capacity > MAX_PACKET_LENGTH); - assertTrue(capacity < MIN_CONNECTION_LENGTH); + assertTrue(capacity < MIN_STREAM_LENGTH); // Check that there really is room for a packet byte[] payload = new byte[MAX_PACKET_LENGTH]; w.getOutputStream().write(payload); w.getOutputStream().close(); long used = out.size(); assertTrue(used > MAX_PACKET_LENGTH); - assertTrue(used <= MIN_CONNECTION_LENGTH); + assertTrue(used <= MIN_STREAM_LENGTH); } } diff --git a/briar-tests/src/org/briarproject/transport/TransportConnectionRecogniserTest.java b/briar-tests/src/org/briarproject/transport/TransportTagRecogniserTest.java similarity index 80% rename from briar-tests/src/org/briarproject/transport/TransportConnectionRecogniserTest.java rename to briar-tests/src/org/briarproject/transport/TransportTagRecogniserTest.java index fb53b18c11..ba1e84d48a 100644 --- a/briar-tests/src/org/briarproject/transport/TransportConnectionRecogniserTest.java +++ b/briar-tests/src/org/briarproject/transport/TransportTagRecogniserTest.java @@ -11,7 +11,7 @@ import org.briarproject.api.TransportId; import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.db.DatabaseComponent; -import org.briarproject.api.transport.ConnectionContext; +import org.briarproject.api.transport.StreamContext; import org.briarproject.api.transport.TemporarySecret; import org.briarproject.util.ByteUtils; import org.hamcrest.Description; @@ -21,7 +21,7 @@ import org.jmock.api.Action; import org.jmock.api.Invocation; import org.junit.Test; -public class TransportConnectionRecogniserTest extends BriarTestCase { +public class TransportTagRecogniserTest extends BriarTestCase { private final ContactId contactId = new ContactId(234); private final TransportId transportId = new TransportId("id"); @@ -57,15 +57,15 @@ public class TransportConnectionRecogniserTest extends BriarTestCase { }}); TemporarySecret s = new TemporarySecret(contactId, transportId, 123, alice, 0, secret, 0, 0, new byte[4]); - TransportConnectionRecogniser recogniser = - new TransportConnectionRecogniser(crypto, db, transportId); + TransportTagRecogniser recogniser = + new TransportTagRecogniser(crypto, db, transportId); recogniser.addSecret(s); recogniser.removeSecret(contactId, 0); context.assertIsSatisfied(); } @Test - public void testAcceptConnection() throws Exception { + public void testRecogniseTag() throws Exception { Mockery context = new Mockery(); final CryptoComponent crypto = context.mock(CryptoComponent.class); final byte[] secret = new byte[32]; @@ -83,33 +83,35 @@ public class TransportConnectionRecogniserTest extends BriarTestCase { will(new EncodeTagAction()); } oneOf(tagKey).erase(); - // Accept connection 0 + // Recognise tag 0 oneOf(crypto).deriveTagKey(secret, !alice); will(returnValue(tagKey)); - // The window should slide to include connection 16 + // The window should slide to include tag 16 oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey), with(16L)); will(new EncodeTagAction()); // The updated window should be stored - oneOf(db).setConnectionWindow(contactId, transportId, 0, 1, + oneOf(db).setReorderingWindow(contactId, transportId, 0, 1, new byte[] {0, 1, 0, 0}); oneOf(tagKey).erase(); - // Accept connection again - no expectations + // Recognise tag again - no expectations }}); TemporarySecret s = new TemporarySecret(contactId, transportId, 123, alice, 0, secret, 0, 0, new byte[4]); - TransportConnectionRecogniser recogniser = - new TransportConnectionRecogniser(crypto, db, transportId); + TransportTagRecogniser recogniser = + new TransportTagRecogniser(crypto, db, transportId); recogniser.addSecret(s); - // Connection 0 should be expected + // Tag 0 should be expected byte[] tag = new byte[TAG_LENGTH]; - ConnectionContext ctx = recogniser.acceptConnection(tag); + StreamContext ctx = recogniser.recogniseTag(tag); assertNotNull(ctx); assertEquals(contactId, ctx.getContactId()); assertEquals(transportId, ctx.getTransportId()); assertArrayEquals(secret, ctx.getSecret()); - assertEquals(0, ctx.getConnectionNumber()); + assertEquals(0, ctx.getStreamNumber()); assertEquals(alice, ctx.getAlice()); + // Tag 0 should not be expected again + assertNull(recogniser.recogniseTag(tag)); context.assertIsSatisfied(); } @@ -121,9 +123,9 @@ public class TransportConnectionRecogniserTest extends BriarTestCase { public Object invoke(Invocation invocation) throws Throwable { byte[] tag = (byte[]) invocation.getParameter(0); - long connection = (Long) invocation.getParameter(2); - // Encode a fake tag based on the connection number - ByteUtils.writeUint32(connection, tag, 0); + long streamNumber = (Long) invocation.getParameter(2); + // Encode a fake tag based on the stream number + ByteUtils.writeUint32(streamNumber, tag, 0); return null; } } diff --git a/briar-tests/src/org/briarproject/util/ByteUtilsTest.java b/briar-tests/src/org/briarproject/util/ByteUtilsTest.java index a188eb77ee..fee925e205 100644 --- a/briar-tests/src/org/briarproject/util/ByteUtilsTest.java +++ b/briar-tests/src/org/briarproject/util/ByteUtilsTest.java @@ -1,7 +1,6 @@ package org.briarproject.util; import org.briarproject.BriarTestCase; - import org.junit.Test; public class ByteUtilsTest extends BriarTestCase { diff --git a/briar-tests/src/org/briarproject/util/StringUtilsTest.java b/briar-tests/src/org/briarproject/util/StringUtilsTest.java index 13dfc67411..d23dd397f3 100644 --- a/briar-tests/src/org/briarproject/util/StringUtilsTest.java +++ b/briar-tests/src/org/briarproject/util/StringUtilsTest.java @@ -1,8 +1,8 @@ package org.briarproject.util; import static org.junit.Assert.assertArrayEquals; -import org.briarproject.BriarTestCase; +import org.briarproject.BriarTestCase; import org.junit.Test; public class StringUtilsTest extends BriarTestCase { -- GitLab