Commit d430b4fd authored by Torsten Grote's avatar Torsten Grote

Move introduction role into IntroductionResponse

parent fcf7cf72
package org.briarproject.briar.api.messaging;
package org.briarproject.bramble.api;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
......
package org.briarproject.bramble.api.identity;
import org.briarproject.bramble.api.Nameable;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.util.StringUtils;
......@@ -13,7 +14,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
*/
@Immutable
@NotNullByDefault
public class Author {
public class Author implements Nameable {
public enum Status {
NONE, ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES
......
......@@ -183,7 +183,7 @@ abstract class ConversationItem {
if (ir.wasAccepted()) {
res = R.string.introduction_response_accepted_received;
} else {
if (ir.getNameable().isIntroducer()) {
if (ir.isIntroducer()) {
res = R.string.introduction_response_declined_received;
} else {
res =
......
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;
}
}
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.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -11,16 +12,16 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class IntroductionRequest extends PrivateRequest<Introduction> {
public class IntroductionRequest extends PrivateRequest<Author> {
private final boolean contact;
public IntroductionRequest(MessageId messageId, GroupId groupId,
long time, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, Introduction introduction,
@Nullable String message, boolean answered, boolean contact) {
SessionId sessionId, Author author, @Nullable String message,
boolean answered, boolean contact) {
super(messageId, groupId, time, local, sent, seen, read, sessionId,
introduction, message, answered);
author, message, answered);
this.contact = contact;
}
......
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.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -8,15 +9,24 @@ import org.briarproject.briar.api.messaging.PrivateResponse;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
@Immutable
@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,
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,
introduction, accepted);
author, accepted);
this.ourRole = role;
}
public boolean isIntroducer() {
return ourRole == INTRODUCER;
}
}
package org.briarproject.briar.api.messaging;
import org.briarproject.bramble.api.Nameable;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......
package org.briarproject.briar.api.messaging;
import org.briarproject.bramble.api.Nameable;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
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.sync.GroupId;
import org.briarproject.briar.api.messaging.Nameable;
import org.briarproject.bramble.api.Nameable;
@NotNullByDefault
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.briar.api.client.MessageTracker;
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.event.IntroductionResponseReceivedEvent;
......@@ -148,14 +147,13 @@ abstract class AbstractProtocolEngine<S extends Session>
void broadcastIntroductionResponseReceivedEvent(Transaction txn, Session s,
AuthorId sender, Author otherAuthor, AbstractIntroductionMessage m)
throws DbException {
Introduction introduction = new Introduction(otherAuthor, s.getRole());
AuthorId localAuthorId = identityManager.getLocalAuthor(txn).getId();
Contact c = contactManager.getContact(txn, sender, localAuthorId);
IntroductionResponse response =
new IntroductionResponse(m.getMessageId(), m.getGroupId(),
m.getTimestamp(), false, false, false, false,
s.getSessionId(), introduction,
m instanceof AcceptMessage);
s.getSessionId(), otherAuthor,
m instanceof AcceptMessage, s.getRole());
IntroductionResponseReceivedEvent e =
new IntroductionResponseReceivedEvent(response, c.getId());
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.ProtocolStateException;
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.event.IntroductionAbortedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
......@@ -255,11 +254,9 @@ class IntroduceeProtocolEngine
localAuthor.getId());
boolean contactExists = contactManager
.contactExists(txn, m.getAuthor().getId(), localAuthor.getId());
Introduction introduction =
new Introduction(m.getAuthor(), s.getRole());
IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
m.getGroupId(), m.getTimestamp(), false, false, false, false,
s.getSessionId(), introduction, m.getMessage(), false,
s.getSessionId(), m.getAuthor(), m.getMessage(), false,
contactExists);
IntroductionRequestReceivedEvent e =
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.briar.api.client.MessageTracker;
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.IntroductionRequest;
import org.briarproject.briar.api.introduction.IntroductionResponse;
......@@ -467,10 +466,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
boolean contactExists = contactManager
.contactExists(txn, rm.getAuthor().getId(),
localAuthor.getId());
Introduction introduction = new Introduction(author, role);
return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
sessionId, introduction, message, !meta.isAvailableToAnswer(),
sessionId, author, message, !meta.isAvailableToAnswer(),
contactExists);
}
......@@ -495,10 +493,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
sessionId = session.getSessionId();
author = session.getRemote().author;
} else throw new AssertionError();
Introduction introduction = new Introduction(author, role);
return new IntroductionResponse(m, contactGroupId, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
sessionId, introduction, accept);
sessionId, author, accept, role);
}
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.briar.api.client.ProtocolStateException;
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.IntroductionRequest;
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.briar.api.introduction.event.IntroductionSucceededEvent;
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.junit.Before;
import org.junit.Test;
......@@ -1148,7 +1146,7 @@ public class IntroductionIntegrationTest
protected volatile Event latestEvent;
@SuppressWarnings("WeakerAccess")
PrivateResponse<Introduction> getResponse() {
IntroductionResponse getResponse() {
assertTrue(
latestEvent instanceof IntroductionResponseReceivedEvent);
return ((IntroductionResponseReceivedEvent) latestEvent)
......@@ -1180,7 +1178,7 @@ public class IntroductionIntegrationTest
IntroductionRequestReceivedEvent introEvent =
((IntroductionRequestReceivedEvent) e);
requestReceived = true;
PrivateRequest<Introduction> ir = introEvent.getMessageHeader();
IntroductionRequest ir = introEvent.getMessageHeader();
ContactId contactId = introEvent.getContactId();
sessionId = ir.getSessionId();
long time = clock.currentTimeMillis();
......@@ -1217,7 +1215,7 @@ public class IntroductionIntegrationTest
}
}
private PrivateRequest<Introduction> getRequest() {
private IntroductionRequest getRequest() {
assertTrue(
latestEvent instanceof IntroductionRequestReceivedEvent);
return ((IntroductionRequestReceivedEvent) latestEvent)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment