From 3b4a92f66c03ca72d4083772e7924144eef2b607 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 26 Mar 2019 15:59:26 -0300 Subject: [PATCH] Fix introduction after one was declined When we received a remote decline we always went into the REMOTE_DECLINED state while there's two cases where we need to go into the START state instead. So when the new request arrived, we weren't in START and thus aborted the protocol. This commit fixes this. Fixes #1516 --- .../IntroduceeProtocolEngine.java | 11 +++-- .../IntroductionIntegrationTest.java | 45 +++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java index 68a0a8d41..995c64b99 100644 --- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java +++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java @@ -365,10 +365,13 @@ class IntroduceeProtocolEngine broadcastIntroductionResponseReceivedEvent(txn, s, s.getIntroducer().getId(), s.getRemote().author, m); - // Move to REMOTE_DECLINED state - return IntroduceeSession.clear(s, REMOTE_DECLINED, - s.getLastLocalMessageId(), s.getLocalTimestamp(), - m.getMessageId()); + // Determine next state + IntroduceeState state = + s.getState() == AWAIT_RESPONSES ? REMOTE_DECLINED : START; + + // Move to the next state + return IntroduceeSession.clear(s, state, s.getLastLocalMessageId(), + s.getLocalTimestamp(), m.getMessageId()); } private IntroduceeSession onRemoteResponseWhenDeclined(Transaction txn, diff --git a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java index fe48ba387..eafd3db73 100644 --- a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java @@ -405,6 +405,51 @@ public class IntroductionIntegrationTest assertFalse(listener2.aborted); } + @Test + public void testNewIntroductionAfterDecline() throws Exception { + addListeners(false, true); + + // make introduction + long time = clock.currentTimeMillis(); + introductionManager0 + .makeIntroduction(contact1From0, contact2From0, null, time); + + // sync request messages + sync0To1(1, true); + sync0To2(1, true); + eventWaiter.await(TIMEOUT, 2); + + // sync first response + sync1To0(1, true); + eventWaiter.await(TIMEOUT, 1); + + // sync second response + sync2To0(1, true); + eventWaiter.await(TIMEOUT, 1); + + // sync both forwarded response + sync0To2(1, true); + sync0To1(1, true); + eventWaiter.await(TIMEOUT, 1); + + assertFalse(listener0.aborted); + assertFalse(listener1.aborted); + assertFalse(listener2.aborted); + + time = clock.currentTimeMillis(); + introductionManager0 + .makeIntroduction(contact1From0, contact2From0, null, time); + + // sync request messages + sync0To1(1, true); + sync0To2(1, true); + eventWaiter.await(TIMEOUT, 2); + + assertFalse(listener0.aborted); + assertFalse(listener1.aborted); + assertFalse(listener2.aborted); + } + @Test public void testResponseAndAuthInOneSync() throws Exception { addListeners(true, true);