mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Code cleanup: don't use L for long constants unless it's necessary.
This commit is contained in:
@@ -142,8 +142,8 @@ class CryptoComponentImpl implements CryptoComponent {
|
||||
}
|
||||
|
||||
public ErasableKey deriveTagKey(byte[] secret, boolean alice) {
|
||||
if(alice) return deriveKey(secret, A_TAG, 0L);
|
||||
else return deriveKey(secret, B_TAG, 0L);
|
||||
if(alice) return deriveKey(secret, A_TAG, 0);
|
||||
else return deriveKey(secret, B_TAG, 0);
|
||||
}
|
||||
|
||||
public ErasableKey deriveFrameKey(byte[] secret, long connection,
|
||||
|
||||
@@ -28,7 +28,7 @@ class DatabaseCleanerImpl extends TimerTask implements DatabaseCleaner {
|
||||
|
||||
public void startCleaning(Callback callback, long msBetweenSweeps) {
|
||||
this.callback = callback;
|
||||
timer.scheduleAtFixedRate(this, 0L, msBetweenSweeps);
|
||||
timer.scheduleAtFixedRate(this, 0, msBetweenSweeps);
|
||||
}
|
||||
|
||||
public void stopCleaning() {
|
||||
|
||||
@@ -109,8 +109,8 @@ DatabaseCleaner.Callback {
|
||||
new CopyOnWriteArrayList<DatabaseListener>();
|
||||
|
||||
private final Object spaceLock = new Object();
|
||||
private long bytesStoredSinceLastCheck = 0L; // Locking: spaceLock
|
||||
private long timeOfLastCheck = 0L; // Locking: spaceLock
|
||||
private long bytesStoredSinceLastCheck = 0; // Locking: spaceLock
|
||||
private long timeOfLastCheck = 0; // Locking: spaceLock
|
||||
|
||||
private final Object openCloseLock = new Object();
|
||||
private boolean open = false; // Locking: openCloseLock;
|
||||
@@ -1829,7 +1829,7 @@ DatabaseCleaner.Callback {
|
||||
long now = clock.currentTimeMillis();
|
||||
if(bytesStoredSinceLastCheck > MAX_BYTES_BETWEEN_SPACE_CHECKS
|
||||
|| now - timeOfLastCheck > MAX_MS_BETWEEN_SPACE_CHECKS) {
|
||||
bytesStoredSinceLastCheck = 0L;
|
||||
bytesStoredSinceLastCheck = 0;
|
||||
timeOfLastCheck = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ interface DatabaseConstants {
|
||||
* The amount of free space will be checked whenever this many milliseconds
|
||||
* 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
|
||||
@@ -40,11 +40,11 @@ interface DatabaseConstants {
|
||||
* The timestamp of the oldest message in the database is rounded using
|
||||
* 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
|
||||
* 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) {
|
||||
long total = 0L;
|
||||
long total = 0;
|
||||
if(f.isDirectory()) {
|
||||
for(File child : f.listFiles()) total += getDiskSpace(child);
|
||||
return total;
|
||||
@@ -1812,7 +1812,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, c.getInt());
|
||||
rs = ps.executeQuery();
|
||||
List<Group> subs = new ArrayList<Group>();
|
||||
long version = 0L;
|
||||
long version = 0;
|
||||
while(rs.next()) {
|
||||
byte[] id = rs.getBytes(1);
|
||||
String name = rs.getString(2);
|
||||
@@ -2053,7 +2053,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
if(!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
return -1L;
|
||||
return -1;
|
||||
}
|
||||
long connection = rs.getLong(1);
|
||||
if(rs.next()) throw new DbStateException();
|
||||
@@ -2492,12 +2492,12 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setBytes(2, t.getBytes());
|
||||
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();
|
||||
rs.close();
|
||||
ps.close();
|
||||
// Mark the update as needing to be acked
|
||||
if(currentVersion == -1L) {
|
||||
if(currentVersion == -1) {
|
||||
// The row doesn't exist - create it
|
||||
sql = "INSERT INTO contactTransportVersions (contactId,"
|
||||
+ " transportId, remoteVersion, remoteAcked)"
|
||||
|
||||
@@ -59,7 +59,7 @@ class MessageReader implements StructReader<UnverifiedMessage> {
|
||||
String subject = r.readString(MAX_SUBJECT_LENGTH);
|
||||
// Read the timestamp
|
||||
long timestamp = r.readInt64();
|
||||
if(timestamp < 0L) throw new FormatException();
|
||||
if(timestamp < 0) throw new FormatException();
|
||||
// Read the salt
|
||||
byte[] salt = r.readBytes(SALT_LENGTH);
|
||||
if(salt.length < SALT_LENGTH) throw new FormatException();
|
||||
|
||||
@@ -156,7 +156,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
public RetentionAck readRetentionAck() throws IOException {
|
||||
r.readStructId(RETENTION_ACK);
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
if(version < 0) throw new FormatException();
|
||||
return new RetentionAck(version);
|
||||
}
|
||||
|
||||
@@ -167,9 +167,9 @@ class PacketReaderImpl implements PacketReader {
|
||||
public RetentionUpdate readRetentionUpdate() throws IOException {
|
||||
r.readStructId(RETENTION_UPDATE);
|
||||
long retention = r.readInt64();
|
||||
if(retention < 0L) throw new FormatException();
|
||||
if(retention < 0) throw new FormatException();
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
if(version < 0) throw new FormatException();
|
||||
return new RetentionUpdate(retention, version);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
public SubscriptionAck readSubscriptionAck() throws IOException {
|
||||
r.readStructId(SUBSCRIPTION_ACK);
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
if(version < 0) throw new FormatException();
|
||||
return new SubscriptionAck(version);
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||
if(b.length < UniqueId.LENGTH) throw new FormatException();
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
if(version < 0) throw new FormatException();
|
||||
return new TransportAck(new TransportId(b), version);
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
throw new FormatException();
|
||||
// Read the version number
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
if(version < 0) throw new FormatException();
|
||||
r.removeConsumer(counting);
|
||||
// Build and return the transport update
|
||||
return new TransportUpdate(id, new TransportProperties(m), version);
|
||||
|
||||
@@ -35,7 +35,7 @@ class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> {
|
||||
r.readListEnd();
|
||||
// Read the version number
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
if(version < 0) throw new FormatException();
|
||||
r.removeConsumer(counting);
|
||||
// Build and return the subscription update
|
||||
subs = Collections.unmodifiableList(subs);
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
|
||||
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 minutes
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Clock clock;
|
||||
|
||||
@@ -12,8 +12,8 @@ import android.content.Context;
|
||||
|
||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 minutes
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final AndroidExecutor androidExecutor;
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class FilePlugin implements SimplexPlugin {
|
||||
}
|
||||
|
||||
private long getCapacity(String path) throws IOException {
|
||||
return FileSystemUtils.freeSpaceKb(path) * 1024L;
|
||||
return FileSystemUtils.freeSpaceKb(path) * 1024;
|
||||
}
|
||||
|
||||
protected void createReaderFromFile(final File f) {
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.sf.briar.util.OsUtils;
|
||||
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||
|
||||
// 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 POLLING_INTERVAL = 10L * 1000L; // 10 seconds
|
||||
private static final long MAX_LATENCY = 14 * 24 * 60 * 60 * 1000;
|
||||
private static final long POLLING_INTERVAL = 10 * 1000; // 10 seconds
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.sf.briar.util.StringUtils;
|
||||
|
||||
public class ModemPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 60L * 60L * 1000L; // 1 hour
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final ModemFactory modemFactory;
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
|
||||
public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long MAX_LATENCY = 60L * 1000L; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 60L * 1000L; // 1 minute
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 60 * 1000; // 1 minute
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Clock clock;
|
||||
|
||||
@@ -11,8 +11,8 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
|
||||
public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long MAX_LATENCY = 1L * 60L; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 minutes
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final ShutdownManager shutdownManager;
|
||||
|
||||
@@ -11,8 +11,8 @@ import net.sf.briar.util.StringUtils;
|
||||
|
||||
public class TorPluginFactory implements DuplexPluginFactory {
|
||||
|
||||
private static final long MAX_LATENCY = 5L * 60L * 1000L; // 5 minutes
|
||||
private static final long POLLING_INTERVAL = 15L * 60L * 1000L; // 15 mins
|
||||
private static final long MAX_LATENCY = 5 * 60 * 1000; // 5 minutes
|
||||
private static final long POLLING_INTERVAL = 15 * 60 * 1000; // 15 minutes
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class Receiver implements ReadHandler {
|
||||
|
||||
private int windowSize = MAX_WINDOW_SIZE; // Locking: this
|
||||
private long finalSequenceNumber = Long.MAX_VALUE;
|
||||
private long nextSequenceNumber = 1L;
|
||||
private long nextSequenceNumber = 1;
|
||||
|
||||
private volatile boolean valid = true;
|
||||
|
||||
@@ -42,7 +42,7 @@ class Receiver implements ReadHandler {
|
||||
dataFrames.remove(d);
|
||||
// Update the window
|
||||
windowSize += d.getPayloadLength();
|
||||
sender.sendAck(0L, windowSize);
|
||||
sender.sendAck(0, windowSize);
|
||||
nextSequenceNumber++;
|
||||
return d;
|
||||
} else {
|
||||
@@ -92,7 +92,7 @@ class Receiver implements ReadHandler {
|
||||
return;
|
||||
}
|
||||
long sequenceNumber = d.getSequenceNumber();
|
||||
if(sequenceNumber == 0L) {
|
||||
if(sequenceNumber == 0) {
|
||||
// Window probe
|
||||
} else if(sequenceNumber < nextSequenceNumber) {
|
||||
// Duplicate data frame
|
||||
|
||||
@@ -9,7 +9,7 @@ class SenderOutputStream extends OutputStream {
|
||||
private final byte[] buf = new byte[Data.MAX_LENGTH];
|
||||
|
||||
private int offset = Data.HEADER_LENGTH;
|
||||
private long sequenceNumber = 1L;
|
||||
private long sequenceNumber = 1;
|
||||
|
||||
SenderOutputStream(Sender sender) {
|
||||
this.sender = sender;
|
||||
|
||||
@@ -12,7 +12,7 @@ class FrameEncoder {
|
||||
|
||||
static void encodeIv(byte[] iv, long frameNumber) {
|
||||
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();
|
||||
ByteUtils.writeUint32(frameNumber, iv, 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) {
|
||||
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();
|
||||
if(plaintextLength < HEADER_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -35,7 +35,7 @@ class IncomingEncryptionLayer implements FrameReader {
|
||||
iv = new byte[IV_LENGTH];
|
||||
aad = new byte[AAD_LENGTH];
|
||||
ciphertext = new byte[frameLength];
|
||||
frameNumber = 0L;
|
||||
frameNumber = 0;
|
||||
finalFrame = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class OutgoingEncryptionLayer implements FrameWriter {
|
||||
iv = new byte[IV_LENGTH];
|
||||
aad = new byte[AAD_LENGTH];
|
||||
ciphertext = new byte[frameLength];
|
||||
frameNumber = 0L;
|
||||
frameNumber = 0;
|
||||
writeTag = true;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class OutgoingEncryptionLayer implements FrameWriter {
|
||||
iv = new byte[IV_LENGTH];
|
||||
aad = new byte[AAD_LENGTH];
|
||||
ciphertext = new byte[frameLength];
|
||||
frameNumber = 0L;
|
||||
frameNumber = 0;
|
||||
writeTag = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ByteUtils {
|
||||
}
|
||||
|
||||
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(b.length < offset + 4) throw new IllegalArgumentException();
|
||||
b[offset] = (byte) (i >> 24);
|
||||
|
||||
@@ -91,7 +91,7 @@ public class FileUtils {
|
||||
StatFs s = new StatFs(f.getAbsolutePath());
|
||||
return (long) s.getAvailableBlocks() * s.getBlockSize();
|
||||
} else {
|
||||
return FileSystemUtils.freeSpaceKb(f.getAbsolutePath()) * 1024L;
|
||||
return FileSystemUtils.freeSpaceKb(f.getAbsolutePath()) * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user