mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Split transport identifiers into two: TransportId (globally unique)
and TransportIndex (locally unique). This is the first step towards forward secrecy. Also removed the Writable interface and unnecessary user-defined types, moved various constants to ProtocolConstants and renamed some classes.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package net.sf.briar.api;
|
||||
|
||||
/** Type-safe wrapper for an integer that uniquely identifies a contact. */
|
||||
/**
|
||||
* Type-safe wrapper for an integer that uniquely identifies a contact within
|
||||
* the scope of a single node.
|
||||
*/
|
||||
public class ContactId {
|
||||
|
||||
private final int id;
|
||||
@@ -23,9 +26,4 @@ public class ContactId {
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package net.sf.briar.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.serial.Writable;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for an integer that uniquely identifies a transport plugin.
|
||||
*/
|
||||
public class TransportId implements Writable {
|
||||
|
||||
public static final int MIN_ID = 0;
|
||||
public static final int MAX_ID = 65535;
|
||||
|
||||
private final int id;
|
||||
|
||||
public TransportId(int id) {
|
||||
if(id < MIN_ID || id > MAX_ID) throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void writeTo(Writer w) throws IOException {
|
||||
w.writeInt32(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof TransportId) return id == ((TransportId) o).id;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import java.util.Map;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.db.event.DatabaseListener;
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
@@ -19,6 +18,9 @@ import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||
import net.sf.briar.api.protocol.Transport;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
import net.sf.briar.api.protocol.TransportUpdate;
|
||||
import net.sf.briar.api.protocol.writers.AckWriter;
|
||||
import net.sf.briar.api.protocol.writers.BatchWriter;
|
||||
@@ -51,11 +53,10 @@ public interface DatabaseComponent {
|
||||
void removeListener(DatabaseListener d);
|
||||
|
||||
/**
|
||||
* Adds a new contact to the database with the given transport properties
|
||||
* and shared secret, returns an ID for the contact.
|
||||
* Adds a new contact to the database with the given secret and returns an
|
||||
* ID for the contact.
|
||||
*/
|
||||
ContactId addContact(Map<TransportId, TransportProperties> transports,
|
||||
byte[] secret) throws DbException;
|
||||
ContactId addContact(byte[] secret) throws DbException;
|
||||
|
||||
/** Adds a locally generated group message to the database. */
|
||||
void addLocalGroupMessage(Message m) throws DbException;
|
||||
@@ -63,6 +64,12 @@ public interface DatabaseComponent {
|
||||
/** Adds a locally generated private message to the database. */
|
||||
void addLocalPrivateMessage(Message m, ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Allocates and returns a local index for the given transport. Returns
|
||||
* null if all indices have been allocated.
|
||||
*/
|
||||
TransportIndex addTransport(TransportId t) throws DbException;
|
||||
|
||||
/**
|
||||
* Generates an acknowledgement for the given contact.
|
||||
* @return True if any batch IDs were added to the acknowledgement.
|
||||
@@ -109,24 +116,29 @@ public interface DatabaseComponent {
|
||||
* Returns an outgoing connection number for the given contact and
|
||||
* transport.
|
||||
*/
|
||||
long getConnectionNumber(ContactId c, TransportId t) throws DbException;
|
||||
long getConnectionNumber(ContactId c, TransportIndex i) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the connection reordering window for the given contact and
|
||||
* transport.
|
||||
*/
|
||||
ConnectionWindow getConnectionWindow(ContactId c, TransportId t)
|
||||
ConnectionWindow getConnectionWindow(ContactId c, TransportIndex i)
|
||||
throws DbException;
|
||||
|
||||
/** Returns the IDs of all contacts. */
|
||||
Collection<ContactId> getContacts() throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the local index for the given transport, or null if no index
|
||||
* has been allocated.
|
||||
*/
|
||||
TransportIndex getLocalIndex(TransportId t) throws DbException;
|
||||
|
||||
/** Returns the local transport properties for the given transport. */
|
||||
TransportProperties getLocalProperties(TransportId t) throws DbException;
|
||||
|
||||
/** Returns all local transport properties. */
|
||||
Map<TransportId, TransportProperties> getLocalTransports()
|
||||
throws DbException;
|
||||
/** Returns all local transports. */
|
||||
Collection<Transport> getLocalTransports() throws DbException;
|
||||
|
||||
/** Returns the headers of all messages in the given group. */
|
||||
Collection<MessageHeader> getMessageHeaders(GroupId g) throws DbException;
|
||||
@@ -134,6 +146,13 @@ public interface DatabaseComponent {
|
||||
/** Returns the user's rating for the given author. */
|
||||
Rating getRating(AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the given contact's index for the given transport, or null if
|
||||
* the contact does not support the transport.
|
||||
*/
|
||||
TransportIndex getRemoteIndex(ContactId c, TransportId t)
|
||||
throws DbException;
|
||||
|
||||
/** Returns all remote transport properties for the given transport. */
|
||||
Map<ContactId, TransportProperties> getRemoteProperties(TransportId t)
|
||||
throws DbException;
|
||||
@@ -191,8 +210,8 @@ public interface DatabaseComponent {
|
||||
* Sets the connection reordering window for the given contact and
|
||||
* transport.
|
||||
*/
|
||||
void setConnectionWindow(ContactId c, TransportId t, ConnectionWindow w)
|
||||
throws DbException;
|
||||
void setConnectionWindow(ContactId c, TransportIndex i,
|
||||
ConnectionWindow w) throws DbException;
|
||||
|
||||
/**
|
||||
* Sets the local transport properties for the given transport, replacing
|
||||
|
||||
@@ -3,9 +3,15 @@ package net.sf.briar.api.db.event;
|
||||
import net.sf.briar.api.ContactId;
|
||||
|
||||
/** An event that is broadcast when a contact is removed. */
|
||||
public class ContactRemovedEvent extends ContactAddedEvent {
|
||||
public class ContactRemovedEvent extends DatabaseEvent {
|
||||
|
||||
private final ContactId contactId;
|
||||
|
||||
public ContactRemovedEvent(ContactId contactId) {
|
||||
super(contactId);
|
||||
this.contactId = contactId;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when the local transport properties are
|
||||
* updated.
|
||||
*/
|
||||
public class LocalTransportsUpdatedEvent extends DatabaseEvent {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
|
||||
/** An event that is broadcast when a contact's transports are updated. */
|
||||
public class RemoteTransportsUpdatedEvent extends DatabaseEvent {
|
||||
|
||||
private final ContactId contactId;
|
||||
|
||||
public RemoteTransportsUpdatedEvent(ContactId contactId) {
|
||||
this.contactId = contactId;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
}
|
||||
17
api/net/sf/briar/api/db/event/TransportAddedEvent.java
Normal file
17
api/net/sf/briar/api/db/event/TransportAddedEvent.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
|
||||
/** An event that is broadcast when a transport is added. */
|
||||
public class TransportAddedEvent extends DatabaseEvent {
|
||||
|
||||
private final TransportId transportId;
|
||||
|
||||
public TransportAddedEvent(TransportId transportId) {
|
||||
this.transportId = transportId;
|
||||
}
|
||||
|
||||
public TransportId getTransportId() {
|
||||
return transportId;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
/** An event that is broadcast when the local transports are updated. */
|
||||
public class TransportsUpdatedEvent extends DatabaseEvent {
|
||||
|
||||
}
|
||||
@@ -4,6 +4,5 @@ import java.util.concurrent.Executor;
|
||||
|
||||
public interface BatchPluginFactory {
|
||||
|
||||
BatchPlugin createPlugin(Executor executor,
|
||||
BatchPluginCallback callback);
|
||||
BatchPlugin createPlugin(Executor executor, BatchPluginCallback callback);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.sf.briar.api.plugins;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
|
||||
public interface Plugin {
|
||||
|
||||
|
||||
@@ -3,14 +3,13 @@ package net.sf.briar.api.plugins;
|
||||
public interface PluginManager {
|
||||
|
||||
/**
|
||||
* Starts all the plugins the manager knows about and returns the number of
|
||||
* plugins successfully started.
|
||||
* Starts the plugins and returns the number of plugins successfully
|
||||
* started.
|
||||
*/
|
||||
int startPlugins();
|
||||
|
||||
/**
|
||||
* Stops all the plugins started by startPlugins() and returns the number
|
||||
* of plugins successfully stopped.
|
||||
* Stops the plugins and returns the number of plugins successfully stopped.
|
||||
*/
|
||||
int stopPlugins();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,5 @@ import java.util.concurrent.Executor;
|
||||
|
||||
public interface StreamPluginFactory {
|
||||
|
||||
StreamPlugin createPlugin(Executor executor,
|
||||
StreamPluginCallback callback);
|
||||
StreamPlugin createPlugin(Executor executor, StreamPluginCallback callback);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import net.sf.briar.api.serial.Writable;
|
||||
|
||||
/** A pseudonymous author of messages. */
|
||||
public interface Author extends Writable {
|
||||
|
||||
/** The maximum length of an author's name in UTF-8 bytes. */
|
||||
static final int MAX_NAME_LENGTH = 50;
|
||||
|
||||
/** The maximum length of an author's public key in bytes. */
|
||||
static final int MAX_PUBLIC_KEY_LENGTH = 100;
|
||||
public interface Author {
|
||||
|
||||
/** Returns the author's unique identifier. */
|
||||
AuthorId getId();
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
/** Type-safe wrapper for a byte array that uniquely identifies an author. */
|
||||
public class AuthorId extends UniqueId {
|
||||
|
||||
@@ -12,11 +9,6 @@ public class AuthorId extends UniqueId {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public void writeTo(Writer w) throws IOException {
|
||||
w.writeUserDefinedId(Types.AUTHOR_ID);
|
||||
w.writeBytes(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof AuthorId)
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a byte array that uniquely identifies a batch of
|
||||
* messages.
|
||||
@@ -15,11 +12,6 @@ public class BatchId extends UniqueId {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public void writeTo(Writer w) throws IOException {
|
||||
w.writeUserDefinedId(Types.BATCH_ID);
|
||||
w.writeBytes(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof BatchId)
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import net.sf.briar.api.serial.Writable;
|
||||
|
||||
/** A group to which users may subscribe. */
|
||||
public interface Group extends Writable {
|
||||
|
||||
/** The maximum length of a group's name in UTF-8 bytes. */
|
||||
static final int MAX_NAME_LENGTH = 50;
|
||||
|
||||
/** The maximum length of a group's public key in bytes. */
|
||||
static final int MAX_PUBLIC_KEY_LENGTH = 100;
|
||||
public interface Group {
|
||||
|
||||
/** Returns the group's unique identifier. */
|
||||
GroupId getId();
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a byte array that uniquely identifies a group to which
|
||||
* users may subscribe.
|
||||
@@ -15,11 +12,6 @@ public class GroupId extends UniqueId {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public void writeTo(Writer w) throws IOException {
|
||||
w.writeUserDefinedId(Types.GROUP_ID);
|
||||
w.writeBytes(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof GroupId)
|
||||
|
||||
@@ -2,23 +2,6 @@ package net.sf.briar.api.protocol;
|
||||
|
||||
public interface Message {
|
||||
|
||||
/**
|
||||
* 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_BODY_LENGTH =
|
||||
ProtocolConstants.MAX_PACKET_LENGTH - 1024;
|
||||
|
||||
/** The maximum length of a subject line in UTF-8 bytes. */
|
||||
static final int MAX_SUBJECT_LENGTH = 100;
|
||||
|
||||
/** The maximum length of a signature in bytes. */
|
||||
static final int MAX_SIGNATURE_LENGTH = 100;
|
||||
|
||||
/** The length of the random salt in bytes. */
|
||||
static final int SALT_LENGTH = 8;
|
||||
|
||||
/** Returns the message's unique identifier. */
|
||||
MessageId getId();
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
/** Type-safe wrapper for a byte array that uniquely identifies a message. */
|
||||
public class MessageId extends UniqueId {
|
||||
|
||||
@@ -12,11 +9,6 @@ public class MessageId extends UniqueId {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public void writeTo(Writer w) throws IOException {
|
||||
w.writeUserDefinedId(Types.MESSAGE_ID);
|
||||
w.writeBytes(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof MessageId)
|
||||
|
||||
@@ -11,4 +11,41 @@ public interface ProtocolConstants {
|
||||
*/
|
||||
static final int MAX_PACKET_LENGTH =
|
||||
TransportConstants.MIN_CONNECTION_LENGTH - 1024;
|
||||
|
||||
/** The maximum number of transport plugins a node may support. */
|
||||
static final int MAX_TRANSPORTS = 50;
|
||||
|
||||
/** The maximum number of properties per transport plugin. */
|
||||
static final int MAX_PROPERTIES_PER_TRANSPORT = 100;
|
||||
|
||||
/** The maximum length of a property's key or value in UTF-8 bytes. */
|
||||
static final int MAX_PROPERTY_LENGTH = 100;
|
||||
|
||||
/** The maximum number of groups a node may subscribe to. */
|
||||
static final int MAX_GROUPS = 6000;
|
||||
|
||||
/** The maximum length of a group's name in UTF-8 bytes. */
|
||||
static final int MAX_GROUP_NAME_LENGTH = 50;
|
||||
|
||||
/** The maximum length of a serialised public key in bytes. */
|
||||
static final int MAX_PUBLIC_KEY_LENGTH = 100;
|
||||
|
||||
/** The maximum length of an author's name in UTF-8 bytes. */
|
||||
static final int MAX_AUTHOR_NAME_LENGTH = 50;
|
||||
|
||||
/**
|
||||
* 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_BODY_LENGTH = MAX_PACKET_LENGTH - 1024;
|
||||
|
||||
/** The maximum length of a message's subject line in UTF-8 bytes. */
|
||||
static final int MAX_SUBJECT_LENGTH = 100;
|
||||
|
||||
/** The maximum length of a signature in bytes. */
|
||||
static final int MAX_SIGNATURE_LENGTH = 100;
|
||||
|
||||
/** The length of a message's random salt in bytes. */
|
||||
static final int SALT_LENGTH = 8;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@ 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();
|
||||
|
||||
|
||||
47
api/net/sf/briar/api/protocol/Transport.java
Normal file
47
api/net/sf/briar/api/protocol/Transport.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Transport extends TreeMap<String, String> {
|
||||
|
||||
private static final long serialVersionUID = 4900420175715429560L;
|
||||
|
||||
private final TransportId id;
|
||||
private final TransportIndex index;
|
||||
|
||||
public Transport(TransportId id, TransportIndex index,
|
||||
Map<String, String> p) {
|
||||
super(p);
|
||||
this.id = id;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public Transport(TransportId id, TransportIndex index) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public TransportId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public TransportIndex getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof Transport) {
|
||||
Transport t = (Transport) o;
|
||||
return id.equals(t.id) && index.equals(t.index) && super.equals(o);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
21
api/net/sf/briar/api/protocol/TransportId.java
Normal file
21
api/net/sf/briar/api/protocol/TransportId.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a byte array that uniquely identifies a transport
|
||||
* plugin.
|
||||
*/
|
||||
public class TransportId extends UniqueId {
|
||||
|
||||
public TransportId(byte[] id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof TransportId)
|
||||
return Arrays.equals(id, ((TransportId) o).id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
33
api/net/sf/briar/api/protocol/TransportIndex.java
Normal file
33
api/net/sf/briar/api/protocol/TransportIndex.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for an integer that uniquely identifies a transport plugin
|
||||
* within the scope of a single node.
|
||||
*/
|
||||
public class TransportIndex {
|
||||
|
||||
private final int index;
|
||||
|
||||
public TransportIndex(int index) {
|
||||
if(index < 0 || index >= ProtocolConstants.MAX_TRANSPORTS)
|
||||
throw new IllegalArgumentException();
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof TransportIndex)
|
||||
return index == ((TransportIndex) o).index;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,12 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import java.util.Collection;
|
||||
|
||||
/** A packet updating the sender's transport properties. */
|
||||
public interface TransportUpdate {
|
||||
|
||||
/** 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<TransportId, TransportProperties> getTransports();
|
||||
/** Returns the transports contained in the update. */
|
||||
Collection<Transport> getTransports();
|
||||
|
||||
/**
|
||||
* Returns the update's timestamp. Updates that are older than the newest
|
||||
|
||||
@@ -5,16 +5,14 @@ public interface Types {
|
||||
|
||||
static final int ACK = 0;
|
||||
static final int AUTHOR = 1;
|
||||
static final int AUTHOR_ID = 2;
|
||||
static final int BATCH = 3;
|
||||
static final int BATCH_ID = 4;
|
||||
static final int GROUP = 5;
|
||||
static final int GROUP_ID = 6;
|
||||
static final int MESSAGE = 7;
|
||||
static final int MESSAGE_ID = 8;
|
||||
static final int OFFER = 9;
|
||||
static final int REQUEST = 10;
|
||||
static final int SUBSCRIPTION_UPDATE = 11;
|
||||
static final int TRANSPORT_PROPERTIES = 12;
|
||||
static final int TRANSPORT_UPDATE = 13;
|
||||
static final int BATCH = 2;
|
||||
static final int BATCH_ID = 3;
|
||||
static final int GROUP = 4;
|
||||
static final int MESSAGE = 5;
|
||||
static final int MESSAGE_ID = 6;
|
||||
static final int OFFER = 7;
|
||||
static final int REQUEST = 8;
|
||||
static final int SUBSCRIPTION_UPDATE = 9;
|
||||
static final int TRANSPORT = 10;
|
||||
static final int TRANSPORT_UPDATE = 11;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package net.sf.briar.api.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.sf.briar.api.serial.Writable;
|
||||
|
||||
public abstract class UniqueId implements Writable {
|
||||
public abstract class UniqueId {
|
||||
|
||||
/** The length of a unique identifier in bytes. */
|
||||
public static final int LENGTH = 32;
|
||||
|
||||
11
api/net/sf/briar/api/protocol/writers/AuthorWriter.java
Normal file
11
api/net/sf/briar/api/protocol/writers/AuthorWriter.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package net.sf.briar.api.protocol.writers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.protocol.Author;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
public interface AuthorWriter {
|
||||
|
||||
void writeAuthor(Writer w, Author a) throws IOException;
|
||||
}
|
||||
11
api/net/sf/briar/api/protocol/writers/GroupWriter.java
Normal file
11
api/net/sf/briar/api/protocol/writers/GroupWriter.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package net.sf.briar.api.protocol.writers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
|
||||
public interface GroupWriter {
|
||||
|
||||
void writeGroup(Writer w, Group g) throws IOException;
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
package net.sf.briar.api.protocol.writers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.PrivateKey;
|
||||
|
||||
import net.sf.briar.api.protocol.Author;
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
|
||||
public interface MessageEncoder {
|
||||
|
||||
/** Encodes a private message. */
|
||||
@@ -1,15 +1,14 @@
|
||||
package net.sf.briar.api.protocol.writers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.protocol.Transport;
|
||||
|
||||
/** An interface for creating a transport update. */
|
||||
public interface TransportWriter {
|
||||
|
||||
/** Writes the contents of the update. */
|
||||
void writeTransports(Map<TransportId, TransportProperties> transports,
|
||||
long timestamp) throws IOException;
|
||||
void writeTransports(Collection<Transport> transports, long timestamp)
|
||||
throws IOException;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Writable {
|
||||
|
||||
void writeTo(Writer w) throws IOException;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
|
||||
public interface BatchConnectionFactory {
|
||||
|
||||
void createIncomingConnection(TransportId t, ContactId c,
|
||||
void createIncomingConnection(TransportIndex i, ContactId c,
|
||||
BatchTransportReader r, byte[] encryptedIv);
|
||||
|
||||
void createOutgoingConnection(TransportId t, ContactId c,
|
||||
void createOutgoingConnection(TransportIndex i, ContactId c,
|
||||
BatchTransportWriter w);
|
||||
}
|
||||
|
||||
16
api/net/sf/briar/api/transport/ConnectionContext.java
Normal file
16
api/net/sf/briar/api/transport/ConnectionContext.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
|
||||
public interface ConnectionContext {
|
||||
|
||||
ContactId getContactId();
|
||||
|
||||
TransportId getTransportId();
|
||||
|
||||
TransportIndex getTransportIndex();
|
||||
|
||||
long getConnectionNumber();
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
|
||||
public interface ConnectionDispatcher {
|
||||
|
||||
void dispatchReader(TransportId t, BatchTransportReader r);
|
||||
|
||||
void dispatchWriter(TransportId t, ContactId c,
|
||||
BatchTransportWriter w);
|
||||
void dispatchWriter(TransportIndex i, ContactId c, BatchTransportWriter w);
|
||||
|
||||
void dispatchIncomingConnection(TransportId t, StreamTransportConnection s);
|
||||
|
||||
void dispatchOutgoingConnection(TransportId t, ContactId c,
|
||||
void dispatchOutgoingConnection(TransportIndex i, ContactId c,
|
||||
StreamTransportConnection s);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.sf.briar.api.transport;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
|
||||
public interface ConnectionReaderFactory {
|
||||
|
||||
@@ -10,13 +10,13 @@ public interface ConnectionReaderFactory {
|
||||
* Creates a connection reader for a batch-mode connection or the
|
||||
* initiator's side of a stream-mode connection.
|
||||
*/
|
||||
ConnectionReader createConnectionReader(InputStream in, TransportId t,
|
||||
ConnectionReader createConnectionReader(InputStream in, TransportIndex i,
|
||||
byte[] encryptedIv, byte[] secret);
|
||||
|
||||
/**
|
||||
* Creates a connection reader for the responder's side of a stream-mode
|
||||
* connection.
|
||||
*/
|
||||
ConnectionReader createConnectionReader(InputStream in, TransportId t,
|
||||
ConnectionReader createConnectionReader(InputStream in, TransportIndex i,
|
||||
long connection, byte[] secret);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
|
||||
/**
|
||||
* Maintains a transport plugin's connection reordering window and decides
|
||||
* whether incoming connections should be accepted or rejected.
|
||||
* Maintains the connection reordering windows and decides whether incoming
|
||||
* connections should be accepted or rejected.
|
||||
*/
|
||||
public interface ConnectionRecogniser {
|
||||
|
||||
/**
|
||||
* Returns the ID of the contact who created the encrypted IV if the
|
||||
* connection should be accepted, or null if the connection should be
|
||||
* rejected.
|
||||
* Returns the connection's context if the connection should be accepted,
|
||||
* or null if the connection should be rejected.
|
||||
*/
|
||||
ContactId acceptConnection(byte[] encryptedIv) throws DbException;
|
||||
ConnectionContext acceptConnection(byte[] encryptedIv) throws DbException;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public interface ConnectionRecogniserFactory {
|
||||
|
||||
ConnectionRecogniser createConnectionRecogniser(TransportId t);
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package net.sf.briar.api.transport;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
|
||||
public interface ConnectionWriterFactory {
|
||||
|
||||
@@ -11,12 +11,12 @@ public interface ConnectionWriterFactory {
|
||||
* initiator's side of a stream-mode connection.
|
||||
*/
|
||||
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
||||
TransportId t, long connection, byte[] secret);
|
||||
TransportIndex i, long connection, byte[] secret);
|
||||
|
||||
/**
|
||||
* Creates a connection writer for the responder's side of a stream-mode
|
||||
* connection.
|
||||
*/
|
||||
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
||||
TransportId t, byte[] encryptedIv, byte[] secret);
|
||||
TransportIndex i, byte[] encryptedIv, byte[] secret);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
|
||||
public interface StreamConnectionFactory {
|
||||
|
||||
void createIncomingConnection(TransportId t, ContactId c,
|
||||
void createIncomingConnection(TransportIndex i, ContactId c,
|
||||
StreamTransportConnection s, byte[] encryptedIv);
|
||||
|
||||
void createOutgoingConnection(TransportId t, ContactId c,
|
||||
void createOutgoingConnection(TransportIndex i, ContactId c,
|
||||
StreamTransportConnection s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user