mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Renamed user-defined tags "user-defined type identifiers".
This commit is contained in:
@@ -7,7 +7,7 @@ import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Consumer;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -28,11 +28,11 @@ class AckReader implements ObjectReader<Ack> {
|
||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
// Read and digest the data
|
||||
r.addConsumer(counting);
|
||||
r.readUserDefinedTag(Tags.ACK);
|
||||
r.addObjectReader(Tags.BATCH_ID, batchIdReader);
|
||||
r.readUserDefinedId(Types.ACK);
|
||||
r.addObjectReader(Types.BATCH_ID, batchIdReader);
|
||||
Collection<BatchId> batches = r.readList(BatchId.class);
|
||||
if(batches.size() > Ack.MAX_IDS_PER_ACK) throw new FormatException();
|
||||
r.removeObjectReader(Tags.BATCH_ID);
|
||||
r.removeObjectReader(Types.BATCH_ID);
|
||||
r.removeConsumer(counting);
|
||||
// Build and return the ack
|
||||
return ackFactory.createAck(batches);
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.protocol.Author;
|
||||
import net.sf.briar.api.protocol.AuthorId;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
class AuthorImpl implements Author {
|
||||
@@ -32,7 +32,7 @@ class AuthorImpl implements Author {
|
||||
}
|
||||
|
||||
public void writeTo(Writer w) throws IOException {
|
||||
w.writeUserDefinedTag(Tags.AUTHOR);
|
||||
w.writeUserDefinedTag(Types.AUTHOR);
|
||||
w.writeString(name);
|
||||
w.writeBytes(publicKey);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
||||
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.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
|
||||
@@ -27,7 +27,7 @@ class AuthorReader implements ObjectReader<Author> {
|
||||
messageDigest.reset();
|
||||
// Read and digest the data
|
||||
r.addConsumer(digesting);
|
||||
r.readUserDefinedTag(Tags.AUTHOR);
|
||||
r.readUserDefinedId(Types.AUTHOR);
|
||||
String name = r.readString(Author.MAX_NAME_LENGTH);
|
||||
byte[] publicKey = r.readBytes(Author.MAX_PUBLIC_KEY_LENGTH);
|
||||
r.removeConsumer(digesting);
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.UniqueId;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -12,7 +12,7 @@ import net.sf.briar.api.serial.Reader;
|
||||
class BatchIdReader implements ObjectReader<BatchId> {
|
||||
|
||||
public BatchId readObject(Reader r) throws IOException {
|
||||
r.readUserDefinedTag(Tags.BATCH_ID);
|
||||
r.readUserDefinedId(Types.BATCH_ID);
|
||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
||||
return new BatchId(b);
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.sf.briar.api.protocol.Batch;
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Consumer;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -36,10 +36,10 @@ class BatchReader implements ObjectReader<Batch> {
|
||||
// Read and digest the data
|
||||
r.addConsumer(counting);
|
||||
r.addConsumer(digesting);
|
||||
r.readUserDefinedTag(Tags.BATCH);
|
||||
r.addObjectReader(Tags.MESSAGE, messageReader);
|
||||
r.readUserDefinedId(Types.BATCH);
|
||||
r.addObjectReader(Types.MESSAGE, messageReader);
|
||||
List<Message> messages = r.readList(Message.class);
|
||||
r.removeObjectReader(Tags.MESSAGE);
|
||||
r.removeObjectReader(Types.MESSAGE);
|
||||
r.removeConsumer(digesting);
|
||||
r.removeConsumer(counting);
|
||||
// Build and return the batch
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.GroupId;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.UniqueId;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -12,7 +12,7 @@ import net.sf.briar.api.serial.Reader;
|
||||
class GroupIdReader implements ObjectReader<GroupId> {
|
||||
|
||||
public GroupId readObject(Reader r) throws IOException {
|
||||
r.readUserDefinedTag(Tags.GROUP_ID);
|
||||
r.readUserDefinedId(Types.GROUP_ID);
|
||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
||||
return new GroupId(b);
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.GroupId;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
class GroupImpl implements Group {
|
||||
@@ -32,7 +32,7 @@ class GroupImpl implements Group {
|
||||
}
|
||||
|
||||
public void writeTo(Writer w) throws IOException {
|
||||
w.writeUserDefinedTag(Tags.GROUP);
|
||||
w.writeUserDefinedTag(Types.GROUP);
|
||||
w.writeString(name);
|
||||
if(publicKey == null) w.writeNull();
|
||||
else w.writeBytes(publicKey);
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
||||
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.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
|
||||
@@ -27,7 +27,7 @@ class GroupReader implements ObjectReader<Group> {
|
||||
messageDigest.reset();
|
||||
// Read and digest the data
|
||||
r.addConsumer(digesting);
|
||||
r.readUserDefinedTag(Tags.GROUP);
|
||||
r.readUserDefinedId(Types.GROUP);
|
||||
String name = r.readString(Group.MAX_NAME_LENGTH);
|
||||
byte[] publicKey = null;
|
||||
if(r.hasNull()) r.readNull();
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageEncoder;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
|
||||
@@ -65,7 +65,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Writer w = writerFactory.createWriter(out);
|
||||
// Write the message
|
||||
w.writeUserDefinedTag(Tags.MESSAGE);
|
||||
w.writeUserDefinedTag(Types.MESSAGE);
|
||||
parent.writeTo(w);
|
||||
group.writeTo(w);
|
||||
if(author == null) w.writeNull();
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.UniqueId;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -12,7 +12,7 @@ import net.sf.briar.api.serial.Reader;
|
||||
class MessageIdReader implements ObjectReader<MessageId> {
|
||||
|
||||
public MessageId readObject(Reader r) throws IOException {
|
||||
r.readUserDefinedTag(Tags.MESSAGE_ID);
|
||||
r.readUserDefinedId(Types.MESSAGE_ID);
|
||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
||||
return new MessageId(b);
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
|
||||
@@ -47,21 +47,21 @@ class MessageReader implements ObjectReader<Message> {
|
||||
r.addConsumer(copying);
|
||||
r.addConsumer(counting);
|
||||
// Read the initial tag
|
||||
r.readUserDefinedTag(Tags.MESSAGE);
|
||||
r.readUserDefinedId(Types.MESSAGE);
|
||||
// Read the parent's message ID
|
||||
r.addObjectReader(Tags.MESSAGE_ID, messageIdReader);
|
||||
MessageId parent = r.readUserDefined(Tags.MESSAGE_ID, MessageId.class);
|
||||
r.removeObjectReader(Tags.MESSAGE_ID);
|
||||
r.addObjectReader(Types.MESSAGE_ID, messageIdReader);
|
||||
MessageId parent = r.readUserDefined(Types.MESSAGE_ID, MessageId.class);
|
||||
r.removeObjectReader(Types.MESSAGE_ID);
|
||||
// Read the group
|
||||
r.addObjectReader(Tags.GROUP, groupReader);
|
||||
Group group = r.readUserDefined(Tags.GROUP, Group.class);
|
||||
r.removeObjectReader(Tags.GROUP);
|
||||
r.addObjectReader(Types.GROUP, groupReader);
|
||||
Group group = r.readUserDefined(Types.GROUP, Group.class);
|
||||
r.removeObjectReader(Types.GROUP);
|
||||
// Read the author, if there is one
|
||||
r.addObjectReader(Tags.AUTHOR, authorReader);
|
||||
r.addObjectReader(Types.AUTHOR, authorReader);
|
||||
Author author = null;
|
||||
if(r.hasNull()) r.readNull();
|
||||
else author = r.readUserDefined(Tags.AUTHOR, Author.class);
|
||||
r.removeObjectReader(Tags.AUTHOR);
|
||||
else author = r.readUserDefined(Types.AUTHOR, Author.class);
|
||||
r.removeObjectReader(Types.AUTHOR);
|
||||
// Read the timestamp
|
||||
long timestamp = r.readInt64();
|
||||
if(timestamp < 0L) throw new FormatException();
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Consumer;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -29,12 +29,12 @@ class OfferReader implements ObjectReader<Offer> {
|
||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
// Read the data
|
||||
r.addConsumer(counting);
|
||||
r.readUserDefinedTag(Tags.OFFER);
|
||||
r.addObjectReader(Tags.MESSAGE_ID, messageIdReader);
|
||||
r.readUserDefinedId(Types.OFFER);
|
||||
r.addObjectReader(Types.MESSAGE_ID, messageIdReader);
|
||||
Collection<MessageId> messages = r.readList(MessageId.class);
|
||||
if(messages.size() > Offer.MAX_IDS_PER_OFFER)
|
||||
throw new FormatException();
|
||||
r.removeObjectReader(Tags.MESSAGE_ID);
|
||||
r.removeObjectReader(Types.MESSAGE_ID);
|
||||
r.removeConsumer(counting);
|
||||
// Build and return the offer
|
||||
return offerFactory.createOffer(messages);
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.ProtocolReader;
|
||||
import net.sf.briar.api.protocol.Request;
|
||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.TransportUpdate;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -26,60 +26,60 @@ class ProtocolReaderImpl implements ProtocolReader {
|
||||
ObjectReader<SubscriptionUpdate> subscriptionReader,
|
||||
ObjectReader<TransportUpdate> transportReader) {
|
||||
reader = readerFactory.createReader(in);
|
||||
reader.addObjectReader(Tags.ACK, ackReader);
|
||||
reader.addObjectReader(Tags.BATCH, batchReader);
|
||||
reader.addObjectReader(Tags.OFFER, offerReader);
|
||||
reader.addObjectReader(Tags.REQUEST, requestReader);
|
||||
reader.addObjectReader(Tags.SUBSCRIPTION_UPDATE, subscriptionReader);
|
||||
reader.addObjectReader(Tags.TRANSPORT_UPDATE, transportReader);
|
||||
reader.addObjectReader(Types.ACK, ackReader);
|
||||
reader.addObjectReader(Types.BATCH, batchReader);
|
||||
reader.addObjectReader(Types.OFFER, offerReader);
|
||||
reader.addObjectReader(Types.REQUEST, requestReader);
|
||||
reader.addObjectReader(Types.SUBSCRIPTION_UPDATE, subscriptionReader);
|
||||
reader.addObjectReader(Types.TRANSPORT_UPDATE, transportReader);
|
||||
}
|
||||
|
||||
public boolean hasAck() throws IOException {
|
||||
return reader.hasUserDefined(Tags.ACK);
|
||||
return reader.hasUserDefined(Types.ACK);
|
||||
}
|
||||
|
||||
public Ack readAck() throws IOException {
|
||||
return reader.readUserDefined(Tags.ACK, Ack.class);
|
||||
return reader.readUserDefined(Types.ACK, Ack.class);
|
||||
}
|
||||
|
||||
public boolean hasBatch() throws IOException {
|
||||
return reader.hasUserDefined(Tags.BATCH);
|
||||
return reader.hasUserDefined(Types.BATCH);
|
||||
}
|
||||
|
||||
public Batch readBatch() throws IOException {
|
||||
return reader.readUserDefined(Tags.BATCH, Batch.class);
|
||||
return reader.readUserDefined(Types.BATCH, Batch.class);
|
||||
}
|
||||
|
||||
public boolean hasOffer() throws IOException {
|
||||
return reader.hasUserDefined(Tags.OFFER);
|
||||
return reader.hasUserDefined(Types.OFFER);
|
||||
}
|
||||
|
||||
public Offer readOffer() throws IOException {
|
||||
return reader.readUserDefined(Tags.OFFER, Offer.class);
|
||||
return reader.readUserDefined(Types.OFFER, Offer.class);
|
||||
}
|
||||
|
||||
public boolean hasRequest() throws IOException {
|
||||
return reader.hasUserDefined(Tags.REQUEST);
|
||||
return reader.hasUserDefined(Types.REQUEST);
|
||||
}
|
||||
|
||||
public Request readRequest() throws IOException {
|
||||
return reader.readUserDefined(Tags.REQUEST, Request.class);
|
||||
return reader.readUserDefined(Types.REQUEST, Request.class);
|
||||
}
|
||||
|
||||
public boolean hasSubscriptionUpdate() throws IOException {
|
||||
return reader.hasUserDefined(Tags.SUBSCRIPTION_UPDATE);
|
||||
return reader.hasUserDefined(Types.SUBSCRIPTION_UPDATE);
|
||||
}
|
||||
|
||||
public SubscriptionUpdate readSubscriptionUpdate() throws IOException {
|
||||
return reader.readUserDefined(Tags.SUBSCRIPTION_UPDATE,
|
||||
return reader.readUserDefined(Types.SUBSCRIPTION_UPDATE,
|
||||
SubscriptionUpdate.class);
|
||||
}
|
||||
|
||||
public boolean hasTransportUpdate() throws IOException {
|
||||
return reader.hasUserDefined(Tags.TRANSPORT_UPDATE);
|
||||
return reader.hasUserDefined(Types.TRANSPORT_UPDATE);
|
||||
}
|
||||
|
||||
public TransportUpdate readTransportUpdate() throws IOException {
|
||||
return reader.readUserDefined(Tags.TRANSPORT_UPDATE, TransportUpdate.class);
|
||||
return reader.readUserDefined(Types.TRANSPORT_UPDATE, TransportUpdate.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.BitSet;
|
||||
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Request;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Consumer;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -24,7 +24,7 @@ class RequestReader implements ObjectReader<Request> {
|
||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
// Read the data
|
||||
r.addConsumer(counting);
|
||||
r.readUserDefinedTag(Tags.REQUEST);
|
||||
r.readUserDefinedId(Types.REQUEST);
|
||||
byte[] bitmap = r.readBytes(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
r.removeConsumer(counting);
|
||||
// Convert the bitmap into a BitSet
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Consumer;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -28,10 +28,10 @@ class SubscriptionReader implements ObjectReader<SubscriptionUpdate> {
|
||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
// Read the data
|
||||
r.addConsumer(counting);
|
||||
r.readUserDefinedTag(Tags.SUBSCRIPTION_UPDATE);
|
||||
r.addObjectReader(Tags.GROUP, groupReader);
|
||||
r.readUserDefinedId(Types.SUBSCRIPTION_UPDATE);
|
||||
r.addObjectReader(Types.GROUP, groupReader);
|
||||
Map<Group, Long> subs = r.readMap(Group.class, Long.class);
|
||||
r.removeObjectReader(Tags.GROUP);
|
||||
r.removeObjectReader(Types.GROUP);
|
||||
long timestamp = r.readInt64();
|
||||
r.removeConsumer(counting);
|
||||
// Build and return the subscription update
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.TreeMap;
|
||||
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.TransportUpdate;
|
||||
import net.sf.briar.api.serial.Consumer;
|
||||
import net.sf.briar.api.serial.ObjectReader;
|
||||
@@ -29,12 +29,12 @@ class TransportReader implements ObjectReader<TransportUpdate> {
|
||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
// Read the data
|
||||
r.addConsumer(counting);
|
||||
r.readUserDefinedTag(Tags.TRANSPORT_UPDATE);
|
||||
r.addObjectReader(Tags.TRANSPORT_PROPERTIES, propertiesReader);
|
||||
r.readUserDefinedId(Types.TRANSPORT_UPDATE);
|
||||
r.addObjectReader(Types.TRANSPORT_PROPERTIES, propertiesReader);
|
||||
r.setMaxStringLength(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
List<TransportProperties> l = r.readList(TransportProperties.class);
|
||||
r.resetMaxStringLength();
|
||||
r.removeObjectReader(Tags.TRANSPORT_PROPERTIES);
|
||||
r.removeObjectReader(Types.TRANSPORT_PROPERTIES);
|
||||
if(l.size() > TransportUpdate.MAX_PLUGINS_PER_UPDATE)
|
||||
throw new FormatException();
|
||||
Map<String, Map<String, String>> transports =
|
||||
@@ -64,7 +64,7 @@ class TransportReader implements ObjectReader<TransportUpdate> {
|
||||
implements ObjectReader<TransportProperties> {
|
||||
|
||||
public TransportProperties readObject(Reader r) throws IOException {
|
||||
r.readUserDefinedTag(Tags.TRANSPORT_PROPERTIES);
|
||||
r.readUserDefinedId(Types.TRANSPORT_PROPERTIES);
|
||||
String name = r.readString(TransportUpdate.MAX_NAME_LENGTH);
|
||||
r.setMaxStringLength(TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||
Map<String, String> properties =
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
||||
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.writers.AckWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
@@ -25,7 +25,7 @@ class AckWriterImpl implements AckWriter {
|
||||
|
||||
public boolean writeBatchId(BatchId b) throws IOException {
|
||||
if(!started) {
|
||||
w.writeUserDefinedTag(Tags.ACK);
|
||||
w.writeUserDefinedTag(Types.ACK);
|
||||
w.writeListStart();
|
||||
started = true;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class AckWriterImpl implements AckWriter {
|
||||
|
||||
public void finish() throws IOException {
|
||||
if(!started) {
|
||||
w.writeUserDefinedTag(Tags.ACK);
|
||||
w.writeUserDefinedTag(Types.ACK);
|
||||
w.writeListStart();
|
||||
started = true;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.security.MessageDigest;
|
||||
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.writers.BatchWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
@@ -36,7 +36,7 @@ class BatchWriterImpl implements BatchWriter {
|
||||
public boolean writeMessage(byte[] message) throws IOException {
|
||||
if(!started) {
|
||||
messageDigest.reset();
|
||||
w.writeUserDefinedTag(Tags.BATCH);
|
||||
w.writeUserDefinedTag(Types.BATCH);
|
||||
w.writeListStart();
|
||||
started = true;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class BatchWriterImpl implements BatchWriter {
|
||||
public BatchId finish() throws IOException {
|
||||
if(!started) {
|
||||
messageDigest.reset();
|
||||
w.writeUserDefinedTag(Tags.BATCH);
|
||||
w.writeUserDefinedTag(Types.BATCH);
|
||||
w.writeListStart();
|
||||
started = true;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
||||
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.writers.OfferWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
@@ -25,7 +25,7 @@ class OfferWriterImpl implements OfferWriter {
|
||||
|
||||
public boolean writeMessageId(MessageId m) throws IOException {
|
||||
if(!started) {
|
||||
w.writeUserDefinedTag(Tags.OFFER);
|
||||
w.writeUserDefinedTag(Types.OFFER);
|
||||
w.writeListStart();
|
||||
started = true;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class OfferWriterImpl implements OfferWriter {
|
||||
|
||||
public void finish() throws IOException {
|
||||
if(!started) {
|
||||
w.writeUserDefinedTag(Tags.OFFER);
|
||||
w.writeUserDefinedTag(Types.OFFER);
|
||||
w.writeListStart();
|
||||
started = true;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.BitSet;
|
||||
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.writers.RequestWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
@@ -21,7 +21,7 @@ class RequestWriterImpl implements RequestWriter {
|
||||
|
||||
public void writeRequest(BitSet b, int length)
|
||||
throws IOException {
|
||||
w.writeUserDefinedTag(Tags.REQUEST);
|
||||
w.writeUserDefinedTag(Types.REQUEST);
|
||||
// If the number of bits isn't a multiple of 8, round up to a byte
|
||||
int bytes = length % 8 == 0 ? length / 8 : length / 8 + 1;
|
||||
byte[] bitmap = new byte[bytes];
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.writers.SubscriptionWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
@@ -22,7 +22,7 @@ class SubscriptionWriterImpl implements SubscriptionWriter {
|
||||
|
||||
public void writeSubscriptions(Map<Group, Long> subs, long timestamp)
|
||||
throws IOException {
|
||||
w.writeUserDefinedTag(Tags.SUBSCRIPTION_UPDATE);
|
||||
w.writeUserDefinedTag(Types.SUBSCRIPTION_UPDATE);
|
||||
w.writeMap(subs);
|
||||
w.writeInt64(timestamp);
|
||||
out.flush();
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.writers.TransportWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
@@ -22,10 +22,10 @@ class TransportWriterImpl implements TransportWriter {
|
||||
|
||||
public void writeTransports(Map<String, Map<String, String>> transports,
|
||||
long timestamp) throws IOException {
|
||||
w.writeUserDefinedTag(Tags.TRANSPORT_UPDATE);
|
||||
w.writeUserDefinedTag(Types.TRANSPORT_UPDATE);
|
||||
w.writeListStart();
|
||||
for(Entry<String, Map<String, String>> e : transports.entrySet()) {
|
||||
w.writeUserDefinedTag(Tags.TRANSPORT_PROPERTIES);
|
||||
w.writeUserDefinedTag(Types.TRANSPORT_PROPERTIES);
|
||||
w.writeString(e.getKey());
|
||||
w.writeMap(e.getValue());
|
||||
}
|
||||
|
||||
@@ -110,21 +110,21 @@ class ReaderImpl implements Reader {
|
||||
else throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public void addObjectReader(int tag, ObjectReader<?> o) {
|
||||
if(tag < 0 || tag > 255) throw new IllegalArgumentException();
|
||||
if(objectReaders.length < tag + 1) {
|
||||
ObjectReader<?>[] newObjectReaders = new ObjectReader<?>[tag + 1];
|
||||
public void addObjectReader(int id, ObjectReader<?> o) {
|
||||
if(id < 0 || id > 255) throw new IllegalArgumentException();
|
||||
if(objectReaders.length < id + 1) {
|
||||
ObjectReader<?>[] newObjectReaders = new ObjectReader<?>[id + 1];
|
||||
System.arraycopy(objectReaders, 0, newObjectReaders, 0,
|
||||
objectReaders.length);
|
||||
objectReaders = newObjectReaders;
|
||||
}
|
||||
objectReaders[tag] = o;
|
||||
objectReaders[id] = o;
|
||||
}
|
||||
|
||||
public void removeObjectReader(int tag) {
|
||||
if(tag < 0 || tag > objectReaders.length)
|
||||
public void removeObjectReader(int id) {
|
||||
if(id < 0 || id > objectReaders.length)
|
||||
throw new IllegalArgumentException();
|
||||
objectReaders[tag] = null;
|
||||
objectReaders[id] = null;
|
||||
}
|
||||
|
||||
public boolean hasBoolean() throws IOException {
|
||||
@@ -551,21 +551,21 @@ class ReaderImpl implements Reader {
|
||||
consumeLookahead();
|
||||
}
|
||||
|
||||
public boolean hasUserDefined(int tag) throws IOException {
|
||||
if(tag < 0 || tag > 255) throw new IllegalArgumentException();
|
||||
public boolean hasUserDefined(int id) throws IOException {
|
||||
if(id < 0 || id > 255) throw new IllegalArgumentException();
|
||||
if(!hasLookahead) readLookahead(true);
|
||||
if(eof) return false;
|
||||
if(next == Tag.USER)
|
||||
return tag == (0xFF & nextNext);
|
||||
return id == (0xFF & nextNext);
|
||||
else if((next & Tag.SHORT_USER_MASK) == Tag.SHORT_USER)
|
||||
return tag == (0xFF & next ^ Tag.SHORT_USER);
|
||||
return id == (0xFF & next ^ Tag.SHORT_USER);
|
||||
else return false;
|
||||
}
|
||||
|
||||
public <T> T readUserDefined(int tag, Class<T> t) throws IOException {
|
||||
if(!hasUserDefined(tag)) throw new FormatException();
|
||||
if(tag >= objectReaders.length) throw new FormatException();
|
||||
ObjectReader<?> o = objectReaders[tag];
|
||||
public <T> T readUserDefined(int id, Class<T> t) throws IOException {
|
||||
if(!hasUserDefined(id)) throw new FormatException();
|
||||
if(id >= objectReaders.length) throw new FormatException();
|
||||
ObjectReader<?> o = objectReaders[id];
|
||||
if(o == null) throw new FormatException();
|
||||
try {
|
||||
return t.cast(o.readObject(this));
|
||||
@@ -574,8 +574,8 @@ class ReaderImpl implements Reader {
|
||||
}
|
||||
}
|
||||
|
||||
public void readUserDefinedTag(int tag) throws IOException {
|
||||
if(!hasUserDefined(tag)) throw new FormatException();
|
||||
public void readUserDefinedId(int id) throws IOException {
|
||||
if(!hasUserDefined(id)) throw new FormatException();
|
||||
consumeLookahead();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user