Changed the root package from net.sf.briar to org.briarproject.

This commit is contained in:
akwizgran
2014-01-08 16:18:30 +00:00
parent dce70f487c
commit 832476412c
427 changed files with 2507 additions and 2507 deletions

View File

@@ -0,0 +1,18 @@
package org.briarproject.api.messaging;
import java.util.Collection;
/** A packet acknowledging receipt of one or more {@link Message}s. */
public class Ack {
private final Collection<MessageId> acked;
public Ack(Collection<MessageId> acked) {
this.acked = acked;
}
/** Returns the identifiers of the acknowledged messages. */
public Collection<MessageId> getMessageIds() {
return acked;
}
}

View File

@@ -0,0 +1,43 @@
package org.briarproject.api.messaging;
/** A group to which users may subscribe. */
public class Group {
private final GroupId id;
private final String name;
private final byte[] salt;
public Group(GroupId id, String name, byte[] salt) {
this.id = id;
this.name = name;
this.salt = salt;
}
/** Returns the group's unique identifier. */
public GroupId getId() {
return id;
}
/** Returns the group's name. */
public String getName() {
return name;
}
/**
* Returns the salt used to distinguish the group from other groups with
* the same name.
*/
public byte[] getSalt() {
return salt;
}
@Override
public int hashCode() {
return id.hashCode();
}
@Override
public boolean equals(Object o) {
return o instanceof Group && id.equals(((Group) o).id);
}
}

View File

@@ -0,0 +1,10 @@
package org.briarproject.api.messaging;
public interface GroupFactory {
/** Creates a group with the given name and a random salt. */
Group createGroup(String name);
/** Creates a group with the given name and salt. */
Group createGroup(String name, byte[] salt);
}

View File

@@ -0,0 +1,22 @@
package org.briarproject.api.messaging;
import java.util.Arrays;
import org.briarproject.api.UniqueId;
/**
* Type-safe wrapper for a byte array that uniquely identifies a {@link Group}.
*/
public class GroupId extends UniqueId {
public GroupId(byte[] id) {
super(id);
}
@Override
public boolean equals(Object o) {
if(o instanceof GroupId)
return Arrays.equals(id, ((GroupId) o).id);
return false;
}
}

View File

@@ -0,0 +1,25 @@
package org.briarproject.api.messaging;
public class GroupStatus {
private final Group group;
private final boolean subscribed, visibleToAll;
public GroupStatus(Group group, boolean subscribed, boolean visibleToAll) {
this.group = group;
this.subscribed = subscribed;
this.visibleToAll = visibleToAll;
}
public Group getGroup() {
return group;
}
public boolean isSubscribed() {
return subscribed;
}
public boolean isVisibleToAll() {
return visibleToAll;
}
}

View File

@@ -0,0 +1,42 @@
package org.briarproject.api.messaging;
import org.briarproject.api.Author;
public interface Message {
/** Returns the message's unique identifier. */
MessageId getId();
/**
* Returns the identifier of the message's parent, or null if this is the
* first message in a thread.
*/
MessageId getParent();
/**
* Returns the {@link Group} to which the message belongs, or null if this
* is a private message.
*/
Group getGroup();
/**
* Returns the message's {@link org.briarproject.api.Author Author}, or null
* if this is an anonymous message.
*/
Author getAuthor();
/** Returns the message's content type. */
String getContentType();
/** Returns the message's timestamp. */
long getTimestamp();
/** Returns the serialised message. */
byte[] getSerialised();
/** Returns the offset of the message body within the serialised message. */
int getBodyStart();
/** Returns the length of the message body in bytes. */
int getBodyLength();
}

View File

@@ -0,0 +1,19 @@
package org.briarproject.api.messaging;
import java.io.IOException;
import java.security.GeneralSecurityException;
import org.briarproject.api.Author;
import org.briarproject.api.crypto.PrivateKey;
public interface MessageFactory {
Message createAnonymousMessage(MessageId parent, Group group,
String contentType, long timestamp, byte[] body) throws IOException,
GeneralSecurityException;
Message createPseudonymousMessage(MessageId parent, Group group,
Author author, PrivateKey privateKey, String contentType,
long timestamp, byte[] body) throws IOException,
GeneralSecurityException;
}

View File

@@ -0,0 +1,23 @@
package org.briarproject.api.messaging;
import java.util.Arrays;
import org.briarproject.api.UniqueId;
/**
* Type-safe wrapper for a byte array that uniquely identifies a
* {@link Message}.
*/
public class MessageId extends UniqueId {
public MessageId(byte[] id) {
super(id);
}
@Override
public boolean equals(Object o) {
if(o instanceof MessageId)
return Arrays.equals(id, ((MessageId) o).id);
return false;
}
}

View File

@@ -0,0 +1,9 @@
package org.briarproject.api.messaging;
import java.security.GeneralSecurityException;
/** Verifies the signatures on an {@link UnverifiedMessage}. */
public interface MessageVerifier {
Message verifyMessage(UnverifiedMessage m) throws GeneralSecurityException;
}

View File

@@ -0,0 +1,45 @@
package org.briarproject.api.messaging;
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_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 connection
* length minus the maximum encryption and authentication overhead.
*/
int MAX_PACKET_LENGTH = MIN_CONNECTION_LENGTH / 2;
/** The maximum number of public groups a user may subscribe to. */
int MAX_SUBSCRIPTIONS = 3000;
/** The maximum length of a group's name in UTF-8 bytes. */
int MAX_GROUP_NAME_LENGTH = 50;
/** The length of a group's random salt in bytes. */
int GROUP_SALT_LENGTH = 32;
/**
* 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.
*/
int MAX_BODY_LENGTH = MAX_PACKET_LENGTH - 1024;
/** The maximum length of a message's content type in UTF-8 bytes. */
int MAX_CONTENT_TYPE_LENGTH = 50;
/** The maximum length of a message's subject line in UTF-8 bytes. */
int MAX_SUBJECT_LENGTH = 100;
/** The length of a message's random salt in bytes. */
int MESSAGE_SALT_LENGTH = 32;
/**
* When calculating the retention time of the database, the timestamp of
* the oldest message in the database is rounded down to a multiple of
* this value to avoid revealing the presence of any particular message.
*/
int RETENTION_GRANULARITY = 60 * 1000; // 1 minute
}

View File

@@ -0,0 +1,18 @@
package org.briarproject.api.messaging;
import java.util.Collection;
/** A packet offering the recipient one or more {@link Messages}. */
public class Offer {
private final Collection<MessageId> offered;
public Offer(Collection<MessageId> offered) {
this.offered = offered;
}
/** Returns the identifiers of the offered messages. */
public Collection<MessageId> getMessageIds() {
return offered;
}
}

View File

@@ -0,0 +1,38 @@
package org.briarproject.api.messaging;
import java.io.IOException;
public interface PacketReader {
boolean eof() throws IOException;
boolean hasAck() throws IOException;
Ack readAck() throws IOException;
boolean hasMessage() throws IOException;
UnverifiedMessage readMessage() throws IOException;
boolean hasOffer() throws IOException;
Offer readOffer() throws IOException;
boolean hasRequest() throws IOException;
Request readRequest() throws IOException;
boolean hasRetentionAck() throws IOException;
RetentionAck readRetentionAck() throws IOException;
boolean hasRetentionUpdate() throws IOException;
RetentionUpdate readRetentionUpdate() throws IOException;
boolean hasSubscriptionAck() throws IOException;
SubscriptionAck readSubscriptionAck() throws IOException;
boolean hasSubscriptionUpdate() throws IOException;
SubscriptionUpdate readSubscriptionUpdate() throws IOException;
boolean hasTransportAck() throws IOException;
TransportAck readTransportAck() throws IOException;
boolean hasTransportUpdate() throws IOException;
TransportUpdate readTransportUpdate() throws IOException;
}

View File

@@ -0,0 +1,8 @@
package org.briarproject.api.messaging;
import java.io.InputStream;
public interface PacketReaderFactory {
PacketReader createPacketReader(InputStream in);
}

View File

@@ -0,0 +1,34 @@
package org.briarproject.api.messaging;
import java.io.IOException;
public interface PacketWriter {
int getMaxMessagesForRequest(long capacity);
int getMaxMessagesForOffer(long capacity);
void writeAck(Ack a) throws IOException;
void writeMessage(byte[] raw) throws IOException;
void writeOffer(Offer o) throws IOException;
void writeRequest(Request r) throws IOException;
void writeRetentionAck(RetentionAck a) throws IOException;
void writeRetentionUpdate(RetentionUpdate u) throws IOException;
void writeSubscriptionAck(SubscriptionAck a) throws IOException;
void writeSubscriptionUpdate(SubscriptionUpdate u) throws IOException;
void writeTransportAck(TransportAck a) throws IOException;
void writeTransportUpdate(TransportUpdate u) throws IOException;
void flush() throws IOException;
void close() throws IOException;
}

View File

@@ -0,0 +1,8 @@
package org.briarproject.api.messaging;
import java.io.OutputStream;
public interface PacketWriterFactory {
PacketWriter createPacketWriter(OutputStream out, boolean flush);
}

View File

@@ -0,0 +1,18 @@
package org.briarproject.api.messaging;
import java.util.Collection;
/** A packet requesting one or more {@link Message}s from the recipient. */
public class Request {
private final Collection<MessageId> requested;
public Request(Collection<MessageId> requested) {
this.requested = requested;
}
/** Returns the identifiers of the requested messages. */
public Collection<MessageId> getMessageIds() {
return requested;
}
}

View File

@@ -0,0 +1,16 @@
package org.briarproject.api.messaging;
/** A packet acknowledging a (@link RetentionUpdate} */
public class RetentionAck {
private final long version;
public RetentionAck(long version) {
this.version = version;
}
/** Returns the version number of the acknowledged update. */
public long getVersion() {
return version;
}
}

View File

@@ -0,0 +1,23 @@
package org.briarproject.api.messaging;
/**
* A packet updating the recipient's view of the retention time of the sender's
* database.
*/
public class RetentionUpdate {
private final long retention, version;
public RetentionUpdate(long retention, long version) {
this.retention = retention;
this.version = version;
}
public long getRetentionTime() {
return retention;
}
public long getVersion() {
return version;
}
}

View File

@@ -0,0 +1,16 @@
package org.briarproject.api.messaging;
/** A packet acknowledging a {@link SubscriptionUpdate}. */
public class SubscriptionAck {
private final long version;
public SubscriptionAck(long version) {
this.version = version;
}
/** Returns the version number of the acknowledged update. */
public long getVersion() {
return version;
}
}

View File

@@ -0,0 +1,28 @@
package org.briarproject.api.messaging;
import java.util.Collection;
/** A packet updating the recipient's view of the sender's subscriptions. */
public class SubscriptionUpdate {
private final Collection<Group> groups;
private final long version;
public SubscriptionUpdate(Collection<Group> groups, long version) {
this.groups = groups;
this.version = version;
}
/**
* Returns the groups to which the sender subscribes, and which the sender
* has made visible to the recipient.
*/
public Collection<Group> getGroups() {
return groups;
}
/** Returns the update's version number. */
public long getVersion() {
return version;
}
}

View File

@@ -0,0 +1,25 @@
package org.briarproject.api.messaging;
import org.briarproject.api.TransportId;
/** A packet acknowledging a {@link TransportUpdate}. */
public class TransportAck {
private final TransportId id;
private final long version;
public TransportAck(TransportId id, long version) {
this.id = id;
this.version = version;
}
/** Returns the identifier of the updated transport. */
public TransportId getId() {
return id;
}
/** Returns the version number of the acknowledged update. */
public long getVersion() {
return version;
}
}

View File

@@ -0,0 +1,36 @@
package org.briarproject.api.messaging;
import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties;
/**
* A packet updating the recipient's view of the sender's transport properties.
*/
public class TransportUpdate {
private final TransportId id;
private final TransportProperties properties;
private final long version;
public TransportUpdate(TransportId id, TransportProperties properties,
long version) {
this.id = id;
this.properties = properties;
this.version = version;
}
/** Returns the identifier of the updated transport. */
public TransportId getId() {
return id;
}
/** Returns the transport's updated properties. */
public TransportProperties getProperties() {
return properties;
}
/** Returns the update's version number. */
public long getVersion() {
return version;
}
}

View File

@@ -0,0 +1,18 @@
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,94 @@
package org.briarproject.api.messaging;
import org.briarproject.api.Author;
/** A {@link Message} that has not yet had its signatures (if any) verified. */
public class UnverifiedMessage {
private final MessageId parent;
private final Group group;
private final Author author;
private final String contentType;
private final long timestamp;
private final byte[] raw, signature;
private final int bodyStart, bodyLength, signedLength;
public UnverifiedMessage(MessageId parent, Group group, Author author,
String contentType, long timestamp, byte[] raw, byte[] signature,
int bodyStart, int bodyLength, int signedLength) {
this.parent = parent;
this.group = group;
this.author = author;
this.contentType = contentType;
this.timestamp = timestamp;
this.raw = raw;
this.signature = signature;
this.bodyStart = bodyStart;
this.bodyLength = bodyLength;
this.signedLength = signedLength;
}
/**
* Returns the identifier of the message's parent, or null if this is the
* first message in a thread.
*/
public MessageId getParent() {
return parent;
}
/**
* Returns the {@link Group} to which the message belongs, or null if this
* is a private message.
*/
public Group getGroup() {
return group;
}
/**
* Returns the message's {@link org.briarproject.api.Author Author}, or null
* if this is an anonymous message.
*/
public Author getAuthor() {
return author;
}
/** Returns the message's content type. */
public String getContentType() {
return contentType;
}
/** Returns the message's timestamp. */
public long getTimestamp() {
return timestamp;
}
/** Returns the serialised message. */
public byte[] getSerialised() {
return raw;
}
/**
* Returns the author's signature, or null if this is an anonymous message.
*/
public byte[] getSignature() {
return signature;
}
/** Returns the offset of the message body within the serialised message. */
public int getBodyStart() {
return bodyStart;
}
/** Returns the length of the message body in bytes. */
public int getBodyLength() {
return bodyLength;
}
/**
* Returns the length in bytes of the data covered by the author's
* signature.
*/
public int getSignedLength() {
return signedLength;
}
}

View File

@@ -0,0 +1,15 @@
package org.briarproject.api.messaging.duplex;
import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId;
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
import org.briarproject.api.transport.ConnectionContext;
public interface DuplexConnectionFactory {
void createIncomingConnection(ConnectionContext ctx,
DuplexTransportConnection d);
void createOutgoingConnection(ContactId c, TransportId t,
DuplexTransportConnection d);
}

View File

@@ -0,0 +1,16 @@
package org.briarproject.api.messaging.simplex;
import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId;
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
import org.briarproject.api.transport.ConnectionContext;
public interface SimplexConnectionFactory {
void createIncomingConnection(ConnectionContext ctx,
SimplexTransportReader r);
void createOutgoingConnection(ContactId c, TransportId t,
SimplexTransportWriter w);
}