mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Bring protocols in line with spec
This commit is contained in:
@@ -3,7 +3,7 @@ package org.briarproject.bramble.api.sync;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A packet acknowledging receipt of one or more {@link Message Messages}.
|
||||
* A record acknowledging receipt of one or more {@link Message Messages}.
|
||||
*/
|
||||
public class Ack {
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.briarproject.bramble.api.sync;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
|
||||
public class Group {
|
||||
|
||||
public enum Visibility {
|
||||
@@ -13,6 +15,8 @@ public class Group {
|
||||
private final byte[] descriptor;
|
||||
|
||||
public Group(GroupId id, ClientId clientId, byte[] descriptor) {
|
||||
if (descriptor.length > MAX_GROUP_DESCRIPTOR_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
this.clientId = clientId;
|
||||
this.descriptor = descriptor;
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.briarproject.bramble.api.sync;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A packet offering the recipient one or more {@link Message Messages}.
|
||||
* A record offering the recipient one or more {@link Message Messages}.
|
||||
*/
|
||||
public class Offer {
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import java.io.IOException;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface PacketReader {
|
||||
public interface RecordReader {
|
||||
|
||||
boolean eof() throws IOException;
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import java.io.InputStream;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface PacketReaderFactory {
|
||||
public interface RecordReaderFactory {
|
||||
|
||||
PacketReader createPacketReader(InputStream in);
|
||||
RecordReader createRecordReader(InputStream in);
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
package org.briarproject.bramble.api.sync;
|
||||
|
||||
/**
|
||||
* Packet types for the sync protocol.
|
||||
* Record types for the sync protocol.
|
||||
*/
|
||||
public interface PacketTypes {
|
||||
public interface RecordTypes {
|
||||
|
||||
byte ACK = 0;
|
||||
byte MESSAGE = 1;
|
||||
byte OFFER = 2;
|
||||
byte REQUEST = 3;
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import java.io.IOException;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface PacketWriter {
|
||||
public interface RecordWriter {
|
||||
|
||||
void writeAck(Ack a) throws IOException;
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import java.io.OutputStream;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface PacketWriterFactory {
|
||||
public interface RecordWriterFactory {
|
||||
|
||||
PacketWriter createPacketWriter(OutputStream out);
|
||||
RecordWriter createRecordWriter(OutputStream out);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package org.briarproject.bramble.api.sync;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A packet requesting one or more {@link Message Messages} from the recipient.
|
||||
* A record requesting one or more {@link Message Messages} from the recipient.
|
||||
*/
|
||||
public class Request {
|
||||
|
||||
|
||||
@@ -10,19 +10,22 @@ public interface SyncConstants {
|
||||
byte PROTOCOL_VERSION = 0;
|
||||
|
||||
/**
|
||||
* The length of the packet header in bytes.
|
||||
* The length of the record header in bytes.
|
||||
*/
|
||||
int PACKET_HEADER_LENGTH = 4;
|
||||
int RECORD_HEADER_LENGTH = 4;
|
||||
|
||||
/**
|
||||
* The maximum length of the packet payload in bytes.
|
||||
* The maximum length of the record payload in bytes.
|
||||
*/
|
||||
int MAX_PACKET_PAYLOAD_LENGTH = 32 * 1024; // 32 KiB
|
||||
int MAX_RECORD_PAYLOAD_LENGTH = 32 * 1024; // 32 KiB
|
||||
|
||||
/** The maximum length of a group descriptor in bytes. */
|
||||
int MAX_GROUP_DESCRIPTOR_LENGTH = 32 * 1024; // 32 KiB
|
||||
|
||||
/**
|
||||
* The maximum length of a message in bytes.
|
||||
*/
|
||||
int MAX_MESSAGE_LENGTH = MAX_PACKET_PAYLOAD_LENGTH - PACKET_HEADER_LENGTH;
|
||||
int MAX_MESSAGE_LENGTH = MAX_RECORD_PAYLOAD_LENGTH - RECORD_HEADER_LENGTH;
|
||||
|
||||
/**
|
||||
* The length of the message header in bytes.
|
||||
@@ -32,10 +35,10 @@ public interface SyncConstants {
|
||||
/**
|
||||
* The maximum length of a message body in bytes.
|
||||
*/
|
||||
int MAX_MESSAGE_BODY_LENGTH = MAX_MESSAGE_LENGTH - MESSAGE_HEADER_LENGTH;
|
||||
int MAX_MESSAGE_BODY_LENGTH = 32 * 1024; // 32 KiB
|
||||
|
||||
/**
|
||||
* The maximum number of message IDs in an ack, offer or request packet.
|
||||
* The maximum number of message IDs in an ack, offer or request record.
|
||||
*/
|
||||
int MAX_MESSAGE_IDS = MAX_PACKET_PAYLOAD_LENGTH / UniqueId.LENGTH;
|
||||
int MAX_MESSAGE_IDS = MAX_RECORD_PAYLOAD_LENGTH / UniqueId.LENGTH;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.io.IOException;
|
||||
public interface SyncSession {
|
||||
|
||||
/**
|
||||
* Runs the session. This method returns when there are no more packets to
|
||||
* Runs the session. This method returns when there are no more records to
|
||||
* send or receive, or when the {@link #interrupt()} method has been called.
|
||||
*/
|
||||
void run() throws IOException;
|
||||
|
||||
Reference in New Issue
Block a user