Skip to content
Snippets Groups Projects
Verified Commit 3dde115f authored by Julian Dehm's avatar Julian Dehm Committed by Julian Dehm
Browse files

update intro

parent 93046061
No related branches found
No related tags found
No related merge requests found
Showing
with 725 additions and 598 deletions
...@@ -35,146 +35,143 @@ import static org.briarproject.briar.mailbox.MessageType.MAILBOX_REQUEST; ...@@ -35,146 +35,143 @@ import static org.briarproject.briar.mailbox.MessageType.MAILBOX_REQUEST;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
abstract class AbstractProtocolEngine<S extends Session> abstract class AbstractProtocolEngine<S extends Session>
implements ProtocolEngine<S> { implements ProtocolEngine<S> {
protected final DatabaseComponent db; protected final DatabaseComponent db;
protected final ClientHelper clientHelper; protected final ClientHelper clientHelper;
protected final ContactManager contactManager; protected final ContactManager contactManager;
protected final ContactGroupFactory contactGroupFactory; protected final ContactGroupFactory contactGroupFactory;
protected final MessageTracker messageTracker; protected final MessageTracker messageTracker;
protected final IdentityManager identityManager; protected final IdentityManager identityManager;
protected final MessageParser messageParser; protected final MessageParser messageParser;
protected final MessageEncoder messageEncoder; protected final MessageEncoder messageEncoder;
protected final Clock clock; protected final Clock clock;
AbstractProtocolEngine( AbstractProtocolEngine(
DatabaseComponent db, DatabaseComponent db,
ClientHelper clientHelper, ClientHelper clientHelper,
ContactManager contactManager, ContactManager contactManager,
ContactGroupFactory contactGroupFactory, ContactGroupFactory contactGroupFactory,
MessageTracker messageTracker, MessageTracker messageTracker,
IdentityManager identityManager, IdentityManager identityManager,
MessageParser messageParser, MessageParser messageParser,
MessageEncoder messageEncoder, MessageEncoder messageEncoder,
Clock clock) { Clock clock) {
this.db = db; this.db = db;
this.clientHelper = clientHelper; this.clientHelper = clientHelper;
this.contactManager = contactManager; this.contactManager = contactManager;
this.contactGroupFactory = contactGroupFactory; this.contactGroupFactory = contactGroupFactory;
this.messageTracker = messageTracker; this.messageTracker = messageTracker;
this.identityManager = identityManager; this.identityManager = identityManager;
this.messageParser = messageParser; this.messageParser = messageParser;
this.messageEncoder = messageEncoder; this.messageEncoder = messageEncoder;
this.clock = clock; this.clock = clock;
} }
Message sendMailboxRequestMessage(Transaction txn, PeerSession s, Message sendMailboxRequestMessage(Transaction txn, PeerSession s, long timestamp) throws DbException {
long timestamp, Author author, @Nullable String message) Message m = messageEncoder
throws DbException { .encodeRequestMessage(s.getContactGroupId(), timestamp, s.getLastLocalMessageId());
Message m = messageEncoder sendMessage(txn, MAILBOX_REQUEST, s.getSessionId(), m);
.encodeRequestMessage(s.getContactGroupId(), timestamp, return m;
s.getLastLocalMessageId(), author, message); }
sendMessage(txn, MAILBOX_REQUEST, s.getSessionId(), m);
return m; Message sendMailboxAcceptMessage(Transaction txn, PeerSession s,
} long timestamp,
byte[] ephemeralPublicKey, long acceptTimestamp,
Message sendMailboxAcceptMessage(Transaction txn, PeerSession s, Map<TransportId, TransportProperties> transportProperties,
long timestamp, boolean visible) throws DbException {
byte[] ephemeralPublicKey, long acceptTimestamp, Message m = messageEncoder
Map<TransportId, TransportProperties> transportProperties, .encodeAcceptMessage(s.getContactGroupId(), timestamp,
boolean visible) throws DbException { s.getLastLocalMessageId(), s.getSessionId(),
Message m = messageEncoder ephemeralPublicKey, acceptTimestamp,
.encodeAcceptMessage(s.getContactGroupId(), timestamp, transportProperties);
s.getLastLocalMessageId(), s.getSessionId(), sendMessage(txn, MAILBOX_ACCEPT, s.getSessionId(), m);
ephemeralPublicKey, acceptTimestamp, return m;
transportProperties); }
sendMessage(txn, MAILBOX_ACCEPT, s.getSessionId(), m);
return m; Message sendContactRequestMessage(Transaction txn, PeerSession s,
} long timestamp, Author author, @Nullable String message)
throws DbException {
Message sendContactRequestMessage(Transaction txn, PeerSession s, Message m = messageEncoder
long timestamp, Author author, @Nullable String message) .encodeRequestMessage(s.getContactGroupId(), timestamp,
throws DbException { s.getLastLocalMessageId(), author, message);
Message m = messageEncoder sendMessage(txn, CONTACT_REQUEST, s.getSessionId(), m);
.encodeRequestMessage(s.getContactGroupId(), timestamp, return m;
s.getLastLocalMessageId(), author, message); }
sendMessage(txn, CONTACT_REQUEST, s.getSessionId(), m);
return m; Message sendContactAcceptMessage(Transaction txn, PeerSession s,
} long timestamp,
byte[] ephemeralPublicKey, long acceptTimestamp,
Message sendContactAcceptMessage(Transaction txn, PeerSession s, Map<TransportId, TransportProperties> transportProperties,
long timestamp, boolean visible) throws DbException {
byte[] ephemeralPublicKey, long acceptTimestamp, Message m = messageEncoder
Map<TransportId, TransportProperties> transportProperties, .encodeAcceptMessage(s.getContactGroupId(), timestamp,
boolean visible) throws DbException { s.getLastLocalMessageId(), s.getSessionId(),
Message m = messageEncoder ephemeralPublicKey, acceptTimestamp,
.encodeAcceptMessage(s.getContactGroupId(), timestamp, transportProperties);
s.getLastLocalMessageId(), s.getSessionId(), sendMessage(txn, CONTACT_ACCEPT, s.getSessionId(), m);
ephemeralPublicKey, acceptTimestamp, return m;
transportProperties); }
sendMessage(txn, CONTACT_ACCEPT, s.getSessionId(), m);
return m; Message sendMailboxInfotMessage(Transaction txn, PeerSession s,
} long timestamp,
byte[] ephemeralPublicKey, long acceptTimestamp,
Message sendMailboxInfotMessage(Transaction txn, PeerSession s, Map<TransportId, TransportProperties> transportProperties,
long timestamp, boolean visible) throws DbException {
byte[] ephemeralPublicKey, long acceptTimestamp, Message m = messageEncoder
Map<TransportId, TransportProperties> transportProperties, .encodeAcceptMessage(s.getContactGroupId(), timestamp,
boolean visible) throws DbException { s.getLastLocalMessageId(), s.getSessionId(),
Message m = messageEncoder ephemeralPublicKey, acceptTimestamp,
.encodeAcceptMessage(s.getContactGroupId(), timestamp, transportProperties);
s.getLastLocalMessageId(), s.getSessionId(), sendMessage(txn, MAILBOX_INFO, s.getSessionId(), m);
ephemeralPublicKey, acceptTimestamp, return m;
transportProperties); }
sendMessage(txn, MAILBOX_INFO, s.getSessionId(), m);
return m; Message sendDeclineMessage(Transaction txn, PeerSession s, long timestamp,
} boolean visible) throws DbException {
Message m = messageEncoder
Message sendDeclineMessage(Transaction txn, PeerSession s, long timestamp, .encodeDeclineMessage(s.getContactGroupId(), timestamp,
boolean visible) throws DbException { s.getLastLocalMessageId(), s.getSessionId());
Message m = messageEncoder sendMessage(txn, DECLINE, s.getSessionId(), m);
.encodeDeclineMessage(s.getContactGroupId(), timestamp, return m;
s.getLastLocalMessageId(), s.getSessionId()); }
sendMessage(txn, DECLINE, s.getSessionId(), m);
return m; Message sendAbortMessage(Transaction txn, PeerSession s, long timestamp)
} throws DbException {
Message m = messageEncoder
Message sendAbortMessage(Transaction txn, PeerSession s, long timestamp) .encodeAbortMessage(s.getContactGroupId(), timestamp,
throws DbException { s.getLastLocalMessageId(), s.getSessionId());
Message m = messageEncoder sendMessage(txn, ABORT, s.getSessionId(), m);
.encodeAbortMessage(s.getContactGroupId(), timestamp, return m;
s.getLastLocalMessageId(), s.getSessionId()); }
sendMessage(txn, ABORT, s.getSessionId(), m);
return m; private void sendMessage(Transaction txn, MessageType type,
} SessionId sessionId, Message m)
throws DbException {
private void sendMessage(Transaction txn, MessageType type, BdfDictionary meta = messageEncoder
SessionId sessionId, Message m) .encodeMetadata(type, sessionId, m.getTimestamp(), true, true);
throws DbException { try {
BdfDictionary meta = messageEncoder clientHelper.addLocalMessage(txn, m, meta, true);
.encodeMetadata(type, sessionId, m.getTimestamp(), true, true); } catch (FormatException e) {
try { throw new AssertionError(e);
clientHelper.addLocalMessage(txn, m, meta, true); }
} catch (FormatException e) { }
throw new AssertionError(e);
} boolean isInvalidDependency(@Nullable MessageId lastRemoteMessageId,
} @Nullable MessageId dependency) {
if (dependency == null) return lastRemoteMessageId != null;
boolean isInvalidDependency(@Nullable MessageId lastRemoteMessageId, return lastRemoteMessageId == null ||
@Nullable MessageId dependency) { !dependency.equals(lastRemoteMessageId);
if (dependency == null) return lastRemoteMessageId != null; }
return lastRemoteMessageId == null ||
!dependency.equals(lastRemoteMessageId); long getLocalTimestamp(long localTimestamp, long requestTimestamp) {
} return Math.max(
clock.currentTimeMillis(),
long getLocalTimestamp(long localTimestamp, long requestTimestamp) { Math.max(
return Math.max( localTimestamp,
clock.currentTimeMillis(), requestTimestamp
Math.max( ) + 1
localTimestamp, );
requestTimestamp }
) + 1
);
}
} }
...@@ -23,224 +23,222 @@ import static org.briarproject.briar.mailbox.IntroduceeState.START; ...@@ -23,224 +23,222 @@ import static org.briarproject.briar.mailbox.IntroduceeState.START;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
class IntroduceeSession class IntroduceeSession extends Session<IntroduceeState> implements PeerSession {
extends Session<org.briarproject.briar.mailbox.IntroduceeState>
implements PeerSession { private final GroupId contactGroupId;
private final Author introducer;
private final GroupId contactGroupId; private final Local local;
private final Author introducer; private final Remote remote;
private final Local local; @Nullable
private final Remote remote; private final byte[] masterKey;
@Nullable @Nullable
private final byte[] masterKey; private final Map<TransportId, KeySetId> transportKeys;
@Nullable
private final Map<TransportId, KeySetId> transportKeys; IntroduceeSession(SessionId sessionId, IntroduceeState state,
long requestTimestamp, GroupId contactGroupId, Author introducer,
IntroduceeSession(SessionId sessionId, IntroduceeState state, Local local, Remote remote, @Nullable byte[] masterKey,
long requestTimestamp, GroupId contactGroupId, Author introducer, @Nullable Map<TransportId, KeySetId> transportKeys,
Local local, Remote remote, @Nullable byte[] masterKey, long sessionCounter) {
@Nullable Map<TransportId, KeySetId> transportKeys, super(sessionId, state, requestTimestamp, sessionCounter);
long sessionCounter) { this.contactGroupId = contactGroupId;
super(sessionId, state, requestTimestamp, sessionCounter); this.introducer = introducer;
this.contactGroupId = contactGroupId; this.local = local;
this.introducer = introducer; this.remote = remote;
this.local = local; this.masterKey = masterKey;
this.remote = remote; this.transportKeys = transportKeys;
this.masterKey = masterKey; }
this.transportKeys = transportKeys;
} static IntroduceeSession getInitial(GroupId contactGroupId,
SessionId sessionId, Author introducer, boolean localIsAlice,
static IntroduceeSession getInitial(GroupId contactGroupId, Author remoteAuthor) {
SessionId sessionId, Author introducer, boolean localIsAlice, Local local =
Author remoteAuthor) { new Local(localIsAlice, null, -1, null, null, -1, null);
Local local = Remote remote =
new Local(localIsAlice, null, -1, null, null, -1, null); new Remote(!localIsAlice, remoteAuthor, null, null, null, -1,
Remote remote = null);
new Remote(!localIsAlice, remoteAuthor, null, null, null, -1, return new IntroduceeSession(sessionId, START, -1, contactGroupId,
null); introducer, local, remote, null, null, 0);
return new IntroduceeSession(sessionId, START, -1, contactGroupId, }
introducer, local, remote, null, null, 0);
} static IntroduceeSession addRemoteRequest(
IntroduceeSession s,
static IntroduceeSession addRemoteRequest( IntroduceeState state,
IntroduceeSession s, ContactRequestMessage m, byte[] ephemeralPublicKey,
IntroduceeState state, byte[] ephemeralPrivateKey,
ContactRequestMessage m, byte[] ephemeralPublicKey, long acceptTimestamp, boolean alice) {
byte[] ephemeralPrivateKey, Local local = new Local(alice, m.getMessageId(),
long acceptTimestamp, boolean alice) { m.getTimestamp(), ephemeralPublicKey, ephemeralPrivateKey,
Local local = new Local(alice, m.getMessageId(), acceptTimestamp, null);
m.getTimestamp(), ephemeralPublicKey, ephemeralPrivateKey, Remote remote =
acceptTimestamp, null); new Remote(!alice, s.remote.author, m.getMessageId(),
Remote remote = m.getEphemeralPublicKey(), null, m.getAcceptTimestamp(),
new Remote(!alice, s.remote.author, m.getMessageId(), null);
m.getEphemeralPublicKey(), null, m.getAcceptTimestamp(), return new IntroduceeSession(s.getSessionId(), state, m.getTimestamp(),
null); s.contactGroupId, s.introducer, local, remote, s.masterKey,
return new IntroduceeSession(s.getSessionId(), state, m.getTimestamp(), s.transportKeys, s.getSessionCounter());
s.contactGroupId, s.introducer, local, remote, s.masterKey, }
s.transportKeys, s.getSessionCounter());
} static IntroduceeSession addLocalAuth(
IntroduceeSession s,
static IntroduceeSession addLocalAuth( IntroduceeState state, Message m, SecretKey masterKey,
IntroduceeSession s, SecretKey aliceMacKey, SecretKey bobMacKey) {
IntroduceeState state, Message m, SecretKey masterKey, // add mac key and sent message
SecretKey aliceMacKey, SecretKey bobMacKey) { Local local = new Local(s.local.alice, m.getId(), m.getTimestamp(),
// add mac key and sent message s.local.ephemeralPublicKey, s.local.ephemeralPrivateKey,
Local local = new Local(s.local.alice, m.getId(), m.getTimestamp(), s.local.acceptTimestamp,
s.local.ephemeralPublicKey, s.local.ephemeralPrivateKey, s.local.alice ? aliceMacKey.getBytes() : bobMacKey.getBytes());
s.local.acceptTimestamp, // just add the mac key
s.local.alice ? aliceMacKey.getBytes() : bobMacKey.getBytes()); Remote remote = new Remote(s.remote.alice, s.remote.author,
// just add the mac key s.remote.lastMessageId, s.remote.ephemeralPublicKey,
Remote remote = new Remote(s.remote.alice, s.remote.author, s.remote.transportProperties, s.remote.acceptTimestamp,
s.remote.lastMessageId, s.remote.ephemeralPublicKey, s.remote.alice ? aliceMacKey.getBytes() : bobMacKey.getBytes());
s.remote.transportProperties, s.remote.acceptTimestamp, // add master key
s.remote.alice ? aliceMacKey.getBytes() : bobMacKey.getBytes()); return new IntroduceeSession(s.getSessionId(), state,
// add master key s.getRequestTimestamp(), s.contactGroupId, s.introducer, local,
return new IntroduceeSession(s.getSessionId(), state, remote, masterKey.getBytes(), s.transportKeys,
s.getRequestTimestamp(), s.contactGroupId, s.introducer, local, s.getSessionCounter());
remote, masterKey.getBytes(), s.transportKeys, }
s.getSessionCounter());
} static IntroduceeSession awaitAuth(
IntroduceeSession s, MailboxAuthMessage m,
static IntroduceeSession awaitAuth( Message sent, @Nullable Map<TransportId, KeySetId> transportKeys) {
IntroduceeSession s, MailboxAuthMessage m, Local local = new Local(s.local, sent.getId(), sent.getTimestamp());
Message sent, @Nullable Map<TransportId, KeySetId> transportKeys) { Remote remote = new Remote(s.remote, m.getMessageId());
Local local = new Local(s.local, sent.getId(), sent.getTimestamp()); return new IntroduceeSession(s.getSessionId(), AWAIT_REMOTE_RESPONSE,
Remote remote = new Remote(s.remote, m.getMessageId()); s.getRequestTimestamp(), s.contactGroupId, s.introducer, local,
return new IntroduceeSession(s.getSessionId(), AWAIT_REMOTE_RESPONSE, remote, null, transportKeys, s.getSessionCounter());
s.getRequestTimestamp(), s.contactGroupId, s.introducer, local, }
remote, null, transportKeys, s.getSessionCounter());
} static IntroduceeSession clear(
IntroduceeSession s, IntroduceeState state,
static IntroduceeSession clear( @Nullable MessageId lastLocalMessageId, long localTimestamp,
IntroduceeSession s, IntroduceeState state, @Nullable MessageId lastRemoteMessageId) {
@Nullable MessageId lastLocalMessageId, long localTimestamp, Local local =
@Nullable MessageId lastRemoteMessageId) { new Local(s.local.alice, lastLocalMessageId, localTimestamp,
Local local = null, null, -1, null);
new Local(s.local.alice, lastLocalMessageId, localTimestamp, Remote remote =
null, null, -1, null); new Remote(s.remote.alice, s.remote.author, lastRemoteMessageId,
Remote remote = null, null, -1, null);
new Remote(s.remote.alice, s.remote.author, lastRemoteMessageId, return new IntroduceeSession(s.getSessionId(), state,
null, null, -1, null); s.getRequestTimestamp(), s.contactGroupId, s.introducer, local,
return new IntroduceeSession(s.getSessionId(), state, remote, null, null, s.getSessionCounter());
s.getRequestTimestamp(), s.contactGroupId, s.introducer, local, }
remote, null, null, s.getSessionCounter());
} @Override
Role getRole() {
@Override return INTRODUCEE;
Role getRole() { }
return INTRODUCEE;
} @Override
public GroupId getContactGroupId() {
@Override return contactGroupId;
public GroupId getContactGroupId() { }
return contactGroupId;
} @Override
public long getLocalTimestamp() {
@Override return local.lastMessageTimestamp;
public long getLocalTimestamp() { }
return local.lastMessageTimestamp;
} @Nullable
@Override
@Nullable public MessageId getLastLocalMessageId() {
@Override return local.lastMessageId;
public MessageId getLastLocalMessageId() { }
return local.lastMessageId;
} @Nullable
@Override
@Nullable public MessageId getLastRemoteMessageId() {
@Override return remote.lastMessageId;
public MessageId getLastRemoteMessageId() { }
return remote.lastMessageId;
} Author getIntroducer() {
return introducer;
Author getIntroducer() { }
return introducer;
} public Local getLocal() {
return local;
public Local getLocal() { }
return local;
} public Remote getRemote() {
return remote;
public Remote getRemote() { }
return remote;
} @Nullable
byte[] getMasterKey() {
@Nullable return masterKey;
byte[] getMasterKey() { }
return masterKey;
} @Nullable
Map<TransportId, KeySetId> getTransportKeys() {
@Nullable return transportKeys;
Map<TransportId, KeySetId> getTransportKeys() { }
return transportKeys;
} abstract static class Common {
final boolean alice;
abstract static class Common { @Nullable
final boolean alice; final MessageId lastMessageId;
@Nullable @Nullable
final MessageId lastMessageId; final byte[] ephemeralPublicKey;
@Nullable
final byte[] ephemeralPublicKey; final long acceptTimestamp;
@Nullable
final long acceptTimestamp; final byte[] macKey;
@Nullable
final byte[] macKey; private Common(boolean alice, @Nullable MessageId lastMessageId,
@Nullable byte[] ephemeralPublicKey, @Nullable
private Common(boolean alice, @Nullable MessageId lastMessageId, long acceptTimestamp, @Nullable byte[] macKey) {
@Nullable byte[] ephemeralPublicKey, @Nullable this.alice = alice;
long acceptTimestamp, @Nullable byte[] macKey) { this.lastMessageId = lastMessageId;
this.alice = alice; this.ephemeralPublicKey = ephemeralPublicKey;
this.lastMessageId = lastMessageId; this.acceptTimestamp = acceptTimestamp;
this.ephemeralPublicKey = ephemeralPublicKey; this.macKey = macKey;
this.acceptTimestamp = acceptTimestamp; }
this.macKey = macKey; }
}
} static class Local extends Common {
final long lastMessageTimestamp;
static class Local extends Common { @Nullable
final long lastMessageTimestamp; final byte[] ephemeralPrivateKey;
@Nullable
final byte[] ephemeralPrivateKey; Local(boolean alice, @Nullable MessageId lastMessageId,
long lastMessageTimestamp, @Nullable byte[] ephemeralPublicKey,
Local(boolean alice, @Nullable MessageId lastMessageId, @Nullable byte[] ephemeralPrivateKey, long acceptTimestamp,
long lastMessageTimestamp, @Nullable byte[] ephemeralPublicKey, @Nullable byte[] macKey) {
@Nullable byte[] ephemeralPrivateKey, long acceptTimestamp, super(alice, lastMessageId, ephemeralPublicKey, acceptTimestamp,
@Nullable byte[] macKey) { macKey);
super(alice, lastMessageId, ephemeralPublicKey, acceptTimestamp, this.lastMessageTimestamp = lastMessageTimestamp;
macKey); this.ephemeralPrivateKey = ephemeralPrivateKey;
this.lastMessageTimestamp = lastMessageTimestamp; }
this.ephemeralPrivateKey = ephemeralPrivateKey;
} private Local(Local s, @Nullable MessageId lastMessageId,
long lastMessageTimestamp) {
private Local(Local s, @Nullable MessageId lastMessageId, this(s.alice, lastMessageId, lastMessageTimestamp,
long lastMessageTimestamp) { s.ephemeralPublicKey, s.ephemeralPrivateKey,
this(s.alice, lastMessageId, lastMessageTimestamp, s.acceptTimestamp, s.macKey);
s.ephemeralPublicKey, s.ephemeralPrivateKey, }
s.acceptTimestamp, s.macKey); }
}
} static class Remote extends Common {
final Author author;
static class Remote extends Common { @Nullable
final Author author; final Map<TransportId, TransportProperties> transportProperties;
@Nullable
final Map<TransportId, TransportProperties> transportProperties; Remote(boolean alice, Author author,
@Nullable MessageId lastMessageId,
Remote(boolean alice, Author author, @Nullable byte[] ephemeralPublicKey, @Nullable
@Nullable MessageId lastMessageId, Map<TransportId, TransportProperties> transportProperties,
@Nullable byte[] ephemeralPublicKey, @Nullable long acceptTimestamp, @Nullable byte[] macKey) {
Map<TransportId, TransportProperties> transportProperties, super(alice, lastMessageId, ephemeralPublicKey, acceptTimestamp,
long acceptTimestamp, @Nullable byte[] macKey) { macKey);
super(alice, lastMessageId, ephemeralPublicKey, acceptTimestamp, this.author = author;
macKey); this.transportProperties = transportProperties;
this.author = author; }
this.transportProperties = transportProperties;
} private Remote(Remote s, @Nullable MessageId lastMessageId) {
this(s.alice, s.author, lastMessageId, s.ephemeralPublicKey,
private Remote(Remote s, @Nullable MessageId lastMessageId) { s.transportProperties, s.acceptTimestamp, s.macKey);
this(s.alice, s.author, lastMessageId, s.ephemeralPublicKey, }
s.transportProperties, s.acceptTimestamp, s.macKey);
} }
}
} }
package org.briarproject.briar.mailbox;
interface IntroductionConstants {
// Group metadata keys
String GROUP_KEY_CONTACT_ID = "contactId";
// Message metadata keys
String MSG_KEY_MESSAGE_TYPE = "messageType";
String MSG_KEY_SESSION_ID = "sessionId";
String MSG_KEY_TIMESTAMP = "timestamp";
String MSG_KEY_LOCAL = "local";
String MSG_KEY_VISIBLE_IN_UI = "visibleInUi";
String MSG_KEY_AVAILABLE_TO_ANSWER = "availableToAnswer";
// Session Keys
String SESSION_KEY_SESSION_ID = "sessionId";
String SESSION_KEY_ROLE = "role";
String SESSION_KEY_STATE = "state";
String SESSION_KEY_REQUEST_TIMESTAMP = "requestTimestamp";
String SESSION_KEY_LOCAL_TIMESTAMP = "localTimestamp";
String SESSION_KEY_LAST_LOCAL_MESSAGE_ID = "lastLocalMessageId";
String SESSION_KEY_LAST_REMOTE_MESSAGE_ID = "lastRemoteMessageId";
// Session Keys Introducer
String SESSION_KEY_INTRODUCEE_A = "introduceeA";
String SESSION_KEY_INTRODUCEE_B = "introduceeB";
String SESSION_KEY_GROUP_ID = "groupId";
String SESSION_KEY_AUTHOR = "author";
// Session Keys Introducee
String SESSION_KEY_INTRODUCER = "introducer";
String SESSION_KEY_LOCAL = "local";
String SESSION_KEY_REMOTE = "remote";
String SESSION_KEY_MASTER_KEY = "masterKey";
String SESSION_KEY_TRANSPORT_KEYS = "transportKeys";
String SESSION_KEY_ALICE = "alice";
String SESSION_KEY_EPHEMERAL_PUBLIC_KEY = "ephemeralPublicKey";
String SESSION_KEY_EPHEMERAL_PRIVATE_KEY = "ephemeralPrivateKey";
String SESSION_KEY_TRANSPORT_PROPERTIES = "transportProperties";
String SESSION_KEY_ACCEPT_TIMESTAMP = "acceptTimestamp";
String SESSION_KEY_MAC_KEY = "macKey";
String SESSION_KEY_REMOTE_AUTHOR = "remoteAuthor";
}
package org.briarproject.briar.mailbox; package org.briarproject.briar.mailbox;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.properties.TransportProperties; import org.briarproject.bramble.api.properties.TransportProperties;
...@@ -9,7 +8,6 @@ import org.briarproject.bramble.api.sync.GroupId; ...@@ -9,7 +8,6 @@ import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message; import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.SessionId; import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.introduction.MessageType;
import java.util.Map; import java.util.Map;
...@@ -18,39 +16,36 @@ import javax.annotation.Nullable; ...@@ -18,39 +16,36 @@ import javax.annotation.Nullable;
@NotNullByDefault @NotNullByDefault
interface MessageEncoder { interface MessageEncoder {
BdfDictionary encodeRequestMetadata(long timestamp); BdfDictionary encodeRequestMetadata(long timestamp);
BdfDictionary encodeMetadata(MessageType type, BdfDictionary encodeMetadata(MessageType type, @Nullable SessionId sessionId, long timestamp, boolean local);
@Nullable SessionId sessionId, long timestamp, boolean local,
boolean read, boolean visible);
void addSessionId(BdfDictionary meta, SessionId sessionId); void addSessionId(BdfDictionary meta, SessionId sessionId);
void setVisibleInUi(BdfDictionary meta, boolean visible); void setVisibleInUi(BdfDictionary meta, boolean visible);
void setAvailableToAnswer(BdfDictionary meta, boolean available); void setAvailableToAnswer(BdfDictionary meta, boolean available);
Message encodeRequestMessage(GroupId contactGroupId, long timestamp, Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, Author author, @Nullable MessageId previousMessageId);
@Nullable String message);
Message encodeAcceptMessage(GroupId contactGroupId, long timestamp, Message encodeAcceptMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId, @Nullable MessageId previousMessageId, SessionId sessionId,
byte[] ephemeralPublicKey, long acceptTimestamp, byte[] ephemeralPublicKey, long acceptTimestamp,
Map<TransportId, TransportProperties> transportProperties); Map<TransportId, TransportProperties> transportProperties);
Message encodeDeclineMessage(GroupId contactGroupId, long timestamp, Message encodeDeclineMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId); @Nullable MessageId previousMessageId, SessionId sessionId);
Message encodeAuthMessage(GroupId contactGroupId, long timestamp, Message encodeAuthMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId, @Nullable MessageId previousMessageId, SessionId sessionId,
byte[] mac, byte[] signature); byte[] mac, byte[] signature);
Message encodeActivateMessage(GroupId contactGroupId, long timestamp, Message encodeActivateMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId, @Nullable MessageId previousMessageId, SessionId sessionId,
byte[] mac); byte[] mac);
Message encodeAbortMessage(GroupId contactGroupId, long timestamp, Message encodeAbortMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId); @Nullable MessageId previousMessageId, SessionId sessionId);
} }
...@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.FormatException; ...@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfList; import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.properties.TransportProperties; import org.briarproject.bramble.api.properties.TransportProperties;
...@@ -13,173 +12,158 @@ import org.briarproject.bramble.api.sync.Message; ...@@ -13,173 +12,158 @@ import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageFactory; import org.briarproject.bramble.api.sync.MessageFactory;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.SessionId; import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.introduction.MessageType;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ; import static org.briarproject.briar.mailbox.IntroductionConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
import static org.briarproject.briar.introduction.IntroductionConstants.MSG_KEY_AVAILABLE_TO_ANSWER; import static org.briarproject.briar.mailbox.IntroductionConstants.MSG_KEY_LOCAL;
import static org.briarproject.briar.introduction.IntroductionConstants.MSG_KEY_LOCAL; import static org.briarproject.briar.mailbox.IntroductionConstants.MSG_KEY_MESSAGE_TYPE;
import static org.briarproject.briar.introduction.IntroductionConstants.MSG_KEY_MESSAGE_TYPE; import static org.briarproject.briar.mailbox.IntroductionConstants.MSG_KEY_SESSION_ID;
import static org.briarproject.briar.introduction.IntroductionConstants.MSG_KEY_SESSION_ID; import static org.briarproject.briar.mailbox.IntroductionConstants.MSG_KEY_TIMESTAMP;
import static org.briarproject.briar.introduction.IntroductionConstants.MSG_KEY_TIMESTAMP; import static org.briarproject.briar.mailbox.IntroductionConstants.MSG_KEY_VISIBLE_IN_UI;
import static org.briarproject.briar.introduction.IntroductionConstants.MSG_KEY_VISIBLE_IN_UI; import static org.briarproject.briar.mailbox.MessageType.DECLINE;
import static org.briarproject.briar.introduction.MessageType.ABORT; import static org.briarproject.briar.mailbox.MessageType.MAILBOX_REQUEST;
import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
import static org.briarproject.briar.introduction.MessageType.AUTH;
import static org.briarproject.briar.introduction.MessageType.DECLINE;
import static org.briarproject.briar.introduction.MessageType.REQUEST;
@NotNullByDefault @NotNullByDefault
class MessageEncoderImpl implements class MessageEncoderImpl implements
MessageEncoder { MessageEncoder {
private final ClientHelper clientHelper; private final ClientHelper clientHelper;
private final MessageFactory messageFactory; private final MessageFactory messageFactory;
@Inject @Inject
MessageEncoderImpl(ClientHelper clientHelper, MessageEncoderImpl(ClientHelper clientHelper,
MessageFactory messageFactory) { MessageFactory messageFactory) {
this.clientHelper = clientHelper; this.clientHelper = clientHelper;
this.messageFactory = messageFactory; this.messageFactory = messageFactory;
} }
@Override @Override
public BdfDictionary encodeRequestMetadata(long timestamp) { public BdfDictionary encodeRequestMetadata(long timestamp) {
BdfDictionary meta = BdfDictionary meta =
encodeMetadata(REQUEST, null, timestamp, false, false, false); encodeMetadata(MAILBOX_REQUEST, null, timestamp, false);
meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, false); meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, false);
return meta; return meta;
} }
@Override @Override
public BdfDictionary encodeMetadata(MessageType type, public BdfDictionary encodeMetadata(MessageType type,
@Nullable SessionId sessionId, long timestamp, boolean local, @Nullable SessionId sessionId, long timestamp, boolean local) {
boolean read, boolean visible) { BdfDictionary meta = new BdfDictionary();
BdfDictionary meta = new BdfDictionary(); meta.put(MSG_KEY_MESSAGE_TYPE, type.getValue());
meta.put(MSG_KEY_MESSAGE_TYPE, type.getValue()); if (sessionId != null)
if (sessionId != null) meta.put(MSG_KEY_SESSION_ID, sessionId);
meta.put(MSG_KEY_SESSION_ID, sessionId); else if (type != MAILBOX_REQUEST)
else if (type != REQUEST) throw new IllegalArgumentException();
throw new IllegalArgumentException(); meta.put(MSG_KEY_TIMESTAMP, timestamp);
meta.put(MSG_KEY_TIMESTAMP, timestamp); meta.put(MSG_KEY_LOCAL, local);
meta.put(MSG_KEY_LOCAL, local); return meta;
meta.put(MSG_KEY_READ, read); }
meta.put(MSG_KEY_VISIBLE_IN_UI, visible);
return meta; @Override
} public void addSessionId(BdfDictionary meta, SessionId sessionId) {
meta.put(MSG_KEY_SESSION_ID, sessionId);
@Override }
public void addSessionId(BdfDictionary meta, SessionId sessionId) {
meta.put(MSG_KEY_SESSION_ID, sessionId); @Override
} public void setVisibleInUi(BdfDictionary meta, boolean visible) {
meta.put(MSG_KEY_VISIBLE_IN_UI, visible);
@Override }
public void setVisibleInUi(BdfDictionary meta, boolean visible) {
meta.put(MSG_KEY_VISIBLE_IN_UI, visible); @Override
} public void setAvailableToAnswer(BdfDictionary meta, boolean available) {
meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, available);
@Override }
public void setAvailableToAnswer(BdfDictionary meta, boolean available) {
meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, available); @Override
} public Message encodeRequestMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId) {
@Override BdfList body = BdfList.of(
public Message encodeRequestMessage(GroupId contactGroupId, long timestamp, MAILBOX_REQUEST.getValue(),
@Nullable MessageId previousMessageId, Author author, previousMessageId
@Nullable String message) { );
if (message != null && message.equals("")) { return createMessage(contactGroupId, timestamp, body);
throw new IllegalArgumentException(); }
}
BdfList body = BdfList.of( @Override
REQUEST.getValue(), public Message encodeAcceptMessage(GroupId contactGroupId, long timestamp,
previousMessageId, @Nullable MessageId previousMessageId, SessionId sessionId,
clientHelper.toList(author), byte[] ephemeralPublicKey, long acceptTimestamp,
message Map<TransportId, TransportProperties> transportProperties) {
); BdfList body = BdfList.of(
return createMessage(contactGroupId, timestamp, body); ACCEPT.getValue(),
} sessionId,
previousMessageId,
@Override ephemeralPublicKey,
public Message encodeAcceptMessage(GroupId contactGroupId, long timestamp, acceptTimestamp,
@Nullable MessageId previousMessageId, SessionId sessionId, clientHelper.toDictionary(transportProperties)
byte[] ephemeralPublicKey, long acceptTimestamp, );
Map<TransportId, TransportProperties> transportProperties) { return createMessage(contactGroupId, timestamp, body);
BdfList body = BdfList.of( }
ACCEPT.getValue(),
sessionId, @Override
previousMessageId, public Message encodeDeclineMessage(GroupId contactGroupId, long timestamp,
ephemeralPublicKey, @Nullable MessageId previousMessageId, SessionId sessionId) {
acceptTimestamp, return encodeMessage(DECLINE, contactGroupId, sessionId, timestamp,
clientHelper.toDictionary(transportProperties) previousMessageId);
); }
return createMessage(contactGroupId, timestamp, body);
} @Override
public Message encodeAuthMessage(GroupId contactGroupId, long timestamp,
@Override @Nullable MessageId previousMessageId, SessionId sessionId,
public Message encodeDeclineMessage(GroupId contactGroupId, long timestamp, byte[] mac, byte[] signature) {
@Nullable MessageId previousMessageId, SessionId sessionId) { BdfList body = BdfList.of(
return encodeMessage(DECLINE, contactGroupId, sessionId, timestamp, AUTH.getValue(),
previousMessageId); sessionId,
} previousMessageId,
mac,
@Override signature
public Message encodeAuthMessage(GroupId contactGroupId, long timestamp, );
@Nullable MessageId previousMessageId, SessionId sessionId, return createMessage(contactGroupId, timestamp, body);
byte[] mac, byte[] signature) { }
BdfList body = BdfList.of(
AUTH.getValue(), @Override
sessionId, public Message encodeActivateMessage(GroupId contactGroupId, long timestamp,
previousMessageId, @Nullable MessageId previousMessageId, SessionId sessionId,
mac, byte[] mac) {
signature BdfList body = BdfList.of(
); ACTIVATE.getValue(),
return createMessage(contactGroupId, timestamp, body); sessionId,
} previousMessageId,
mac
@Override );
public Message encodeActivateMessage(GroupId contactGroupId, long timestamp, return createMessage(contactGroupId, timestamp, body);
@Nullable MessageId previousMessageId, SessionId sessionId, }
byte[] mac) {
BdfList body = BdfList.of( @Override
ACTIVATE.getValue(), public Message encodeAbortMessage(GroupId contactGroupId, long timestamp,
sessionId, @Nullable MessageId previousMessageId, SessionId sessionId) {
previousMessageId, return encodeMessage(ABORT, contactGroupId, sessionId, timestamp,
mac previousMessageId);
); }
return createMessage(contactGroupId, timestamp, body);
} private Message encodeMessage(MessageType type, GroupId contactGroupId,
SessionId sessionId, long timestamp,
@Override @Nullable MessageId previousMessageId) {
public Message encodeAbortMessage(GroupId contactGroupId, long timestamp, BdfList body = BdfList.of(
@Nullable MessageId previousMessageId, SessionId sessionId) { type.getValue(),
return encodeMessage(ABORT, contactGroupId, sessionId, timestamp, sessionId,
previousMessageId); previousMessageId
} );
return createMessage(contactGroupId, timestamp, body);
private Message encodeMessage(MessageType type, GroupId contactGroupId, }
SessionId sessionId, long timestamp,
@Nullable MessageId previousMessageId) { private Message createMessage(GroupId contactGroupId, long timestamp,
BdfList body = BdfList.of( BdfList body) {
type.getValue(), try {
sessionId, return messageFactory.createMessage(contactGroupId, timestamp,
previousMessageId clientHelper.toByteArray(body));
); } catch (FormatException e) {
return createMessage(contactGroupId, timestamp, body); throw new AssertionError(e);
} }
}
private Message createMessage(GroupId contactGroupId, long timestamp,
BdfList body) {
try {
return messageFactory.createMessage(contactGroupId, timestamp,
clientHelper.toByteArray(body));
} catch (FormatException e) {
throw new AssertionError(e);
}
}
} }
package org.briarproject.briar.mailbox; package org.briarproject.briar.mailbox;
class OwnerProtocolEngine extends AbstractProtocolEngine { import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.client.ProtocolStateException;
import javax.inject.Inject;
import static org.briarproject.briar.mailbox.OwnerState.AWAIT_RESPONSE_M;
class OwnerProtocolEngine extends AbstractProtocolEngine<OwnerSession> {
@Inject
OwnerProtocolEngine(
DatabaseComponent db,
ClientHelper clientHelper,
ContactManager contactManager,
ContactGroupFactory contactGroupFactory,
MessageTracker messageTracker,
IdentityManager identityManager,
MessageParser messageParser,
MessageEncoder messageEncoder,
Clock clock) {
super(db, clientHelper, contactManager, contactGroupFactory,
messageTracker, identityManager, messageParser, messageEncoder,
clock);
}
@Override
public OwnerSession onRequestAction(Transaction txn, OwnerSession s, long timestamp)
throws DbException {
switch (s.getState()) {
case START:
return onLocalRequest(txn, s, timestamp);
case AWAIT_RESPONSE_M:
case M_DECLINED:
case AWAIT_RESPONSE_B:
case B_DECLINED:
case AWAIT_AUTH_M:
case ADDED:
throw new ProtocolStateException(); // Invalid in these states
default:
throw new AssertionError();
}
}
@Override
public OwnerSession onAcceptAction(Transaction txn, OwnerSession session, long timestamp) throws DbException {
return null;
}
@Override
public OwnerSession onDeclineAction(Transaction txn, OwnerSession session, long timestamp) throws DbException {
return null;
}
@Override
public OwnerSession onRequestMessage(Transaction txn, OwnerSession session, RequestMessage m) throws DbException, FormatException {
return null;
}
@Override
public OwnerSession onAcceptMessage(Transaction txn, OwnerSession session, MailboxAcceptMessage m) throws DbException, FormatException {
return null;
}
@Override
public OwnerSession onDeclineMessage(Transaction txn, OwnerSession session, DeclineMessage m) throws DbException, FormatException {
return null;
}
@Override
public OwnerSession onAuthMessage(Transaction txn, OwnerSession session, MailboxAuthMessage m) throws DbException, FormatException {
return null;
}
@Override
public OwnerSession onAbortMessage(Transaction txn, OwnerSession session, AbortMessage m) throws DbException, FormatException {
return null;
}
private OwnerSession onLocalRequest(Transaction txn, OwnerSession s, long timestamp)
throws DbException {
// Send REQUEST messages
long maxIntroduceeTimestamp =
Math.max(getLocalTimestamp(s, s.getMailbox()), getLocalTimestamp(s, s.getIntroducee()));
long localTimestamp = Math.max(timestamp, maxIntroduceeTimestamp);
Message sentMailbox = sendMailboxRequestMessage(txn, s.getMailbox(), localTimestamp);
/*
// Track the message
messageTracker.trackOutgoingMessage(txn, sentMailbox);
*/
// Move to the AWAIT_RESPONSES state
Introducee mailbox = new Introducee(s.getMailbox(), sentMailbox);
Introducee b = new Introducee(s.getIntroducee().sessionId, s.getIntroducee().groupId, s.getIntroducee().author);
return new OwnerSession(s.getSessionId(), AWAIT_RESPONSE_M,
localTimestamp, mailbox, b, s.getSessionCounter());
}
private long getLocalTimestamp(OwnerSession s, PeerSession p) {
return getLocalTimestamp(p.getLocalTimestamp(),
s.getRequestTimestamp());
}
} }
...@@ -12,38 +12,37 @@ import static org.briarproject.briar.api.introduction.Role.INTRODUCER; ...@@ -12,38 +12,37 @@ import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
class OwnerSession class OwnerSession extends Session<OwnerState> {
extends Session<OwnerState> {
private final Introducee mailbox, introducee;
private final Introducee mailbox, introducee;
OwnerSession(SessionId sessionId, OwnerState state,
OwnerSession(SessionId sessionId, OwnerState state, long requestTimestamp, Introducee mailbox,
long requestTimestamp, Introducee mailbox, Introducee introducee, long sessionCounter) {
Introducee introducee, long sessionCounter) { super(sessionId, state, requestTimestamp, sessionCounter);
super(sessionId, state, requestTimestamp, sessionCounter); this.mailbox = mailbox;
this.mailbox = mailbox; this.introducee = introducee;
this.introducee = introducee; }
}
OwnerSession(SessionId sessionId, GroupId groupIdA, Author authorA,
OwnerSession(SessionId sessionId, GroupId groupIdA, Author authorA, GroupId groupIdB, Author authorB, long sessionCounter) {
GroupId groupIdB, Author authorB, long sessionCounter) { this(sessionId, OwnerState.START, -1,
this(sessionId, OwnerState.START, -1, new Introducee(sessionId, groupIdA, authorA),
new Introducee(sessionId, groupIdA, authorA), new Introducee(sessionId, groupIdB, authorB), sessionCounter);
new Introducee(sessionId, groupIdB, authorB), sessionCounter); }
}
@Override
@Override Role getRole() {
Role getRole() { return INTRODUCER;
return INTRODUCER; }
}
Introducee getMailbox() {
Introducee getMailbox() { return mailbox;
return mailbox; }
}
Introducee getIntroducee() {
Introducee getIntroducee() { return introducee;
return introducee; }
}
} }
...@@ -11,7 +11,7 @@ enum OwnerState implements State { ...@@ -11,7 +11,7 @@ enum OwnerState implements State {
START(0), START(0),
AWAIT_RESPONSE_M(1), AWAIT_RESPONSE_M(1),
M_DECLINE(2), M_DECLINED(2),
AWAIT_RESPONSE_B(3), AWAIT_RESPONSE_B(3),
B_DECLINED(4), B_DECLINED(4),
AWAIT_AUTH_M(5), AWAIT_AUTH_M(5),
......
...@@ -5,33 +5,30 @@ import org.briarproject.bramble.api.db.DbException; ...@@ -5,33 +5,30 @@ import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.Nullable;
@NotNullByDefault @NotNullByDefault
interface ProtocolEngine<S extends Session> { interface ProtocolEngine<S extends Session> {
S onRequestAction(Transaction txn, S session, @Nullable String message, S onRequestAction(Transaction txn, S session, long timestamp) throws DbException;
long timestamp) throws DbException;
S onAcceptAction(Transaction txn, S session, long timestamp) S onAcceptAction(Transaction txn, S session, long timestamp)
throws DbException; throws DbException;
S onDeclineAction(Transaction txn, S session, long timestamp) S onDeclineAction(Transaction txn, S session, long timestamp)
throws DbException; throws DbException;
S onRequestMessage(Transaction txn, S session, RequestMessage m) S onRequestMessage(Transaction txn, S session, RequestMessage m)
throws DbException, FormatException; throws DbException, FormatException;
S onAcceptMessage(Transaction txn, S session, MailboxAcceptMessage m) S onAcceptMessage(Transaction txn, S session, MailboxAcceptMessage m)
throws DbException, FormatException; throws DbException, FormatException;
S onDeclineMessage(Transaction txn, S session, DeclineMessage m) S onDeclineMessage(Transaction txn, S session, DeclineMessage m)
throws DbException, FormatException; throws DbException, FormatException;
S onAuthMessage(Transaction txn, S session, MailboxAuthMessage m) S onAuthMessage(Transaction txn, S session, MailboxAuthMessage m)
throws DbException, FormatException; throws DbException, FormatException;
S onAbortMessage(Transaction txn, S session, AbortMessage m) S onAbortMessage(Transaction txn, S session, AbortMessage m)
throws DbException, FormatException; throws DbException, FormatException;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment