mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Implement CONFIRM remote wipe message
This commit is contained in:
@@ -7,6 +7,7 @@ import org.briarproject.briar.api.remotewipe.MessageEncoder;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.api.remotewipe.MessageType.CONFIRM;
|
||||||
import static org.briarproject.briar.api.remotewipe.MessageType.SETUP;
|
import static org.briarproject.briar.api.remotewipe.MessageType.SETUP;
|
||||||
import static org.briarproject.briar.api.remotewipe.MessageType.WIPE;
|
import static org.briarproject.briar.api.remotewipe.MessageType.WIPE;
|
||||||
import static org.briarproject.briar.api.remotewipe.MessageType.REVOKE;
|
import static org.briarproject.briar.api.remotewipe.MessageType.REVOKE;
|
||||||
@@ -44,6 +45,14 @@ public class MessageEncoderImpl implements MessageEncoder {
|
|||||||
return encodeBody(body);
|
return encodeBody(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] encodeConfirmMessage() {
|
||||||
|
BdfList body = BdfList.of(
|
||||||
|
CONFIRM.getValue()
|
||||||
|
);
|
||||||
|
return encodeBody(body);
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] encodeBody(BdfList body) {
|
private byte[] encodeBody(BdfList body) {
|
||||||
try {
|
try {
|
||||||
return clientHelper.toByteArray(body);
|
return clientHelper.toByteArray(body);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.briar.api.remotewipe.MessageType.CONFIRM;
|
||||||
import static org.briarproject.briar.api.remotewipe.MessageType.REVOKE;
|
import static org.briarproject.briar.api.remotewipe.MessageType.REVOKE;
|
||||||
import static org.briarproject.briar.api.remotewipe.MessageType.SETUP;
|
import static org.briarproject.briar.api.remotewipe.MessageType.SETUP;
|
||||||
import static org.briarproject.briar.api.remotewipe.MessageType.WIPE;
|
import static org.briarproject.briar.api.remotewipe.MessageType.WIPE;
|
||||||
@@ -191,7 +192,11 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (receivedWipeMessages.size() + 1 == THRESHOLD) {
|
if (receivedWipeMessages.size() + 1 == THRESHOLD) {
|
||||||
LOG.warning("Threshold reached - panic!");
|
LOG.warning("Threshold number of remote wipe signals reached - panic!");
|
||||||
|
|
||||||
|
// Send a CONFIRM message to each wiper
|
||||||
|
sendConfirmMessages(txn);
|
||||||
|
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
observer.onPanic();
|
observer.onPanic();
|
||||||
}
|
}
|
||||||
@@ -227,6 +232,14 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
db.addGroup(txn, localGroup);
|
db.addGroup(txn, localGroup);
|
||||||
clientHelper
|
clientHelper
|
||||||
.mergeGroupMetadata(txn, localGroup.getId(), localRecord);
|
.mergeGroupMetadata(txn, localGroup.getId(), localRecord);
|
||||||
|
} else if (type == CONFIRM) {
|
||||||
|
messageTracker.trackIncomingMessage(txn, m);
|
||||||
|
ContactId contactId = getContactId(txn, m.getGroupId());
|
||||||
|
|
||||||
|
MessageStatus status = db.getMessageStatus(txn, contactId,
|
||||||
|
m.getId());
|
||||||
|
txn.attach(new RemoteWipeReceivedEvent(
|
||||||
|
createMessageHeader(m, meta, status, type), contactId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -314,6 +327,34 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
messageTracker.trackOutgoingMessage(txn, m);
|
messageTracker.trackOutgoingMessage(txn, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendConfirmMessages(Transaction txn)
|
||||||
|
throws DbException, FormatException {
|
||||||
|
List<ContactId> wipers = getWiperContactIds(txn);
|
||||||
|
for (ContactId c : wipers) {
|
||||||
|
Contact contact = contactManager.getContact(txn, c);
|
||||||
|
sendConfirmMessage(txn, contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendConfirmMessage(Transaction txn, Contact contact)
|
||||||
|
throws DbException, FormatException {
|
||||||
|
Group group = getContactGroup(contact);
|
||||||
|
GroupId g = group.getId();
|
||||||
|
if (!db.containsGroup(txn, g)) db.addGroup(txn, group);
|
||||||
|
long timestamp = clock.currentTimeMillis();
|
||||||
|
|
||||||
|
byte[] body = messageEncoder.encodeConfirmMessage();
|
||||||
|
|
||||||
|
Message m = clientHelper.createMessage(g, timestamp, body);
|
||||||
|
BdfDictionary meta = BdfDictionary.of(
|
||||||
|
new BdfEntry(MSG_KEY_MESSAGE_TYPE, CONFIRM.getValue()),
|
||||||
|
new BdfEntry(MSG_KEY_LOCAL, true),
|
||||||
|
new BdfEntry(MSG_KEY_TIMESTAMP, timestamp)
|
||||||
|
);
|
||||||
|
clientHelper.addLocalMessage(txn, m, meta, true, false);
|
||||||
|
messageTracker.trackOutgoingMessage(txn, m);
|
||||||
|
}
|
||||||
|
|
||||||
public void wipe(Transaction txn, Contact contact)
|
public void wipe(Transaction txn, Contact contact)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
// Check that we have wiper status
|
// Check that we have wiper status
|
||||||
|
|||||||
Reference in New Issue
Block a user