mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Created expiry update and expiry ack packets for BMP.
This commit is contained in:
20
briar-core/src/net/sf/briar/protocol/ExpiryAckReader.java
Normal file
20
briar-core/src/net/sf/briar/protocol/ExpiryAckReader.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package net.sf.briar.protocol;
|
||||
|
||||
import static net.sf.briar.api.protocol.Types.EXPIRY_ACK;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.ExpiryAck;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
import net.sf.briar.api.serial.StructReader;
|
||||
|
||||
class ExpiryAckReader implements StructReader<ExpiryAck> {
|
||||
|
||||
public ExpiryAck readStruct(Reader r) throws IOException {
|
||||
r.readStructId(EXPIRY_ACK);
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
return new ExpiryAck(version);
|
||||
}
|
||||
}
|
||||
22
briar-core/src/net/sf/briar/protocol/ExpiryUpdateReader.java
Normal file
22
briar-core/src/net/sf/briar/protocol/ExpiryUpdateReader.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package net.sf.briar.protocol;
|
||||
|
||||
import static net.sf.briar.api.protocol.Types.EXPIRY_UPDATE;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.ExpiryUpdate;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
import net.sf.briar.api.serial.StructReader;
|
||||
|
||||
class ExpiryUpdateReader implements StructReader<ExpiryUpdate> {
|
||||
|
||||
public ExpiryUpdate readStruct(Reader r) throws IOException {
|
||||
r.readStructId(EXPIRY_UPDATE);
|
||||
long expiry = r.readInt64();
|
||||
if(expiry < 0L) throw new FormatException();
|
||||
long version = r.readInt64();
|
||||
if(version < 0L) throw new FormatException();
|
||||
return new ExpiryUpdate(expiry, version);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@ 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_SUBJECT_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;
|
||||
@@ -51,22 +49,12 @@ class MessageReader implements StructReader<UnverifiedMessage> {
|
||||
}
|
||||
// Read the group, if there is one
|
||||
Group group = null;
|
||||
if(r.hasNull()) {
|
||||
r.readNull();
|
||||
} else {
|
||||
r.addStructReader(GROUP, groupReader);
|
||||
group = r.readStruct(GROUP, Group.class);
|
||||
r.removeStructReader(GROUP);
|
||||
}
|
||||
if(r.hasNull()) r.readNull();
|
||||
else group = groupReader.readStruct(r);
|
||||
// Read the author, if there is one
|
||||
Author author = null;
|
||||
if(r.hasNull()) {
|
||||
r.readNull();
|
||||
} else {
|
||||
r.addStructReader(AUTHOR, authorReader);
|
||||
author = r.readStruct(AUTHOR, Author.class);
|
||||
r.removeStructReader(AUTHOR);
|
||||
}
|
||||
if(r.hasNull()) r.readNull();
|
||||
else author = authorReader.readStruct(r);
|
||||
// Read the subject
|
||||
String subject = r.readString(MAX_SUBJECT_LENGTH);
|
||||
// Read the timestamp
|
||||
|
||||
@@ -6,6 +6,8 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.Author;
|
||||
import net.sf.briar.api.protocol.AuthorFactory;
|
||||
import net.sf.briar.api.protocol.ExpiryAck;
|
||||
import net.sf.briar.api.protocol.ExpiryUpdate;
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.GroupFactory;
|
||||
import net.sf.briar.api.protocol.MessageFactory;
|
||||
@@ -58,11 +60,6 @@ public class ProtocolModule extends AbstractModule {
|
||||
MIN_VERIFIER_THREADS, MAX_VERIFIER_THREADS));
|
||||
}
|
||||
|
||||
@Provides
|
||||
StructReader<Ack> getAckReader() {
|
||||
return new AckReader();
|
||||
}
|
||||
|
||||
@Provides
|
||||
StructReader<Author> getAuthorReader(CryptoComponent crypto) {
|
||||
return new AuthorReader(crypto);
|
||||
@@ -73,6 +70,21 @@ public class ProtocolModule extends AbstractModule {
|
||||
return new GroupReader(crypto);
|
||||
}
|
||||
|
||||
@Provides
|
||||
StructReader<Ack> getAckReader() {
|
||||
return new AckReader();
|
||||
}
|
||||
|
||||
@Provides
|
||||
StructReader<ExpiryAck> getExpiryAckReader() {
|
||||
return new ExpiryAckReader();
|
||||
}
|
||||
|
||||
@Provides
|
||||
StructReader<ExpiryUpdate> getExpiryUpdateReader() {
|
||||
return new ExpiryUpdateReader();
|
||||
}
|
||||
|
||||
@Provides
|
||||
StructReader<UnverifiedMessage> getMessageReader(
|
||||
StructReader<Group> groupReader,
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.sf.briar.protocol;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.ExpiryAck;
|
||||
import net.sf.briar.api.protocol.ExpiryUpdate;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.ProtocolReader;
|
||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||
@@ -23,6 +25,8 @@ class ProtocolReaderFactoryImpl implements ProtocolReaderFactory {
|
||||
|
||||
private final ReaderFactory readerFactory;
|
||||
private final Provider<StructReader<Ack>> ackProvider;
|
||||
private final Provider<StructReader<ExpiryAck>> expiryAckProvider;
|
||||
private final Provider<StructReader<ExpiryUpdate>> expiryUpdateProvider;
|
||||
private final Provider<StructReader<UnverifiedMessage>> messageProvider;
|
||||
private final Provider<StructReader<Offer>> offerProvider;
|
||||
private final Provider<StructReader<Request>> requestProvider;
|
||||
@@ -35,6 +39,8 @@ class ProtocolReaderFactoryImpl implements ProtocolReaderFactory {
|
||||
ProtocolReaderFactoryImpl(ReaderFactory readerFactory,
|
||||
Provider<StructReader<Ack>> ackProvider,
|
||||
Provider<StructReader<UnverifiedMessage>> messageProvider,
|
||||
Provider<StructReader<ExpiryAck>> expiryAckProvider,
|
||||
Provider<StructReader<ExpiryUpdate>> expiryUpdateProvider,
|
||||
Provider<StructReader<Offer>> offerProvider,
|
||||
Provider<StructReader<Request>> requestProvider,
|
||||
Provider<StructReader<SubscriptionAck>> subscriptionAckProvider,
|
||||
@@ -43,6 +49,8 @@ class ProtocolReaderFactoryImpl implements ProtocolReaderFactory {
|
||||
Provider<StructReader<TransportUpdate>> transportUpdateProvider) {
|
||||
this.readerFactory = readerFactory;
|
||||
this.ackProvider = ackProvider;
|
||||
this.expiryAckProvider = expiryAckProvider;
|
||||
this.expiryUpdateProvider = expiryUpdateProvider;
|
||||
this.messageProvider = messageProvider;
|
||||
this.offerProvider = offerProvider;
|
||||
this.requestProvider = requestProvider;
|
||||
@@ -54,6 +62,7 @@ class ProtocolReaderFactoryImpl implements ProtocolReaderFactory {
|
||||
|
||||
public ProtocolReader createProtocolReader(InputStream in) {
|
||||
return new ProtocolReaderImpl(in, readerFactory, ackProvider.get(),
|
||||
expiryAckProvider.get(), expiryUpdateProvider.get(),
|
||||
messageProvider.get(), offerProvider.get(),
|
||||
requestProvider.get(), subscriptionAckProvider.get(),
|
||||
subscriptionUpdateProvider.get(), transportAckProvider.get(),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.sf.briar.protocol;
|
||||
|
||||
import static net.sf.briar.api.protocol.Types.ACK;
|
||||
import static net.sf.briar.api.protocol.Types.EXPIRY_ACK;
|
||||
import static net.sf.briar.api.protocol.Types.EXPIRY_UPDATE;
|
||||
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;
|
||||
@@ -13,6 +15,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.ExpiryAck;
|
||||
import net.sf.briar.api.protocol.ExpiryUpdate;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.ProtocolReader;
|
||||
import net.sf.briar.api.protocol.Request;
|
||||
@@ -31,6 +35,8 @@ class ProtocolReaderImpl implements ProtocolReader {
|
||||
|
||||
ProtocolReaderImpl(InputStream in, ReaderFactory readerFactory,
|
||||
StructReader<Ack> ackReader,
|
||||
StructReader<ExpiryAck> expiryAckReader,
|
||||
StructReader<ExpiryUpdate> expiryUpdateReader,
|
||||
StructReader<UnverifiedMessage> messageReader,
|
||||
StructReader<Offer> offerReader,
|
||||
StructReader<Request> requestReader,
|
||||
@@ -43,6 +49,8 @@ class ProtocolReaderImpl implements ProtocolReader {
|
||||
reader.addStructReader(MESSAGE, messageReader);
|
||||
reader.addStructReader(OFFER, offerReader);
|
||||
reader.addStructReader(REQUEST, requestReader);
|
||||
reader.addStructReader(EXPIRY_ACK, expiryAckReader);
|
||||
reader.addStructReader(EXPIRY_UPDATE, expiryUpdateReader);
|
||||
reader.addStructReader(SUBSCRIPTION_ACK, subscriptionAckReader);
|
||||
reader.addStructReader(SUBSCRIPTION_UPDATE, subscriptionUpdateReader);
|
||||
reader.addStructReader(TRANSPORT_ACK, transportAckReader);
|
||||
@@ -61,6 +69,22 @@ class ProtocolReaderImpl implements ProtocolReader {
|
||||
return reader.readStruct(ACK, Ack.class);
|
||||
}
|
||||
|
||||
public boolean hasExpiryAck() throws IOException {
|
||||
return reader.hasStruct(EXPIRY_ACK);
|
||||
}
|
||||
|
||||
public ExpiryAck readExpiryAck() throws IOException {
|
||||
return reader.readStruct(EXPIRY_ACK, ExpiryAck.class);
|
||||
}
|
||||
|
||||
public boolean hasExpiryUpdate() throws IOException {
|
||||
return reader.hasStruct(EXPIRY_UPDATE);
|
||||
}
|
||||
|
||||
public ExpiryUpdate readExpiryUpdate() throws IOException {
|
||||
return reader.readStruct(EXPIRY_UPDATE, ExpiryUpdate.class);
|
||||
}
|
||||
|
||||
public boolean hasMessage() throws IOException {
|
||||
return reader.hasStruct(MESSAGE);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.sf.briar.protocol;
|
||||
|
||||
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.EXPIRY_ACK;
|
||||
import static net.sf.briar.api.protocol.Types.EXPIRY_UPDATE;
|
||||
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;
|
||||
@@ -15,6 +17,8 @@ import java.io.OutputStream;
|
||||
import java.util.BitSet;
|
||||
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.ExpiryAck;
|
||||
import net.sf.briar.api.protocol.ExpiryUpdate;
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
@@ -70,6 +74,19 @@ class ProtocolWriterImpl implements ProtocolWriter {
|
||||
if(flush) out.flush();
|
||||
}
|
||||
|
||||
public void writeExpiryAck(ExpiryAck a) throws IOException {
|
||||
w.writeStructId(EXPIRY_ACK);
|
||||
w.writeInt64(a.getVersionNumber());
|
||||
if(flush) out.flush();
|
||||
}
|
||||
|
||||
public void writeExpiryUpdate(ExpiryUpdate e) throws IOException {
|
||||
w.writeStructId(EXPIRY_UPDATE);
|
||||
w.writeInt64(e.getExpiryTime());
|
||||
w.writeInt64(e.getVersionNumber());
|
||||
if(flush) out.flush();
|
||||
}
|
||||
|
||||
public void writeMessage(byte[] raw) throws IOException {
|
||||
out.write(raw);
|
||||
if(flush) out.flush();
|
||||
|
||||
Reference in New Issue
Block a user