* Locking: write.
*/
- boolean addTransport(T txn, TransportId t, long maxLatency)
+ boolean addTransport(T txn, TransportId t, int maxLatency)
throws DbException;
/**
@@ -460,7 +460,7 @@ interface Database
* Locking: write.
*/
- RetentionUpdate getRetentionUpdate(T txn, ContactId c, long maxLatency)
+ RetentionUpdate getRetentionUpdate(T txn, ContactId c, int maxLatency)
throws DbException;
/**
@@ -499,7 +499,7 @@ interface Database
* Locking: read.
*/
- Map
* Locking: write.
*/
- void updateExpiryTime(T txn, ContactId c, MessageId m, long maxLatency)
+ void updateExpiryTime(T txn, ContactId c, MessageId m, int maxLatency)
throws DbException;
}
diff --git a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
index c22643f0b..1c8bc564d 100644
--- a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
+++ b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
@@ -314,7 +314,7 @@ DatabaseCleaner.Callback {
}
}
- public boolean addTransport(TransportId t, long maxLatency)
+ public boolean addTransport(TransportId t, int maxLatency)
throws DbException {
boolean added;
lock.writeLock().lock();
@@ -357,7 +357,7 @@ DatabaseCleaner.Callback {
}
public Collection
* This class is not thread-safe.
*/
-class StreamWriterImpl extends OutputStream implements StreamWriter {
+class StreamWriterImpl extends OutputStream {
- private final FrameWriter out;
- private final byte[] frame;
- private final int frameLength;
+ private final StreamEncrypter encrypter;
+ private final byte[] payload;
private int length = 0;
- StreamWriterImpl(FrameWriter out, int frameLength) {
- this.out = out;
- this.frameLength = frameLength;
- frame = new byte[frameLength - MAC_LENGTH];
- }
-
- public OutputStream getOutputStream() {
- return this;
+ StreamWriterImpl(StreamEncrypter encrypter) {
+ this.encrypter = encrypter;
+ payload = new byte[MAX_PAYLOAD_LENGTH];
}
@Override
public void close() throws IOException {
writeFrame(true);
- out.flush();
+ encrypter.flush();
super.close();
}
@Override
public void flush() throws IOException {
- if(length > 0) writeFrame(false);
- out.flush();
+ writeFrame(false);
+ encrypter.flush();
}
@Override
public void write(int b) throws IOException {
- frame[HEADER_LENGTH + length] = (byte) b;
+ payload[length] = (byte) b;
length++;
- if(HEADER_LENGTH + length + MAC_LENGTH == frameLength)
- writeFrame(false);
+ if(length == payload.length) writeFrame(false);
}
@Override
@@ -61,21 +53,21 @@ class StreamWriterImpl extends OutputStream implements StreamWriter {
@Override
public void write(byte[] b, int off, int len) throws IOException {
- int available = frameLength - HEADER_LENGTH - length - MAC_LENGTH;
+ int available = payload.length - length;
while(available <= len) {
- System.arraycopy(b, off, frame, HEADER_LENGTH + length, available);
+ System.arraycopy(b, off, payload, length, available);
length += available;
writeFrame(false);
off += available;
len -= available;
- available = frameLength - HEADER_LENGTH - length - MAC_LENGTH;
+ available = payload.length - length;
}
- System.arraycopy(b, off, frame, HEADER_LENGTH + length, len);
+ System.arraycopy(b, off, payload, length, len);
length += len;
}
private void writeFrame(boolean finalFrame) throws IOException {
- out.writeFrame(frame, length, finalFrame);
+ encrypter.writeFrame(payload, length, 0, finalFrame);
length = 0;
}
}
diff --git a/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java
index 353681d49..b7042429a 100644
--- a/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java
+++ b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java
@@ -62,13 +62,10 @@ class TransportTagRecogniser {
assert duplicate == null;
}
}
- key.erase();
// 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 StreamContext(t.contactId, transportId, secret,
+ return new StreamContext(t.contactId, transportId, t.secret,
t.streamNumber, t.alice);
}
finally{
@@ -96,7 +93,6 @@ class TransportTagRecogniser {
TagContext duplicate = tagMap.put(new Bytes(tag), added);
assert duplicate == null;
}
- key.erase();
// Create a removal context to remove the window and the tags later
RemovalContext r = new RemovalContext(window, secret, alice);
removalMap.put(new RemovalKey(contactId, period), r);
@@ -128,7 +124,6 @@ class TransportTagRecogniser {
TagContext removed = tagMap.remove(new Bytes(tag));
assert removed != null;
}
- key.erase();
}
void removeSecrets(ContactId c) {
diff --git a/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java.orig b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java.orig
new file mode 100644
index 000000000..0e46da82e
--- /dev/null
+++ b/briar-core/src/org/briarproject/transport/TransportTagRecogniser.java.orig
@@ -0,0 +1,235 @@
+package org.briarproject.transport;
+
+import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.briarproject.api.Bytes;
+import org.briarproject.api.ContactId;
+import org.briarproject.api.TransportId;
+import org.briarproject.api.crypto.CryptoComponent;
+import org.briarproject.api.crypto.SecretKey;
+import org.briarproject.api.db.DatabaseComponent;
+import org.briarproject.api.db.DbException;
+import org.briarproject.api.transport.StreamContext;
+import org.briarproject.api.transport.TemporarySecret;
+
+// FIXME: Don't make alien calls with a lock held
+/**
+ * A {@link org.briarproject.api.transport.TagRecogniser TagRecogniser} for a
+ * specific transport.
+ */
+class TransportTagRecogniser {
+
+ private final CryptoComponent crypto;
+ private final DatabaseComponent db;
+ private final TransportId transportId;
+ private final Map