diff --git a/briar-android/src/org/briarproject/android/TestingActivity.java b/briar-android/src/org/briarproject/android/TestingActivity.java
index 7fcc1b35791c868a666704cf9c9d92754e212f47..80f0d8fd7338c367eacf71e064e96d65550c52dc 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 82916876676d451d62216225415a6ebd49b4445f..62d60102d0d6ba608b9ceb6bcb69502b9aa3440a 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 f53b1fea540dfa0790c638e990e04e6e6158bac0..2cc9ac48d590bc9fc259ef825e5ca8831074cd0e 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 e40614efc635836a59f99ba02de030c10227dcdc..b946f57606f956cc90abfab69169fdaa27a41877 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 94bc503a130e59ceb9e59797ae5f49e7508b0e15..59e4d7af3083c5d034de0ef0040806a5162944a3 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 751ef78c9a5774d0a138e4adcaec714eaf905c4d..e7b55dd6d2bf857e89825fcdc12d7bdff18521e1 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 a30881eca663f3c7c6f373f2edb80b1ee834e14d..0f52b490100a54f6a7352d7a09db211a1d426342 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 b0c8e313ea559720990b1aba01219c20a117c7de..977df2176ffef7733c817167ef8d10e57b9e0d39 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 8ecd4978bdc2498fe61cdee9165cfe09e75c34d5..61f75a084a3300bce0584f252cddb08c8d31f354 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 eb81685ec7d8284f7247552978b6d9cfb59ea14e..27f41ce3fad0057d2dd13c09f149bfa2ce34d2de 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 2757e43180209c1c3880a78085ad859d59af7b9b..0000000000000000000000000000000000000000
--- 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 39ec863005eddcfa0a4bdde72a399df90a9262e4..0000000000000000000000000000000000000000
--- 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 017ca9fdae5cb8a4add6a049dcaa5da362b1fd0b..0000000000000000000000000000000000000000
--- 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 16434bdc538fe8f5ca8a1f3865ef72fa8cdfeef3..61554c0aceb5043482ef499b653340ea5d5b00d6 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 a4dc40b15233467e63153a91e655cf934215c69d..2fef7b4df0a913f119c7436090d85046f8fbb164 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 0000000000000000000000000000000000000000..8c43c30eb539c8c90c769feb05b6a17e808f8f61
--- /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 b195785991c174403a467baa5b0263faa8e6cb48..e5f50ecce8bbc229470a11367c7e7aef0052863b 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 0000000000000000000000000000000000000000..f3b8e1c2f86e5afdb364c42168797c4d6cce2b6d
--- /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 0000000000000000000000000000000000000000..a6823a2e932a85f45bd6a79e1a32b4e8a9b22f2d
--- /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 f3a858425e37c857df6e076239350c2d0965e584..37ed630e463286c0a2a65943933426193e59bb53 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 da5eff390fda3547c7ad0ace899f83b9943f7345..666d74e964b00202b89b907c1011caa5e98616d3 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 167fb84f336417edd5cd0364c9f2ad1d89aad8ba..dc4dbba95cef4dfd8486d6c24ed70a59d049620b 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 c6186596f18f76a6d70d0905e84ea5e05b3a44d4..1d1fdd99d1b5f5d040da4b2bdbf29a97cd0eea5f 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 256001dbaf74f66e13b572e59473c89f21174c58..ff3877207426e1f7898ca0c83373162be8187836 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 ad0fb223e0fe77e67e9db09977a4e0747bc73e0c..5bce51798e1ce545ec8e51b5656a85006cf7239c 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 6683d36702c6d13b7c5c89ded82292c70d28ffd8..c22643f0be075806ecc43d52659faddb86a11bf5 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 5d51ad10491df44a9e907ea1093f4849d17863c9..fdeab4e543fb2d5806cf0244978e325bbbaccb03 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 18d603ba0056b6d39ff2622dd6b3525ff9cb73c3..455e1a6bda1dfd6bc09bb67a0836fb19f390f75d 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 c51dec4e22d1665a2235e02aea68dc019403197f..584f5b81f972282a6f62c5304425eb11b26fb24b 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 74d88dac0fff8177251dd41a3dbc961024ab676b..36b84860f532b7a30a68bd07a97425006468cc07 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 7ce73fcc85c620788d74c66ad5950d1785335127..7473c27b7e6f7e100b5dbdc5052b09fb55ef3f2d 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 c0b048720491e36c8cf7ee24369cbc916b90a5ae..e847269f703a203fe06caa4ae98b4f333723e35e 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 e967a97077d56a39ed47fdb0d09a97963f9a1984..3ac77ef5bf3ccc1b93fd86c1193dd4e4dd22be19 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 88c7fbbe82db3ea198c7786935b18e9da2bf4345..0ba89f29fd93a0b649a9586b507c10bbe71af0da 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 dfb71541dc0a838cbc1d99e2f4c303936796bbe5..f8affa8dde6ddb479ac883c32e65488dc3797952 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 ed63fe015f214d973036332960ded5b152ee60f0..52e4e931810f29948de4e5eb495660b75e28c6c4 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 4305674c1645aed2addcd46adc7eb9497a4091bb..7eab0226d9e8cabeccc18752f156f72190ff9a97 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 ac997916f81c14173cde529561b203f35fe1e576..72162747c2c5ac167a27d0f107d78dc290d174c1 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 1f1b205fd8026ca9dc11e6f84168f6adc49179ec..94fd128ff7aab12e6409709a87d77b0ef8e7f5ed 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 aeff21e837cc469570cd7b8c2a059e13758af379..f202d061eba2b9715943a3cb8c6fd251617fe49b 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 722897476e04e8b08f50421f4f9e3156b70d942d..1e14f9c72c0cbd00ecf6c283ee3af63df753d33c 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 60628f33e066861fe4d23f7ac42b772fd1e6570d..03020373660ff631dd65106b376e82428b6d2be6 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 648fbaa5eeb06c1194b58200927a9ad4f83e0211..5ac8251fc73dc608f94e11d942de43c741fb4b20 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 9844ad30e349b8b6837435a870650896e32897cd..adda06a5602036dd9483de27d06d7ca9fa8061eb 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 53f89941245063618f5801cb1bf20aec834dd6a5..684b8754248391d6d8c01dca3b89b12ca55cf252 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 3b0ff81c89e6278aca91479254b68cd013f4245f..c6617da8bc2cbc3fda991b3f72cfd338c4a14f5e 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 13cdcb5e3a1e1fdf7e65108f9287b02e7a414c35..951319ddfa64855ca0f61b9b4b97acf90b39278d 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 fca67c69e227d51c1876ef525f9b15a69540d855..d2997b36635c4548306c0e80a95e45bd27cc92de 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 f1a7e4328537bf41cdef57cc7032d699520abec7..0de048a6fa67f805425a645c01affdc8fbd46cf0 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 7ad0ec06e3be7986666fc03e8f405dfec7aa085e..1935fea1be241f80218264eb3ae7bcbc2fe92fe8 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 0274b7b3921483b9f579e5800a5b97b3b0c8cc18..82de19e1e0012fc6ad0ae396c21e19986f34bee3 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 421791317a2cee35f19c81fb4b5fdf5430d19f53..a929bc2d985cdadef26696823166f274de093f7a 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 6ac7a15c939dbfc2b8ab4afd72222a1f2bee2bdc..3567b45fb466014b578d9dad995c4a81b404764a 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 75f1a57a8dd9643a2c4c2676b32e8d0cd1f08dab..3c9508397c757219c331a469b0c61489a0c7fde1 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 5cabb5cf0c7373b0f11d12335be6a1a8b065b20c..ea0af1c42596ccd754f9b071e9785e7718660281 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 a93657ab504d4d80f448d72e02f77d50bf500d2e..e126d2dceb96441e923f8ad36bfa1af844c0db75 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 6441b83e41da2d833e688a4110eeb5c637ec9412..9e1b190adfb1baba0d647bf762ee4dfb3d8e9b43 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 d2c02c078aef2a11dada6f80e868ccf540d36096..4b27522e84c17a756ce52e1a6e0f261f277758ac 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 a4d8e7b78f0d3fc2bb9c38193d29df7d00b0ba91..44b4d3a9fc8faa0ec32779570ac11a2a07f86fb6 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 b56b73900a0956706b49129c2084be76f6fa0ff1..20ee3605bf954d68df560c0d11bfb47d4bbeb599 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 fc5b1434c9117dcd78379982bb20aebdfe012a15..bf490af01347e16784b4bdca6a4c569e2e51af78 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 7bb0c12ce7a8951eca492738bb79b0e26d48175e..57855cfb6f8e8c6277ec501ca7acd720a99343e4 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 06ab48e61539b58c938ad5bd2e4cce96c7189b76..923939e304409933a61520588f800dfdc94aa35a 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 40658bf428fdefd69adb87112fcdee0621974905..3ecaf692a1501f0bc085b8d2c25c463bfce7828c 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 9bc3c222d3d37d14e3eedd86c01a65994942998f..8243cd4641a3a96cad335b3916324276c974b0be 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 ad026476234747e663e242e6fae264e2260dd2c3..d93f42d05b63c7bcdf14e57c5b63edee85f3a965 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 daf7559ff35e483e6be0392f75a78c736054538c..ccf1038d22e55962c453e4f9c7abe700cd0b00d9 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 e3b1af51413145989dbc6c8255bf7a823fb798a6..097f2dab19861ab8dd44ae107f5c6ad68f06114b 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 4f421c6127362d30aa57ad3d4901216a8a00be32..3de41423c4f04d3135a61882f8b42ff1abc2e759 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 659d4d8412d826818abcdaeba5339050a0950e83..e26b4be88458e1ed464fc54d3090c5dddfab28c7 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 a9c4bc5bb68d81312552cd1f7ca98249889db520..d79fad795e3e471d85a84e36cba7dc0b85b070ea 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 87ad6f655c40cbe8047912ce6b093c0993176542..f9156c913662014221e584e9dde6106268440d8c 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 b34b826137c00b0f871011767f71b2e3a1e205ab..061d6d007efab04a753a79bebf52a5a09e2cd2ed 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 3875c1f7025fef9b4b7b4e93ef8c80bbe70b24fe..b799262185d751e8cc068677e41ce8d6244d2a94 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 da85b94bb453ecf4b85b6291f946c099106877ab..29786b4432e851824434fb6fb7cb8c12571d50bb 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 08b05a38e07eb54c6805bafada631d2afa5ccd06..85a8ce4b4cdbb6dc9d48958ea659c527f367c151 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 6969f67df5398af49a50c2995b464d0515872ac7..d7beae54dd517a8245208246bf4c339cde5a01ff 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 2d60c037f71d1b6be24d27b87a041e08de4f7619..f2b9f5837b968bc1d53b67c6eaba39fb2700328e 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 72650e2e223a2e74cab8723af8a2e7171e84337c..67337a50ca4fca64e76f3ffa6b82fd54450e84ce 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 8ac7d795b60eb5ae7d869cc93d8616dd9009fb08..8fc9cd6f1ab1dda270ba31fb02ab7189b8e93c72 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 baf7b000c19f8c7487be63521ce616d7460ff5f4..742e2074128fd4602ecb54fbf03ffa7b9b25363e 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 fb53b18c1106ca6f6bf2c13efe0b4b516a9100c0..ba1e84d48a13f583801e135f55255faf8df808a1 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 a188eb77eec63e65d3b683c59b65afc19d1ddc40..fee925e205f6ff9966c11504c1f88debfb8cfc23 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 13dfc674118a746b7b8b0c0009c8410eafe0905f..d23dd397f36745aefb000cf745318e13d437b148 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 {