mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Changed the root package from net.sf.briar to org.briarproject.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
|
||||
public class ConnectionContext {
|
||||
|
||||
private final ContactId contactId;
|
||||
private final TransportId transportId;
|
||||
private final byte[] secret;
|
||||
private final long connection;
|
||||
private final boolean alice;
|
||||
|
||||
public ConnectionContext(ContactId contactId, TransportId transportId,
|
||||
byte[] secret, long connection, boolean alice) {
|
||||
this.contactId = contactId;
|
||||
this.transportId = transportId;
|
||||
this.secret = secret;
|
||||
this.connection = connection;
|
||||
this.alice = alice;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public TransportId getTransportId() {
|
||||
return transportId;
|
||||
}
|
||||
|
||||
public byte[] getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public long getConnectionNumber() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public boolean getAlice() {
|
||||
return alice;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
||||
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||
|
||||
public interface ConnectionDispatcher {
|
||||
|
||||
void dispatchReader(TransportId t, SimplexTransportReader r);
|
||||
|
||||
void dispatchWriter(ContactId c, TransportId t,
|
||||
SimplexTransportWriter w);
|
||||
|
||||
void dispatchIncomingConnection(TransportId t, DuplexTransportConnection d);
|
||||
|
||||
void dispatchOutgoingConnection(ContactId c, TransportId t,
|
||||
DuplexTransportConnection d);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
|
||||
/** An interface for listening for connection and disconnection events. */
|
||||
public interface ConnectionListener {
|
||||
|
||||
/** Called when a contact connects and has no existing connections. */
|
||||
void contactConnected(ContactId c);
|
||||
|
||||
/** Called when a contact disconnects and has no remaining connections. */
|
||||
void contactDisconnected(ContactId c);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/** Decrypts and authenticates data received over a connection. */
|
||||
public interface ConnectionReader {
|
||||
|
||||
/**
|
||||
* Returns an input stream from which the decrypted, authenticated data can
|
||||
* be read.
|
||||
*/
|
||||
InputStream getInputStream();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface ConnectionReaderFactory {
|
||||
|
||||
/** Creates a connection reader for one side of a connection. */
|
||||
ConnectionReader createConnectionReader(InputStream in, int maxFrameLength,
|
||||
ConnectionContext ctx, boolean incoming, boolean initiator);
|
||||
|
||||
/** Creates a connection reader for one side of an invitation connection. */
|
||||
ConnectionReader createInvitationConnectionReader(InputStream in,
|
||||
int maxFrameLength, byte[] secret, boolean alice);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.db.DbException;
|
||||
|
||||
/**
|
||||
* Maintains the connection reordering windows and decides whether incoming
|
||||
* connections should be accepted or rejected.
|
||||
*/
|
||||
public interface ConnectionRecogniser {
|
||||
|
||||
/**
|
||||
* Returns the context for the given connection if the connection was
|
||||
* expected, or null if the connection was not expected.
|
||||
*/
|
||||
ConnectionContext acceptConnection(TransportId t, byte[] tag)
|
||||
throws DbException;
|
||||
|
||||
void addSecret(TemporarySecret s);
|
||||
|
||||
void removeSecret(ContactId c, TransportId t, long period);
|
||||
|
||||
void removeSecrets(ContactId c);
|
||||
|
||||
void removeSecrets(TransportId t);
|
||||
|
||||
void removeSecrets();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
|
||||
/**
|
||||
* Keeps track of which contacts are currently connected by which transports.
|
||||
*/
|
||||
public interface ConnectionRegistry {
|
||||
|
||||
void addListener(ConnectionListener c);
|
||||
|
||||
void removeListener(ConnectionListener c);
|
||||
|
||||
void registerConnection(ContactId c, TransportId t);
|
||||
|
||||
void unregisterConnection(ContactId c, TransportId t);
|
||||
|
||||
Collection<ContactId> getConnectedContacts(TransportId t);
|
||||
|
||||
boolean isConnected(ContactId c);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
/** Encrypts and authenticates data to be sent over a connection. */
|
||||
public interface ConnectionWriter {
|
||||
|
||||
/**
|
||||
* Returns an output stream to which unencrypted, unauthenticated data can
|
||||
* be written.
|
||||
*/
|
||||
OutputStream getOutputStream();
|
||||
|
||||
/** Returns the maximum number of bytes that can be written. */
|
||||
long getRemainingCapacity();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface ConnectionWriterFactory {
|
||||
|
||||
/** Creates a connection writer for one side of a connection. */
|
||||
ConnectionWriter createConnectionWriter(OutputStream out,
|
||||
int maxFrameLength, long capacity, ConnectionContext ctx,
|
||||
boolean incoming, boolean initiator);
|
||||
|
||||
/** Creates a connection writer for one side of an invitation connection. */
|
||||
ConnectionWriter createInvitationConnectionWriter(OutputStream out,
|
||||
int maxFrameLength, byte[] secret, boolean alice);
|
||||
}
|
||||
36
briar-api/src/org/briarproject/api/transport/Endpoint.java
Normal file
36
briar-api/src/org/briarproject/api/transport/Endpoint.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
|
||||
public class Endpoint {
|
||||
|
||||
protected final ContactId contactId;
|
||||
protected final TransportId transportId;
|
||||
private final long epoch;
|
||||
private final boolean alice;
|
||||
|
||||
public Endpoint(ContactId contactId, TransportId transportId, long epoch,
|
||||
boolean alice) {
|
||||
this.contactId = contactId;
|
||||
this.transportId = transportId;
|
||||
this.epoch = epoch;
|
||||
this.alice = alice;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public TransportId getTransportId() {
|
||||
return transportId;
|
||||
}
|
||||
|
||||
public long getEpoch() {
|
||||
return epoch;
|
||||
}
|
||||
|
||||
public boolean getAlice() {
|
||||
return alice;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
/**
|
||||
* Annotation for injecting the executor for recognising incoming connections.
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target({ FIELD, METHOD, PARAMETER })
|
||||
@Retention(RUNTIME)
|
||||
public @interface IncomingConnectionExecutor {}
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
|
||||
public class TemporarySecret extends Endpoint {
|
||||
|
||||
private final long period, outgoing, centre;
|
||||
private final byte[] secret, bitmap;
|
||||
|
||||
/** Creates a temporary secret with the given connection window. */
|
||||
public TemporarySecret(ContactId contactId, TransportId transportId,
|
||||
long epoch, boolean alice, long period, byte[] secret,
|
||||
long outgoing, long centre, byte[] bitmap) {
|
||||
super(contactId, transportId, epoch, alice);
|
||||
this.period = period;
|
||||
this.secret = secret;
|
||||
this.outgoing = outgoing;
|
||||
this.centre = centre;
|
||||
this.bitmap = bitmap;
|
||||
}
|
||||
|
||||
/** Creates a temporary secret with a new connection window. */
|
||||
public TemporarySecret(ContactId contactId, TransportId transportId,
|
||||
long epoch, boolean alice, long period, byte[] secret) {
|
||||
this(contactId, transportId, epoch, alice, period, secret, 0, 0,
|
||||
new byte[CONNECTION_WINDOW_SIZE / 8]);
|
||||
}
|
||||
|
||||
/** Creates a temporary secret derived from the given endpoint. */
|
||||
public TemporarySecret(Endpoint ep, long period, byte[] secret) {
|
||||
this(ep.getContactId(), ep.getTransportId(), ep.getEpoch(),
|
||||
ep.getAlice(), period, secret);
|
||||
}
|
||||
|
||||
public long getPeriod() {
|
||||
return period;
|
||||
}
|
||||
|
||||
public byte[] getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public long getOutgoingConnectionCounter() {
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
public long getWindowCentre() {
|
||||
return centre;
|
||||
}
|
||||
|
||||
public byte[] getWindowBitmap() {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int periodHashCode = (int) (period ^ (period >>> 32));
|
||||
return contactId.hashCode() ^ transportId.hashCode() ^ periodHashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof TemporarySecret) {
|
||||
TemporarySecret s = (TemporarySecret) o;
|
||||
return contactId.equals(s.contactId) &&
|
||||
transportId.equals(s.transportId) && period == s.period;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.briarproject.api.transport;
|
||||
|
||||
public interface TransportConstants {
|
||||
|
||||
/** The length of the connection tag in bytes. */
|
||||
int TAG_LENGTH = 16;
|
||||
|
||||
/** The maximum length of a frame in bytes, including the header and MAC. */
|
||||
int MAX_FRAME_LENGTH = 32768; // 2^15, 32 KiB
|
||||
|
||||
/** The length of the initalisation vector (IV) in bytes. */
|
||||
int IV_LENGTH = 12;
|
||||
|
||||
/** The length of the additional authenticated data (AAD) in bytes. */
|
||||
int AAD_LENGTH = 6;
|
||||
|
||||
/** The length of the frame header in bytes. */
|
||||
int HEADER_LENGTH = 2;
|
||||
|
||||
/** The length of the message authentication code (MAC) in bytes. */
|
||||
int MAC_LENGTH = 16;
|
||||
|
||||
/**
|
||||
* The minimum connection length in bytes that all transport plugins must
|
||||
* support. Connections may be shorter than this length, but all transport
|
||||
* plugins must support connections of at least this length.
|
||||
*/
|
||||
int MIN_CONNECTION_LENGTH = 1024 * 1024; // 2^20, 1 MiB
|
||||
|
||||
/** The maximum difference between two communicating devices' clocks. */
|
||||
int MAX_CLOCK_DIFFERENCE = 60 * 60 * 1000; // 1 hour
|
||||
|
||||
/** The size of the connection reordering window. */
|
||||
int CONNECTION_WINDOW_SIZE = 32;
|
||||
}
|
||||
Reference in New Issue
Block a user