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);