From 7238ab786859e8be0856231c76ef19ab2b3b3fde Mon Sep 17 00:00:00 2001
From: goapunk <goapunk@riseup.net>
Date: Fri, 7 Sep 2018 12:12:05 +0200
Subject: [PATCH] temp save

---
 .../IntroducerProtocolEngine.java             |   1 +
 .../briar/mailbox/OwnerProtocolEngine.java    | 203 ++++++++++--------
 .../briar/mailbox/ProtocolEngine.java         |  34 +--
 3 files changed, 136 insertions(+), 102 deletions(-)

diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerProtocolEngine.java
index c159697ad..eb8295700 100644
--- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerProtocolEngine.java
+++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerProtocolEngine.java
@@ -556,6 +556,7 @@ class IntroducerProtocolEngine
 	private IntroducerSession abort(Transaction txn,
 			IntroducerSession s) throws DbException {
 		// Broadcast abort event for testing
+
 		txn.attach(new IntroductionAbortedEvent(s.getSessionId()));
 
 		// Send an ABORT message to both introducees
diff --git a/briar-core/src/main/java/org/briarproject/briar/mailbox/OwnerProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/mailbox/OwnerProtocolEngine.java
index 5cf7feaf3..a330103c7 100644
--- a/briar-core/src/main/java/org/briarproject/briar/mailbox/OwnerProtocolEngine.java
+++ b/briar-core/src/main/java/org/briarproject/briar/mailbox/OwnerProtocolEngine.java
@@ -19,95 +19,124 @@ 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);
+	@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 {
+		throw new UnsupportedOperationException();
+	}
+
+	@Override
+	public OwnerSession onDeclineAction(Transaction txn, OwnerSession session,
+			long timestamp) throws DbException {
+		throw new UnsupportedOperationException();
+	}
+
+	@Override
+	public OwnerSession onRequestMessage(Transaction txn, OwnerSession session,
+			RequestMessage m) throws DbException, FormatException {
+		return abort(txn, session);
+	}
+
+	@Override
+	public OwnerSession onMailboxAcceptMessage(Transaction txn, OwnerSession s,
+			MailboxAcceptMessage m) throws DbException, FormatException {
+		switch (s.getState()) {
+			case START:
+			case AWAIT_RESPONSE_M:
+				onMailboxAccept(txn, s, 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();
+		}
+	}
+
+	private void onMailboxAccept(Transaction txn, OwnerSession s,
+			MailboxAcceptMessage m) {
+
+	}
+
+	@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());
-    }
+		// 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());
+	}
 }
diff --git a/briar-core/src/main/java/org/briarproject/briar/mailbox/ProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/mailbox/ProtocolEngine.java
index 85db0aa2b..18ffec2e5 100644
--- a/briar-core/src/main/java/org/briarproject/briar/mailbox/ProtocolEngine.java
+++ b/briar-core/src/main/java/org/briarproject/briar/mailbox/ProtocolEngine.java
@@ -8,27 +8,31 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
 @NotNullByDefault
 interface ProtocolEngine<S extends Session> {
 
-    S onRequestAction(Transaction txn, S session, long timestamp) throws DbException;
+	S onRequestAction(Transaction txn, S session, long timestamp)
+			throws DbException;
 
-    S onAcceptAction(Transaction txn, S session, long timestamp)
-            throws DbException;
+	S onAcceptAction(Transaction txn, S session, long timestamp)
+			throws DbException;
 
-    S onDeclineAction(Transaction txn, S session, long timestamp)
-            throws DbException;
+	S onDeclineAction(Transaction txn, S session, long timestamp)
+			throws DbException;
 
-    S onRequestMessage(Transaction txn, S session, RequestMessage m)
-            throws DbException, FormatException;
+	S onRequestMessage(Transaction txn, S session, RequestMessage m)
+			throws DbException, FormatException;
 
-    S onAcceptMessage(Transaction txn, S session, MailboxAcceptMessage m)
-            throws DbException, FormatException;
+	S onMailboxAcceptMessage(Transaction txn, S session, MailboxAcceptMessage m)
+			throws DbException, FormatException;
 
-    S onDeclineMessage(Transaction txn, S session, DeclineMessage m)
-            throws DbException, FormatException;
+	S onContactAcceptMessage(Transaction txn, S session, MailboxAcceptMessage m)
+			throws DbException, FormatException;
 
-    S onAuthMessage(Transaction txn, S session, MailboxAuthMessage m)
-            throws DbException, FormatException;
+	S onDeclineMessage(Transaction txn, S session, DeclineMessage m)
+			throws DbException, FormatException;
 
-    S onAbortMessage(Transaction txn, S session, AbortMessage m)
-            throws DbException, FormatException;
+	S onAuthMessage(Transaction txn, S session, MailboxAuthMessage m)
+			throws DbException, FormatException;
+
+	S onAbortMessage(Transaction txn, S session, AbortMessage m)
+			throws DbException, FormatException;
 
 }
-- 
GitLab