mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Code cleanup: import static.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package net.sf.briar.db;
|
package net.sf.briar.db;
|
||||||
|
|
||||||
|
import static java.sql.Types.BINARY;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static net.sf.briar.db.DatabaseConstants.EXPIRY_MODULUS;
|
import static net.sf.briar.db.DatabaseConstants.EXPIRY_MODULUS;
|
||||||
@@ -12,7 +13,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Types;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -514,10 +514,10 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ZERO())";
|
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ZERO())";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBytes(1, m.getId().getBytes());
|
ps.setBytes(1, m.getId().getBytes());
|
||||||
if(m.getParent() == null) ps.setNull(2, Types.BINARY);
|
if(m.getParent() == null) ps.setNull(2, BINARY);
|
||||||
else ps.setBytes(2, m.getParent().getBytes());
|
else ps.setBytes(2, m.getParent().getBytes());
|
||||||
ps.setBytes(3, m.getGroup().getBytes());
|
ps.setBytes(3, m.getGroup().getBytes());
|
||||||
if(m.getAuthor() == null) ps.setNull(4, Types.BINARY);
|
if(m.getAuthor() == null) ps.setNull(4, BINARY);
|
||||||
else ps.setBytes(4, m.getAuthor().getBytes());
|
else ps.setBytes(4, m.getAuthor().getBytes());
|
||||||
ps.setString(5, m.getSubject());
|
ps.setString(5, m.getSubject());
|
||||||
ps.setLong(6, m.getTimestamp());
|
ps.setLong(6, m.getTimestamp());
|
||||||
@@ -607,7 +607,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBytes(1, m.getId().getBytes());
|
ps.setBytes(1, m.getId().getBytes());
|
||||||
if(m.getParent() == null) ps.setNull(2, Types.BINARY);
|
if(m.getParent() == null) ps.setNull(2, BINARY);
|
||||||
else ps.setBytes(2, m.getParent().getBytes());
|
else ps.setBytes(2, m.getParent().getBytes());
|
||||||
ps.setString(3, m.getSubject());
|
ps.setString(3, m.getSubject());
|
||||||
ps.setLong(4, m.getTimestamp());
|
ps.setLong(4, m.getTimestamp());
|
||||||
@@ -795,7 +795,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setBytes(2, g.getBytes());
|
ps.setBytes(2, g.getBytes());
|
||||||
if(nextId == null) ps.setNull(3, Types.BINARY); // At the tail
|
if(nextId == null) ps.setNull(3, BINARY); // At the tail
|
||||||
else ps.setBytes(3, nextId); // In the middle
|
else ps.setBytes(3, nextId); // In the middle
|
||||||
ps.setLong(4, deleted);
|
ps.setLong(4, deleted);
|
||||||
affected = ps.executeUpdate();
|
affected = ps.executeUpdate();
|
||||||
@@ -2086,7 +2086,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
sql = "UPDATE visibilities SET nextId = ?, deleted = ?"
|
sql = "UPDATE visibilities SET nextId = ?, deleted = ?"
|
||||||
+ " WHERE contactId = ? AND nextId = ?";
|
+ " WHERE contactId = ? AND nextId = ?";
|
||||||
ps1 = txn.prepareStatement(sql);
|
ps1 = txn.prepareStatement(sql);
|
||||||
if(nextId == null) ps1.setNull(1, Types.BINARY); // At the tail
|
if(nextId == null) ps1.setNull(1, BINARY); // At the tail
|
||||||
else ps1.setBytes(1, nextId); // At the head or in the middle
|
else ps1.setBytes(1, nextId); // At the head or in the middle
|
||||||
ps1.setLong(2, now);
|
ps1.setLong(2, now);
|
||||||
ps1.setInt(3, contactId);
|
ps1.setInt(3, contactId);
|
||||||
@@ -2182,7 +2182,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
sql = "UPDATE visibilities SET nextId = ?, deleted = ?"
|
sql = "UPDATE visibilities SET nextId = ?, deleted = ?"
|
||||||
+ " WHERE contactId = ? AND nextId = ?";
|
+ " WHERE contactId = ? AND nextId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
if(nextId == null) ps.setNull(1, Types.BINARY); // At the tail
|
if(nextId == null) ps.setNull(1, BINARY); // At the tail
|
||||||
else ps.setBytes(1, nextId); // At the head or in the middle
|
else ps.setBytes(1, nextId); // At the head or in the middle
|
||||||
ps.setLong(2, clock.currentTimeMillis());
|
ps.setLong(2, clock.currentTimeMillis());
|
||||||
ps.setInt(3, c.getInt());
|
ps.setInt(3, c.getInt());
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.ACK;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -12,12 +13,11 @@ import net.sf.briar.api.FormatException;
|
|||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.CountingConsumer;
|
import net.sf.briar.api.serial.CountingConsumer;
|
||||||
import net.sf.briar.api.serial.StructReader;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
|
import net.sf.briar.api.serial.StructReader;
|
||||||
|
|
||||||
class AckReader implements StructReader<Ack> {
|
class AckReader implements StructReader<Ack> {
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class AckReader implements StructReader<Ack> {
|
|||||||
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readStructId(Types.ACK);
|
r.readStructId(ACK);
|
||||||
r.setMaxBytesLength(UniqueId.LENGTH);
|
r.setMaxBytesLength(UniqueId.LENGTH);
|
||||||
List<Bytes> raw = r.readList(Bytes.class);
|
List<Bytes> raw = r.readList(Bytes.class);
|
||||||
r.resetMaxBytesLength();
|
r.resetMaxBytesLength();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
|
import static net.sf.briar.api.protocol.Types.AUTHOR;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -8,7 +10,6 @@ import net.sf.briar.api.crypto.MessageDigest;
|
|||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
import net.sf.briar.api.protocol.AuthorFactory;
|
import net.sf.briar.api.protocol.AuthorFactory;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ class AuthorFactoryImpl implements AuthorFactory {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.AUTHOR);
|
w.writeStructId(AUTHOR);
|
||||||
w.writeString(name);
|
w.writeString(name);
|
||||||
w.writeBytes(publicKey);
|
w.writeBytes(publicKey);
|
||||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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_AUTHOR_NAME_LENGTH;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.AUTHOR;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -10,7 +11,6 @@ import net.sf.briar.api.crypto.MessageDigest;
|
|||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
import net.sf.briar.api.protocol.AuthorFactory;
|
import net.sf.briar.api.protocol.AuthorFactory;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.DigestingConsumer;
|
import net.sf.briar.api.serial.DigestingConsumer;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.StructReader;
|
import net.sf.briar.api.serial.StructReader;
|
||||||
@@ -30,7 +30,7 @@ class AuthorReader implements StructReader<Author> {
|
|||||||
DigestingConsumer digesting = new DigestingConsumer(messageDigest);
|
DigestingConsumer digesting = new DigestingConsumer(messageDigest);
|
||||||
// Read and digest the data
|
// Read and digest the data
|
||||||
r.addConsumer(digesting);
|
r.addConsumer(digesting);
|
||||||
r.readStructId(Types.AUTHOR);
|
r.readStructId(AUTHOR);
|
||||||
String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
|
String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
|
||||||
byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH);
|
byte[] publicKey = r.readBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||||
r.removeConsumer(digesting);
|
r.removeConsumer(digesting);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
|
import static net.sf.briar.api.protocol.Types.GROUP;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -8,7 +10,6 @@ import net.sf.briar.api.crypto.MessageDigest;
|
|||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
import net.sf.briar.api.protocol.GroupFactory;
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ class GroupFactoryImpl implements GroupFactory {
|
|||||||
public Group createGroup(String name, byte[] publicKey) throws IOException {
|
public Group createGroup(String name, byte[] publicKey) throws IOException {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.GROUP);
|
w.writeStructId(GROUP);
|
||||||
w.writeString(name);
|
w.writeString(name);
|
||||||
if(publicKey == null) w.writeNull();
|
if(publicKey == null) w.writeNull();
|
||||||
else w.writeBytes(publicKey);
|
else w.writeBytes(publicKey);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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_GROUP_NAME_LENGTH;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.GROUP;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -9,7 +10,6 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
|||||||
import net.sf.briar.api.crypto.MessageDigest;
|
import net.sf.briar.api.crypto.MessageDigest;
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.DigestingConsumer;
|
import net.sf.briar.api.serial.DigestingConsumer;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.StructReader;
|
import net.sf.briar.api.serial.StructReader;
|
||||||
@@ -27,7 +27,7 @@ class GroupReader implements StructReader<Group> {
|
|||||||
DigestingConsumer digesting = new DigestingConsumer(messageDigest);
|
DigestingConsumer digesting = new DigestingConsumer(messageDigest);
|
||||||
// Read and digest the data
|
// Read and digest the data
|
||||||
r.addConsumer(digesting);
|
r.addConsumer(digesting);
|
||||||
r.readStructId(Types.GROUP);
|
r.readStructId(GROUP);
|
||||||
String name = r.readString(MAX_GROUP_NAME_LENGTH);
|
String name = r.readString(MAX_GROUP_NAME_LENGTH);
|
||||||
byte[] publicKey = null;
|
byte[] publicKey = null;
|
||||||
if(r.hasNull()) r.readNull();
|
if(r.hasNull()) r.readNull();
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
|||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SIGNATURE_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SIGNATURE_LENGTH;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SUBJECT_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SUBJECT_LENGTH;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.SALT_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.SALT_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.AUTHOR;
|
||||||
|
import static net.sf.briar.api.protocol.Types.GROUP;
|
||||||
|
import static net.sf.briar.api.protocol.Types.MESSAGE;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -23,7 +26,6 @@ import net.sf.briar.api.protocol.GroupId;
|
|||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.MessageFactory;
|
import net.sf.briar.api.protocol.MessageFactory;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.CountingConsumer;
|
import net.sf.briar.api.serial.CountingConsumer;
|
||||||
import net.sf.briar.api.serial.DigestingConsumer;
|
import net.sf.briar.api.serial.DigestingConsumer;
|
||||||
@@ -111,7 +113,7 @@ class MessageFactoryImpl implements MessageFactory {
|
|||||||
w.addConsumer(groupConsumer);
|
w.addConsumer(groupConsumer);
|
||||||
}
|
}
|
||||||
// Write the message
|
// Write the message
|
||||||
w.writeStructId(Types.MESSAGE);
|
w.writeStructId(MESSAGE);
|
||||||
if(parent == null) w.writeNull();
|
if(parent == null) w.writeNull();
|
||||||
else w.writeBytes(parent.getBytes());
|
else w.writeBytes(parent.getBytes());
|
||||||
if(group == null) w.writeNull();
|
if(group == null) w.writeNull();
|
||||||
@@ -157,7 +159,7 @@ class MessageFactoryImpl implements MessageFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeGroup(Writer w, Group g) throws IOException {
|
private void writeGroup(Writer w, Group g) throws IOException {
|
||||||
w.writeStructId(Types.GROUP);
|
w.writeStructId(GROUP);
|
||||||
w.writeString(g.getName());
|
w.writeString(g.getName());
|
||||||
byte[] publicKey = g.getPublicKey();
|
byte[] publicKey = g.getPublicKey();
|
||||||
if(publicKey == null) w.writeNull();
|
if(publicKey == null) w.writeNull();
|
||||||
@@ -165,7 +167,7 @@ class MessageFactoryImpl implements MessageFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeAuthor(Writer w, Author a) throws IOException {
|
private void writeAuthor(Writer w, Author a) throws IOException {
|
||||||
w.writeStructId(Types.AUTHOR);
|
w.writeStructId(AUTHOR);
|
||||||
w.writeString(a.getName());
|
w.writeString(a.getName());
|
||||||
w.writeBytes(a.getPublicKey());
|
w.writeBytes(a.getPublicKey());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
|||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SIGNATURE_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SIGNATURE_LENGTH;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SUBJECT_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_SUBJECT_LENGTH;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.SALT_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.SALT_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.AUTHOR;
|
||||||
|
import static net.sf.briar.api.protocol.Types.GROUP;
|
||||||
|
import static net.sf.briar.api.protocol.Types.MESSAGE;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -12,7 +15,6 @@ import net.sf.briar.api.FormatException;
|
|||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.protocol.UnverifiedMessage;
|
import net.sf.briar.api.protocol.UnverifiedMessage;
|
||||||
import net.sf.briar.api.serial.CopyingConsumer;
|
import net.sf.briar.api.serial.CopyingConsumer;
|
||||||
@@ -37,7 +39,7 @@ class MessageReader implements StructReader<UnverifiedMessage> {
|
|||||||
r.addConsumer(copying);
|
r.addConsumer(copying);
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
// Read the initial tag
|
// Read the initial tag
|
||||||
r.readStructId(Types.MESSAGE);
|
r.readStructId(MESSAGE);
|
||||||
// Read the parent's message ID, if there is one
|
// Read the parent's message ID, if there is one
|
||||||
MessageId parent = null;
|
MessageId parent = null;
|
||||||
if(r.hasNull()) {
|
if(r.hasNull()) {
|
||||||
@@ -52,18 +54,18 @@ class MessageReader implements StructReader<UnverifiedMessage> {
|
|||||||
if(r.hasNull()) {
|
if(r.hasNull()) {
|
||||||
r.readNull();
|
r.readNull();
|
||||||
} else {
|
} else {
|
||||||
r.addStructReader(Types.GROUP, groupReader);
|
r.addStructReader(GROUP, groupReader);
|
||||||
group = r.readStruct(Types.GROUP, Group.class);
|
group = r.readStruct(GROUP, Group.class);
|
||||||
r.removeStructReader(Types.GROUP);
|
r.removeStructReader(GROUP);
|
||||||
}
|
}
|
||||||
// Read the author, if there is one
|
// Read the author, if there is one
|
||||||
Author author = null;
|
Author author = null;
|
||||||
if(r.hasNull()) {
|
if(r.hasNull()) {
|
||||||
r.readNull();
|
r.readNull();
|
||||||
} else {
|
} else {
|
||||||
r.addStructReader(Types.AUTHOR, authorReader);
|
r.addStructReader(AUTHOR, authorReader);
|
||||||
author = r.readStruct(Types.AUTHOR, Author.class);
|
author = r.readStruct(AUTHOR, Author.class);
|
||||||
r.removeStructReader(Types.AUTHOR);
|
r.removeStructReader(AUTHOR);
|
||||||
}
|
}
|
||||||
// Read the subject
|
// Read the subject
|
||||||
String subject = r.readString(MAX_SUBJECT_LENGTH);
|
String subject = r.readString(MAX_SUBJECT_LENGTH);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.OFFER;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -12,12 +13,11 @@ import net.sf.briar.api.FormatException;
|
|||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.CountingConsumer;
|
import net.sf.briar.api.serial.CountingConsumer;
|
||||||
import net.sf.briar.api.serial.StructReader;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
|
import net.sf.briar.api.serial.StructReader;
|
||||||
|
|
||||||
class OfferReader implements StructReader<Offer> {
|
class OfferReader implements StructReader<Offer> {
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class OfferReader implements StructReader<Offer> {
|
|||||||
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readStructId(Types.OFFER);
|
r.readStructId(OFFER);
|
||||||
r.setMaxBytesLength(UniqueId.LENGTH);
|
r.setMaxBytesLength(UniqueId.LENGTH);
|
||||||
List<Bytes> raw = r.readList(Bytes.class);
|
List<Bytes> raw = r.readList(Bytes.class);
|
||||||
r.resetMaxBytesLength();
|
r.resetMaxBytesLength();
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
|
import static net.sf.briar.api.protocol.Types.ACK;
|
||||||
|
import static net.sf.briar.api.protocol.Types.MESSAGE;
|
||||||
|
import static net.sf.briar.api.protocol.Types.OFFER;
|
||||||
|
import static net.sf.briar.api.protocol.Types.REQUEST;
|
||||||
|
import static net.sf.briar.api.protocol.Types.SUBSCRIPTION_UPDATE;
|
||||||
|
import static net.sf.briar.api.protocol.Types.TRANSPORT_UPDATE;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@@ -9,7 +16,6 @@ import net.sf.briar.api.protocol.ProtocolReader;
|
|||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.protocol.UnverifiedMessage;
|
import net.sf.briar.api.protocol.UnverifiedMessage;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
@@ -27,12 +33,12 @@ class ProtocolReaderImpl implements ProtocolReader {
|
|||||||
StructReader<SubscriptionUpdate> subscriptionReader,
|
StructReader<SubscriptionUpdate> subscriptionReader,
|
||||||
StructReader<TransportUpdate> transportReader) {
|
StructReader<TransportUpdate> transportReader) {
|
||||||
reader = readerFactory.createReader(in);
|
reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.ACK, ackReader);
|
reader.addStructReader(ACK, ackReader);
|
||||||
reader.addStructReader(Types.MESSAGE, messageReader);
|
reader.addStructReader(MESSAGE, messageReader);
|
||||||
reader.addStructReader(Types.OFFER, offerReader);
|
reader.addStructReader(OFFER, offerReader);
|
||||||
reader.addStructReader(Types.REQUEST, requestReader);
|
reader.addStructReader(REQUEST, requestReader);
|
||||||
reader.addStructReader(Types.SUBSCRIPTION_UPDATE, subscriptionReader);
|
reader.addStructReader(SUBSCRIPTION_UPDATE, subscriptionReader);
|
||||||
reader.addStructReader(Types.TRANSPORT_UPDATE, transportReader);
|
reader.addStructReader(TRANSPORT_UPDATE, transportReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean eof() throws IOException {
|
public boolean eof() throws IOException {
|
||||||
@@ -40,51 +46,51 @@ class ProtocolReaderImpl implements ProtocolReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAck() throws IOException {
|
public boolean hasAck() throws IOException {
|
||||||
return reader.hasStruct(Types.ACK);
|
return reader.hasStruct(ACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ack readAck() throws IOException {
|
public Ack readAck() throws IOException {
|
||||||
return reader.readStruct(Types.ACK, Ack.class);
|
return reader.readStruct(ACK, Ack.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMessage() throws IOException {
|
public boolean hasMessage() throws IOException {
|
||||||
return reader.hasStruct(Types.MESSAGE);
|
return reader.hasStruct(MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnverifiedMessage readMessage() throws IOException {
|
public UnverifiedMessage readMessage() throws IOException {
|
||||||
return reader.readStruct(Types.MESSAGE, UnverifiedMessage.class);
|
return reader.readStruct(MESSAGE, UnverifiedMessage.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasOffer() throws IOException {
|
public boolean hasOffer() throws IOException {
|
||||||
return reader.hasStruct(Types.OFFER);
|
return reader.hasStruct(OFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Offer readOffer() throws IOException {
|
public Offer readOffer() throws IOException {
|
||||||
return reader.readStruct(Types.OFFER, Offer.class);
|
return reader.readStruct(OFFER, Offer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRequest() throws IOException {
|
public boolean hasRequest() throws IOException {
|
||||||
return reader.hasStruct(Types.REQUEST);
|
return reader.hasStruct(REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request readRequest() throws IOException {
|
public Request readRequest() throws IOException {
|
||||||
return reader.readStruct(Types.REQUEST, Request.class);
|
return reader.readStruct(REQUEST, Request.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSubscriptionUpdate() throws IOException {
|
public boolean hasSubscriptionUpdate() throws IOException {
|
||||||
return reader.hasStruct(Types.SUBSCRIPTION_UPDATE);
|
return reader.hasStruct(SUBSCRIPTION_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubscriptionUpdate readSubscriptionUpdate() throws IOException {
|
public SubscriptionUpdate readSubscriptionUpdate() throws IOException {
|
||||||
return reader.readStruct(Types.SUBSCRIPTION_UPDATE,
|
return reader.readStruct(SUBSCRIPTION_UPDATE,
|
||||||
SubscriptionUpdate.class);
|
SubscriptionUpdate.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasTransportUpdate() throws IOException {
|
public boolean hasTransportUpdate() throws IOException {
|
||||||
return reader.hasStruct(Types.TRANSPORT_UPDATE);
|
return reader.hasStruct(TRANSPORT_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportUpdate readTransportUpdate() throws IOException {
|
public TransportUpdate readTransportUpdate() throws IOException {
|
||||||
return reader.readStruct(Types.TRANSPORT_UPDATE, TransportUpdate.class);
|
return reader.readStruct(TRANSPORT_UPDATE, TransportUpdate.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.ACK;
|
||||||
|
import static net.sf.briar.api.protocol.Types.GROUP;
|
||||||
|
import static net.sf.briar.api.protocol.Types.OFFER;
|
||||||
|
import static net.sf.briar.api.protocol.Types.REQUEST;
|
||||||
|
import static net.sf.briar.api.protocol.Types.SUBSCRIPTION_UPDATE;
|
||||||
|
import static net.sf.briar.api.protocol.Types.TRANSPORT;
|
||||||
|
import static net.sf.briar.api.protocol.Types.TRANSPORT_UPDATE;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -17,7 +24,6 @@ import net.sf.briar.api.protocol.Request;
|
|||||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||||
import net.sf.briar.api.protocol.Transport;
|
import net.sf.briar.api.protocol.Transport;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.SerialComponent;
|
import net.sf.briar.api.serial.SerialComponent;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
@@ -40,7 +46,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
|
|
||||||
public int getMaxMessagesForAck(long capacity) {
|
public int getMaxMessagesForAck(long capacity) {
|
||||||
int packet = (int) Math.min(capacity, MAX_PACKET_LENGTH);
|
int packet = (int) Math.min(capacity, MAX_PACKET_LENGTH);
|
||||||
int overhead = serial.getSerialisedStructIdLength(Types.ACK)
|
int overhead = serial.getSerialisedStructIdLength(ACK)
|
||||||
+ serial.getSerialisedListStartLength()
|
+ serial.getSerialisedListStartLength()
|
||||||
+ serial.getSerialisedListEndLength();
|
+ serial.getSerialisedListEndLength();
|
||||||
int idLength = serial.getSerialisedUniqueIdLength();
|
int idLength = serial.getSerialisedUniqueIdLength();
|
||||||
@@ -49,7 +55,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
|
|
||||||
public int getMaxMessagesForOffer(long capacity) {
|
public int getMaxMessagesForOffer(long capacity) {
|
||||||
int packet = (int) Math.min(capacity, MAX_PACKET_LENGTH);
|
int packet = (int) Math.min(capacity, MAX_PACKET_LENGTH);
|
||||||
int overhead = serial.getSerialisedStructIdLength(Types.OFFER)
|
int overhead = serial.getSerialisedStructIdLength(OFFER)
|
||||||
+ serial.getSerialisedListStartLength()
|
+ serial.getSerialisedListStartLength()
|
||||||
+ serial.getSerialisedListEndLength();
|
+ serial.getSerialisedListEndLength();
|
||||||
int idLength = serial.getSerialisedUniqueIdLength();
|
int idLength = serial.getSerialisedUniqueIdLength();
|
||||||
@@ -57,7 +63,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeAck(Ack a) throws IOException {
|
public void writeAck(Ack a) throws IOException {
|
||||||
w.writeStructId(Types.ACK);
|
w.writeStructId(ACK);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
for(MessageId m : a.getMessageIds()) w.writeBytes(m.getBytes());
|
for(MessageId m : a.getMessageIds()) w.writeBytes(m.getBytes());
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
@@ -70,7 +76,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeOffer(Offer o) throws IOException {
|
public void writeOffer(Offer o) throws IOException {
|
||||||
w.writeStructId(Types.OFFER);
|
w.writeStructId(OFFER);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
for(MessageId m : o.getMessageIds()) w.writeBytes(m.getBytes());
|
for(MessageId m : o.getMessageIds()) w.writeBytes(m.getBytes());
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
@@ -91,7 +97,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
bitmap[offset] |= bit;
|
bitmap[offset] |= bit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.writeStructId(Types.REQUEST);
|
w.writeStructId(REQUEST);
|
||||||
w.writeUint7((byte) (bytes * 8 - length));
|
w.writeUint7((byte) (bytes * 8 - length));
|
||||||
w.writeBytes(bitmap);
|
w.writeBytes(bitmap);
|
||||||
if(flush) out.flush();
|
if(flush) out.flush();
|
||||||
@@ -99,7 +105,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
|
|
||||||
public void writeSubscriptionUpdate(SubscriptionUpdate s)
|
public void writeSubscriptionUpdate(SubscriptionUpdate s)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
w.writeStructId(Types.SUBSCRIPTION_UPDATE);
|
w.writeStructId(SUBSCRIPTION_UPDATE);
|
||||||
// Holes
|
// Holes
|
||||||
w.writeMapStart();
|
w.writeMapStart();
|
||||||
for(Entry<GroupId, GroupId> e : s.getHoles().entrySet()) {
|
for(Entry<GroupId, GroupId> e : s.getHoles().entrySet()) {
|
||||||
@@ -122,7 +128,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeGroup(Writer w, Group g) throws IOException {
|
private void writeGroup(Writer w, Group g) throws IOException {
|
||||||
w.writeStructId(Types.GROUP);
|
w.writeStructId(GROUP);
|
||||||
w.writeString(g.getName());
|
w.writeString(g.getName());
|
||||||
byte[] publicKey = g.getPublicKey();
|
byte[] publicKey = g.getPublicKey();
|
||||||
if(publicKey == null) w.writeNull();
|
if(publicKey == null) w.writeNull();
|
||||||
@@ -130,10 +136,10 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeTransportUpdate(TransportUpdate t) throws IOException {
|
public void writeTransportUpdate(TransportUpdate t) throws IOException {
|
||||||
w.writeStructId(Types.TRANSPORT_UPDATE);
|
w.writeStructId(TRANSPORT_UPDATE);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
for(Transport p : t.getTransports()) {
|
for(Transport p : t.getTransports()) {
|
||||||
w.writeStructId(Types.TRANSPORT);
|
w.writeStructId(TRANSPORT);
|
||||||
w.writeBytes(p.getId().getBytes());
|
w.writeBytes(p.getId().getBytes());
|
||||||
w.writeMap(p.getProperties());
|
w.writeMap(p.getProperties());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.REQUEST;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
@@ -8,11 +9,10 @@ import java.util.BitSet;
|
|||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.CountingConsumer;
|
import net.sf.briar.api.serial.CountingConsumer;
|
||||||
import net.sf.briar.api.serial.StructReader;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
|
import net.sf.briar.api.serial.StructReader;
|
||||||
|
|
||||||
class RequestReader implements StructReader<Request> {
|
class RequestReader implements StructReader<Request> {
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class RequestReader implements StructReader<Request> {
|
|||||||
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readStructId(Types.REQUEST);
|
r.readStructId(REQUEST);
|
||||||
int padding = r.readUint7();
|
int padding = r.readUint7();
|
||||||
if(padding > 7) throw new FormatException();
|
if(padding > 7) throw new FormatException();
|
||||||
byte[] bitmap = r.readBytes(MAX_PACKET_LENGTH);
|
byte[] bitmap = r.readBytes(MAX_PACKET_LENGTH);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.GROUP;
|
||||||
|
import static net.sf.briar.api.protocol.Types.SUBSCRIPTION_UPDATE;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -11,7 +13,6 @@ import net.sf.briar.api.protocol.Group;
|
|||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.CountingConsumer;
|
import net.sf.briar.api.serial.CountingConsumer;
|
||||||
@@ -34,7 +35,7 @@ class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> {
|
|||||||
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readStructId(Types.SUBSCRIPTION_UPDATE);
|
r.readStructId(SUBSCRIPTION_UPDATE);
|
||||||
// Holes
|
// Holes
|
||||||
Map<GroupId, GroupId> holes = new HashMap<GroupId, GroupId>();
|
Map<GroupId, GroupId> holes = new HashMap<GroupId, GroupId>();
|
||||||
r.setMaxBytesLength(UniqueId.LENGTH);
|
r.setMaxBytesLength(UniqueId.LENGTH);
|
||||||
@@ -49,9 +50,9 @@ class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> {
|
|||||||
r.readMapEnd();
|
r.readMapEnd();
|
||||||
r.resetMaxBytesLength();
|
r.resetMaxBytesLength();
|
||||||
// Subscriptions
|
// Subscriptions
|
||||||
r.addStructReader(Types.GROUP, groupReader);
|
r.addStructReader(GROUP, groupReader);
|
||||||
Map<Group, Long> subs = r.readMap(Group.class, Long.class);
|
Map<Group, Long> subs = r.readMap(Group.class, Long.class);
|
||||||
r.removeStructReader(Types.GROUP);
|
r.removeStructReader(GROUP);
|
||||||
// Expiry time
|
// Expiry time
|
||||||
long expiry = r.readInt64();
|
long expiry = r.readInt64();
|
||||||
if(expiry < 0L) throw new FormatException();
|
if(expiry < 0L) throw new FormatException();
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
|||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PROPERTIES_PER_TRANSPORT;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PROPERTIES_PER_TRANSPORT;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PROPERTY_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PROPERTY_LENGTH;
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_TRANSPORTS;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_TRANSPORTS;
|
||||||
|
import static net.sf.briar.api.protocol.Types.TRANSPORT;
|
||||||
|
import static net.sf.briar.api.protocol.Types.TRANSPORT_UPDATE;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -16,7 +18,6 @@ import net.sf.briar.api.protocol.PacketFactory;
|
|||||||
import net.sf.briar.api.protocol.Transport;
|
import net.sf.briar.api.protocol.Transport;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.CountingConsumer;
|
import net.sf.briar.api.serial.CountingConsumer;
|
||||||
@@ -38,10 +39,10 @@ class TransportUpdateReader implements StructReader<TransportUpdate> {
|
|||||||
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readStructId(Types.TRANSPORT_UPDATE);
|
r.readStructId(TRANSPORT_UPDATE);
|
||||||
r.addStructReader(Types.TRANSPORT, transportReader);
|
r.addStructReader(TRANSPORT, transportReader);
|
||||||
Collection<Transport> transports = r.readList(Transport.class);
|
Collection<Transport> transports = r.readList(Transport.class);
|
||||||
r.removeStructReader(Types.TRANSPORT);
|
r.removeStructReader(TRANSPORT);
|
||||||
if(transports.size() > MAX_TRANSPORTS) throw new FormatException();
|
if(transports.size() > MAX_TRANSPORTS) throw new FormatException();
|
||||||
long timestamp = r.readInt64();
|
long timestamp = r.readInt64();
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
@@ -57,7 +58,7 @@ class TransportUpdateReader implements StructReader<TransportUpdate> {
|
|||||||
private static class TransportReader implements StructReader<Transport> {
|
private static class TransportReader implements StructReader<Transport> {
|
||||||
|
|
||||||
public Transport readStruct(Reader r) throws IOException {
|
public Transport readStruct(Reader r) throws IOException {
|
||||||
r.readStructId(Types.TRANSPORT);
|
r.readStructId(TRANSPORT);
|
||||||
// Read the ID
|
// Read the ID
|
||||||
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();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.sf.briar.db;
|
package net.sf.briar.db;
|
||||||
|
|
||||||
|
import static java.sql.Types.BINARY;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
@@ -7,7 +9,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Types;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -119,7 +120,7 @@ public class BasicH2Test extends BriarTestCase {
|
|||||||
String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
|
String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
|
||||||
try {
|
try {
|
||||||
PreparedStatement ps = connection.prepareStatement(sql);
|
PreparedStatement ps = connection.prepareStatement(sql);
|
||||||
if(id == null) ps.setNull(1, Types.BINARY);
|
if(id == null) ps.setNull(1, BINARY);
|
||||||
else ps.setBytes(1, id);
|
else ps.setBytes(1, id);
|
||||||
ps.setString(2, name);
|
ps.setString(2, name);
|
||||||
int rowsAffected = ps.executeUpdate();
|
int rowsAffected = ps.executeUpdate();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.ACK;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -11,7 +12,6 @@ import net.sf.briar.TestUtils;
|
|||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
import net.sf.briar.api.serial.SerialComponent;
|
import net.sf.briar.api.serial.SerialComponent;
|
||||||
@@ -52,10 +52,10 @@ public class AckReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createAck(true);
|
byte[] b = createAck(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.ACK, ackReader);
|
reader.addStructReader(ACK, ackReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readStruct(Types.ACK, Ack.class);
|
reader.readStruct(ACK, Ack.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -75,9 +75,9 @@ public class AckReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createAck(false);
|
byte[] b = createAck(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.ACK, ackReader);
|
reader.addStructReader(ACK, ackReader);
|
||||||
|
|
||||||
assertEquals(ack, reader.readStruct(Types.ACK, Ack.class));
|
assertEquals(ack, reader.readStruct(ACK, Ack.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,10 +89,10 @@ public class AckReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createEmptyAck();
|
byte[] b = createEmptyAck();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.ACK, ackReader);
|
reader.addStructReader(ACK, ackReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readStruct(Types.ACK, Ack.class);
|
reader.readStruct(ACK, Ack.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -101,7 +101,7 @@ public class AckReaderTest extends BriarTestCase {
|
|||||||
private byte[] createAck(boolean tooBig) throws Exception {
|
private byte[] createAck(boolean tooBig) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.ACK);
|
w.writeStructId(ACK);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
while(out.size() + serial.getSerialisedUniqueIdLength()
|
while(out.size() + serial.getSerialisedUniqueIdLength()
|
||||||
< MAX_PACKET_LENGTH) {
|
< MAX_PACKET_LENGTH) {
|
||||||
@@ -116,7 +116,7 @@ public class AckReaderTest extends BriarTestCase {
|
|||||||
private byte[] createEmptyAck() throws Exception {
|
private byte[] createEmptyAck() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.ACK);
|
w.writeStructId(ACK);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.OFFER;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -11,7 +12,6 @@ import net.sf.briar.TestUtils;
|
|||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
import net.sf.briar.api.serial.SerialComponent;
|
import net.sf.briar.api.serial.SerialComponent;
|
||||||
@@ -52,10 +52,10 @@ public class OfferReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createOffer(true);
|
byte[] b = createOffer(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.OFFER, offerReader);
|
reader.addStructReader(OFFER, offerReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readStruct(Types.OFFER, Offer.class);
|
reader.readStruct(OFFER, Offer.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -75,9 +75,9 @@ public class OfferReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createOffer(false);
|
byte[] b = createOffer(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.OFFER, offerReader);
|
reader.addStructReader(OFFER, offerReader);
|
||||||
|
|
||||||
assertEquals(offer, reader.readStruct(Types.OFFER, Offer.class));
|
assertEquals(offer, reader.readStruct(OFFER, Offer.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,10 +89,10 @@ public class OfferReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createEmptyOffer();
|
byte[] b = createEmptyOffer();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.OFFER, offerReader);
|
reader.addStructReader(OFFER, offerReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readStruct(Types.OFFER, Offer.class);
|
reader.readStruct(OFFER, Offer.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -101,7 +101,7 @@ public class OfferReaderTest extends BriarTestCase {
|
|||||||
private byte[] createOffer(boolean tooBig) throws Exception {
|
private byte[] createOffer(boolean tooBig) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.OFFER);
|
w.writeStructId(OFFER);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
while(out.size() + serial.getSerialisedUniqueIdLength()
|
while(out.size() + serial.getSerialisedUniqueIdLength()
|
||||||
< MAX_PACKET_LENGTH) {
|
< MAX_PACKET_LENGTH) {
|
||||||
@@ -116,7 +116,7 @@ public class OfferReaderTest extends BriarTestCase {
|
|||||||
private byte[] createEmptyOffer() throws Exception {
|
private byte[] createEmptyOffer() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.OFFER);
|
w.writeStructId(OFFER);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
import static net.sf.briar.api.protocol.Types.REQUEST;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -10,7 +11,6 @@ import net.sf.briar.BriarTestCase;
|
|||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.Types;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
@@ -53,10 +53,10 @@ public class RequestReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createRequest(true);
|
byte[] b = createRequest(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.REQUEST, requestReader);
|
reader.addStructReader(REQUEST, requestReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readStruct(Types.REQUEST, Request.class);
|
reader.readStruct(REQUEST, Request.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -76,10 +76,9 @@ public class RequestReaderTest extends BriarTestCase {
|
|||||||
byte[] b = createRequest(false);
|
byte[] b = createRequest(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addStructReader(Types.REQUEST, requestReader);
|
reader.addStructReader(REQUEST, requestReader);
|
||||||
|
|
||||||
assertEquals(request, reader.readStruct(Types.REQUEST,
|
assertEquals(request, reader.readStruct(REQUEST, Request.class));
|
||||||
Request.class));
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,8 +105,8 @@ public class RequestReaderTest extends BriarTestCase {
|
|||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
RequestReader requestReader = new RequestReader(packetFactory);
|
RequestReader requestReader = new RequestReader(packetFactory);
|
||||||
reader.addStructReader(Types.REQUEST, requestReader);
|
reader.addStructReader(REQUEST, requestReader);
|
||||||
Request r = reader.readStruct(Types.REQUEST, Request.class);
|
Request r = reader.readStruct(REQUEST, Request.class);
|
||||||
BitSet decoded = r.getBitmap();
|
BitSet decoded = r.getBitmap();
|
||||||
// Check that the decoded BitSet matches the original - we can't
|
// Check that the decoded BitSet matches the original - we can't
|
||||||
// use equals() because of padding, but the first i bits should
|
// use equals() because of padding, but the first i bits should
|
||||||
@@ -123,7 +122,7 @@ public class RequestReaderTest extends BriarTestCase {
|
|||||||
private byte[] createRequest(boolean tooBig) throws Exception {
|
private byte[] createRequest(boolean tooBig) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.REQUEST);
|
w.writeStructId(REQUEST);
|
||||||
// Allow one byte for the REQUEST tag, one byte for the padding length
|
// 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
|
// as a uint7, one byte for the BYTES tag, and five bytes for the
|
||||||
// length of the byte array as an int32
|
// length of the byte array as an int32
|
||||||
@@ -139,7 +138,7 @@ public class RequestReaderTest extends BriarTestCase {
|
|||||||
private byte[] createRequest(byte[] bitmap) throws Exception {
|
private byte[] createRequest(byte[] bitmap) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(Types.REQUEST);
|
w.writeStructId(REQUEST);
|
||||||
w.writeUint7((byte) 0);
|
w.writeUint7((byte) 0);
|
||||||
w.writeBytes(bitmap);
|
w.writeBytes(bitmap);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
|
|||||||
Reference in New Issue
Block a user