mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Fix rebasing mistakes.
This commit is contained in:
@@ -24,7 +24,7 @@ public abstract class ValidatorTestCase extends BrambleMockTestCase {
|
|||||||
context.mock(MetadataEncoder.class);
|
context.mock(MetadataEncoder.class);
|
||||||
protected final Clock clock = context.mock(Clock.class);
|
protected final Clock clock = context.mock(Clock.class);
|
||||||
|
|
||||||
protected final Group group = getGroup(getClientId());
|
protected final Group group = getGroup(getClientId(), 123);
|
||||||
protected final GroupId groupId = group.getId();
|
protected final GroupId groupId = group.getId();
|
||||||
protected final byte[] descriptor = group.getDescriptor();
|
protected final byte[] descriptor = group.getDescriptor();
|
||||||
protected final Message message = getMessage(groupId);
|
protected final Message message = getMessage(groupId);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import static org.briarproject.briar.api.introduction.IntroductionConstants.LABE
|
|||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.LABEL_BOB_MAC_KEY;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.LABEL_BOB_MAC_KEY;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.LABEL_MASTER_KEY;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.LABEL_MASTER_KEY;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.LABEL_SESSION_ID;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.LABEL_SESSION_ID;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_VERSION;
|
import static org.briarproject.briar.api.introduction.IntroductionManager.MAJOR_VERSION;
|
||||||
import static org.briarproject.briar.introduction.IntroduceeSession.Local;
|
import static org.briarproject.briar.introduction.IntroduceeSession.Local;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -94,7 +94,7 @@ class IntroductionCryptoImpl implements IntroductionCrypto {
|
|||||||
LABEL_MASTER_KEY,
|
LABEL_MASTER_KEY,
|
||||||
remoteEphemeralPublicKey,
|
remoteEphemeralPublicKey,
|
||||||
keyPair,
|
keyPair,
|
||||||
new byte[] {CLIENT_VERSION},
|
new byte[] {MAJOR_VERSION},
|
||||||
alice ? publicKey : remotePublicKey,
|
alice ? publicKey : remotePublicKey,
|
||||||
alice ? remotePublicKey : publicKey
|
alice ? remotePublicKey : publicKey
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -42,13 +42,11 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
|
||||||
import static org.briarproject.briar.api.introduction.Role.INTRODUCEE;
|
import static org.briarproject.briar.api.introduction.Role.INTRODUCEE;
|
||||||
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
|
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
|
||||||
import static org.briarproject.briar.introduction.IntroducerState.START;
|
import static org.briarproject.briar.introduction.IntroducerState.START;
|
||||||
@@ -66,9 +64,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
implements IntroductionManager, Client, ContactHook,
|
implements IntroductionManager, Client, ContactHook,
|
||||||
ClientVersioningHook {
|
ClientVersioningHook {
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(IntroductionManagerImpl.class.getName());
|
|
||||||
|
|
||||||
private final ClientVersioningManager clientVersioningManager;
|
private final ClientVersioningManager clientVersioningManager;
|
||||||
private final ContactGroupFactory contactGroupFactory;
|
private final ContactGroupFactory contactGroupFactory;
|
||||||
private final ContactManager contactManager;
|
private final ContactManager contactManager;
|
||||||
@@ -83,8 +78,12 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
private final Group localGroup;
|
private final Group localGroup;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
IntroductionManagerImpl(DatabaseComponent db, ClientHelper clientHelper,
|
IntroductionManagerImpl(
|
||||||
ClientVersioningManager clientVersioningManager,MetadataParser metadataParser, MessageTracker messageTracker,
|
DatabaseComponent db,
|
||||||
|
ClientHelper clientHelper,
|
||||||
|
ClientVersioningManager clientVersioningManager,
|
||||||
|
MetadataParser metadataParser,
|
||||||
|
MessageTracker messageTracker,
|
||||||
ContactGroupFactory contactGroupFactory,
|
ContactGroupFactory contactGroupFactory,
|
||||||
ContactManager contactManager,
|
ContactManager contactManager,
|
||||||
MessageParser messageParser,
|
MessageParser messageParser,
|
||||||
@@ -106,7 +105,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.identityManager = identityManager;
|
this.identityManager = identityManager;
|
||||||
this.localGroup =
|
this.localGroup =
|
||||||
contactGroupFactory.createLocalGroup(CLIENT_ID, CLIENT_VERSION);
|
contactGroupFactory.createLocalGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -144,7 +143,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
abortOrRemoveSessionWithIntroducee(txn, c);
|
abortOrRemoveSessionWithIntroducee(txn, c);
|
||||||
|
|
||||||
// Remove the contact group (all messages will be removed with it)
|
// Remove the contact group (all messages will be removed with it)
|
||||||
|
|
||||||
db.removeGroup(txn, getContactGroup(c));
|
db.removeGroup(txn, getContactGroup(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,17 +157,16 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
@Override
|
@Override
|
||||||
public Group getContactGroup(Contact c) {
|
public Group getContactGroup(Contact c) {
|
||||||
return contactGroupFactory
|
return contactGroupFactory
|
||||||
.createContactGroup(CLIENT_ID, CLIENT_VERSION, c);
|
.createContactGroup(CLIENT_ID, MAJOR_VERSION, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
||||||
BdfDictionary bdfMeta) throws DbException, FormatException {
|
BdfDictionary bdfMeta) throws DbException, FormatException {
|
||||||
// Parse the metadata
|
// Parse the metadata
|
||||||
MessageMetadata meta = messageParser.parseMetadata(bdfMeta);
|
MessageMetadata meta = messageParser.parseMetadata(bdfMeta);
|
||||||
// Look up the session, if there is one
|
// Look up the session, if there is one
|
||||||
SessionId sessionId = meta.getSessionId();
|
SessionId sessionId = meta.getSessionId();
|
||||||
|
|
||||||
IntroduceeSession newIntroduceeSession = null;
|
IntroduceeSession newIntroduceeSession = null;
|
||||||
if (sessionId == null) {
|
if (sessionId == null) {
|
||||||
if (meta.getMessageType() != REQUEST) throw new AssertionError();
|
if (meta.getMessageType() != REQUEST) throw new AssertionError();
|
||||||
@@ -180,7 +177,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
// Handle the message
|
// Handle the message
|
||||||
Session session;
|
Session session;
|
||||||
MessageId storageId;
|
MessageId storageId;
|
||||||
if (ss == null){
|
if (ss == null) {
|
||||||
if (meta.getMessageType() != REQUEST) throw new FormatException();
|
if (meta.getMessageType() != REQUEST) throw new FormatException();
|
||||||
if (newIntroduceeSession == null) throw new AssertionError();
|
if (newIntroduceeSession == null) throw new AssertionError();
|
||||||
storageId = createStorageId(txn);
|
storageId = createStorageId(txn);
|
||||||
@@ -191,12 +188,12 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
Role role = sessionParser.getRole(ss.bdfSession);
|
Role role = sessionParser.getRole(ss.bdfSession);
|
||||||
if (role == INTRODUCER) {
|
if (role == INTRODUCER) {
|
||||||
session = handleMessage(txn, m, body, meta.getMessageType(),
|
session = handleMessage(txn, m, body, meta.getMessageType(),
|
||||||
sessionParser.parseIntroducerSession(ss.bdfSession),
|
sessionParser.parseIntroducerSession(ss.bdfSession),
|
||||||
introducerEngine);
|
introducerEngine);
|
||||||
} else if (role == INTRODUCEE) {
|
} else if (role == INTRODUCEE) {
|
||||||
session = handleMessage(txn, m, body, meta.getMessageType(),
|
session = handleMessage(txn, m, body, meta.getMessageType(),
|
||||||
sessionParser.parseIntroduceeSession(m.getGroupId(),
|
sessionParser.parseIntroduceeSession(m.getGroupId(),
|
||||||
ss.bdfSession), introduceeEngine);
|
ss.bdfSession), introduceeEngine);
|
||||||
} else throw new AssertionError();
|
} else throw new AssertionError();
|
||||||
}
|
}
|
||||||
// Store the updated session
|
// Store the updated session
|
||||||
@@ -407,14 +404,13 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
List<IntroductionMessage> messages;
|
List<IntroductionMessage> messages;
|
||||||
Transaction txn = db.startTransaction(true);
|
Transaction txn = db.startTransaction(true);
|
||||||
try {
|
try {
|
||||||
Contact contact =db.getContact(txn, c);
|
Contact contact = db.getContact(txn, c);
|
||||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||||
Map<MessageId, BdfDictionary> results = clientHelper.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
Map<MessageId, BdfDictionary> results = clientHelper
|
||||||
messages = new ArrayList<>(results.size());
|
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||||
for (Entry<
|
messages = new ArrayList<>(results.size());
|
||||||
MessageId ,
|
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||||
BdfDictionary > e : results.entrySet()) {
|
|
||||||
MessageId m = e.getKey();
|
MessageId m = e.getKey();
|
||||||
MessageMetadata meta =
|
MessageMetadata meta =
|
||||||
messageParser.parseMetadata(e.getValue());
|
messageParser.parseMetadata(e.getValue());
|
||||||
@@ -425,7 +421,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
if (type == REQUEST) {
|
if (type == REQUEST) {
|
||||||
messages.add(
|
messages.add(
|
||||||
parseInvitationRequest(txn, contactGroupId, m,
|
parseInvitationRequest(txn, contactGroupId, m,
|
||||||
meta, status, ss.bdfSession));
|
meta, status, ss.bdfSession));
|
||||||
} else if (type == ACCEPT) {
|
} else if (type == ACCEPT) {
|
||||||
messages.add(
|
messages.add(
|
||||||
parseInvitationResponse(contactGroupId, m, meta,
|
parseInvitationResponse(contactGroupId, m, meta,
|
||||||
@@ -445,7 +441,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntroductionRequest parseInvitationRequest(Transaction txn, GroupId contactGroupId, MessageId m, MessageMetadata meta,
|
private IntroductionRequest parseInvitationRequest(Transaction txn,
|
||||||
|
GroupId contactGroupId, MessageId m, MessageMetadata meta,
|
||||||
MessageStatus status, BdfDictionary bdfSession)
|
MessageStatus status, BdfDictionary bdfSession)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
Role role = sessionParser.getRole(bdfSession);
|
Role role = sessionParser.getRole(bdfSession);
|
||||||
@@ -516,9 +513,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
Map<MessageId, BdfDictionary> sessions;
|
Map<MessageId, BdfDictionary> sessions;
|
||||||
try {
|
try {
|
||||||
sessions = clientHelper
|
sessions = clientHelper
|
||||||
.getMessageMetadataAsDictionary(txn,localGroup.getId(),
|
.getMessageMetadataAsDictionary(txn, localGroup.getId(),
|
||||||
query);
|
query);
|
||||||
} catch (FormatException e){
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
for (MessageId id : sessions.keySet()) {
|
for (MessageId id : sessions.keySet()) {
|
||||||
@@ -529,20 +526,20 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
private void abortOrRemoveSessionWithIntroducee(Transaction txn,
|
private void abortOrRemoveSessionWithIntroducee(Transaction txn,
|
||||||
Contact c) throws DbException {
|
Contact c) throws DbException {
|
||||||
BdfDictionary query = sessionEncoder.getIntroducerSessionsQuery();
|
BdfDictionary query = sessionEncoder.getIntroducerSessionsQuery();
|
||||||
Map<MessageId, BdfDictionary> sessions;
|
Map<MessageId, BdfDictionary> sessions;
|
||||||
try {
|
try {
|
||||||
sessions = clientHelper
|
sessions = clientHelper
|
||||||
.getMessageMetadataAsDictionary(txn,
|
.getMessageMetadataAsDictionary(txn, localGroup.getId(),
|
||||||
localGroup.getId(),
|
query);
|
||||||
query);
|
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException();
|
throw new DbException();
|
||||||
}
|
}
|
||||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);for (Entry<MessageId, BdfDictionary> session : sessions.entrySet()) {
|
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||||
|
for (Entry<MessageId, BdfDictionary> session : sessions.entrySet()) {
|
||||||
IntroducerSession s;
|
IntroducerSession s;
|
||||||
try {
|
try {
|
||||||
s = sessionParser.parseIntroducerSession(session.getValue());
|
s = sessionParser.parseIntroducerSession(session.getValue());
|
||||||
} catch (FormatException e){
|
} catch (FormatException e) {
|
||||||
throw new DbException();
|
throw new DbException();
|
||||||
}
|
}
|
||||||
if (s.getIntroduceeA().author.equals(c.getAuthor())) {
|
if (s.getIntroduceeA().author.equals(c.getAuthor())) {
|
||||||
|
|||||||
@@ -25,12 +25,14 @@ import javax.inject.Inject;
|
|||||||
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
|
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
|
||||||
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
|
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
|
||||||
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.TestUtils.getGroup;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getTransportPropertiesMap;
|
import static org.briarproject.bramble.test.TestUtils.getTransportPropertiesMap;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
|
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.introduction.IntroductionManager.MAJOR_VERSION;
|
||||||
import static org.briarproject.briar.introduction.MessageType.ABORT;
|
import static org.briarproject.briar.introduction.MessageType.ABORT;
|
||||||
import static org.briarproject.briar.introduction.MessageType.REQUEST;
|
import static org.briarproject.briar.introduction.MessageType.REQUEST;
|
||||||
import static org.briarproject.briar.test.BriarTestUtils.getRealAuthor;
|
import static org.briarproject.briar.test.BriarTestUtils.getRealAuthor;
|
||||||
@@ -57,8 +59,8 @@ public class MessageEncoderParserIntegrationTest extends BrambleTestCase {
|
|||||||
private final MessageParser messageParser;
|
private final MessageParser messageParser;
|
||||||
private final IntroductionValidator validator;
|
private final IntroductionValidator validator;
|
||||||
|
|
||||||
private final GroupId groupId = new GroupId(getRandomId());
|
private final Group group = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||||
private final Group group = new Group(groupId, CLIENT_ID, getRandomId());
|
private final GroupId groupId = group.getId();
|
||||||
private final long timestamp = 42L;
|
private final long timestamp = 42L;
|
||||||
private final SessionId sessionId = new SessionId(getRandomId());
|
private final SessionId sessionId = new SessionId(getRandomId());
|
||||||
private final MessageId previousMsgId = new MessageId(getRandomId());
|
private final MessageId previousMsgId = new MessageId(getRandomId());
|
||||||
|
|||||||
Reference in New Issue
Block a user