mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Allow the max packet length to be reduced from the default.
This commit is contained in:
@@ -18,7 +18,7 @@ class AckWriterImpl implements AckWriter {
|
||||
private final Writer w;
|
||||
|
||||
private boolean started = false;
|
||||
private int capacity = ProtocolConstants.MAX_PACKET_LENGTH; // FIXME
|
||||
private int capacity = ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
|
||||
AckWriterImpl(OutputStream out, SerialComponent serial,
|
||||
WriterFactory writerFactory) {
|
||||
@@ -30,6 +30,13 @@ class AckWriterImpl implements AckWriter {
|
||||
w = writerFactory.createWriter(out);
|
||||
}
|
||||
|
||||
public void setMaxPacketLength(int length) {
|
||||
if(started) throw new IllegalStateException();
|
||||
if(length < 0 || length > ProtocolConstants.MAX_PACKET_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
capacity = length;
|
||||
}
|
||||
|
||||
public boolean writeBatchId(BatchId b) throws IOException {
|
||||
int overhead = started ? footerLength : headerLength + footerLength;
|
||||
if(capacity < idLength + overhead) return false;
|
||||
@@ -43,7 +50,7 @@ class AckWriterImpl implements AckWriter {
|
||||
if(!started) start();
|
||||
w.writeListEnd();
|
||||
out.flush();
|
||||
capacity = ProtocolConstants.MAX_PACKET_LENGTH; // FIXME
|
||||
capacity = ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
started = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class BatchWriterImpl implements BatchWriter {
|
||||
private final MessageDigest messageDigest;
|
||||
|
||||
private boolean started = false;
|
||||
private int capacity = ProtocolConstants.MAX_PACKET_LENGTH; // FIXME
|
||||
private int capacity = ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
|
||||
BatchWriterImpl(OutputStream out, SerialComponent serial,
|
||||
WriterFactory writerFactory, MessageDigest messageDigest) {
|
||||
@@ -33,6 +33,13 @@ class BatchWriterImpl implements BatchWriter {
|
||||
this.messageDigest = messageDigest;
|
||||
}
|
||||
|
||||
public void setMaxPacketLength(int length) {
|
||||
if(started) throw new IllegalStateException();
|
||||
if(length < 0 || length > ProtocolConstants.MAX_PACKET_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
capacity = length;
|
||||
}
|
||||
|
||||
public boolean writeMessage(byte[] message) throws IOException {
|
||||
int overhead = started ? footerLength : headerLength + footerLength;
|
||||
if(capacity < message.length + overhead) return false;
|
||||
@@ -47,7 +54,7 @@ class BatchWriterImpl implements BatchWriter {
|
||||
if(!started) start();
|
||||
w.writeListEnd();
|
||||
out.flush();
|
||||
capacity = ProtocolConstants.MAX_PACKET_LENGTH; // FIXME
|
||||
capacity = ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
started = false;
|
||||
return new BatchId(messageDigest.digest());
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class OfferWriterImpl implements OfferWriter {
|
||||
private final Writer w;
|
||||
|
||||
private boolean started = false;
|
||||
private int capacity = ProtocolConstants.MAX_PACKET_LENGTH; // FIXME
|
||||
private int capacity = ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
|
||||
OfferWriterImpl(OutputStream out, SerialComponent serial,
|
||||
WriterFactory writerFactory) {
|
||||
@@ -30,6 +30,13 @@ class OfferWriterImpl implements OfferWriter {
|
||||
w = writerFactory.createWriter(out);
|
||||
}
|
||||
|
||||
public void setMaxPacketLength(int length) {
|
||||
if(started) throw new IllegalStateException();
|
||||
if(length < 0 || length > ProtocolConstants.MAX_PACKET_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
capacity = length;
|
||||
}
|
||||
|
||||
public boolean writeMessageId(MessageId m) throws IOException {
|
||||
int overhead = started ? footerLength : headerLength + footerLength;
|
||||
if(capacity < idLength + overhead) return false;
|
||||
@@ -43,7 +50,7 @@ class OfferWriterImpl implements OfferWriter {
|
||||
if(!started) start();
|
||||
w.writeListEnd();
|
||||
out.flush();
|
||||
capacity = ProtocolConstants.MAX_PACKET_LENGTH; // FIXME
|
||||
capacity = ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
started = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user