diff --git a/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java b/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java index 74e977ac34b505e49438ec2c1491aecf28908b1d..1031f3c10d29368749f9ec0f8b35802004301bd7 100644 --- a/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java +++ b/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java @@ -260,17 +260,15 @@ class ForumSharingManagerImpl extends BdfIncomingMessageHook SharerSessionState localState = initializeSharerState(txn, f, contactId); - // define action - BdfDictionary localAction = new BdfDictionary(); - localAction.put(TYPE, SHARE_MSG_TYPE_INVITATION); + // add invitation message to local state to be available for engine if (!StringUtils.isNullOrEmpty(msg)) { - localAction.put(INVITATION_MSG, msg); + localState.setMessage(msg); } // start engine and process its state update SharerEngine engine = new SharerEngine(); processSharerStateUpdate(txn, null, - engine.onLocalAction(localState, localAction)); + engine.onLocalAction(localState, Action.LOCAL_INVITATION)); txn.setComplete(); } catch (FormatException e) { @@ -290,11 +288,11 @@ class ForumSharingManagerImpl extends BdfIncomingMessageHook InviteeSessionState localState = getSessionStateForResponse(txn, f); // define action - BdfDictionary localAction = new BdfDictionary(); + InviteeSessionState.Action localAction; if (accept) { - localAction.put(TYPE, SHARE_MSG_TYPE_ACCEPT); + localAction = InviteeSessionState.Action.LOCAL_ACCEPT; } else { - localAction.put(TYPE, SHARE_MSG_TYPE_DECLINE); + localAction = InviteeSessionState.Action.LOCAL_DECLINE; } // start engine and process its state update @@ -812,13 +810,14 @@ class ForumSharingManagerImpl extends BdfIncomingMessageHook throws DbException, FormatException { ForumSharingSessionState state = getSessionStateForLeaving(txn, f, c); - BdfDictionary action = new BdfDictionary(); - action.put(TYPE, SHARE_MSG_TYPE_LEAVE); if (state instanceof SharerSessionState) { + Action action = Action.LOCAL_LEAVE; SharerEngine engine = new SharerEngine(); processSharerStateUpdate(txn, null, engine.onLocalAction((SharerSessionState) state, action)); } else { + InviteeSessionState.Action action = + InviteeSessionState.Action.LOCAL_LEAVE; InviteeEngine engine = new InviteeEngine(forumFactory); processInviteeStateUpdate(txn, null, engine.onLocalAction((InviteeSessionState) state, action)); diff --git a/briar-core/src/org/briarproject/forum/InviteeEngine.java b/briar-core/src/org/briarproject/forum/InviteeEngine.java index 81d4cf766025797813049005487e0e14072e4b5a..3a18581a83064834c22569dff21095d383e0813f 100644 --- a/briar-core/src/org/briarproject/forum/InviteeEngine.java +++ b/briar-core/src/org/briarproject/forum/InviteeEngine.java @@ -42,7 +42,7 @@ import static org.briarproject.forum.InviteeSessionState.State.FINISHED; import static org.briarproject.forum.InviteeSessionState.State.LEFT; public class InviteeEngine - implements ProtocolEngine<BdfDictionary, InviteeSessionState, BdfDictionary> { + implements ProtocolEngine<Action, InviteeSessionState, BdfDictionary> { private final ForumFactory forumFactory; private static final Logger LOG = @@ -54,12 +54,10 @@ public class InviteeEngine @Override public StateUpdate<InviteeSessionState, BdfDictionary> onLocalAction( - InviteeSessionState localState, BdfDictionary localAction) { + InviteeSessionState localState, Action action) { try { State currentState = localState.getState(); - long type = localAction.getLong(TYPE); - Action action = Action.getLocal(type); State nextState = currentState.next(action); localState.setState(nextState); diff --git a/briar-core/src/org/briarproject/forum/InviteeSessionState.java b/briar-core/src/org/briarproject/forum/InviteeSessionState.java index cc4e1c40401b6970add1231e57be46f4067188af..68b397bc726767ecc15b52f72526425470908725 100644 --- a/briar-core/src/org/briarproject/forum/InviteeSessionState.java +++ b/briar-core/src/org/briarproject/forum/InviteeSessionState.java @@ -8,8 +8,6 @@ import org.briarproject.api.sync.MessageId; import static org.briarproject.api.forum.ForumConstants.IS_SHARER; import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_ABORT; -import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_ACCEPT; -import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_DECLINE; import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_INVITATION; import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_LEAVE; import static org.briarproject.api.forum.ForumConstants.STATE; @@ -111,14 +109,6 @@ public class InviteeSessionState extends ForumSharingSessionState { REMOTE_LEAVE, REMOTE_ABORT; - public static Action getLocal(long type) { - if (type == SHARE_MSG_TYPE_ACCEPT) return LOCAL_ACCEPT; - if (type == SHARE_MSG_TYPE_DECLINE) return LOCAL_DECLINE; - if (type == SHARE_MSG_TYPE_LEAVE) return LOCAL_LEAVE; - if (type == SHARE_MSG_TYPE_ABORT) return LOCAL_ABORT; - return null; - } - public static Action getRemote(long type) { if (type == SHARE_MSG_TYPE_INVITATION) return REMOTE_INVITATION; if (type == SHARE_MSG_TYPE_LEAVE) return REMOTE_LEAVE; diff --git a/briar-core/src/org/briarproject/forum/SharerEngine.java b/briar-core/src/org/briarproject/forum/SharerEngine.java index 3e81470ae4812b2956bf31cbb8d91072023ae179..a60437c5ebfb8949e6cf5b9dfb12f640a93d2ab1 100644 --- a/briar-core/src/org/briarproject/forum/SharerEngine.java +++ b/briar-core/src/org/briarproject/forum/SharerEngine.java @@ -42,19 +42,17 @@ import static org.briarproject.forum.SharerSessionState.State.FINISHED; import static org.briarproject.forum.SharerSessionState.State.LEFT; public class SharerEngine - implements ProtocolEngine<BdfDictionary, SharerSessionState, BdfDictionary> { + implements ProtocolEngine<Action, SharerSessionState, BdfDictionary> { private static final Logger LOG = Logger.getLogger(SharerEngine.class.getName()); @Override public StateUpdate<SharerSessionState, BdfDictionary> onLocalAction( - SharerSessionState localState, BdfDictionary localAction) { + SharerSessionState localState, Action action) { try { State currentState = localState.getState(); - long type = localAction.getLong(TYPE); - Action action = Action.getLocal(type); State nextState = currentState.next(action); localState.setState(nextState); @@ -79,9 +77,8 @@ public class SharerEngine msg.put(GROUP_ID, localState.getGroupId()); msg.put(FORUM_NAME, localState.getForumName()); msg.put(FORUM_SALT, localState.getForumSalt()); - if (localAction.containsKey(INVITATION_MSG)) { - msg.put(INVITATION_MSG, - localAction.getString(INVITATION_MSG)); + if (localState.getMessage() != null) { + msg.put(INVITATION_MSG, localState.getMessage()); } messages = Collections.singletonList(msg); logLocalAction(currentState, nextState, msg); diff --git a/briar-core/src/org/briarproject/forum/SharerSessionState.java b/briar-core/src/org/briarproject/forum/SharerSessionState.java index b438c673459d05ef7ebd602ff4a44fc924742c69..6653648530e7e07a830ec50e5381f75e5a9c6e84 100644 --- a/briar-core/src/org/briarproject/forum/SharerSessionState.java +++ b/briar-core/src/org/briarproject/forum/SharerSessionState.java @@ -10,7 +10,6 @@ import static org.briarproject.api.forum.ForumConstants.IS_SHARER; import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_ABORT; import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_ACCEPT; import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_DECLINE; -import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_INVITATION; import static org.briarproject.api.forum.ForumConstants.SHARE_MSG_TYPE_LEAVE; import static org.briarproject.api.forum.ForumConstants.STATE; import static org.briarproject.forum.SharerSessionState.Action.LOCAL_INVITATION; @@ -23,6 +22,7 @@ import static org.briarproject.forum.SharerSessionState.Action.REMOTE_LEAVE; public class SharerSessionState extends ForumSharingSessionState { private State state; + private String msg = null; public SharerSessionState(SessionId sessionId, MessageId storageId, GroupId groupId, State state, ContactId contactId, GroupId forumId, @@ -48,6 +48,14 @@ public class SharerSessionState extends ForumSharingSessionState { return state; } + public void setMessage(String msg) { + this.msg = msg; + } + + public String getMessage() { + return this.msg; + } + public enum State { ERROR(0), PREPARE_INVITATION(1) { @@ -111,13 +119,6 @@ public class SharerSessionState extends ForumSharingSessionState { REMOTE_LEAVE, REMOTE_ABORT; - public static Action getLocal(long type) { - if (type == SHARE_MSG_TYPE_INVITATION) return LOCAL_INVITATION; - if (type == SHARE_MSG_TYPE_LEAVE) return LOCAL_LEAVE; - if (type == SHARE_MSG_TYPE_ABORT) return LOCAL_ABORT; - return null; - } - public static Action getRemote(long type) { if (type == SHARE_MSG_TYPE_ACCEPT) return REMOTE_ACCEPT; if (type == SHARE_MSG_TYPE_DECLINE) return REMOTE_DECLINE;