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 {
private final ContactId contactId;
private final boolean verified;
public ContactAddedEvent(ContactId contactId) {
public ContactAddedEvent(ContactId contactId, boolean verified) {
this.contactId = contactId;
this.verified = verified;
}
public ContactId getContactId() {
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))
throw new ContactExistsException(local, remote);
ContactId c = db.addContact(txn, remote, local, verified);
transaction.attach(new ContactAddedEvent(c));
transaction.attach(new ContactAddedEvent(c, verified));
return c;
}
@@ -265,7 +265,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
ContactId c = db.addContact(txn, remote, local, verified);
db.transferKeys(txn, p, c);
db.removePendingContact(txn, p);
transaction.attach(new ContactAddedEvent(c));
transaction.attach(new ContactAddedEvent(c, verified));
transaction.attach(new PendingContactRemovedEvent(p));
return c;
}

View File

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

View File

@@ -16,6 +16,7 @@ import android.support.v4.app.TaskStackBuilder;
import org.briarproject.bramble.api.Multiset;
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.event.Event;
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.conversation.event.ConversationMessageReceivedEvent;
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 java.util.Set;
@@ -230,8 +230,10 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} else if (e instanceof BlogPostAddedEvent) {
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
if (!b.isLocal()) showBlogPostNotification(b.getGroupId());
} else if (e instanceof ContactAddedRemotelyEvent) {
showContactAddedNotification();
} else if (e instanceof ContactAddedEvent) {
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.contact.Contact;
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.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey;
@@ -453,10 +452,6 @@ class IntroduceeProtocolEngine
//noinspection ConstantConditions
transportPropertyManager.addRemoteProperties(txn, c.getId(),
s.getRemote().transportProperties);
// Broadcast IntroductionSucceededEvent, because contact got added
ContactAddedRemotelyEvent e = new ContactAddedRemotelyEvent(c);
txn.attach(e);
} catch (ContactExistsException e) {
// Ignore this, because the other introducee might have deleted us.
// 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.contact.Contact;
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.BdfEntry;
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.IntroductionRequestReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
import org.briarproject.briar.test.BriarIntegrationTest;
import org.junit.Before;
import org.junit.Test;
@@ -1217,7 +1217,6 @@ public class IntroductionIntegrationTest
volatile boolean aborted = false;
volatile Event latestEvent;
@SuppressWarnings("WeakerAccess")
IntroductionResponse getResponse() {
assertTrue(
latestEvent instanceof IntroductionResponseReceivedEvent);
@@ -1273,12 +1272,11 @@ public class IntroductionIntegrationTest
// only broadcast for DECLINE messages in introducee role
latestEvent = e;
eventWaiter.resume();
} else if (e instanceof ContactAddedRemotelyEvent) {
} else if (e instanceof ContactAddedEvent) {
latestEvent = e;
succeeded = true;
Contact contact = ((ContactAddedRemotelyEvent) e).getContact();
eventWaiter
.assertFalse(contact.getId().equals(contactId0From1));
ContactId contactId = ((ContactAddedEvent) e).getContactId();
eventWaiter.assertFalse(contactId.equals(contactId0From1));
eventWaiter.resume();
} else if (e instanceof IntroductionAbortedEvent) {
latestEvent = e;
@@ -1357,13 +1355,10 @@ public class IntroductionIntegrationTest
Message m = ch.getMessage(id);
BdfList body = ch.getMessageAsList(id);
if (type == ACCEPT) {
//noinspection ConstantConditions
return c0.getMessageParser().parseAcceptMessage(m, body);
} else if (type == DECLINE) {
//noinspection ConstantConditions
return c0.getMessageParser().parseDeclineMessage(m, body);
} else if (type == AUTH) {
//noinspection ConstantConditions
return c0.getMessageParser().parseAuthMessage(m, body);
} 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.HandshakeLinkConstants.LINK_REGEX
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.PendingContactRemovedEvent
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent
@@ -27,7 +27,7 @@ import javax.annotation.concurrent.Immutable
import javax.inject.Inject
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_ADDED = "PendingContactAddedEvent"
internal const val EVENT_PENDING_CONTACT_REMOVED = "PendingContactRemovedEvent"
@@ -43,8 +43,8 @@ constructor(
) : ContactController, EventListener {
override fun eventOccurred(e: Event) = when (e) {
is ContactAddedRemotelyEvent -> {
webSocket.sendEvent(EVENT_CONTACT_ADDED_REMOTELY, e.output())
is ContactAddedEvent -> {
webSocket.sendEvent(EVENT_CONTACT_ADDED, e.output())
}
is PendingContactStateChangedEvent -> {
webSocket.sendEvent(EVENT_PENDING_CONTACT_STATE_CHANGED, e.output())

View File

@@ -1,7 +1,7 @@
package org.briarproject.briar.headless.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.briar.headless.json.JsonDict
@@ -14,6 +14,7 @@ internal fun Contact.output() = JsonDict(
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
}
internal fun ContactAddedRemotelyEvent.output() = JsonDict(
"contact" to contact.output()
internal fun ContactAddedEvent.output() = JsonDict(
"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.PendingContactState.FAILED
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.PendingContactRemovedEvent
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent
@@ -207,12 +207,12 @@ internal class ContactControllerTest : ControllerTest() {
}
@Test
fun testContactAddedRemotelyEvent() {
val event = ContactAddedRemotelyEvent(contact)
fun testContactAddedEvent() {
val event = ContactAddedEvent(contact.id, contact.isVerified)
every {
webSocketController.sendEvent(
EVENT_CONTACT_ADDED_REMOTELY,
EVENT_CONTACT_ADDED,
event.output()
)
} just runs
@@ -291,11 +291,12 @@ internal class ContactControllerTest : ControllerTest() {
}
@Test
fun testOutputContactAddedRemotelyEvent() {
val event = ContactAddedRemotelyEvent(contact)
fun testOutputContactAddedEvent() {
val event = ContactAddedEvent(contact.id, contact.isVerified)
val json = """
{
"contact": ${toJson(contact.output())}
"contactId": ${contact.id.int},
"verified": ${contact.isVerified}
}
"""
assertJsonEquals(json, event.output())