Renamed a load of things from 'connection' to 'stream'.

This commit is contained in:
akwizgran
2014-10-08 16:18:33 +01:00
parent 39f79b55ef
commit b24f153704
84 changed files with 671 additions and 671 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;
/**

View File

@@ -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;

View File

@@ -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,

View File

@@ -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,

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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() {

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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;
}