mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
Removed getCapacity() from BatchWriter interface.
This commit is contained in:
@@ -7,9 +7,6 @@ import net.sf.briar.api.protocol.BatchId;
|
|||||||
/** An interface for creating a batch packet. */
|
/** An interface for creating a batch packet. */
|
||||||
public interface BatchWriter {
|
public interface BatchWriter {
|
||||||
|
|
||||||
/** Returns the capacity of the batch in bytes. */
|
|
||||||
int getCapacity();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to add the given raw message to the batch and returns true if
|
* Attempts to add the given raw message to the batch and returns true if
|
||||||
* it was added.
|
* it was added.
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ 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.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.ProtocolConstants;
|
||||||
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.writers.AckWriter;
|
import net.sf.briar.api.protocol.writers.AckWriter;
|
||||||
@@ -422,7 +423,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
int capacity = b.getCapacity();
|
int capacity = ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
Collection<MessageId> sendable =
|
Collection<MessageId> sendable =
|
||||||
db.getSendableMessages(txn, c, capacity);
|
db.getSendableMessages(txn, c, capacity);
|
||||||
for(MessageId m : sendable) {
|
for(MessageId m : sendable) {
|
||||||
@@ -486,12 +487,12 @@ DatabaseCleaner.Callback {
|
|||||||
Iterator<MessageId> it = requested.iterator();
|
Iterator<MessageId> it = requested.iterator();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
MessageId m = it.next();
|
MessageId m = it.next();
|
||||||
byte[] raw = db.getMessageIfSendable(txn, c, m);
|
|
||||||
// If the message is still sendable, try to add
|
// If the message is still sendable, try to add
|
||||||
// it to the batch. If the batch is full, don't
|
// it to the batch
|
||||||
// treat the message as considered, and don't
|
byte[] raw = db.getMessageIfSendable(txn, c, m);
|
||||||
// try to add any further messages.
|
|
||||||
if(raw != null) {
|
if(raw != null) {
|
||||||
|
// If the batch is full, don't treat the
|
||||||
|
// message as considered
|
||||||
if(!b.writeMessage(raw)) break;
|
if(!b.writeMessage(raw)) break;
|
||||||
sent.add(m);
|
sent.add(m);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,6 @@ class BatchWriterImpl implements BatchWriter {
|
|||||||
this.messageDigest = messageDigest;
|
this.messageDigest = messageDigest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCapacity() {
|
|
||||||
// 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 {
|
public boolean writeMessage(byte[] message) throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
messageDigest.reset();
|
messageDigest.reset();
|
||||||
@@ -41,8 +35,8 @@ class BatchWriterImpl implements BatchWriter {
|
|||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
// Allow one byte for the list end tag
|
// Allow one byte for the list end tag
|
||||||
int capacity =
|
int capacity = ProtocolConstants.MAX_PACKET_LENGTH
|
||||||
ProtocolConstants.MAX_PACKET_LENGTH - (int) w.getBytesWritten() - 1;
|
- (int) w.getBytesWritten() - 1;
|
||||||
if(capacity < message.length) return false;
|
if(capacity < message.length) return false;
|
||||||
// Bypass the writer and write each raw message directly
|
// Bypass the writer and write each raw message directly
|
||||||
out.write(message);
|
out.write(message);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ 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.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.ProtocolConstants;
|
||||||
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.writers.AckWriter;
|
import net.sf.briar.api.protocol.writers.AckWriter;
|
||||||
@@ -41,8 +42,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public abstract class DatabaseComponentTest extends TestCase {
|
public abstract class DatabaseComponentTest extends TestCase {
|
||||||
|
|
||||||
private static final int ONE_MEGABYTE = 1024 * 1024;
|
|
||||||
|
|
||||||
protected final Object txn = new Object();
|
protected final Object txn = new Object();
|
||||||
protected final AuthorId authorId;
|
protected final AuthorId authorId;
|
||||||
protected final BatchId batchId;
|
protected final BatchId batchId;
|
||||||
@@ -740,9 +739,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
allowing(database).containsContact(txn, contactId);
|
allowing(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
// Get the sendable messages
|
// Get the sendable messages
|
||||||
oneOf(batchWriter).getCapacity();
|
oneOf(database).getSendableMessages(txn, contactId,
|
||||||
will(returnValue(ONE_MEGABYTE));
|
ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
oneOf(database).getSendableMessages(txn, contactId, ONE_MEGABYTE);
|
|
||||||
will(returnValue(sendable));
|
will(returnValue(sendable));
|
||||||
// Try to add both messages to the writer - only manage to add one
|
// Try to add both messages to the writer - only manage to add one
|
||||||
oneOf(database).getMessage(txn, messageId);
|
oneOf(database).getMessage(txn, messageId);
|
||||||
|
|||||||
Reference in New Issue
Block a user