Add 'verified' flag to ContactAddedEvent.

This commit is contained in:
akwizgran
2019-05-27 11:40:28 +01:00
parent 677728b9ae
commit 14e604e21e
10 changed files with 35 additions and 57 deletions

View File

@@ -14,12 +14,18 @@ import javax.annotation.concurrent.Immutable;
public class ContactAddedEvent extends Event { public class ContactAddedEvent extends Event {
private final ContactId contactId; private final ContactId contactId;
private final boolean verified;
public ContactAddedEvent(ContactId contactId) { public ContactAddedEvent(ContactId contactId, boolean verified) {
this.contactId = contactId; this.contactId = contactId;
this.verified = verified;
} }
public ContactId getContactId() { public ContactId getContactId() {
return contactId; return contactId;
} }
public boolean isVerified() {
return verified;
}
} }

View File

@@ -1,22 +0,0 @@
package org.briarproject.bramble.api.contact.event;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class ContactAddedRemotelyEvent extends Event {
private final Contact contact;
public ContactAddedRemotelyEvent(Contact contact) {
this.contact = contact;
}
public Contact getContact() {
return contact;
}
}

View File

@@ -244,7 +244,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
if (db.containsContact(txn, remote.getId(), local)) if (db.containsContact(txn, remote.getId(), local))
throw new ContactExistsException(local, remote); throw new ContactExistsException(local, remote);
ContactId c = db.addContact(txn, remote, local, verified); ContactId c = db.addContact(txn, remote, local, verified);
transaction.attach(new ContactAddedEvent(c)); transaction.attach(new ContactAddedEvent(c, verified));
return c; return c;
} }
@@ -265,7 +265,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
ContactId c = db.addContact(txn, remote, local, verified); ContactId c = db.addContact(txn, remote, local, verified);
db.transferKeys(txn, p, c); db.transferKeys(txn, p, c);
db.removePendingContact(txn, p); db.removePendingContact(txn, p);
transaction.attach(new ContactAddedEvent(c)); transaction.attach(new ContactAddedEvent(c, verified));
transaction.attach(new PendingContactRemovedEvent(p)); transaction.attach(new PendingContactRemovedEvent(p));
return c; return c;
} }

View File

@@ -153,7 +153,7 @@ public class PollerImplTest extends BrambleMockTestCase {
will(returnValue(false)); will(returnValue(false));
}}); }});
poller.eventOccurred(new ContactAddedEvent(contactId)); poller.eventOccurred(new ContactAddedEvent(contactId, true));
} }
@Test @Test

View File

@@ -16,6 +16,7 @@ import android.support.v4.app.TaskStackBuilder;
import org.briarproject.bramble.api.Multiset; import org.briarproject.bramble.api.Multiset;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.event.EventListener; import org.briarproject.bramble.api.event.EventListener;
@@ -42,7 +43,6 @@ import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent; import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent; import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent; import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent; import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
import java.util.Set; import java.util.Set;
@@ -230,8 +230,10 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} else if (e instanceof BlogPostAddedEvent) { } else if (e instanceof BlogPostAddedEvent) {
BlogPostAddedEvent b = (BlogPostAddedEvent) e; BlogPostAddedEvent b = (BlogPostAddedEvent) e;
if (!b.isLocal()) showBlogPostNotification(b.getGroupId()); if (!b.isLocal()) showBlogPostNotification(b.getGroupId());
} else if (e instanceof ContactAddedRemotelyEvent) { } else if (e instanceof ContactAddedEvent) {
showContactAddedNotification(); ContactAddedEvent c = (ContactAddedEvent) e;
// Don't show notifications for contacts added in person
if (!c.isVerified()) showContactAddedNotification();
} }
} }

View File

@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.client.ContactGroupFactory; import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
import org.briarproject.bramble.api.crypto.KeyPair; import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.PrivateKey; import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey; import org.briarproject.bramble.api.crypto.PublicKey;
@@ -453,10 +452,6 @@ class IntroduceeProtocolEngine
//noinspection ConstantConditions //noinspection ConstantConditions
transportPropertyManager.addRemoteProperties(txn, c.getId(), transportPropertyManager.addRemoteProperties(txn, c.getId(),
s.getRemote().transportProperties); s.getRemote().transportProperties);
// Broadcast IntroductionSucceededEvent, because contact got added
ContactAddedRemotelyEvent e = new ContactAddedRemotelyEvent(c);
txn.attach(e);
} catch (ContactExistsException e) { } catch (ContactExistsException e) {
// Ignore this, because the other introducee might have deleted us. // Ignore this, because the other introducee might have deleted us.
// So we still want updated transport properties // So we still want updated transport properties

View File

@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry; import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList; import org.briarproject.bramble.api.data.BdfList;
@@ -32,7 +33,6 @@ import org.briarproject.briar.api.introduction.IntroductionResponse;
import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent; import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent; import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent; import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
import org.briarproject.briar.test.BriarIntegrationTest; import org.briarproject.briar.test.BriarIntegrationTest;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -1217,7 +1217,6 @@ public class IntroductionIntegrationTest
volatile boolean aborted = false; volatile boolean aborted = false;
volatile Event latestEvent; volatile Event latestEvent;
@SuppressWarnings("WeakerAccess")
IntroductionResponse getResponse() { IntroductionResponse getResponse() {
assertTrue( assertTrue(
latestEvent instanceof IntroductionResponseReceivedEvent); latestEvent instanceof IntroductionResponseReceivedEvent);
@@ -1273,12 +1272,11 @@ public class IntroductionIntegrationTest
// only broadcast for DECLINE messages in introducee role // only broadcast for DECLINE messages in introducee role
latestEvent = e; latestEvent = e;
eventWaiter.resume(); eventWaiter.resume();
} else if (e instanceof ContactAddedRemotelyEvent) { } else if (e instanceof ContactAddedEvent) {
latestEvent = e; latestEvent = e;
succeeded = true; succeeded = true;
Contact contact = ((ContactAddedRemotelyEvent) e).getContact(); ContactId contactId = ((ContactAddedEvent) e).getContactId();
eventWaiter eventWaiter.assertFalse(contactId.equals(contactId0From1));
.assertFalse(contact.getId().equals(contactId0From1));
eventWaiter.resume(); eventWaiter.resume();
} else if (e instanceof IntroductionAbortedEvent) { } else if (e instanceof IntroductionAbortedEvent) {
latestEvent = e; latestEvent = e;
@@ -1357,13 +1355,10 @@ public class IntroductionIntegrationTest
Message m = ch.getMessage(id); Message m = ch.getMessage(id);
BdfList body = ch.getMessageAsList(id); BdfList body = ch.getMessageAsList(id);
if (type == ACCEPT) { if (type == ACCEPT) {
//noinspection ConstantConditions
return c0.getMessageParser().parseAcceptMessage(m, body); return c0.getMessageParser().parseAcceptMessage(m, body);
} else if (type == DECLINE) { } else if (type == DECLINE) {
//noinspection ConstantConditions
return c0.getMessageParser().parseDeclineMessage(m, body); return c0.getMessageParser().parseDeclineMessage(m, body);
} else if (type == AUTH) { } else if (type == AUTH) {
//noinspection ConstantConditions
return c0.getMessageParser().parseAuthMessage(m, body); return c0.getMessageParser().parseAuthMessage(m, body);
} else throw new AssertionError("Not implemented"); } else throw new AssertionError("Not implemented");
} }

View File

@@ -7,7 +7,7 @@ import io.javalin.NotFoundResponse
import org.briarproject.bramble.api.contact.ContactManager import org.briarproject.bramble.api.contact.ContactManager
import org.briarproject.bramble.api.contact.HandshakeLinkConstants.LINK_REGEX import org.briarproject.bramble.api.contact.HandshakeLinkConstants.LINK_REGEX
import org.briarproject.bramble.api.contact.PendingContactId import org.briarproject.bramble.api.contact.PendingContactId
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent import org.briarproject.bramble.api.contact.event.ContactAddedEvent
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent
@@ -27,7 +27,7 @@ import javax.annotation.concurrent.Immutable
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
internal const val EVENT_CONTACT_ADDED_REMOTELY = "ContactAddedRemotelyEvent" internal const val EVENT_CONTACT_ADDED = "ContactAddedEvent"
internal const val EVENT_PENDING_CONTACT_STATE_CHANGED = "PendingContactStateChangedEvent" internal const val EVENT_PENDING_CONTACT_STATE_CHANGED = "PendingContactStateChangedEvent"
internal const val EVENT_PENDING_CONTACT_ADDED = "PendingContactAddedEvent" internal const val EVENT_PENDING_CONTACT_ADDED = "PendingContactAddedEvent"
internal const val EVENT_PENDING_CONTACT_REMOVED = "PendingContactRemovedEvent" internal const val EVENT_PENDING_CONTACT_REMOVED = "PendingContactRemovedEvent"
@@ -43,8 +43,8 @@ constructor(
) : ContactController, EventListener { ) : ContactController, EventListener {
override fun eventOccurred(e: Event) = when (e) { override fun eventOccurred(e: Event) = when (e) {
is ContactAddedRemotelyEvent -> { is ContactAddedEvent -> {
webSocket.sendEvent(EVENT_CONTACT_ADDED_REMOTELY, e.output()) webSocket.sendEvent(EVENT_CONTACT_ADDED, e.output())
} }
is PendingContactStateChangedEvent -> { is PendingContactStateChangedEvent -> {
webSocket.sendEvent(EVENT_PENDING_CONTACT_STATE_CHANGED, e.output()) webSocket.sendEvent(EVENT_PENDING_CONTACT_STATE_CHANGED, e.output())

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.headless.contact package org.briarproject.briar.headless.contact
import org.briarproject.bramble.api.contact.Contact import org.briarproject.bramble.api.contact.Contact
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent import org.briarproject.bramble.api.contact.event.ContactAddedEvent
import org.briarproject.bramble.identity.output import org.briarproject.bramble.identity.output
import org.briarproject.briar.headless.json.JsonDict import org.briarproject.briar.headless.json.JsonDict
@@ -14,6 +14,7 @@ internal fun Contact.output() = JsonDict(
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) } handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
} }
internal fun ContactAddedRemotelyEvent.output() = JsonDict( internal fun ContactAddedEvent.output() = JsonDict(
"contact" to contact.output() "contactId" to contactId.int,
"verified" to isVerified
) )

View File

@@ -13,7 +13,7 @@ import org.briarproject.bramble.api.contact.ContactId
import org.briarproject.bramble.api.contact.PendingContactId import org.briarproject.bramble.api.contact.PendingContactId
import org.briarproject.bramble.api.contact.PendingContactState.FAILED import org.briarproject.bramble.api.contact.PendingContactState.FAILED
import org.briarproject.bramble.api.contact.PendingContactState.WAITING_FOR_CONNECTION import org.briarproject.bramble.api.contact.PendingContactState.WAITING_FOR_CONNECTION
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent import org.briarproject.bramble.api.contact.event.ContactAddedEvent
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent
@@ -207,12 +207,12 @@ internal class ContactControllerTest : ControllerTest() {
} }
@Test @Test
fun testContactAddedRemotelyEvent() { fun testContactAddedEvent() {
val event = ContactAddedRemotelyEvent(contact) val event = ContactAddedEvent(contact.id, contact.isVerified)
every { every {
webSocketController.sendEvent( webSocketController.sendEvent(
EVENT_CONTACT_ADDED_REMOTELY, EVENT_CONTACT_ADDED,
event.output() event.output()
) )
} just runs } just runs
@@ -291,11 +291,12 @@ internal class ContactControllerTest : ControllerTest() {
} }
@Test @Test
fun testOutputContactAddedRemotelyEvent() { fun testOutputContactAddedEvent() {
val event = ContactAddedRemotelyEvent(contact) val event = ContactAddedEvent(contact.id, contact.isVerified)
val json = """ val json = """
{ {
"contact": ${toJson(contact.output())} "contactId": ${contact.id.int},
"verified": ${contact.isVerified}
} }
""" """
assertJsonEquals(json, event.output()) assertJsonEquals(json, event.output())