Moved the messaging protocol one step closer to BSP.

This breaks backward compatibility for the wire protocol and messages
stored in the database. The database schema version has been
incremented.
This commit is contained in:
akwizgran
2015-05-01 16:58:49 +01:00
parent ffcc8b6b38
commit 32c9ce50d9
33 changed files with 732 additions and 750 deletions

View File

@@ -1,18 +1,19 @@
package org.briarproject.api.messaging;
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
public interface MessagingConstants {
/**
* The maximum length of a serialised packet in bytes. To allow for future
* changes in the protocol, this is smaller than the minimum stream length
* minus the maximum encryption and authentication overhead.
*/
int MAX_PACKET_LENGTH = MIN_STREAM_LENGTH / 2;
/** The current version of the messaging protocol. */
byte PROTOCOL_VERSION = 0;
/** The length of the packet header in bytes. */
int HEADER_LENGTH = 4;
/** The maximum length of the packet payload in bytes. */
int MAX_PAYLOAD_LENGTH = 32 * 1024; // 32 KiB
/** The maximum number of public groups a user may subscribe to. */
int MAX_SUBSCRIPTIONS = 3000;
int MAX_SUBSCRIPTIONS = 300;
/** The maximum length of a group's name in UTF-8 bytes. */
int MAX_GROUP_NAME_LENGTH = 50;
@@ -22,10 +23,10 @@ public interface MessagingConstants {
/**
* 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
* changes in the protocol, this is smaller than the maximum payload length
* even when all the message's other fields have their maximum lengths.
*/
int MAX_BODY_LENGTH = MAX_PACKET_LENGTH - 1024;
int MAX_BODY_LENGTH = MAX_PAYLOAD_LENGTH - 1024;
/** The maximum length of a message's content type in UTF-8 bytes. */
int MAX_CONTENT_TYPE_LENGTH = 50;

View File

@@ -0,0 +1,16 @@
package org.briarproject.api.messaging;
/** Packet types for the messaging protocol. */
public interface PacketTypes {
byte ACK = 0;
byte MESSAGE = 1;
byte OFFER = 2;
byte REQUEST = 3;
byte RETENTION_ACK = 4;
byte RETENTION_UPDATE = 5;
byte SUBSCRIPTION_ACK = 6;
byte SUBSCRIPTION_UPDATE = 7;
byte TRANSPORT_ACK = 8;
byte TRANSPORT_UPDATE = 9;
}

View File

@@ -1,18 +0,0 @@
package org.briarproject.api.messaging;
/** Struct identifiers for encoding and decoding protocol objects. */
public interface Types {
int AUTHOR = 0;
int GROUP = 1;
int ACK = 2;
int MESSAGE = 3;
int OFFER = 4;
int REQUEST = 5;
int RETENTION_ACK = 6;
int RETENTION_UPDATE = 7;
int SUBSCRIPTION_ACK = 8;
int SUBSCRIPTION_UPDATE = 9;
int TRANSPORT_ACK = 10;
int TRANSPORT_UPDATE = 11;
}

View File

@@ -0,0 +1,8 @@
package org.briarproject.api.serial;
import java.io.IOException;
public interface ObjectReader<T> {
T readObject(Reader r) throws IOException;
}

View File

@@ -10,6 +10,10 @@ public interface Reader {
void addConsumer(Consumer c);
void removeConsumer(Consumer c);
boolean hasNull() throws IOException;
void readNull() throws IOException;
void skipNull() throws IOException;
boolean hasBoolean() throws IOException;
boolean readBoolean() throws IOException;
void skipBoolean() throws IOException;
@@ -24,11 +28,11 @@ public interface Reader {
boolean hasString() throws IOException;
String readString(int maxLength) throws IOException;
void skipString(int maxLength) throws IOException;
void skipString() throws IOException;
boolean hasBytes() throws IOException;
byte[] readBytes(int maxLength) throws IOException;
void skipBytes(int maxLength) throws IOException;
void skipBytes() throws IOException;
boolean hasList() throws IOException;
void readListStart() throws IOException;
@@ -41,15 +45,4 @@ public interface Reader {
boolean hasMapEnd() throws IOException;
void readMapEnd() throws IOException;
void skipMap() throws IOException;
boolean hasStruct() throws IOException;
boolean hasStruct(int id) throws IOException;
void readStructStart(int id) throws IOException;
boolean hasStructEnd() throws IOException;
void readStructEnd() throws IOException;
void skipStruct() throws IOException;
boolean hasNull() throws IOException;
void readNull() throws IOException;
void skipNull() throws IOException;
}

View File

@@ -6,9 +6,5 @@ public interface SerialComponent {
int getSerialisedListEndLength();
int getSerialisedStructStartLength(int id);
int getSerialisedStructEndLength();
int getSerialisedUniqueIdLength();
}

View File

@@ -1,8 +0,0 @@
package org.briarproject.api.serial;
import java.io.IOException;
public interface StructReader<T> {
T readStruct(Reader r) throws IOException;
}

View File

@@ -12,6 +12,7 @@ public interface Writer {
void addConsumer(Consumer c);
void removeConsumer(Consumer c);
void writeNull() throws IOException;
void writeBoolean(boolean b) throws IOException;
void writeInteger(long l) throws IOException;
void writeFloat(double d) throws IOException;
@@ -25,9 +26,4 @@ public interface Writer {
void writeMap(Map<?, ?> m) throws IOException;
void writeMapStart() throws IOException;
void writeMapEnd() throws IOException;
void writeStructStart(int id) throws IOException;
void writeStructEnd() throws IOException;
void writeNull() throws IOException;
}

View File

@@ -26,7 +26,7 @@ public interface TransportConstants {
* support. Streams may be shorter than this length, but all transport
* plugins must support streams of at least this length.
*/
int MIN_STREAM_LENGTH = 1024 * 1024; // 2^20, 1 MiB
int MIN_STREAM_LENGTH = 64 * 1024; // 64 KiB
/** The maximum difference between two communicating devices' clocks. */
int MAX_CLOCK_DIFFERENCE = 60 * 60 * 1000; // 1 hour