mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Move introduction role into IntroductionResponse
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.briar.api.messaging;
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.bramble.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.Nameable;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
|
|||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class Author {
|
public class Author implements Nameable {
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
NONE, ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES
|
NONE, ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ abstract class ConversationItem {
|
|||||||
if (ir.wasAccepted()) {
|
if (ir.wasAccepted()) {
|
||||||
res = R.string.introduction_response_accepted_received;
|
res = R.string.introduction_response_accepted_received;
|
||||||
} else {
|
} else {
|
||||||
if (ir.getNameable().isIntroducer()) {
|
if (ir.isIntroducer()) {
|
||||||
res = R.string.introduction_response_declined_received;
|
res = R.string.introduction_response_declined_received;
|
||||||
} else {
|
} else {
|
||||||
res =
|
res =
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package org.briarproject.briar.api.introduction;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.briar.api.messaging.Nameable;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
|
||||||
|
|
||||||
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
@NotNullByDefault
|
|
||||||
public class Introduction implements Nameable {
|
|
||||||
|
|
||||||
private final Author introducedAuthor;
|
|
||||||
private final Role ourRole;
|
|
||||||
|
|
||||||
public Introduction(Author introducedAuthor, Role ourRole) {
|
|
||||||
this.introducedAuthor = introducedAuthor;
|
|
||||||
this.ourRole = ourRole;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return introducedAuthor.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIntroducer() {
|
|
||||||
return ourRole == INTRODUCER;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.api.introduction;
|
package org.briarproject.briar.api.introduction;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
@@ -11,16 +12,16 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class IntroductionRequest extends PrivateRequest<Introduction> {
|
public class IntroductionRequest extends PrivateRequest<Author> {
|
||||||
|
|
||||||
private final boolean contact;
|
private final boolean contact;
|
||||||
|
|
||||||
public IntroductionRequest(MessageId messageId, GroupId groupId,
|
public IntroductionRequest(MessageId messageId, GroupId groupId,
|
||||||
long time, boolean local, boolean sent, boolean seen, boolean read,
|
long time, boolean local, boolean sent, boolean seen, boolean read,
|
||||||
SessionId sessionId, Introduction introduction,
|
SessionId sessionId, Author author, @Nullable String message,
|
||||||
@Nullable String message, boolean answered, boolean contact) {
|
boolean answered, boolean contact) {
|
||||||
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
||||||
introduction, message, answered);
|
author, message, answered);
|
||||||
this.contact = contact;
|
this.contact = contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.api.introduction;
|
package org.briarproject.briar.api.introduction;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
@@ -8,15 +9,24 @@ import org.briarproject.briar.api.messaging.PrivateResponse;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class IntroductionResponse extends PrivateResponse<Introduction> {
|
public class IntroductionResponse extends PrivateResponse<Author> {
|
||||||
|
|
||||||
|
private final Role ourRole;
|
||||||
|
|
||||||
public IntroductionResponse(MessageId messageId, GroupId groupId, long time,
|
public IntroductionResponse(MessageId messageId, GroupId groupId, long time,
|
||||||
boolean local, boolean sent, boolean seen, boolean read,
|
boolean local, boolean sent, boolean seen, boolean read,
|
||||||
SessionId sessionId, Introduction introduction, boolean accepted) {
|
SessionId sessionId, Author author, boolean accepted, Role role) {
|
||||||
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
||||||
introduction, accepted);
|
author, accepted);
|
||||||
|
this.ourRole = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIntroducer() {
|
||||||
|
return ourRole == INTRODUCER;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.api.messaging;
|
package org.briarproject.briar.api.messaging;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.Nameable;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.api.messaging;
|
package org.briarproject.briar.api.messaging;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.Nameable;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.briarproject.briar.api.sharing;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.briar.api.messaging.Nameable;
|
import org.briarproject.bramble.api.Nameable;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface Shareable extends Nameable {
|
public interface Shareable extends Nameable {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.introduction.Introduction;
|
|
||||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||||
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
|
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
|
||||||
|
|
||||||
@@ -148,14 +147,13 @@ abstract class AbstractProtocolEngine<S extends Session>
|
|||||||
void broadcastIntroductionResponseReceivedEvent(Transaction txn, Session s,
|
void broadcastIntroductionResponseReceivedEvent(Transaction txn, Session s,
|
||||||
AuthorId sender, Author otherAuthor, AbstractIntroductionMessage m)
|
AuthorId sender, Author otherAuthor, AbstractIntroductionMessage m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
Introduction introduction = new Introduction(otherAuthor, s.getRole());
|
|
||||||
AuthorId localAuthorId = identityManager.getLocalAuthor(txn).getId();
|
AuthorId localAuthorId = identityManager.getLocalAuthor(txn).getId();
|
||||||
Contact c = contactManager.getContact(txn, sender, localAuthorId);
|
Contact c = contactManager.getContact(txn, sender, localAuthorId);
|
||||||
IntroductionResponse response =
|
IntroductionResponse response =
|
||||||
new IntroductionResponse(m.getMessageId(), m.getGroupId(),
|
new IntroductionResponse(m.getMessageId(), m.getGroupId(),
|
||||||
m.getTimestamp(), false, false, false, false,
|
m.getTimestamp(), false, false, false, false,
|
||||||
s.getSessionId(), introduction,
|
s.getSessionId(), otherAuthor,
|
||||||
m instanceof AcceptMessage);
|
m instanceof AcceptMessage, s.getRole());
|
||||||
IntroductionResponseReceivedEvent e =
|
IntroductionResponseReceivedEvent e =
|
||||||
new IntroductionResponseReceivedEvent(response, c.getId());
|
new IntroductionResponseReceivedEvent(response, c.getId());
|
||||||
txn.attach(e);
|
txn.attach(e);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.briarproject.bramble.api.transport.KeySetId;
|
|||||||
import org.briarproject.briar.api.client.MessageTracker;
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.introduction.Introduction;
|
|
||||||
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||||
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;
|
||||||
@@ -255,11 +254,9 @@ class IntroduceeProtocolEngine
|
|||||||
localAuthor.getId());
|
localAuthor.getId());
|
||||||
boolean contactExists = contactManager
|
boolean contactExists = contactManager
|
||||||
.contactExists(txn, m.getAuthor().getId(), localAuthor.getId());
|
.contactExists(txn, m.getAuthor().getId(), localAuthor.getId());
|
||||||
Introduction introduction =
|
|
||||||
new Introduction(m.getAuthor(), s.getRole());
|
|
||||||
IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
|
IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
|
||||||
m.getGroupId(), m.getTimestamp(), false, false, false, false,
|
m.getGroupId(), m.getTimestamp(), false, false, false, false,
|
||||||
s.getSessionId(), introduction, m.getMessage(), false,
|
s.getSessionId(), m.getAuthor(), m.getMessage(), false,
|
||||||
contactExists);
|
contactExists);
|
||||||
IntroductionRequestReceivedEvent e =
|
IntroductionRequestReceivedEvent e =
|
||||||
new IntroductionRequestReceivedEvent(request, c.getId());
|
new IntroductionRequestReceivedEvent(request, c.getId());
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
|||||||
import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVersioningHook;
|
import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVersioningHook;
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.introduction.Introduction;
|
|
||||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||||
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||||
@@ -467,10 +466,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
boolean contactExists = contactManager
|
boolean contactExists = contactManager
|
||||||
.contactExists(txn, rm.getAuthor().getId(),
|
.contactExists(txn, rm.getAuthor().getId(),
|
||||||
localAuthor.getId());
|
localAuthor.getId());
|
||||||
Introduction introduction = new Introduction(author, role);
|
|
||||||
return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(),
|
return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(),
|
||||||
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
|
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
|
||||||
sessionId, introduction, message, !meta.isAvailableToAnswer(),
|
sessionId, author, message, !meta.isAvailableToAnswer(),
|
||||||
contactExists);
|
contactExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,10 +493,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
sessionId = session.getSessionId();
|
sessionId = session.getSessionId();
|
||||||
author = session.getRemote().author;
|
author = session.getRemote().author;
|
||||||
} else throw new AssertionError();
|
} else throw new AssertionError();
|
||||||
Introduction introduction = new Introduction(author, role);
|
|
||||||
return new IntroductionResponse(m, contactGroupId, meta.getTimestamp(),
|
return new IntroductionResponse(m, contactGroupId, meta.getTimestamp(),
|
||||||
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
|
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
|
||||||
sessionId, introduction, accept);
|
sessionId, author, accept, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeSessionWithIntroducer(Transaction txn,
|
private void removeSessionWithIntroducer(Transaction txn,
|
||||||
|
|||||||
@@ -24,16 +24,14 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.introduction.Introduction;
|
|
||||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||||
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||||
|
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.briar.api.introduction.event.IntroductionSucceededEvent;
|
import org.briarproject.briar.api.introduction.event.IntroductionSucceededEvent;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
|
||||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
|
||||||
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;
|
||||||
@@ -1148,7 +1146,7 @@ public class IntroductionIntegrationTest
|
|||||||
protected volatile Event latestEvent;
|
protected volatile Event latestEvent;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
PrivateResponse<Introduction> getResponse() {
|
IntroductionResponse getResponse() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
latestEvent instanceof IntroductionResponseReceivedEvent);
|
latestEvent instanceof IntroductionResponseReceivedEvent);
|
||||||
return ((IntroductionResponseReceivedEvent) latestEvent)
|
return ((IntroductionResponseReceivedEvent) latestEvent)
|
||||||
@@ -1180,7 +1178,7 @@ public class IntroductionIntegrationTest
|
|||||||
IntroductionRequestReceivedEvent introEvent =
|
IntroductionRequestReceivedEvent introEvent =
|
||||||
((IntroductionRequestReceivedEvent) e);
|
((IntroductionRequestReceivedEvent) e);
|
||||||
requestReceived = true;
|
requestReceived = true;
|
||||||
PrivateRequest<Introduction> ir = introEvent.getMessageHeader();
|
IntroductionRequest ir = introEvent.getMessageHeader();
|
||||||
ContactId contactId = introEvent.getContactId();
|
ContactId contactId = introEvent.getContactId();
|
||||||
sessionId = ir.getSessionId();
|
sessionId = ir.getSessionId();
|
||||||
long time = clock.currentTimeMillis();
|
long time = clock.currentTimeMillis();
|
||||||
@@ -1217,7 +1215,7 @@ public class IntroductionIntegrationTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PrivateRequest<Introduction> getRequest() {
|
private IntroductionRequest getRequest() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
latestEvent instanceof IntroductionRequestReceivedEvent);
|
latestEvent instanceof IntroductionRequestReceivedEvent);
|
||||||
return ((IntroductionRequestReceivedEvent) latestEvent)
|
return ((IntroductionRequestReceivedEvent) latestEvent)
|
||||||
|
|||||||
Reference in New Issue
Block a user