mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
RemoteWipeManager builds messages using the message encoder
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
package org.briarproject.briar.api.remotewipe;
|
||||
|
||||
public interface MessageEncoder {
|
||||
byte[] encodeSetupMessage();
|
||||
|
||||
byte[] encodeWipeMessage();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
package org.briarproject.briar.api.remotewipe;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
|
||||
public interface MessageParser {
|
||||
void parseSetupMessage(BdfList body) throws FormatException;
|
||||
|
||||
void parseWipeMessage(BdfList body) throws FormatException;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,45 @@
|
||||
package org.briarproject.briar.remotewipe;
|
||||
|
||||
public class MessageEncoderImpl {
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.briar.api.remotewipe.MessageEncoder;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.briar.remotewipe.MessageType.SETUP;
|
||||
import static org.briarproject.briar.remotewipe.MessageType.WIPE;
|
||||
|
||||
public class MessageEncoderImpl implements MessageEncoder {
|
||||
|
||||
private final ClientHelper clientHelper;
|
||||
|
||||
@Inject
|
||||
MessageEncoderImpl(ClientHelper clientHelper) {
|
||||
this.clientHelper = clientHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeSetupMessage() {
|
||||
BdfList body = BdfList.of(
|
||||
SETUP.getValue()
|
||||
);
|
||||
return encodeBody(body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeWipeMessage() {
|
||||
BdfList body = BdfList.of(
|
||||
WIPE.getValue()
|
||||
);
|
||||
return encodeBody(body);
|
||||
}
|
||||
|
||||
private byte[] encodeBody(BdfList body) {
|
||||
try {
|
||||
return clientHelper.toByteArray(body);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,24 @@
|
||||
package org.briarproject.briar.remotewipe;
|
||||
|
||||
public class MessageParserImpl {
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.briar.api.remotewipe.MessageParser;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class MessageParserImpl implements MessageParser {
|
||||
|
||||
@Inject
|
||||
MessageParserImpl () {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseSetupMessage(BdfList body) throws FormatException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseWipeMessage(BdfList body) throws FormatException {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||
import org.briarproject.briar.api.conversation.DeletionResult;
|
||||
import org.briarproject.briar.api.remotewipe.MessageEncoder;
|
||||
import org.briarproject.briar.api.remotewipe.MessageParser;
|
||||
import org.briarproject.briar.api.remotewipe.RemoteWipeManager;
|
||||
import org.briarproject.briar.api.remotewipe.RemoteWipeMessageHeader;
|
||||
import org.briarproject.briar.client.ConversationClientImpl;
|
||||
@@ -54,6 +56,8 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
||||
private final Clock clock;
|
||||
private final ContactGroupFactory contactGroupFactory;
|
||||
private final ContactManager contactManager;
|
||||
private final MessageEncoder messageEncoder;
|
||||
private final MessageParser messageParser;
|
||||
|
||||
@Inject
|
||||
protected RemoteWipeManagerImpl(
|
||||
@@ -62,6 +66,8 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
||||
MetadataParser metadataParser,
|
||||
MessageTracker messageTracker,
|
||||
Clock clock,
|
||||
MessageEncoder messageEncoder,
|
||||
MessageParser messageParser,
|
||||
ContactManager contactManager,
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
ContactGroupFactory contactGroupFactory) {
|
||||
@@ -70,6 +76,8 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.contactManager = contactManager;
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.messageEncoder = messageEncoder;
|
||||
this.messageParser = messageParser;
|
||||
localGroup =
|
||||
contactGroupFactory.createLocalGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
}
|
||||
@@ -138,7 +146,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
||||
if (!db.containsGroup(txn, g)) db.addGroup(txn, group);
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
|
||||
byte[] body = "setup message".getBytes(); // TODO
|
||||
byte[] body = messageEncoder.encodeSetupMessage();
|
||||
|
||||
Message m = clientHelper.createMessage(g, timestamp, body);
|
||||
// TODO remote-wipe versions of MESSAGE_KEY
|
||||
@@ -160,7 +168,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
||||
if (!db.containsGroup(txn, g)) db.addGroup(txn, group);
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
|
||||
byte[] body = "wipe message".getBytes(); // TODO
|
||||
byte[] body = messageEncoder.encodeWipeMessage();
|
||||
|
||||
Message m = clientHelper.createMessage(g, timestamp, body);
|
||||
// TODO remote-wipe versions of MESSAGE_KEY
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package org.briarproject.briar.remotewipe;
|
||||
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.sync.validation.ValidationManager;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||
import org.briarproject.briar.api.remotewipe.MessageEncoder;
|
||||
import org.briarproject.briar.api.remotewipe.MessageParser;
|
||||
import org.briarproject.briar.api.remotewipe.RemoteWipeManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -13,15 +18,17 @@ import javax.inject.Singleton;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static org.briarproject.briar.api.socialbackup.SocialBackupManager.CLIENT_ID;
|
||||
import static org.briarproject.briar.api.socialbackup.SocialBackupManager.MAJOR_VERSION;
|
||||
import static org.briarproject.briar.api.socialbackup.SocialBackupManager.MINOR_VERSION;
|
||||
import static org.briarproject.briar.api.remotewipe.RemoteWipeManager.CLIENT_ID;
|
||||
import static org.briarproject.briar.api.remotewipe.RemoteWipeManager.MAJOR_VERSION;
|
||||
import static org.briarproject.briar.api.remotewipe.RemoteWipeManager.MINOR_VERSION;
|
||||
|
||||
@Module
|
||||
public class RemoteWipeModule {
|
||||
public static class EagerSingletons {
|
||||
@Inject
|
||||
RemoteWipeManager remoteWipeManager;
|
||||
@Inject
|
||||
RemoteWipeValidator remoteWipeValidator;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -44,4 +51,28 @@ public class RemoteWipeModule {
|
||||
conversationManager.registerConversationClient(remoteWipeManager);
|
||||
return remoteWipeManager;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
RemoteWipeValidator remoteWipeValidator(
|
||||
ValidationManager validationManager,
|
||||
ClientHelper clientHelper,
|
||||
MetadataEncoder metadataEncoder,
|
||||
Clock clock) {
|
||||
RemoteWipeValidator validator =
|
||||
new RemoteWipeValidator(clientHelper, metadataEncoder, clock);
|
||||
validationManager.registerMessageValidator(CLIENT_ID, MAJOR_VERSION,
|
||||
validator);
|
||||
return validator;
|
||||
}
|
||||
|
||||
@Provides
|
||||
MessageEncoder messageEncoder(MessageEncoderImpl messageEncoder) {
|
||||
return messageEncoder;
|
||||
}
|
||||
|
||||
@Provides
|
||||
MessageParser messageParser(MessageParserImpl messageParser) {
|
||||
return messageParser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,62 @@
|
||||
package org.briarproject.briar.remotewipe;
|
||||
|
||||
public class RemoteWipeValidator {
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.BdfMessageContext;
|
||||
import org.briarproject.bramble.api.client.BdfMessageValidator;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
||||
import static org.briarproject.briar.remotewipe.MessageType.SETUP;
|
||||
import static org.briarproject.briar.remotewipe.MessageType.WIPE;
|
||||
import static org.briarproject.briar.socialbackup.SocialBackupConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.briar.socialbackup.SocialBackupConstants.MSG_KEY_MESSAGE_TYPE;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class RemoteWipeValidator extends BdfMessageValidator {
|
||||
|
||||
@Inject
|
||||
RemoteWipeValidator(ClientHelper clientHelper,
|
||||
MetadataEncoder metadataEncoder, Clock clock) {
|
||||
super(clientHelper, metadataEncoder, clock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BdfMessageContext validateMessage(Message m, Group g,
|
||||
BdfList body) throws FormatException {
|
||||
MessageType type = MessageType
|
||||
.fromValue(body.getLong(0).intValue());
|
||||
if (type == SETUP) return validateSetupMessage(body);
|
||||
else if (type == WIPE) return validateWipeMessage(body);
|
||||
else throw new AssertionError();
|
||||
}
|
||||
|
||||
private BdfMessageContext validateSetupMessage(BdfList body)
|
||||
throws FormatException {
|
||||
checkSize(body, 1);
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_MESSAGE_TYPE, SETUP.getValue()),
|
||||
new BdfEntry(MSG_KEY_LOCAL, false));
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
|
||||
private BdfMessageContext validateWipeMessage(BdfList body)
|
||||
throws FormatException {
|
||||
checkSize(body, 1);
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_MESSAGE_TYPE, WIPE.getValue()),
|
||||
new BdfEntry(MSG_KEY_LOCAL, false));
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user