mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Renamed a load of things from 'connection' to 'stream'.
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.crypto;
|
||||
|
||||
import org.briarproject.api.crypto.MessageDigest;
|
||||
|
||||
import org.spongycastle.crypto.Digest;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.crypto;
|
||||
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
|
||||
import org.spongycastle.crypto.params.ECPrivateKeyParameters;
|
||||
|
||||
class Sec1PrivateKey implements PrivateKey {
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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() {
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user