Merge branch '1281-introduction-bug' into 'master'

Introduction: Reset session information for removed introducees

Closes #1281

See merge request akwizgran/briar!813
This commit is contained in:
akwizgran
2018-05-22 09:09:13 +00:00
4 changed files with 70 additions and 4 deletions

View File

@@ -92,9 +92,27 @@ class IntroducerProtocolEngine
throw new UnsupportedOperationException(); // Invalid in this role throw new UnsupportedOperationException(); // Invalid in this role
} }
IntroducerSession onAbortAction(Transaction txn, IntroducerSession s) IntroducerSession onIntroduceeRemoved(Transaction txn,
Introducee remainingIntroducee, IntroducerSession session)
throws DbException { throws DbException {
return abort(txn, s); // abort session
IntroducerSession s = abort(txn, session);
// reset information for introducee that was removed
Introducee introduceeA, introduceeB;
if (remainingIntroducee.author.equals(s.getIntroduceeA().author)) {
introduceeA = s.getIntroduceeA();
introduceeB =
new Introducee(s.getSessionId(), s.getIntroduceeB().groupId,
s.getIntroduceeB().author);
} else if (remainingIntroducee.author
.equals(s.getIntroduceeB().author)) {
introduceeA =
new Introducee(s.getSessionId(), s.getIntroduceeA().groupId,
s.getIntroduceeA().author);
introduceeB = s.getIntroduceeB();
} else throw new DbException();
return new IntroducerSession(s.getSessionId(), s.getState(),
s.getRequestTimestamp(), introduceeA, introduceeB);
} }
@Override @Override

View File

@@ -79,7 +79,7 @@ class IntroducerSession extends Session<IntroducerState> {
i.lastLocalMessageId, remoteMessageId); i.lastLocalMessageId, remoteMessageId);
} }
private Introducee(SessionId sessionId, GroupId groupId, Introducee(SessionId sessionId, GroupId groupId,
Author author) { Author author) {
this(sessionId, groupId, author, -1, null, null); this(sessionId, groupId, author, -1, null, null);
} }

View File

@@ -555,7 +555,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
IntroducerSession s, MessageId storageId, Introducee i, IntroducerSession s, MessageId storageId, Introducee i,
LocalAuthor localAuthor) throws DbException { LocalAuthor localAuthor) throws DbException {
if (db.containsContact(txn, i.author.getId(), localAuthor.getId())) { if (db.containsContact(txn, i.author.getId(), localAuthor.getId())) {
IntroducerSession session = introducerEngine.onAbortAction(txn, s); IntroducerSession session =
introducerEngine.onIntroduceeRemoved(txn, i, s);
storeSession(txn, storageId, session); storeSession(txn, storageId, session);
} else { } else {
db.removeMessage(txn, storageId); db.removeMessage(txn, storageId);

View File

@@ -44,6 +44,7 @@ import java.util.concurrent.TimeoutException;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.test.TestPluginConfigModule.TRANSPORT_ID; import static org.briarproject.bramble.test.TestPluginConfigModule.TRANSPORT_ID;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTransportProperties; import static org.briarproject.bramble.test.TestUtils.getTransportProperties;
import static org.briarproject.bramble.test.TestUtils.getTransportPropertiesMap; import static org.briarproject.bramble.test.TestUtils.getTransportPropertiesMap;
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID; import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
@@ -918,6 +919,51 @@ public class IntroductionIntegrationTest
.getMessageMetadataAsDictionary(group0.getId()).size()); .getMessageMetadataAsDictionary(group0.getId()).size());
} }
@Test
public void testIntroductionAfterReAddingContacts() throws Exception {
// make introduction
long time = clock.currentTimeMillis();
introductionManager0
.makeIntroduction(contact1From0, contact2From0, null, time);
// 0 and 1 remove and re-add each other
contactManager0.removeContact(contactId1From0);
contactManager1.removeContact(contactId0From1);
contactId1From0 = contactManager0
.addContact(author1, author0.getId(), getSecretKey(),
clock.currentTimeMillis(), true, true, true);
contact1From0 = contactManager0.getContact(contactId1From0);
contactId0From1 = contactManager1
.addContact(author0, author1.getId(), getSecretKey(),
clock.currentTimeMillis(), true, true, true);
contact0From1 = contactManager1.getContact(contactId0From1);
// Sync initial client versioning updates and transport properties
sync0To1(1, true);
sync1To0(1, true);
sync0To1(2, true);
sync1To0(1, true);
// a new introduction should be possible
assertTrue(introductionManager0
.canIntroduce(contact1From0, contact2From0));
// listen to events, so we don't miss new request
addListeners(true, true);
// make new introduction
time = clock.currentTimeMillis();
introductionManager0
.makeIntroduction(contact1From0, contact2From0, null, time);
// introduction should sync and not be INVALID or PENDING
sync0To1(1, true);
// assert that new request was received
eventWaiter.await(TIMEOUT, 1);
assertTrue(listener1.requestReceived);
}
private void testModifiedResponse(StateVisitor visitor) private void testModifiedResponse(StateVisitor visitor)
throws Exception { throws Exception {
addListeners(true, true); addListeners(true, true);
@@ -1099,6 +1145,7 @@ public class IntroductionIntegrationTest
protected volatile boolean aborted = false; protected volatile boolean aborted = false;
protected volatile Event latestEvent; protected volatile Event latestEvent;
@SuppressWarnings("WeakerAccess")
IntroductionResponse getResponse() { IntroductionResponse getResponse() {
assertTrue( assertTrue(
latestEvent instanceof IntroductionResponseReceivedEvent); latestEvent instanceof IntroductionResponseReceivedEvent);