mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Code cleanup: don't use L for long constants unless it's necessary.
This commit is contained in:
@@ -11,7 +11,7 @@ import net.sf.briar.api.FormatException;
|
|||||||
public class CountingConsumer implements Consumer {
|
public class CountingConsumer implements Consumer {
|
||||||
|
|
||||||
private final long limit;
|
private final long limit;
|
||||||
private long count = 0L;
|
private long count = 0;
|
||||||
|
|
||||||
public CountingConsumer(long limit) {
|
public CountingConsumer(long limit) {
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class TemporarySecret extends Endpoint {
|
|||||||
long epoch, long clockDiff, long latency, boolean alice,
|
long epoch, long clockDiff, long latency, boolean alice,
|
||||||
long period, byte[] secret) {
|
long period, byte[] secret) {
|
||||||
this(contactId, transportId, epoch, clockDiff, latency, alice, period,
|
this(contactId, transportId, epoch, clockDiff, latency, alice, period,
|
||||||
secret, 0L, 0L, new byte[CONNECTION_WINDOW_SIZE / 8]);
|
secret, 0, 0, new byte[CONNECTION_WINDOW_SIZE / 8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a temporary secret derived from the given endpoint. */
|
/** Creates a temporary secret derived from the given endpoint. */
|
||||||
|
|||||||
@@ -142,8 +142,8 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ErasableKey deriveTagKey(byte[] secret, boolean alice) {
|
public ErasableKey deriveTagKey(byte[] secret, boolean alice) {
|
||||||
if(alice) return deriveKey(secret, A_TAG, 0L);
|
if(alice) return deriveKey(secret, A_TAG, 0);
|
||||||
else return deriveKey(secret, B_TAG, 0L);
|
else return deriveKey(secret, B_TAG, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErasableKey deriveFrameKey(byte[] secret, long connection,
|
public ErasableKey deriveFrameKey(byte[] secret, long connection,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class DatabaseCleanerImpl extends TimerTask implements DatabaseCleaner {
|
|||||||
|
|
||||||
public void startCleaning(Callback callback, long msBetweenSweeps) {
|
public void startCleaning(Callback callback, long msBetweenSweeps) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
timer.scheduleAtFixedRate(this, 0L, msBetweenSweeps);
|
timer.scheduleAtFixedRate(this, 0, msBetweenSweeps);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopCleaning() {
|
public void stopCleaning() {
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ DatabaseCleaner.Callback {
|
|||||||
new CopyOnWriteArrayList<DatabaseListener>();
|
new CopyOnWriteArrayList<DatabaseListener>();
|
||||||
|
|
||||||
private final Object spaceLock = new Object();
|
private final Object spaceLock = new Object();
|
||||||
private long bytesStoredSinceLastCheck = 0L; // Locking: spaceLock
|
private long bytesStoredSinceLastCheck = 0; // Locking: spaceLock
|
||||||
private long timeOfLastCheck = 0L; // Locking: spaceLock
|
private long timeOfLastCheck = 0; // Locking: spaceLock
|
||||||
|
|
||||||
private final Object openCloseLock = new Object();
|
private final Object openCloseLock = new Object();
|
||||||
private boolean open = false; // Locking: openCloseLock;
|
private boolean open = false; // Locking: openCloseLock;
|
||||||
@@ -1829,7 +1829,7 @@ DatabaseCleaner.Callback {
|
|||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
if(bytesStoredSinceLastCheck > MAX_BYTES_BETWEEN_SPACE_CHECKS
|
if(bytesStoredSinceLastCheck > MAX_BYTES_BETWEEN_SPACE_CHECKS
|
||||||
|| now - timeOfLastCheck > MAX_MS_BETWEEN_SPACE_CHECKS) {
|
|| now - timeOfLastCheck > MAX_MS_BETWEEN_SPACE_CHECKS) {
|
||||||
bytesStoredSinceLastCheck = 0L;
|
bytesStoredSinceLastCheck = 0;
|
||||||
timeOfLastCheck = now;
|
timeOfLastCheck = now;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ interface DatabaseConstants {
|
|||||||
* The amount of free space will be checked whenever this many milliseconds
|
* The amount of free space will be checked whenever this many milliseconds
|
||||||
* have passed since the last check.
|
* have passed since the last check.
|
||||||
*/
|
*/
|
||||||
long MAX_MS_BETWEEN_SPACE_CHECKS = 60L * 1000L; // 1 min
|
long MAX_MS_BETWEEN_SPACE_CHECKS = 60 * 1000; // 1 min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Up to this many bytes of messages will be expired from the database each
|
* Up to this many bytes of messages will be expired from the database each
|
||||||
@@ -40,11 +40,11 @@ interface DatabaseConstants {
|
|||||||
* The timestamp of the oldest message in the database is rounded using
|
* The timestamp of the oldest message in the database is rounded using
|
||||||
* this modulus to avoid revealing the presence of any particular message.
|
* this modulus to avoid revealing the presence of any particular message.
|
||||||
*/
|
*/
|
||||||
long RETENTION_MODULUS = 60L * 60L * 1000L; // 1 hour
|
long RETENTION_MODULUS = 60 * 60 * 1000; // 1 hour
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time in milliseconds after which a subscription or transport update
|
* The time in milliseconds after which a subscription or transport update
|
||||||
* should be sent to a contact even if no changes have occurred.
|
* should be sent to a contact even if no changes have occurred.
|
||||||
*/
|
*/
|
||||||
long MAX_UPDATE_INTERVAL = 12L * 60L * 60L * 1000L; // 12 hours
|
long MAX_UPDATE_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1017,7 +1017,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected long getDiskSpace(File f) {
|
protected long getDiskSpace(File f) {
|
||||||
long total = 0L;
|
long total = 0;
|
||||||
if(f.isDirectory()) {
|
if(f.isDirectory()) {
|
||||||
for(File child : f.listFiles()) total += getDiskSpace(child);
|
for(File child : f.listFiles()) total += getDiskSpace(child);
|
||||||
return total;
|
return total;
|
||||||
@@ -1812,7 +1812,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
List<Group> subs = new ArrayList<Group>();
|
List<Group> subs = new ArrayList<Group>();
|
||||||
long version = 0L;
|
long version = 0;
|
||||||
while(rs.next()) {
|
while(rs.next()) {
|
||||||
byte[] id = rs.getBytes(1);
|
byte[] id = rs.getBytes(1);
|
||||||
String name = rs.getString(2);
|
String name = rs.getString(2);
|
||||||
@@ -2053,7 +2053,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if(!rs.next()) {
|
if(!rs.next()) {
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
return -1L;
|
return -1;
|
||||||
}
|
}
|
||||||
long connection = rs.getLong(1);
|
long connection = rs.getLong(1);
|
||||||
if(rs.next()) throw new DbStateException();
|
if(rs.next()) throw new DbStateException();
|
||||||
@@ -2492,12 +2492,12 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setBytes(2, t.getBytes());
|
ps.setBytes(2, t.getBytes());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
long currentVersion = rs.next() ? rs.getLong(1) : -1L;
|
long currentVersion = rs.next() ? rs.getLong(1) : -1;
|
||||||
if(rs.next()) throw new DbStateException();
|
if(rs.next()) throw new DbStateException();
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
// Mark the update as needing to be acked
|
// Mark the update as needing to be acked
|
||||||
if(currentVersion == -1L) {
|
if(currentVersion == -1) {
|
||||||
// The row doesn't exist - create it
|
// The row doesn't exist - create it
|
||||||
sql = "INSERT INTO contactTransportVersions (contactId,"
|
sql = "INSERT INTO contactTransportVersions (contactId,"
|
||||||
+ " transportId, remoteVersion, remoteAcked)"
|
+ " transportId, remoteVersion, remoteAcked)"
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class MessageReader implements StructReader<UnverifiedMessage> {
|
|||||||
String subject = r.readString(MAX_SUBJECT_LENGTH);
|
String subject = r.readString(MAX_SUBJECT_LENGTH);
|
||||||
// Read the timestamp
|
// Read the timestamp
|
||||||
long timestamp = r.readInt64();
|
long timestamp = r.readInt64();
|
||||||
if(timestamp < 0L) throw new FormatException();
|
if(timestamp < 0) throw new FormatException();
|
||||||
// Read the salt
|
// Read the salt
|
||||||
byte[] salt = r.readBytes(SALT_LENGTH);
|
byte[] salt = r.readBytes(SALT_LENGTH);
|
||||||
if(salt.length < SALT_LENGTH) throw new FormatException();
|
if(salt.length < SALT_LENGTH) throw new FormatException();
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
public RetentionAck readRetentionAck() throws IOException {
|
public RetentionAck readRetentionAck() throws IOException {
|
||||||
r.readStructId(RETENTION_ACK);
|
r.readStructId(RETENTION_ACK);
|
||||||
long version = r.readInt64();
|
long version = r.readInt64();
|
||||||
if(version < 0L) throw new FormatException();
|
if(version < 0) throw new FormatException();
|
||||||
return new RetentionAck(version);
|
return new RetentionAck(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,9 +167,9 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
public RetentionUpdate readRetentionUpdate() throws IOException {
|
public RetentionUpdate readRetentionUpdate() throws IOException {
|
||||||
r.readStructId(RETENTION_UPDATE);
|
r.readStructId(RETENTION_UPDATE);
|
||||||
long retention = r.readInt64();
|
long retention = r.readInt64();
|
||||||
if(retention < 0L) throw new FormatException();
|
if(retention < 0) throw new FormatException();
|
||||||
long version = r.readInt64();
|
long version = r.readInt64();
|
||||||
if(version < 0L) throw new FormatException();
|
if(version < 0) throw new FormatException();
|
||||||
return new RetentionUpdate(retention, version);
|
return new RetentionUpdate(retention, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
public SubscriptionAck readSubscriptionAck() throws IOException {
|
public SubscriptionAck readSubscriptionAck() throws IOException {
|
||||||
r.readStructId(SUBSCRIPTION_ACK);
|
r.readStructId(SUBSCRIPTION_ACK);
|
||||||
long version = r.readInt64();
|
long version = r.readInt64();
|
||||||
if(version < 0L) throw new FormatException();
|
if(version < 0) throw new FormatException();
|
||||||
return new SubscriptionAck(version);
|
return new SubscriptionAck(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||||
if(b.length < UniqueId.LENGTH) throw new FormatException();
|
if(b.length < UniqueId.LENGTH) throw new FormatException();
|
||||||
long version = r.readInt64();
|
long version = r.readInt64();
|
||||||
if(version < 0L) throw new FormatException();
|
if(version < 0) throw new FormatException();
|
||||||
return new TransportAck(new TransportId(b), version);
|
return new TransportAck(new TransportId(b), version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ class PacketReaderImpl implements PacketReader {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
// Read the version number
|
// Read the version number
|
||||||
long version = r.readInt64();
|
long version = r.readInt64();
|
||||||
if(version < 0L) throw new FormatException();
|
if(version < 0) throw new FormatException();
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Build and return the transport update
|
// Build and return the transport update
|
||||||
return new TransportUpdate(id, new TransportProperties(m), version);
|
return new TransportUpdate(id, new TransportProperties(m), version);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> {
|
|||||||
r.readListEnd();
|
r.readListEnd();
|
||||||
// Read the version number
|
// Read the version number
|
||||||
long version = r.readInt64();
|
long version = r.readInt64();
|
||||||
if(version < 0L) throw new FormatException();
|
if(version < 0) throw new FormatException();
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Build and return the subscription update
|
// Build and return the subscription update
|
||||||
subs = Collections.unmodifiableList(subs);
|
subs = Collections.unmodifiableList(subs);
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 minutes
|
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import android.content.Context;
|
|||||||
|
|
||||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 minutes
|
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public abstract class FilePlugin implements SimplexPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private long getCapacity(String path) throws IOException {
|
private long getCapacity(String path) throws IOException {
|
||||||
return FileSystemUtils.freeSpaceKb(path) * 1024L;
|
return FileSystemUtils.freeSpaceKb(path) * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createReaderFromFile(final File f) {
|
protected void createReaderFromFile(final File f) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import net.sf.briar.util.OsUtils;
|
|||||||
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||||
|
|
||||||
// Maximum latency 14 days (Royal Mail or lackadaisical carrier pigeon)
|
// Maximum latency 14 days (Royal Mail or lackadaisical carrier pigeon)
|
||||||
private static final long MAX_LATENCY = 14L * 24L * 60L * 60L * 1000L;
|
private static final long MAX_LATENCY = 14 * 24 * 60 * 60 * 1000;
|
||||||
private static final long POLLING_INTERVAL = 10L * 1000L; // 10 seconds
|
private static final long POLLING_INTERVAL = 10 * 1000; // 10 seconds
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import net.sf.briar.util.StringUtils;
|
|||||||
|
|
||||||
public class ModemPluginFactory implements DuplexPluginFactory {
|
public class ModemPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 60L * 60L * 1000L; // 1 hour
|
private static final long POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final ModemFactory modemFactory;
|
private final ModemFactory modemFactory;
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 60L * 1000L; // 1 minute
|
private static final long POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
|||||||
|
|
||||||
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long MAX_LATENCY = 1L * 60L; // 1 minute
|
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||||
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 minutes
|
private static final long POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final ShutdownManager shutdownManager;
|
private final ShutdownManager shutdownManager;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import net.sf.briar.util.StringUtils;
|
|||||||
|
|
||||||
public class TorPluginFactory implements DuplexPluginFactory {
|
public class TorPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long MAX_LATENCY = 5L * 60L * 1000L; // 5 minutes
|
private static final long MAX_LATENCY = 5 * 60 * 1000; // 5 minutes
|
||||||
private static final long POLLING_INTERVAL = 15L * 60L * 1000L; // 15 mins
|
private static final long POLLING_INTERVAL = 15 * 60 * 1000; // 15 minutes
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Receiver implements ReadHandler {
|
|||||||
|
|
||||||
private int windowSize = MAX_WINDOW_SIZE; // Locking: this
|
private int windowSize = MAX_WINDOW_SIZE; // Locking: this
|
||||||
private long finalSequenceNumber = Long.MAX_VALUE;
|
private long finalSequenceNumber = Long.MAX_VALUE;
|
||||||
private long nextSequenceNumber = 1L;
|
private long nextSequenceNumber = 1;
|
||||||
|
|
||||||
private volatile boolean valid = true;
|
private volatile boolean valid = true;
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ class Receiver implements ReadHandler {
|
|||||||
dataFrames.remove(d);
|
dataFrames.remove(d);
|
||||||
// Update the window
|
// Update the window
|
||||||
windowSize += d.getPayloadLength();
|
windowSize += d.getPayloadLength();
|
||||||
sender.sendAck(0L, windowSize);
|
sender.sendAck(0, windowSize);
|
||||||
nextSequenceNumber++;
|
nextSequenceNumber++;
|
||||||
return d;
|
return d;
|
||||||
} else {
|
} else {
|
||||||
@@ -92,7 +92,7 @@ class Receiver implements ReadHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long sequenceNumber = d.getSequenceNumber();
|
long sequenceNumber = d.getSequenceNumber();
|
||||||
if(sequenceNumber == 0L) {
|
if(sequenceNumber == 0) {
|
||||||
// Window probe
|
// Window probe
|
||||||
} else if(sequenceNumber < nextSequenceNumber) {
|
} else if(sequenceNumber < nextSequenceNumber) {
|
||||||
// Duplicate data frame
|
// Duplicate data frame
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class SenderOutputStream extends OutputStream {
|
|||||||
private final byte[] buf = new byte[Data.MAX_LENGTH];
|
private final byte[] buf = new byte[Data.MAX_LENGTH];
|
||||||
|
|
||||||
private int offset = Data.HEADER_LENGTH;
|
private int offset = Data.HEADER_LENGTH;
|
||||||
private long sequenceNumber = 1L;
|
private long sequenceNumber = 1;
|
||||||
|
|
||||||
SenderOutputStream(Sender sender) {
|
SenderOutputStream(Sender sender) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class FrameEncoder {
|
|||||||
|
|
||||||
static void encodeIv(byte[] iv, long frameNumber) {
|
static void encodeIv(byte[] iv, long frameNumber) {
|
||||||
if(iv.length < IV_LENGTH) throw new IllegalArgumentException();
|
if(iv.length < IV_LENGTH) throw new IllegalArgumentException();
|
||||||
if(frameNumber < 0L || frameNumber > MAX_32_BIT_UNSIGNED)
|
if(frameNumber < 0 || frameNumber > MAX_32_BIT_UNSIGNED)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
ByteUtils.writeUint32(frameNumber, iv, 0);
|
ByteUtils.writeUint32(frameNumber, iv, 0);
|
||||||
for(int i = 4; i < IV_LENGTH; i++) iv[i] = 0;
|
for(int i = 4; i < IV_LENGTH; i++) iv[i] = 0;
|
||||||
@@ -20,7 +20,7 @@ class FrameEncoder {
|
|||||||
|
|
||||||
static void encodeAad(byte[] aad, long frameNumber, int plaintextLength) {
|
static void encodeAad(byte[] aad, long frameNumber, int plaintextLength) {
|
||||||
if(aad.length < AAD_LENGTH) throw new IllegalArgumentException();
|
if(aad.length < AAD_LENGTH) throw new IllegalArgumentException();
|
||||||
if(frameNumber < 0L || frameNumber > MAX_32_BIT_UNSIGNED)
|
if(frameNumber < 0 || frameNumber > MAX_32_BIT_UNSIGNED)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
if(plaintextLength < HEADER_LENGTH)
|
if(plaintextLength < HEADER_LENGTH)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class IncomingEncryptionLayer implements FrameReader {
|
|||||||
iv = new byte[IV_LENGTH];
|
iv = new byte[IV_LENGTH];
|
||||||
aad = new byte[AAD_LENGTH];
|
aad = new byte[AAD_LENGTH];
|
||||||
ciphertext = new byte[frameLength];
|
ciphertext = new byte[frameLength];
|
||||||
frameNumber = 0L;
|
frameNumber = 0;
|
||||||
finalFrame = false;
|
finalFrame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class OutgoingEncryptionLayer implements FrameWriter {
|
|||||||
iv = new byte[IV_LENGTH];
|
iv = new byte[IV_LENGTH];
|
||||||
aad = new byte[AAD_LENGTH];
|
aad = new byte[AAD_LENGTH];
|
||||||
ciphertext = new byte[frameLength];
|
ciphertext = new byte[frameLength];
|
||||||
frameNumber = 0L;
|
frameNumber = 0;
|
||||||
writeTag = true;
|
writeTag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class OutgoingEncryptionLayer implements FrameWriter {
|
|||||||
iv = new byte[IV_LENGTH];
|
iv = new byte[IV_LENGTH];
|
||||||
aad = new byte[AAD_LENGTH];
|
aad = new byte[AAD_LENGTH];
|
||||||
ciphertext = new byte[frameLength];
|
ciphertext = new byte[frameLength];
|
||||||
frameNumber = 0L;
|
frameNumber = 0;
|
||||||
writeTag = false;
|
writeTag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class ByteUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void writeUint32(long i, byte[] b, int offset) {
|
public static void writeUint32(long i, byte[] b, int offset) {
|
||||||
if(i < 0L) throw new IllegalArgumentException();
|
if(i < 0) throw new IllegalArgumentException();
|
||||||
if(i > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException();
|
if(i > MAX_32_BIT_UNSIGNED) throw new IllegalArgumentException();
|
||||||
if(b.length < offset + 4) throw new IllegalArgumentException();
|
if(b.length < offset + 4) throw new IllegalArgumentException();
|
||||||
b[offset] = (byte) (i >> 24);
|
b[offset] = (byte) (i >> 24);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class FileUtils {
|
|||||||
StatFs s = new StatFs(f.getAbsolutePath());
|
StatFs s = new StatFs(f.getAbsolutePath());
|
||||||
return (long) s.getAvailableBlocks() * s.getBlockSize();
|
return (long) s.getAvailableBlocks() * s.getBlockSize();
|
||||||
} else {
|
} else {
|
||||||
return FileSystemUtils.freeSpaceKb(f.getAbsolutePath()) * 1024L;
|
return FileSystemUtils.freeSpaceKb(f.getAbsolutePath()) * 1024;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
private byte[] write() throws Exception {
|
private byte[] write() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret.clone(), 0L, true);
|
secret.clone(), 0, true);
|
||||||
ConnectionWriter conn = connectionWriterFactory.createConnectionWriter(
|
ConnectionWriter conn = connectionWriterFactory.createConnectionWriter(
|
||||||
out, Long.MAX_VALUE, ctx, false, true);
|
out, Long.MAX_VALUE, ctx, false, true);
|
||||||
OutputStream out1 = conn.getOutputStream();
|
OutputStream out1 = conn.getOutputStream();
|
||||||
@@ -155,11 +155,11 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
writer.writeRequest(new Request(requested, 4));
|
writer.writeRequest(new Request(requested, 4));
|
||||||
|
|
||||||
SubscriptionUpdate su = new SubscriptionUpdate(
|
SubscriptionUpdate su = new SubscriptionUpdate(
|
||||||
Arrays.asList(group, group1), 1L);
|
Arrays.asList(group, group1), 1);
|
||||||
writer.writeSubscriptionUpdate(su);
|
writer.writeSubscriptionUpdate(su);
|
||||||
|
|
||||||
TransportUpdate tu = new TransportUpdate(transportId,
|
TransportUpdate tu = new TransportUpdate(transportId,
|
||||||
transportProperties, 1L);
|
transportProperties, 1);
|
||||||
writer.writeTransportUpdate(tu);
|
writer.writeTransportUpdate(tu);
|
||||||
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
@@ -172,7 +172,7 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
||||||
// FIXME: Check that the expected tag was received
|
// FIXME: Check that the expected tag was received
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret.clone(), 0L, false);
|
secret.clone(), 0, false);
|
||||||
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
||||||
in, ctx, true, true);
|
in, ctx, true, true);
|
||||||
InputStream in1 = conn.getInputStream();
|
InputStream in1 = conn.getInputStream();
|
||||||
@@ -217,14 +217,14 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
assertTrue(reader.hasSubscriptionUpdate());
|
assertTrue(reader.hasSubscriptionUpdate());
|
||||||
SubscriptionUpdate su = reader.readSubscriptionUpdate();
|
SubscriptionUpdate su = reader.readSubscriptionUpdate();
|
||||||
assertEquals(Arrays.asList(group, group1), su.getGroups());
|
assertEquals(Arrays.asList(group, group1), su.getGroups());
|
||||||
assertEquals(1L, su.getVersion());
|
assertEquals(1, su.getVersion());
|
||||||
|
|
||||||
// Read the transport update
|
// Read the transport update
|
||||||
assertTrue(reader.hasTransportUpdate());
|
assertTrue(reader.hasTransportUpdate());
|
||||||
TransportUpdate tu = reader.readTransportUpdate();
|
TransportUpdate tu = reader.readTransportUpdate();
|
||||||
assertEquals(transportId, tu.getId());
|
assertEquals(transportId, tu.getId());
|
||||||
assertEquals(transportProperties, tu.getProperties());
|
assertEquals(transportProperties, tu.getProperties());
|
||||||
assertEquals(1L, tu.getVersion());
|
assertEquals(1, tu.getVersion());
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class DatabaseCleanerImplTest extends BriarTestCase {
|
|||||||
Timer timer = new SystemTimer();
|
Timer timer = new SystemTimer();
|
||||||
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl(timer);
|
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl(timer);
|
||||||
// Start the cleaner
|
// Start the cleaner
|
||||||
cleaner.startCleaning(callback, 10L);
|
cleaner.startCleaning(callback, 10);
|
||||||
// The database should be cleaned five times (allow 5s for system load)
|
// The database should be cleaned five times (allow 5s for system load)
|
||||||
assertTrue(latch.await(5, SECONDS));
|
assertTrue(latch.await(5, SECONDS));
|
||||||
// Stop the cleaner
|
// Stop the cleaner
|
||||||
@@ -55,13 +55,13 @@ public class DatabaseCleanerImplTest extends BriarTestCase {
|
|||||||
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl(timer);
|
DatabaseCleanerImpl cleaner = new DatabaseCleanerImpl(timer);
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
// Start the cleaner
|
// Start the cleaner
|
||||||
cleaner.startCleaning(callback, 10L * 1000L);
|
cleaner.startCleaning(callback, 10 * 1000);
|
||||||
// The database should be cleaned once at startup
|
// The database should be cleaned once at startup
|
||||||
assertTrue(latch.await(5, SECONDS));
|
assertTrue(latch.await(5, SECONDS));
|
||||||
// Stop the cleaner (it should be waiting between sweeps)
|
// Stop the cleaner (it should be waiting between sweeps)
|
||||||
cleaner.stopCleaning();
|
cleaner.stopCleaning();
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
// Check that much less than 10 seconds expired
|
// Check that much less than 10 seconds expired
|
||||||
assertTrue(end - start < 10L * 1000L);
|
assertTrue(end - start < 10 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
transportId = new TransportId(TestUtils.getRandomId());
|
transportId = new TransportId(TestUtils.getRandomId());
|
||||||
transportProperties = new TransportProperties(
|
transportProperties = new TransportProperties(
|
||||||
Collections.singletonMap("foo", "bar"));
|
Collections.singletonMap("foo", "bar"));
|
||||||
endpoint = new Endpoint(contactId, transportId, 123L, 234L, 345L, true);
|
endpoint = new Endpoint(contactId, transportId, 123, 234, 345, true);
|
||||||
temporarySecret = new TemporarySecret(contactId, transportId, 1L, 2L,
|
temporarySecret = new TemporarySecret(contactId, transportId, 1, 2,
|
||||||
3L, false, 4L, new byte[32], 5L, 6L, new byte[4]);
|
3, false, 4, new byte[32], 5, 6, new byte[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract <T> DatabaseComponent createDatabaseComponent(
|
protected abstract <T> DatabaseComponent createDatabaseComponent(
|
||||||
@@ -569,14 +569,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
SubscriptionUpdate u = new SubscriptionUpdate(
|
SubscriptionUpdate u = new SubscriptionUpdate(
|
||||||
Collections.<Group>emptyList(), 1L);
|
Collections.<Group>emptyList(), 1);
|
||||||
db.receiveSubscriptionUpdate(contactId, u);
|
db.receiveSubscriptionUpdate(contactId, u);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TransportUpdate u = new TransportUpdate(transportId,
|
TransportUpdate u = new TransportUpdate(transportId,
|
||||||
transportProperties, 1L);
|
transportProperties, 1);
|
||||||
db.receiveTransportUpdate(contactId, u);
|
db.receiveTransportUpdate(contactId, u);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
@@ -625,12 +625,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact());
|
assertEquals(contactId, db.addContact());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.incrementConnectionCounter(contactId, transportId, 0L);
|
db.incrementConnectionCounter(contactId, transportId, 0);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchTransportException expected) {}
|
} catch(NoSuchTransportException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setConnectionWindow(contactId, transportId, 0L, 0L, new byte[4]);
|
db.setConnectionWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchTransportException expected) {}
|
} catch(NoSuchTransportException expected) {}
|
||||||
|
|
||||||
@@ -809,14 +809,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
allowing(database).containsContact(txn, contactId);
|
allowing(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getSubscriptionUpdate(txn, contactId);
|
oneOf(database).getSubscriptionUpdate(txn, contactId);
|
||||||
will(returnValue(new SubscriptionUpdate(Arrays.asList(group), 1L)));
|
will(returnValue(new SubscriptionUpdate(Arrays.asList(group), 1)));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
SubscriptionUpdate u = db.generateSubscriptionUpdate(contactId);
|
SubscriptionUpdate u = db.generateSubscriptionUpdate(contactId);
|
||||||
assertEquals(Arrays.asList(group), u.getGroups());
|
assertEquals(Arrays.asList(group), u.getGroups());
|
||||||
assertEquals(1L, u.getVersion());
|
assertEquals(1, u.getVersion());
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -860,7 +860,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getTransportUpdates(txn, contactId);
|
oneOf(database).getTransportUpdates(txn, contactId);
|
||||||
will(returnValue(Arrays.asList(new TransportUpdate(transportId,
|
will(returnValue(Arrays.asList(new TransportUpdate(transportId,
|
||||||
transportProperties, 1L))));
|
transportProperties, 1))));
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||||
shutdown);
|
shutdown);
|
||||||
@@ -872,7 +872,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
TransportUpdate u = updates.iterator().next();
|
TransportUpdate u = updates.iterator().next();
|
||||||
assertEquals(transportId, u.getId());
|
assertEquals(transportId, u.getId());
|
||||||
assertEquals(transportProperties, u.getProperties());
|
assertEquals(transportProperties, u.getProperties());
|
||||||
assertEquals(1L, u.getVersion());
|
assertEquals(1, u.getVersion());
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -1155,12 +1155,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
allowing(database).containsContact(txn, contactId);
|
allowing(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).setSubscriptions(txn, contactId,
|
oneOf(database).setSubscriptions(txn, contactId,
|
||||||
Arrays.asList(group), 1L);
|
Arrays.asList(group), 1);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
SubscriptionUpdate u = new SubscriptionUpdate(Arrays.asList(group), 1L);
|
SubscriptionUpdate u = new SubscriptionUpdate(Arrays.asList(group), 1);
|
||||||
db.receiveSubscriptionUpdate(contactId, u);
|
db.receiveSubscriptionUpdate(contactId, u);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -1180,13 +1180,13 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
allowing(database).containsContact(txn, contactId);
|
allowing(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).setRemoteProperties(txn, contactId, transportId,
|
oneOf(database).setRemoteProperties(txn, contactId, transportId,
|
||||||
transportProperties, 1L);
|
transportProperties, 1);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
TransportUpdate u = new TransportUpdate(transportId,
|
TransportUpdate u = new TransportUpdate(transportId,
|
||||||
transportProperties, 1L);
|
transportProperties, 1);
|
||||||
db.receiveTransportUpdate(contactId, u);
|
db.receiveTransportUpdate(contactId, u);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.setStatus(txn, contactId, messageId, Status.NEW);
|
db.setStatus(txn, contactId, messageId, Status.NEW);
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.setSendability(txn, messageId, 1);
|
db.setSendability(txn, messageId, 1);
|
||||||
|
|
||||||
@@ -387,7 +387,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
|
|
||||||
// The contact subscribing should make the message sendable
|
// The contact subscribing should make the message sendable
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
assertTrue(db.hasSendableMessages(txn, contactId));
|
assertTrue(db.hasSendableMessages(txn, contactId));
|
||||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
@@ -395,7 +395,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
|
|
||||||
// The contact unsubscribing should make the message unsendable
|
// The contact unsubscribing should make the message unsendable
|
||||||
db.setSubscriptions(txn, contactId, Collections.<Group>emptyList(), 2L);
|
db.setSubscriptions(txn, contactId, Collections.<Group>emptyList(), 2);
|
||||||
assertFalse(db.hasSendableMessages(txn, contactId));
|
assertFalse(db.hasSendableMessages(txn, contactId));
|
||||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
@@ -413,7 +413,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.setSendability(txn, messageId, 1);
|
db.setSendability(txn, messageId, 1);
|
||||||
db.setStatus(txn, contactId, messageId, Status.NEW);
|
db.setStatus(txn, contactId, messageId, Status.NEW);
|
||||||
@@ -443,7 +443,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.setSendability(txn, messageId, 1);
|
db.setSendability(txn, messageId, 1);
|
||||||
db.setStatus(txn, contactId, messageId, Status.NEW);
|
db.setStatus(txn, contactId, messageId, Status.NEW);
|
||||||
@@ -527,7 +527,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.setSendability(txn, messageId, 1);
|
db.setSendability(txn, messageId, 1);
|
||||||
db.setStatus(txn, contactId, messageId, Status.NEW);
|
db.setStatus(txn, contactId, messageId, Status.NEW);
|
||||||
@@ -668,7 +668,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Sanity check: there should be enough space on disk for this test
|
// Sanity check: there should be enough space on disk for this test
|
||||||
String path = testDir.getAbsolutePath();
|
String path = testDir.getAbsolutePath();
|
||||||
assertTrue(FileSystemUtils.freeSpaceKb(path) * 1024L > MAX_SIZE);
|
assertTrue(FileSystemUtils.freeSpaceKb(path) * 1024 > MAX_SIZE);
|
||||||
|
|
||||||
// The free space should not be more than the allowed maximum size
|
// The free space should not be more than the allowed maximum size
|
||||||
long free = db.getFreeSpace();
|
long free = db.getFreeSpace();
|
||||||
@@ -766,20 +766,20 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
TransportProperties p = new TransportProperties(
|
TransportProperties p = new TransportProperties(
|
||||||
Collections.singletonMap("foo", "bar"));
|
Collections.singletonMap("foo", "bar"));
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p, 1L);
|
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
||||||
assertEquals(Collections.singletonMap(contactId, p),
|
assertEquals(Collections.singletonMap(contactId, p),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
// Replace the transport properties
|
// Replace the transport properties
|
||||||
TransportProperties p1 = new TransportProperties(
|
TransportProperties p1 = new TransportProperties(
|
||||||
Collections.singletonMap("baz", "bam"));
|
Collections.singletonMap("baz", "bam"));
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p1, 2L);
|
db.setRemoteProperties(txn, contactId, transportId, p1, 2);
|
||||||
assertEquals(Collections.singletonMap(contactId, p1),
|
assertEquals(Collections.singletonMap(contactId, p1),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
// Remove the transport properties
|
// Remove the transport properties
|
||||||
TransportProperties p2 = new TransportProperties();
|
TransportProperties p2 = new TransportProperties();
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p2, 3L);
|
db.setRemoteProperties(txn, contactId, transportId, p2, 3);
|
||||||
assertEquals(Collections.emptyMap(),
|
assertEquals(Collections.emptyMap(),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
@@ -856,21 +856,21 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
TransportProperties p = new TransportProperties(
|
TransportProperties p = new TransportProperties(
|
||||||
Collections.singletonMap("foo", "bar"));
|
Collections.singletonMap("foo", "bar"));
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p, 1L);
|
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
||||||
assertEquals(Collections.singletonMap(contactId, p),
|
assertEquals(Collections.singletonMap(contactId, p),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
// Replace the transport properties with version 2
|
// Replace the transport properties with version 2
|
||||||
TransportProperties p1 = new TransportProperties(
|
TransportProperties p1 = new TransportProperties(
|
||||||
Collections.singletonMap("baz", "bam"));
|
Collections.singletonMap("baz", "bam"));
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p1, 2L);
|
db.setRemoteProperties(txn, contactId, transportId, p1, 2);
|
||||||
assertEquals(Collections.singletonMap(contactId, p1),
|
assertEquals(Collections.singletonMap(contactId, p1),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
// Try to replace the transport properties with version 1
|
// Try to replace the transport properties with version 1
|
||||||
TransportProperties p2 = new TransportProperties(
|
TransportProperties p2 = new TransportProperties(
|
||||||
Collections.singletonMap("quux", "etc"));
|
Collections.singletonMap("quux", "etc"));
|
||||||
db.setRemoteProperties(txn, contactId, transportId, p2, 1L);
|
db.setRemoteProperties(txn, contactId, transportId, p2, 1);
|
||||||
|
|
||||||
// Version 2 of the properties should still be there
|
// Version 2 of the properties should still be there
|
||||||
assertEquals(Collections.singletonMap(contactId, p1),
|
assertEquals(Collections.singletonMap(contactId, p1),
|
||||||
@@ -889,7 +889,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Add a contact and subscribe to a group
|
// Add a contact and subscribe to a group
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
// The message is not in the database
|
// The message is not in the database
|
||||||
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
||||||
@@ -906,7 +906,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
|
|
||||||
// Set the sendability to > 0 and the status to SEEN
|
// Set the sendability to > 0 and the status to SEEN
|
||||||
@@ -929,7 +929,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Add a contact, subscribe to a group and store a message
|
// Add a contact, subscribe to a group and store a message
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
|
|
||||||
// Set the sendability to 0 and the status to NEW
|
// Set the sendability to 0 and the status to NEW
|
||||||
@@ -953,8 +953,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.setRetentionTime(txn, contactId, timestamp + 1, 1L);
|
db.setRetentionTime(txn, contactId, timestamp + 1, 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
|
|
||||||
// Set the sendability to > 0 and the status to NEW
|
// Set the sendability to > 0 and the status to NEW
|
||||||
@@ -977,7 +977,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
|
|
||||||
// Set the sendability to > 0 and the status to NEW
|
// Set the sendability to > 0 and the status to NEW
|
||||||
@@ -1002,7 +1002,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
// The message is not in the database
|
// The message is not in the database
|
||||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||||
@@ -1019,7 +1019,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Add a contact with a subscription
|
// Add a contact with a subscription
|
||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
// There's no local subscription for the group
|
// There's no local subscription for the group
|
||||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||||
@@ -1057,7 +1057,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.setStatus(txn, contactId, messageId, Status.NEW);
|
db.setStatus(txn, contactId, messageId, Status.NEW);
|
||||||
|
|
||||||
// The subscription is not visible
|
// The subscription is not visible
|
||||||
@@ -1077,7 +1077,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
|
|
||||||
// The message has already been seen by the contact
|
// The message has already been seen by the contact
|
||||||
@@ -1099,7 +1099,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn));
|
assertEquals(contactId, db.addContact(txn));
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1L);
|
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addGroupMessage(txn, message);
|
db.addGroupMessage(txn, message);
|
||||||
|
|
||||||
// The message has not been seen by the contact
|
// The message has not been seen by the contact
|
||||||
@@ -1511,11 +1511,11 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testTemporarySecrets() throws Exception {
|
public void testTemporarySecrets() throws Exception {
|
||||||
// Create an endpoint and three consecutive temporary secrets
|
// Create an endpoint and three consecutive temporary secrets
|
||||||
long epoch = 123L, clockDiff = 234L, latency = 345L;
|
long epoch = 123, clockDiff = 234, latency = 345;
|
||||||
boolean alice = false;
|
boolean alice = false;
|
||||||
long outgoing1 = 456L, centre1 = 567L;
|
long outgoing1 = 456, centre1 = 567;
|
||||||
long outgoing2 = 678L, centre2 = 789L;
|
long outgoing2 = 678, centre2 = 789;
|
||||||
long outgoing3 = 890L, centre3 = 901L;
|
long outgoing3 = 890, centre3 = 901;
|
||||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
||||||
latency, alice);
|
latency, alice);
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -1523,19 +1523,19 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
random.nextBytes(secret1);
|
random.nextBytes(secret1);
|
||||||
random.nextBytes(bitmap1);
|
random.nextBytes(bitmap1);
|
||||||
TemporarySecret s1 = new TemporarySecret(contactId, transportId, epoch,
|
TemporarySecret s1 = new TemporarySecret(contactId, transportId, epoch,
|
||||||
clockDiff, latency, alice, 0L, secret1, outgoing1, centre1,
|
clockDiff, latency, alice, 0, secret1, outgoing1, centre1,
|
||||||
bitmap1);
|
bitmap1);
|
||||||
byte[] secret2 = new byte[32], bitmap2 = new byte[4];
|
byte[] secret2 = new byte[32], bitmap2 = new byte[4];
|
||||||
random.nextBytes(secret2);
|
random.nextBytes(secret2);
|
||||||
random.nextBytes(bitmap2);
|
random.nextBytes(bitmap2);
|
||||||
TemporarySecret s2 = new TemporarySecret(contactId, transportId, epoch,
|
TemporarySecret s2 = new TemporarySecret(contactId, transportId, epoch,
|
||||||
clockDiff, latency, alice, 1L, secret2, outgoing2, centre2,
|
clockDiff, latency, alice, 1, secret2, outgoing2, centre2,
|
||||||
bitmap2);
|
bitmap2);
|
||||||
byte[] secret3 = new byte[32], bitmap3 = new byte[4];
|
byte[] secret3 = new byte[32], bitmap3 = new byte[4];
|
||||||
random.nextBytes(secret3);
|
random.nextBytes(secret3);
|
||||||
random.nextBytes(bitmap3);
|
random.nextBytes(bitmap3);
|
||||||
TemporarySecret s3 = new TemporarySecret(contactId, transportId, epoch,
|
TemporarySecret s3 = new TemporarySecret(contactId, transportId, epoch,
|
||||||
clockDiff, latency, alice, 2L, secret3, outgoing3, centre3,
|
clockDiff, latency, alice, 2, secret3, outgoing3, centre3,
|
||||||
bitmap3);
|
bitmap3);
|
||||||
|
|
||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
@@ -1562,13 +1562,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(clockDiff, s.getClockDifference());
|
assertEquals(clockDiff, s.getClockDifference());
|
||||||
assertEquals(latency, s.getLatency());
|
assertEquals(latency, s.getLatency());
|
||||||
assertEquals(alice, s.getAlice());
|
assertEquals(alice, s.getAlice());
|
||||||
if(s.getPeriod() == 0L) {
|
if(s.getPeriod() == 0) {
|
||||||
assertArrayEquals(secret1, s.getSecret());
|
assertArrayEquals(secret1, s.getSecret());
|
||||||
assertEquals(outgoing1, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing1, s.getOutgoingConnectionCounter());
|
||||||
assertEquals(centre1, s.getWindowCentre());
|
assertEquals(centre1, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap1, s.getWindowBitmap());
|
assertArrayEquals(bitmap1, s.getWindowBitmap());
|
||||||
foundFirst = true;
|
foundFirst = true;
|
||||||
} else if(s.getPeriod() == 1L) {
|
} else if(s.getPeriod() == 1) {
|
||||||
assertArrayEquals(secret2, s.getSecret());
|
assertArrayEquals(secret2, s.getSecret());
|
||||||
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
||||||
assertEquals(centre2, s.getWindowCentre());
|
assertEquals(centre2, s.getWindowCentre());
|
||||||
@@ -1594,13 +1594,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(clockDiff, s.getClockDifference());
|
assertEquals(clockDiff, s.getClockDifference());
|
||||||
assertEquals(latency, s.getLatency());
|
assertEquals(latency, s.getLatency());
|
||||||
assertEquals(alice, s.getAlice());
|
assertEquals(alice, s.getAlice());
|
||||||
if(s.getPeriod() == 1L) {
|
if(s.getPeriod() == 1) {
|
||||||
assertArrayEquals(secret2, s.getSecret());
|
assertArrayEquals(secret2, s.getSecret());
|
||||||
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
||||||
assertEquals(centre2, s.getWindowCentre());
|
assertEquals(centre2, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
||||||
foundSecond = true;
|
foundSecond = true;
|
||||||
} else if(s.getPeriod() == 2L) {
|
} else if(s.getPeriod() == 2) {
|
||||||
assertArrayEquals(secret3, s.getSecret());
|
assertArrayEquals(secret3, s.getSecret());
|
||||||
assertEquals(outgoing3, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing3, s.getOutgoingConnectionCounter());
|
||||||
assertEquals(centre3, s.getWindowCentre());
|
assertEquals(centre3, s.getWindowCentre());
|
||||||
@@ -1624,9 +1624,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testIncrementConnectionCounter() throws Exception {
|
public void testIncrementConnectionCounter() throws Exception {
|
||||||
// Create an endpoint and a temporary secret
|
// Create an endpoint and a temporary secret
|
||||||
long epoch = 123L, clockDiff = 234L, latency = 345L;
|
long epoch = 123, clockDiff = 234, latency = 345;
|
||||||
boolean alice = false;
|
boolean alice = false;
|
||||||
long period = 456L, outgoing = 567L, centre = 678L;
|
long period = 456, outgoing = 567, centre = 678;
|
||||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
||||||
latency, alice);
|
latency, alice);
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -1660,7 +1660,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Increment the connection counter twice and retrieve the secret again
|
// Increment the connection counter twice and retrieve the secret again
|
||||||
assertEquals(outgoing, db.incrementConnectionCounter(txn,
|
assertEquals(outgoing, db.incrementConnectionCounter(txn,
|
||||||
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
||||||
assertEquals(outgoing + 1L, db.incrementConnectionCounter(txn,
|
assertEquals(outgoing + 1, db.incrementConnectionCounter(txn,
|
||||||
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
||||||
secrets = db.getSecrets(txn);
|
secrets = db.getSecrets(txn);
|
||||||
assertEquals(1, secrets.size());
|
assertEquals(1, secrets.size());
|
||||||
@@ -1669,7 +1669,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(transportId, s.getTransportId());
|
assertEquals(transportId, s.getTransportId());
|
||||||
assertEquals(period, s.getPeriod());
|
assertEquals(period, s.getPeriod());
|
||||||
assertArrayEquals(secret, s.getSecret());
|
assertArrayEquals(secret, s.getSecret());
|
||||||
assertEquals(outgoing + 2L, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing + 2, s.getOutgoingConnectionCounter());
|
||||||
assertEquals(centre, s.getWindowCentre());
|
assertEquals(centre, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||||
|
|
||||||
@@ -1680,9 +1680,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testSetConnectionWindow() throws Exception {
|
public void testSetConnectionWindow() throws Exception {
|
||||||
// Create an endpoint and a temporary secret
|
// Create an endpoint and a temporary secret
|
||||||
long epoch = 123L, clockDiff = 234L, latency = 345L;
|
long epoch = 123, clockDiff = 234, latency = 345;
|
||||||
boolean alice = false;
|
boolean alice = false;
|
||||||
long period = 456L, outgoing = 567L, centre = 678L;
|
long period = 456, outgoing = 567, centre = 678;
|
||||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
||||||
latency, alice);
|
latency, alice);
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -1729,7 +1729,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||||
|
|
||||||
// Updating a nonexistent window should not throw an exception
|
// Updating a nonexistent window should not throw an exception
|
||||||
db.setConnectionWindow(txn, contactId, transportId, period + 1L, 1L,
|
db.setConnectionWindow(txn, contactId, transportId, period + 1, 1,
|
||||||
bitmap);
|
bitmap);
|
||||||
// The nonexistent window should not have been created
|
// The nonexistent window should not have been created
|
||||||
secrets = db.getSecrets(txn);
|
secrets = db.getSecrets(txn);
|
||||||
@@ -1750,8 +1750,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testContactTransports() throws Exception {
|
public void testContactTransports() throws Exception {
|
||||||
// Create some endpoints
|
// Create some endpoints
|
||||||
long epoch1 = 123L, clockDiff1 = 234L, latency1 = 345L;
|
long epoch1 = 123, clockDiff1 = 234, latency1 = 345;
|
||||||
long epoch2 = 456L, clockDiff2 = 567L, latency2 = 678L;
|
long epoch2 = 456, clockDiff2 = 567, latency2 = 678;
|
||||||
boolean alice1 = true, alice2 = false;
|
boolean alice1 = true, alice2 = false;
|
||||||
TransportId transportId1 = new TransportId(TestUtils.getRandomId());
|
TransportId transportId1 = new TransportId(TestUtils.getRandomId());
|
||||||
TransportId transportId2 = new TransportId(TestUtils.getRandomId());
|
TransportId transportId2 = new TransportId(TestUtils.getRandomId());
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MAX_PACKET_LENGTH, true);
|
out, MAX_PACKET_LENGTH, true);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret, 0L, true);
|
secret, 0, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||||
transport);
|
transport);
|
||||||
@@ -107,7 +107,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MIN_CONNECTION_LENGTH, true);
|
out, MIN_CONNECTION_LENGTH, true);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret, 0L, true);
|
secret, 0, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||||
transport);
|
transport);
|
||||||
@@ -152,7 +152,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MIN_CONNECTION_LENGTH, true);
|
out, MIN_CONNECTION_LENGTH, true);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret, 0L, true);
|
secret, 0, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||||
transport);
|
transport);
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ import com.google.inject.Injector;
|
|||||||
|
|
||||||
public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||||
|
|
||||||
private static final long CLOCK_DIFFERENCE = 60 * 1000L;
|
private static final long CLOCK_DIFFERENCE = 60 * 1000;
|
||||||
private static final long LATENCY = 60 * 1000L;
|
private static final long LATENCY = 60 * 1000;
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
private final File aliceDir = new File(testDir, "alice");
|
private final File aliceDir = new File(testDir, "alice");
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ public class BluetoothClientTest extends DuplexClientTest {
|
|||||||
// Create the plugin
|
// Create the plugin
|
||||||
callback = new ClientCallback(new TransportConfig(),
|
callback = new ClientCallback(new TransportConfig(),
|
||||||
new TransportProperties(), remote);
|
new TransportProperties(), remote);
|
||||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L,
|
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0,
|
||||||
0L);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ public class BluetoothServerTest extends DuplexServerTest {
|
|||||||
// Create the plugin
|
// Create the plugin
|
||||||
callback = new ServerCallback(new TransportConfig(), local,
|
callback = new ServerCallback(new TransportConfig(), local,
|
||||||
Collections.singletonMap(contactId, new TransportProperties()));
|
Collections.singletonMap(contactId, new TransportProperties()));
|
||||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L,
|
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0,
|
||||||
0L);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -89,7 +89,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -126,7 +126,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -165,7 +165,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNull(plugin.createWriter(contactId));
|
assertNull(plugin.createWriter(contactId));
|
||||||
@@ -204,7 +204,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
assertNotNull(plugin.createWriter(contactId));
|
assertNotNull(plugin.createWriter(contactId));
|
||||||
@@ -212,7 +212,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
File[] files = drive1.listFiles();
|
File[] files = drive1.listFiles();
|
||||||
assertNotNull(files);
|
assertNotNull(files);
|
||||||
assertEquals(1, files.length);
|
assertEquals(1, files.length);
|
||||||
assertEquals(0L, files[0].length());
|
assertEquals(0, files[0].length());
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
||||||
@@ -256,7 +256,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
File[] files = drive1.listFiles();
|
File[] files = drive1.listFiles();
|
||||||
assertNotNull(files);
|
assertNotNull(files);
|
||||||
assertEquals(1, files.length);
|
assertEquals(1, files.length);
|
||||||
assertEquals(0L, files[0].length());
|
assertEquals(0, files[0].length());
|
||||||
// Writing to the output stream should increase the size of the file
|
// Writing to the output stream should increase the size of the file
|
||||||
OutputStream out = writer.getOutputStream();
|
OutputStream out = writer.getOutputStream();
|
||||||
out.write(new byte[123]);
|
out.write(new byte[123]);
|
||||||
@@ -265,7 +265,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
// Disposing of the writer should not delete the file
|
// Disposing of the writer should not delete the file
|
||||||
writer.dispose(false);
|
writer.dispose(false);
|
||||||
assertTrue(files[0].exists());
|
assertTrue(files[0].exists());
|
||||||
assertEquals(123L, files[0].length());
|
assertEquals(123, files[0].length());
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
plugin.driveInserted(testDir);
|
plugin.driveInserted(testDir);
|
||||||
@@ -306,7 +306,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
context.mock(RemovableDriveMonitor.class);
|
context.mock(RemovableDriveMonitor.class);
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||||
callback, finder, monitor, 0L);
|
callback, finder, monitor, 0);
|
||||||
|
|
||||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
|
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
|
||||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
|
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
|
||||||
@@ -334,7 +334,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
|
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
|
||||||
new ImmediateExecutor(), callback, finder, monitor, 0L);
|
new ImmediateExecutor(), callback, finder, monitor, 0);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
File f = new File(testDir, "abcdefgh.dat");
|
File f = new File(testDir, "abcdefgh.dat");
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final SerialPortList serialPortList =
|
final SerialPortList serialPortList =
|
||||||
context.mock(SerialPortList.class);
|
context.mock(SerialPortList.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, null, 0L, 0L, true);
|
serialPortList, null, 0, 0, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(serialPortList).getPortNames();
|
oneOf(serialPortList).getPortNames();
|
||||||
@@ -71,7 +71,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L, 0L, true);
|
serialPortList, callback, 0, 0, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -112,7 +112,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L, 0L, true);
|
serialPortList, callback, 0, 0, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -153,7 +153,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L, 0L, true);
|
serialPortList, callback, 0, 0, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -204,7 +204,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
// Disable shuffling for this test, it confuses jMock
|
// Disable shuffling for this test, it confuses jMock
|
||||||
final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory,
|
||||||
serialPortList, callback, 0L, 0L, false);
|
serialPortList, callback, 0, 0, false);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ public class ReaderImplTest extends BriarTestCase {
|
|||||||
public void testReadInt64() throws Exception {
|
public void testReadInt64() throws Exception {
|
||||||
setContents("FA0000000000000000" + "FAFFFFFFFFFFFFFFFF"
|
setContents("FA0000000000000000" + "FAFFFFFFFFFFFFFFFF"
|
||||||
+ "FA7FFFFFFFFFFFFFFF" + "FA8000000000000000");
|
+ "FA7FFFFFFFFFFFFFFF" + "FA8000000000000000");
|
||||||
assertEquals(0L, r.readInt64());
|
assertEquals(0, r.readInt64());
|
||||||
assertEquals(-1L, r.readInt64());
|
assertEquals(-1, r.readInt64());
|
||||||
assertEquals(Long.MAX_VALUE, r.readInt64());
|
assertEquals(Long.MAX_VALUE, r.readInt64());
|
||||||
assertEquals(Long.MIN_VALUE, r.readInt64());
|
assertEquals(Long.MIN_VALUE, r.readInt64());
|
||||||
assertTrue(r.eof());
|
assertTrue(r.eof());
|
||||||
@@ -73,14 +73,14 @@ public class ReaderImplTest extends BriarTestCase {
|
|||||||
public void testReadIntAny() throws Exception {
|
public void testReadIntAny() throws Exception {
|
||||||
setContents("00" + "7F" + "FD80" + "FDFF" + "FC0080" + "FC7FFF"
|
setContents("00" + "7F" + "FD80" + "FDFF" + "FC0080" + "FC7FFF"
|
||||||
+ "FB00008000" + "FB7FFFFFFF" + "FA0000000080000000");
|
+ "FB00008000" + "FB7FFFFFFF" + "FA0000000080000000");
|
||||||
assertEquals(0L, r.readIntAny());
|
assertEquals(0, r.readIntAny());
|
||||||
assertEquals(127L, r.readIntAny());
|
assertEquals(127, r.readIntAny());
|
||||||
assertEquals(-128L, r.readIntAny());
|
assertEquals(-128, r.readIntAny());
|
||||||
assertEquals(-1L, r.readIntAny());
|
assertEquals(-1, r.readIntAny());
|
||||||
assertEquals(128L, r.readIntAny());
|
assertEquals(128, r.readIntAny());
|
||||||
assertEquals(32767L, r.readIntAny());
|
assertEquals(32767, r.readIntAny());
|
||||||
assertEquals(32768L, r.readIntAny());
|
assertEquals(32768, r.readIntAny());
|
||||||
assertEquals(2147483647L, r.readIntAny());
|
assertEquals(2147483647, r.readIntAny());
|
||||||
assertEquals(2147483648L, r.readIntAny());
|
assertEquals(2147483648L, r.readIntAny());
|
||||||
assertTrue(r.eof());
|
assertTrue(r.eof());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ public class WriterImplTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteInt64() throws IOException {
|
public void testWriteInt64() throws IOException {
|
||||||
w.writeInt64(0L);
|
w.writeInt64(0);
|
||||||
w.writeInt64(-1L);
|
w.writeInt64(-1);
|
||||||
w.writeInt64(Long.MIN_VALUE);
|
w.writeInt64(Long.MIN_VALUE);
|
||||||
w.writeInt64(Long.MAX_VALUE);
|
w.writeInt64(Long.MAX_VALUE);
|
||||||
// INT64 tag, 0, INT64 tag, -1, etc
|
// INT64 tag, 0, INT64 tag, -1, etc
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testReadValidFrames() throws Exception {
|
public void testReadValidFrames() throws Exception {
|
||||||
// Generate two valid frames
|
// Generate two valid frames
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH, 123, false, false);
|
byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, false);
|
||||||
byte[] frame1 = generateFrame(1L, FRAME_LENGTH, 123, false, false);
|
byte[] frame1 = generateFrame(1, FRAME_LENGTH, 123, false, false);
|
||||||
// Concatenate the frames
|
// Concatenate the frames
|
||||||
byte[] valid = new byte[FRAME_LENGTH * 2];
|
byte[] valid = new byte[FRAME_LENGTH * 2];
|
||||||
System.arraycopy(frame, 0, valid, 0, FRAME_LENGTH);
|
System.arraycopy(frame, 0, valid, 0, FRAME_LENGTH);
|
||||||
@@ -61,7 +61,7 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testTruncatedFrameThrowsException() throws Exception {
|
public void testTruncatedFrameThrowsException() throws Exception {
|
||||||
// Generate a valid frame
|
// Generate a valid frame
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH, 123, false, false);
|
byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, false);
|
||||||
// Chop off the last byte
|
// Chop off the last byte
|
||||||
byte[] truncated = new byte[FRAME_LENGTH - 1];
|
byte[] truncated = new byte[FRAME_LENGTH - 1];
|
||||||
System.arraycopy(frame, 0, truncated, 0, FRAME_LENGTH - 1);
|
System.arraycopy(frame, 0, truncated, 0, FRAME_LENGTH - 1);
|
||||||
@@ -78,7 +78,7 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testModifiedFrameThrowsException() throws Exception {
|
public void testModifiedFrameThrowsException() throws Exception {
|
||||||
// Generate a valid frame
|
// Generate a valid frame
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH, 123, false, false);
|
byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, false);
|
||||||
// Modify a randomly chosen byte of the frame
|
// Modify a randomly chosen byte of the frame
|
||||||
frame[(int) (Math.random() * FRAME_LENGTH)] ^= 1;
|
frame[(int) (Math.random() * FRAME_LENGTH)] ^= 1;
|
||||||
// Try to read the frame, which should fail due to modification
|
// Try to read the frame, which should fail due to modification
|
||||||
@@ -94,7 +94,7 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testShortNonFinalFrameThrowsException() throws Exception {
|
public void testShortNonFinalFrameThrowsException() throws Exception {
|
||||||
// Generate a short non-final frame
|
// Generate a short non-final frame
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH - 1, 123, false, false);
|
byte[] frame = generateFrame(0, FRAME_LENGTH - 1, 123, false, false);
|
||||||
// Try to read the frame, which should fail due to invalid length
|
// Try to read the frame, which should fail due to invalid length
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
||||||
IncomingEncryptionLayer i = new IncomingEncryptionLayer(in, frameCipher,
|
IncomingEncryptionLayer i = new IncomingEncryptionLayer(in, frameCipher,
|
||||||
@@ -108,7 +108,7 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testShortFinalFrameDoesNotThrowException() throws Exception {
|
public void testShortFinalFrameDoesNotThrowException() throws Exception {
|
||||||
// Generate a short final frame
|
// Generate a short final frame
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH - 1, 123, true, false);
|
byte[] frame = generateFrame(0, FRAME_LENGTH - 1, 123, true, false);
|
||||||
// Read the frame
|
// Read the frame
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
||||||
IncomingEncryptionLayer i = new IncomingEncryptionLayer(in, frameCipher,
|
IncomingEncryptionLayer i = new IncomingEncryptionLayer(in, frameCipher,
|
||||||
@@ -120,7 +120,7 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testInvalidPayloadLengthThrowsException() throws Exception {
|
public void testInvalidPayloadLengthThrowsException() throws Exception {
|
||||||
// Generate a frame with an invalid payload length
|
// Generate a frame with an invalid payload length
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH, MAX_PAYLOAD_LENGTH + 1,
|
byte[] frame = generateFrame(0, FRAME_LENGTH, MAX_PAYLOAD_LENGTH + 1,
|
||||||
false, false);
|
false, false);
|
||||||
// Try to read the frame, which should fail due to invalid length
|
// Try to read the frame, which should fail due to invalid length
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
||||||
@@ -135,7 +135,7 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testNonZeroPaddingThrowsException() throws Exception {
|
public void testNonZeroPaddingThrowsException() throws Exception {
|
||||||
// Generate a frame with bad padding
|
// Generate a frame with bad padding
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH, 123, false, true);
|
byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, true);
|
||||||
// Try to read the frame, which should fail due to bad padding
|
// Try to read the frame, which should fail due to bad padding
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
ByteArrayInputStream in = new ByteArrayInputStream(frame);
|
||||||
IncomingEncryptionLayer i = new IncomingEncryptionLayer(in, frameCipher,
|
IncomingEncryptionLayer i = new IncomingEncryptionLayer(in, frameCipher,
|
||||||
@@ -149,9 +149,9 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testCannotReadBeyondFinalFrame() throws Exception {
|
public void testCannotReadBeyondFinalFrame() throws Exception {
|
||||||
// Generate a valid final frame and another valid final frame after it
|
// Generate a valid final frame and another valid final frame after it
|
||||||
byte[] frame = generateFrame(0L, FRAME_LENGTH, MAX_PAYLOAD_LENGTH, true,
|
byte[] frame = generateFrame(0, FRAME_LENGTH, MAX_PAYLOAD_LENGTH, true,
|
||||||
false);
|
false);
|
||||||
byte[] frame1 = generateFrame(1L, FRAME_LENGTH, 123, true, false);
|
byte[] frame1 = generateFrame(1, FRAME_LENGTH, 123, true, false);
|
||||||
// Concatenate the frames
|
// Concatenate the frames
|
||||||
byte[] extraFrame = new byte[FRAME_LENGTH * 2];
|
byte[] extraFrame = new byte[FRAME_LENGTH * 2];
|
||||||
System.arraycopy(frame, 0, extraFrame, 0, FRAME_LENGTH);
|
System.arraycopy(frame, 0, extraFrame, 0, FRAME_LENGTH);
|
||||||
|
|||||||
@@ -62,12 +62,12 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
|||||||
will(new EncodeTagAction());
|
will(new EncodeTagAction());
|
||||||
oneOf(tagKey).erase();
|
oneOf(tagKey).erase();
|
||||||
}});
|
}});
|
||||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 0L,
|
TemporarySecret s = new TemporarySecret(contactId, transportId, 0, 0, 0,
|
||||||
0L, 0L, alice, 0L, secret, 0L, 0L, new byte[4]);
|
alice, 0, secret, 0, 0, new byte[4]);
|
||||||
TransportConnectionRecogniser recogniser =
|
TransportConnectionRecogniser recogniser =
|
||||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
new TransportConnectionRecogniser(crypto, db, transportId);
|
||||||
recogniser.addSecret(s);
|
recogniser.addSecret(s);
|
||||||
recogniser.removeSecret(contactId, 0L);
|
recogniser.removeSecret(contactId, 0);
|
||||||
// The secret should have been erased
|
// The secret should have been erased
|
||||||
assertArrayEquals(new byte[32], secret);
|
assertArrayEquals(new byte[32], secret);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -103,13 +103,13 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
|||||||
with(tagKey), with(16L));
|
with(tagKey), with(16L));
|
||||||
will(new EncodeTagAction());
|
will(new EncodeTagAction());
|
||||||
// The updated window should be stored
|
// The updated window should be stored
|
||||||
oneOf(db).setConnectionWindow(contactId, transportId, 0L, 1L,
|
oneOf(db).setConnectionWindow(contactId, transportId, 0, 1,
|
||||||
new byte[] {0, 1, 0, 0});
|
new byte[] {0, 1, 0, 0});
|
||||||
oneOf(tagKey).erase();
|
oneOf(tagKey).erase();
|
||||||
// Accept connection again - no expectations
|
// Accept connection again - no expectations
|
||||||
}});
|
}});
|
||||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 0L,
|
TemporarySecret s = new TemporarySecret(contactId, transportId, 0, 0, 0,
|
||||||
0L, 0L, alice, 0L, secret, 0L, 0L, new byte[4]);
|
alice, 0, secret, 0, 0, new byte[4]);
|
||||||
TransportConnectionRecogniser recogniser =
|
TransportConnectionRecogniser recogniser =
|
||||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
new TransportConnectionRecogniser(crypto, db, transportId);
|
||||||
recogniser.addSecret(s);
|
recogniser.addSecret(s);
|
||||||
@@ -120,7 +120,7 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret, ctx.getSecret());
|
assertArrayEquals(secret, ctx.getSecret());
|
||||||
assertEquals(0L, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getConnectionNumber());
|
||||||
assertEquals(alice, ctx.getAlice());
|
assertEquals(alice, ctx.getAlice());
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
// Since we're sending frames to ourselves, we only need outgoing keys
|
// Since we're sending frames to ourselves, we only need outgoing keys
|
||||||
secret = new byte[32];
|
secret = new byte[32];
|
||||||
random.nextBytes(secret);
|
random.nextBytes(secret);
|
||||||
frameKey = crypto.deriveFrameKey(secret, 0L, true, true);
|
frameKey = crypto.deriveFrameKey(secret, 0, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -127,7 +127,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out =
|
||||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret, 0L, true);
|
secret, 0, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||||
MIN_CONNECTION_LENGTH, ctx, false, true);
|
MIN_CONNECTION_LENGTH, ctx, false, true);
|
||||||
// Check that the connection writer thinks there's room for a packet
|
// Check that the connection writer thinks there's room for a packet
|
||||||
@@ -148,7 +148,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out =
|
||||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
secret, 0L, true);
|
secret, 0, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||||
MIN_CONNECTION_LENGTH, ctx, false, false);
|
MIN_CONNECTION_LENGTH, ctx, false, false);
|
||||||
// Check that the connection writer thinks there's room for a packet
|
// Check that the connection writer thinks there's room for a packet
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ public class ByteUtilsTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testReadUint32() {
|
public void testReadUint32() {
|
||||||
byte[] b = StringUtils.fromHexString("0000000000");
|
byte[] b = StringUtils.fromHexString("0000000000");
|
||||||
assertEquals(0L, ByteUtils.readUint32(b, 1));
|
assertEquals(0, ByteUtils.readUint32(b, 1));
|
||||||
b = StringUtils.fromHexString("0000000001");
|
b = StringUtils.fromHexString("0000000001");
|
||||||
assertEquals(1L, ByteUtils.readUint32(b, 1));
|
assertEquals(1, ByteUtils.readUint32(b, 1));
|
||||||
b = StringUtils.fromHexString("00FFFFFFFF");
|
b = StringUtils.fromHexString("00FFFFFFFF");
|
||||||
assertEquals(4294967295L, ByteUtils.readUint32(b, 1));
|
assertEquals(4294967295L, ByteUtils.readUint32(b, 1));
|
||||||
}
|
}
|
||||||
@@ -41,9 +41,9 @@ public class ByteUtilsTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testWriteUint32() {
|
public void testWriteUint32() {
|
||||||
byte[] b = new byte[5];
|
byte[] b = new byte[5];
|
||||||
ByteUtils.writeUint32(0L, b, 1);
|
ByteUtils.writeUint32(0, b, 1);
|
||||||
assertEquals("0000000000", StringUtils.toHexString(b));
|
assertEquals("0000000000", StringUtils.toHexString(b));
|
||||||
ByteUtils.writeUint32(1L, b, 1);
|
ByteUtils.writeUint32(1, b, 1);
|
||||||
assertEquals("0000000001", StringUtils.toHexString(b));
|
assertEquals("0000000001", StringUtils.toHexString(b));
|
||||||
ByteUtils.writeUint32(4294967295L, b, 1);
|
ByteUtils.writeUint32(4294967295L, b, 1);
|
||||||
assertEquals("00FFFFFFFF", StringUtils.toHexString(b));
|
assertEquals("00FFFFFFFF", StringUtils.toHexString(b));
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class FileUtilsTest extends BriarTestCase {
|
|||||||
File temp = FileUtils.createTempFile();
|
File temp = FileUtils.createTempFile();
|
||||||
assertTrue(temp.exists());
|
assertTrue(temp.exists());
|
||||||
assertTrue(temp.isFile());
|
assertTrue(temp.isFile());
|
||||||
assertEquals(0L, temp.length());
|
assertEquals(0, temp.length());
|
||||||
temp.delete();
|
temp.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user