Changed maximum packet and message sizes in preparation for new

transport format.
This commit is contained in:
akwizgran
2011-08-18 15:14:48 +02:00
parent 5e0aadd373
commit 4dd303d9e1
40 changed files with 210 additions and 146 deletions

View File

@@ -3,8 +3,8 @@ package net.sf.briar.protocol.writers;
import java.io.IOException;
import java.io.OutputStream;
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.writers.AckWriter;
import net.sf.briar.api.serial.Writer;
@@ -28,8 +28,11 @@ class AckWriterImpl implements AckWriter {
w.writeListStart();
started = true;
}
int capacity = Ack.MAX_SIZE - (int) w.getBytesWritten() - 1;
if(capacity < BatchId.SERIALISED_LENGTH) return false;
int capacity = ProtocolConstants.MAX_PACKET_LENGTH
- (int) w.getBytesWritten() - 1;
// Allow one byte for the BATCH_ID tag, one byte for the BYTES tag and
// one byte for the length as a uint7
if(capacity < BatchId.LENGTH + 3) return false;
b.writeTo(w);
return true;
}

View File

@@ -5,8 +5,8 @@ import java.io.OutputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import net.sf.briar.api.protocol.Batch;
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.writers.BatchWriter;
import net.sf.briar.api.serial.Writer;
@@ -28,7 +28,9 @@ class BatchWriterImpl implements BatchWriter {
}
public int getCapacity() {
return Batch.MAX_SIZE - 3;
// Allow one byte for the batch tag, one for the list start tag and
// one for the list end tag
return ProtocolConstants.MAX_PACKET_LENGTH - 3;
}
public boolean writeMessage(byte[] message) throws IOException {
@@ -38,7 +40,8 @@ class BatchWriterImpl implements BatchWriter {
w.writeListStart();
started = true;
}
int capacity = Batch.MAX_SIZE - (int) w.getBytesWritten() - 1;
int capacity = ProtocolConstants.MAX_PACKET_LENGTH
- (int) w.getBytesWritten() - 1;
if(capacity < message.length) return false;
// Bypass the writer and write each raw message directly
out.write(message);

View File

@@ -6,8 +6,8 @@ import java.security.DigestOutputStream;
import java.security.MessageDigest;
import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.OfferId;
import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Tags;
import net.sf.briar.api.protocol.writers.OfferWriter;
import net.sf.briar.api.serial.Writer;
@@ -35,8 +35,11 @@ class OfferWriterImpl implements OfferWriter {
w.writeListStart();
started = true;
}
int capacity = Offer.MAX_SIZE - (int) w.getBytesWritten() - 1;
if(capacity < MessageId.SERIALISED_LENGTH) return false;
int capacity = ProtocolConstants.MAX_PACKET_LENGTH
- (int) w.getBytesWritten() - 1;
// Allow one byte for the MESSAGE_ID tag, one byte for the BYTES tag
// and one byte for the length as a uint7
if(capacity < MessageId.LENGTH + 3) return false;
m.writeTo(w);
return true;
}