Commit 7f94707d authored by akwizgran's avatar akwizgran

Code cleanup: import static.

parent e534722d
......@@ -4,6 +4,7 @@ import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP;
import static net.sf.briar.db.DatabaseConstants.CRITICAL_FREE_SPACE;
import static net.sf.briar.db.DatabaseConstants.MAX_BYTES_BETWEEN_SPACE_CHECKS;
import static net.sf.briar.db.DatabaseConstants.MAX_MS_BETWEEN_SPACE_CHECKS;
import static net.sf.briar.db.DatabaseConstants.MAX_UPDATE_INTERVAL;
import static net.sf.briar.db.DatabaseConstants.MIN_FREE_SPACE;
import java.io.IOException;
......@@ -673,7 +674,7 @@ DatabaseCleaner.Callback {
private boolean updateIsDue(long sent) {
long now = clock.currentTimeMillis();
return now - sent >= DatabaseConstants.MAX_UPDATE_INTERVAL;
return now - sent >= MAX_UPDATE_INTERVAL;
}
public TransportUpdate generateTransportUpdate(ContactId c)
......
package net.sf.briar.plugins;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PROPERTIES_PER_TRANSPORT;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PROPERTY_LENGTH;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
......@@ -30,7 +33,6 @@ import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexPluginFactory;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.transport.ConnectionDispatcher;
import net.sf.briar.api.ui.UiCallback;
......@@ -241,20 +243,20 @@ class PluginManagerImpl implements PluginManager {
public void setLocalProperties(TransportProperties p) {
assert id != null;
if(p.size() > ProtocolConstants.MAX_PROPERTIES_PER_TRANSPORT) {
if(p.size() > MAX_PROPERTIES_PER_TRANSPORT) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning("Plugin " + id + " set too many properties");
return;
}
for(String s : p.keySet()) {
if(s.length() > ProtocolConstants.MAX_PROPERTY_LENGTH) {
if(s.length() > MAX_PROPERTY_LENGTH) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning("Plugin " + id + " set long key: " + s);
return;
}
}
for(String s : p.values()) {
if(s.length() > ProtocolConstants.MAX_PROPERTY_LENGTH) {
if(s.length() > MAX_PROPERTY_LENGTH) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning("Plugin " + id + " set long value: " + s);
return;
......
package net.sf.briar.plugins.file;
import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......@@ -16,7 +18,6 @@ import net.sf.briar.api.plugins.simplex.SimplexPlugin;
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
import net.sf.briar.api.transport.TransportConstants;
import org.apache.commons.io.FileSystemUtils;
......@@ -69,7 +70,7 @@ public abstract class FilePlugin implements SimplexPlugin {
File f = new File(dir, filename);
try {
long capacity = getCapacity(dir.getPath());
if(capacity < TransportConstants.MIN_CONNECTION_LENGTH) return null;
if(capacity < MIN_CONNECTION_LENGTH) return null;
OutputStream out = new FileOutputStream(f);
return new FileTransportWriter(f, out, capacity, this);
} catch(IOException e) {
......
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_AUTHOR_NAME_LENGTH;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PUBLIC_KEY_LENGTH;
import java.io.IOException;
import net.sf.briar.api.crypto.CryptoComponent;
......@@ -7,11 +10,10 @@ import net.sf.briar.api.crypto.MessageDigest;
import net.sf.briar.api.protocol.Author;
import net.sf.briar.api.protocol.AuthorFactory;
import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.DigestingConsumer;
import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.StructReader;
class AuthorReader implements StructReader<Author> {
......@@ -29,8 +31,8 @@ class AuthorReader implements StructReader<Author> {
// Read and digest the data
r.addConsumer(digesting);
r.readStructId(Types.AUTHOR);
String name = r.readString(ProtocolConstants.MAX_AUTHOR_NAME_LENGTH);
byte[] publicKey = r.readBytes(ProtocolConstants.MAX_PUBLIC_KEY_LENGTH);
String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH);
r.removeConsumer(digesting);
// Build and return the author
AuthorId id = new AuthorId(messageDigest.digest());
......
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_GROUP_NAME_LENGTH;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PUBLIC_KEY_LENGTH;
import java.io.IOException;
import net.sf.briar.api.crypto.CryptoComponent;
......@@ -7,11 +10,10 @@ import net.sf.briar.api.crypto.MessageDigest;
import net.sf.briar.api.protocol.Group;
import net.sf.briar.api.protocol.GroupFactory;
import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.DigestingConsumer;
import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.StructReader;
class GroupReader implements StructReader<Group> {
......@@ -29,10 +31,10 @@ class GroupReader implements StructReader<Group> {
// Read and digest the data
r.addConsumer(digesting);
r.readStructId(Types.GROUP);
String name = r.readString(ProtocolConstants.MAX_GROUP_NAME_LENGTH);
String name = r.readString(MAX_GROUP_NAME_LENGTH);
byte[] publicKey = null;
if(r.hasNull()) r.readNull();
else publicKey = r.readBytes(ProtocolConstants.MAX_PUBLIC_KEY_LENGTH);
else publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH);
r.removeConsumer(digesting);
// Build and return the group
GroupId id = new GroupId(messageDigest.digest());
......
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_BODY_LENGTH;
import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.Message;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.protocol.ProtocolConstants;
/** A simple in-memory implementation of a message. */
class MessageImpl implements Message {
......@@ -22,7 +22,7 @@ class MessageImpl implements Message {
int bodyStart, int bodyLength) {
if(bodyStart + bodyLength > raw.length)
throw new IllegalArgumentException();
if(bodyLength > ProtocolConstants.MAX_BODY_LENGTH)
if(bodyLength > MAX_BODY_LENGTH)
throw new IllegalArgumentException();
this.id = id;
this.parent = parent;
......
package net.sf.briar.transport;
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
......@@ -19,7 +21,6 @@ import net.sf.briar.api.transport.ConnectionContext;
import net.sf.briar.api.transport.ConnectionDispatcher;
import net.sf.briar.api.transport.ConnectionRecogniser;
import net.sf.briar.api.transport.IncomingConnectionExecutor;
import net.sf.briar.api.transport.TransportConstants;
import com.google.inject.Inject;
......@@ -64,7 +65,7 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
}
private byte[] readTag(InputStream in) throws IOException {
byte[] b = new byte[TransportConstants.TAG_LENGTH];
byte[] b = new byte[TAG_LENGTH];
int offset = 0;
while(offset < b.length) {
int read = in.read(b, offset, b.length - offset);
......
package net.sf.briar.db;
import static net.sf.briar.db.DatabaseConstants.RETRANSMIT_THRESHOLD;
import static org.junit.Assert.assertArrayEquals;
import java.io.File;
......@@ -705,7 +706,7 @@ public class H2DatabaseTest extends BriarTestCase {
@Test
public void testRetransmission() throws Exception {
BatchId[] ids = new BatchId[DatabaseConstants.RETRANSMIT_THRESHOLD + 5];
BatchId[] ids = new BatchId[RETRANSMIT_THRESHOLD + 5];
for(int i = 0; i < ids.length; i++) {
ids[i] = new BatchId(TestUtils.getRandomId());
}
......@@ -724,7 +725,7 @@ public class H2DatabaseTest extends BriarTestCase {
// The contact acks the batches in reverse order. The first
// RETRANSMIT_THRESHOLD - 1 acks should not trigger any retransmissions
for(int i = 0; i < DatabaseConstants.RETRANSMIT_THRESHOLD - 1; i++) {
for(int i = 0; i < RETRANSMIT_THRESHOLD - 1; i++) {
db.removeAckedBatch(txn, contactId, ids[ids.length - i - 1]);
Collection<BatchId> lost = db.getLostBatches(txn, contactId);
assertEquals(Collections.emptyList(), lost);
......@@ -732,7 +733,7 @@ public class H2DatabaseTest extends BriarTestCase {
// The next ack should trigger the retransmission of the remaining
// five outstanding batches
int index = ids.length - DatabaseConstants.RETRANSMIT_THRESHOLD;
int index = ids.length - RETRANSMIT_THRESHOLD;
db.removeAckedBatch(txn, contactId, ids[index]);
Collection<BatchId> lost = db.getLostBatches(txn, contactId);
for(int i = 0; i < index; i++) {
......@@ -745,7 +746,7 @@ public class H2DatabaseTest extends BriarTestCase {
@Test
public void testNoRetransmission() throws Exception {
BatchId[] ids = new BatchId[DatabaseConstants.RETRANSMIT_THRESHOLD * 2];
BatchId[] ids = new BatchId[RETRANSMIT_THRESHOLD * 2];
for(int i = 0; i < ids.length; i++) {
ids[i] = new BatchId(TestUtils.getRandomId());
}
......
package net.sf.briar.plugins.file;
import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
import static org.junit.Assert.assertArrayEquals;
import java.io.File;
......@@ -15,7 +16,6 @@ import net.sf.briar.TestUtils;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
import net.sf.briar.api.transport.TransportConstants;
import net.sf.briar.plugins.ImmediateExecutor;
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
......@@ -360,10 +360,10 @@ public class RemovableDrivePluginTest extends BriarTestCase {
File f = new File(testDir, "abcdefgh.dat");
OutputStream out = new FileOutputStream(f);
out.write(new byte[TransportConstants.MIN_CONNECTION_LENGTH]);
out.write(new byte[MIN_CONNECTION_LENGTH]);
out.flush();
out.close();
assertEquals(TransportConstants.MIN_CONNECTION_LENGTH, f.length());
assertEquals(MIN_CONNECTION_LENGTH, f.length());
plugin.driveInserted(testDir);
context.assertIsSatisfied();
......
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Collection;
......@@ -9,7 +11,6 @@ import net.sf.briar.TestUtils;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.protocol.Ack;
import net.sf.briar.api.protocol.PacketFactory;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.ReaderFactory;
......@@ -103,12 +104,12 @@ public class AckReaderTest extends BriarTestCase {
w.writeStructId(Types.ACK);
w.writeListStart();
while(out.size() + serial.getSerialisedUniqueIdLength()
< ProtocolConstants.MAX_PACKET_LENGTH) {
< MAX_PACKET_LENGTH) {
w.writeBytes(TestUtils.getRandomId());
}
if(tooBig) w.writeBytes(TestUtils.getRandomId());
w.writeListEnd();
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
assertEquals(tooBig, out.size() > MAX_PACKET_LENGTH);
return out.toByteArray();
}
......
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
......@@ -7,12 +9,11 @@ import java.util.Collections;
import net.sf.briar.BriarTestCase;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.protocol.UnverifiedBatch;
import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.ReaderFactory;
import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Writer;
import net.sf.briar.api.serial.WriterFactory;
import net.sf.briar.serial.SerialModule;
......@@ -50,7 +51,7 @@ public class BatchReaderTest extends BriarTestCase {
context.mock(UnverifiedBatchFactory.class);
BatchReader batchReader = new BatchReader(messageReader, batchFactory);
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH + 1);
byte[] b = createBatch(MAX_PACKET_LENGTH + 1);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.BATCH, batchReader);
......@@ -74,7 +75,7 @@ public class BatchReaderTest extends BriarTestCase {
will(returnValue(batch));
}});
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH);
byte[] b = createBatch(MAX_PACKET_LENGTH);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.BATCH, batchReader);
......
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Collection;
......@@ -9,7 +11,6 @@ import net.sf.briar.TestUtils;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.PacketFactory;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.ReaderFactory;
......@@ -103,12 +104,12 @@ public class OfferReaderTest extends BriarTestCase {
w.writeStructId(Types.OFFER);
w.writeListStart();
while(out.size() + serial.getSerialisedUniqueIdLength()
< ProtocolConstants.MAX_PACKET_LENGTH) {
< MAX_PACKET_LENGTH) {
w.writeBytes(TestUtils.getRandomId());
}
if(tooBig) w.writeBytes(TestUtils.getRandomId());
w.writeListEnd();
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
assertEquals(tooBig, out.size() > MAX_PACKET_LENGTH);
return out.toByteArray();
}
......
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.BitSet;
......@@ -7,7 +9,6 @@ import java.util.BitSet;
import net.sf.briar.BriarTestCase;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.protocol.PacketFactory;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.Reader;
......@@ -125,12 +126,12 @@ public class RequestReaderTest extends BriarTestCase {
// Allow one byte for the REQUEST tag, one byte for the padding length
// as a uint7, one byte for the BYTES tag, and five bytes for the
// length of the byte array as an int32
int size = ProtocolConstants.MAX_PACKET_LENGTH - 8;
int size = MAX_PACKET_LENGTH - 8;
if(tooBig) size++;
assertTrue(size > Short.MAX_VALUE);
w.writeUint7((byte) 0);
w.writeBytes(new byte[size]);
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
assertEquals(tooBig, out.size() > MAX_PACKET_LENGTH);
return out.toByteArray();
}
......
package net.sf.briar.transport;
import static net.sf.briar.util.ByteUtils.MAX_32_BIT_UNSIGNED;
import java.util.HashSet;
import java.util.Set;
import net.sf.briar.BriarTestCase;
import net.sf.briar.api.transport.ConnectionWindow;
import net.sf.briar.util.ByteUtils;
import org.junit.Test;
......@@ -45,13 +46,11 @@ public class ConnectionWindowImplTest extends BriarTestCase {
} catch(IllegalArgumentException expected) {}
// Values greater than 2^32 - 1 should never be allowed
Set<Long> unseen = new HashSet<Long>();
for(int i = 0; i < 32; i++) {
unseen.add(ByteUtils.MAX_32_BIT_UNSIGNED - i);
}
for(int i = 0; i < 32; i++) unseen.add(MAX_32_BIT_UNSIGNED - i);
w = new ConnectionWindowImpl(unseen);
w.setSeen(ByteUtils.MAX_32_BIT_UNSIGNED);
w.setSeen(MAX_32_BIT_UNSIGNED);
try {
w.setSeen(ByteUtils.MAX_32_BIT_UNSIGNED + 1);
w.setSeen(MAX_32_BIT_UNSIGNED + 1);
fail();
} catch(IllegalArgumentException expected) {}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment