Increased the maximum packet size to 1 MiB.

This should provide acceptable memory usage and database locking
granularity, while making subscription and transport updates large
enough for the incremental update issue to be kicked into the long
grass.

Removed awareness of the serialisation format from the protocol
component wherever possible, and added tests to ensure that the
constants defined in the protocol package's API are compatible with
the serialisation format.
This commit is contained in:
akwizgran
2011-09-07 13:51:30 +01:00
parent 1ac1609dc2
commit 331e7e0547
18 changed files with 258 additions and 42 deletions

View File

@@ -5,6 +5,9 @@ import java.util.Collection;
/** A packet acknowledging receipt of one or more batches. */
public interface Ack {
/** The maximum number of batch IDs per ack. */
static final int MAX_IDS_PER_ACK = 29959;
/** Returns the IDs of the acknowledged batches. */
Collection<BatchId> getBatchIds();
}

View File

@@ -11,9 +11,6 @@ public interface Author extends Writable {
/** The maximum length of an author's public key in bytes. */
static final int MAX_PUBLIC_KEY_LENGTH = 100;
/** The maximum length of a serialised author in bytes. */
static final int MAX_LENGTH = MAX_NAME_LENGTH + MAX_PUBLIC_KEY_LENGTH + 5;
/** Returns the author's unique identifier. */
AuthorId getId();

View File

@@ -11,9 +11,6 @@ public interface Group extends Writable {
/** The maximum length of a group's public key in bytes. */
static final int MAX_PUBLIC_KEY_LENGTH = 100;
/** The maximum length of a serialised group in bytes. */
static final int MAX_LENGTH = MAX_NAME_LENGTH + MAX_PUBLIC_KEY_LENGTH + 5;
/** Returns the group's unique identifier. */
GroupId getId();

View File

@@ -3,22 +3,16 @@ package net.sf.briar.api.protocol;
public interface Message {
/**
* The maximum length of a serialised message in bytes. To allow for future
* changes in the batch format, this is smaller than the amount of data
* that can fit in a batch using the current format.
* The maximum length of a message body in bytes. To allow for future
* changes in the protocol, this is smaller than the maximum packet length
* even when all the message's other fields have their maximum lengths.
*/
static final int MAX_LENGTH = ProtocolConstants.MAX_PACKET_LENGTH - 1024;
static final int MAX_BODY_LENGTH =
ProtocolConstants.MAX_PACKET_LENGTH - 1024;
/** The maximum length of a signature in bytes. */
static final int MAX_SIGNATURE_LENGTH = 100;
/**
* The maximum length of a message body in bytes. To allow for future
* changes in the message format, this is smaller than the amount of data
* that can fit in a message using the current format.
*/
static final int MAX_BODY_LENGTH = MAX_LENGTH - 1024;
/** Returns the message's unique identifier. */
MessageId getId();

View File

@@ -5,6 +5,9 @@ import java.util.Collection;
/** A packet offering the recipient some messages. */
public interface Offer {
/** The maximum number of message IDs per offer. */
static final int MAX_IDS_PER_OFFER = 29959;
/** Returns the offer's unique identifier. */
OfferId getId();

View File

@@ -1,14 +1,12 @@
package net.sf.briar.api.protocol;
import net.sf.briar.api.transport.TransportConstants;
public interface ProtocolConstants {
/**
* The maximum length of a serialised packet in bytes. To allow for future
* changes in the frame format, this is smaller than the amount of data
* that can fit in a frame using the current format.
* The maximum length of a serialised packet in bytes. Since the protocol
* does not aim for low latency, the two main constraints here are the
* amount of memory used for parsing packets and the granularity of the
* database transactions for generating and receiving packets.
*/
static final int MAX_PACKET_LENGTH =
TransportConstants.MAX_FRAME_LENGTH - 1024;
static final int MAX_PACKET_LENGTH = 1024 * 1024; // 1 MiB
}

View File

@@ -5,6 +5,9 @@ import java.util.Map;
/** A packet updating the sender's subscriptions. */
public interface SubscriptionUpdate {
/** The maximum number of subscriptions per update. */
static final int MAX_SUBS_PER_UPDATE = 6000;
/** Returns the subscriptions contained in the update. */
Map<Group, Long> getSubscriptions();

View File

@@ -5,6 +5,18 @@ import java.util.Map;
/** A packet updating the sender's transport properties. */
public interface TransportUpdate {
/** The maximum length of a plugin's name in UTF-8 bytes. */
static final int MAX_NAME_LENGTH = 50;
/** The maximum length of a property's key or value in UTF-8 bytes. */
static final int MAX_KEY_OR_VALUE_LENGTH = 100;
/** The maximum number of properties per plugin. */
static final int MAX_PROPERTIES_PER_PLUGIN = 100;
/** The maximum number of plugins per update. */
static final int MAX_PLUGINS_PER_UPDATE = 50;
/** Returns the transport properties contained in the update. */
Map<String, Map<String, String>> getTransports();