mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Tidy
This commit is contained in:
@@ -35,7 +35,6 @@ import org.briarproject.briar.client.ConversationClientImpl;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -49,7 +48,6 @@ import static org.briarproject.briar.remotewipe.MessageType.WIPE;
|
|||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_CONTACT_ID;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_CONTACT_ID;
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_RECEIVED_WIPE;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_RECEIVED_WIPE;
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_WIPERS;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_WIPERS;
|
||||||
|
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.MAX_MESSAGE_AGE;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.MAX_MESSAGE_AGE;
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.MSG_KEY_LOCAL;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.MSG_KEY_LOCAL;
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.MSG_KEY_MESSAGE_TYPE;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.MSG_KEY_MESSAGE_TYPE;
|
||||||
@@ -58,7 +56,8 @@ import static org.briarproject.briar.remotewipe.RemoteWipeConstants.THRESHOLD;
|
|||||||
|
|
||||||
public class RemoteWipeManagerImpl extends ConversationClientImpl
|
public class RemoteWipeManagerImpl extends ConversationClientImpl
|
||||||
implements RemoteWipeManager, ContactManager.ContactHook,
|
implements RemoteWipeManager, ContactManager.ContactHook,
|
||||||
ClientVersioningManager.ClientVersioningHook, LifecycleManager.OpenDatabaseHook {
|
ClientVersioningManager.ClientVersioningHook,
|
||||||
|
LifecycleManager.OpenDatabaseHook {
|
||||||
|
|
||||||
private final ClientVersioningManager clientVersioningManager;
|
private final ClientVersioningManager clientVersioningManager;
|
||||||
private final Group localGroup;
|
private final Group localGroup;
|
||||||
@@ -123,56 +122,66 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
MessageType type = MessageType.fromValue(body.getLong(0).intValue());
|
MessageType type = MessageType.fromValue(body.getLong(0).intValue());
|
||||||
if (type == SETUP) {
|
if (type == SETUP) {
|
||||||
messageTracker.trackIncomingMessage(txn, m);
|
messageTracker.trackIncomingMessage(txn, m);
|
||||||
// message.getGroupId turn into contactid
|
// message.getGroupId turn into contactid
|
||||||
// txn.attach event
|
// txn.attach event
|
||||||
} else if (type == WIPE) {
|
} else if (type == WIPE) {
|
||||||
if (!remoteWipeIsSetup(txn)) return false;
|
if (!remoteWipeIsSetup(txn)) return false;
|
||||||
if (clock.currentTimeMillis() - m.getTimestamp() > MAX_MESSAGE_AGE) return false;
|
if (clock.currentTimeMillis() - m.getTimestamp() > MAX_MESSAGE_AGE)
|
||||||
|
return false;
|
||||||
|
|
||||||
ContactId contactId = getContactId(txn, m.getGroupId());
|
ContactId contactId = getContactId(txn, m.getGroupId());
|
||||||
// Check if contact is in list of wipers
|
// Check if contact is in list of wipers
|
||||||
if (findMessage(txn, m.getGroupId(), SETUP, true) != null) {
|
if (findMessage(txn, m.getGroupId(), SETUP, true) != null) {
|
||||||
System.out.println("Got a valid wipe message from a wiper");
|
System.out.println("Got a valid wipe message from a wiper");
|
||||||
|
|
||||||
BdfDictionary existingMeta = clientHelper.getGroupMetadataAsDictionary(txn,
|
BdfDictionary existingMeta =
|
||||||
localGroup.getId());
|
clientHelper.getGroupMetadataAsDictionary(txn,
|
||||||
BdfList receivedWipeMessages = existingMeta.getOptionalList(GROUP_KEY_RECEIVED_WIPE);
|
localGroup.getId());
|
||||||
|
BdfList receivedWipeMessages =
|
||||||
|
existingMeta.getOptionalList(GROUP_KEY_RECEIVED_WIPE);
|
||||||
|
|
||||||
if (receivedWipeMessages == null) receivedWipeMessages = new BdfList();
|
if (receivedWipeMessages == null)
|
||||||
|
receivedWipeMessages = new BdfList();
|
||||||
|
|
||||||
// Traverse the list backwards to avoid problems when removing items
|
// Traverse the list backwards to avoid problems when removing items
|
||||||
for (int i = receivedWipeMessages.size() -1; i >= 0; --i) {
|
for (int i = receivedWipeMessages.size() - 1; i >= 0; --i) {
|
||||||
BdfList receivedWipeMessage = receivedWipeMessages.getList(i);
|
BdfList receivedWipeMessage =
|
||||||
|
receivedWipeMessages.getList(i);
|
||||||
|
|
||||||
long timestamp = receivedWipeMessage.getLong(1);
|
long timestamp = receivedWipeMessage.getLong(1);
|
||||||
System.out.println("Message age: " + (clock.currentTimeMillis() - timestamp));
|
System.out.println("Message age: " +
|
||||||
|
(clock.currentTimeMillis() - timestamp));
|
||||||
// Filter the messages for old ones
|
// Filter the messages for old ones
|
||||||
if (clock.currentTimeMillis() - timestamp > MAX_MESSAGE_AGE) {
|
if (clock.currentTimeMillis() - timestamp >
|
||||||
|
MAX_MESSAGE_AGE) {
|
||||||
System.out.println("Removing outdated wipe message");
|
System.out.println("Removing outdated wipe message");
|
||||||
receivedWipeMessages.remove(i);
|
receivedWipeMessages.remove(i);
|
||||||
} else if (receivedWipeMessage.getLong(0).intValue() == contactId.getInt()) {
|
} else if (receivedWipeMessage.getLong(0).intValue() ==
|
||||||
|
contactId.getInt()) {
|
||||||
// If we already have one from this contact, ignore
|
// If we already have one from this contact, ignore
|
||||||
System.out.println("Duplicate wipe message received - ignoring");
|
System.out.println(
|
||||||
|
"Duplicate wipe message received - ignoring");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receivedWipeMessages.size() + 1 == THRESHOLD) {
|
if (receivedWipeMessages.size() + 1 == THRESHOLD) {
|
||||||
System.out.println("Threshold reached - panic!");
|
System.out.println("Threshold reached - panic!");
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
observer.onPanic();
|
observer.onPanic();
|
||||||
}
|
}
|
||||||
// we could here clear the metadata to allow us to send
|
// we could here clear the metadata to allow us to send
|
||||||
// the wipe messages several times when testing
|
// the wipe messages several times when testing
|
||||||
} else {
|
} else {
|
||||||
BdfList newReceivedWipeMessage = new BdfList();
|
BdfList newReceivedWipeMessage = new BdfList();
|
||||||
newReceivedWipeMessage.add(contactId.getInt());
|
newReceivedWipeMessage.add(contactId.getInt());
|
||||||
newReceivedWipeMessage.add(m.getTimestamp());
|
newReceivedWipeMessage.add(m.getTimestamp());
|
||||||
receivedWipeMessages.add(newReceivedWipeMessage);
|
receivedWipeMessages.add(newReceivedWipeMessage);
|
||||||
BdfDictionary newMeta = new BdfDictionary();
|
BdfDictionary newMeta = new BdfDictionary();
|
||||||
newMeta.put(GROUP_KEY_RECEIVED_WIPE, receivedWipeMessages);
|
newMeta.put(GROUP_KEY_RECEIVED_WIPE, receivedWipeMessages);
|
||||||
clientHelper.mergeGroupMetadata(txn, localGroup.getId(), newMeta);
|
clientHelper.mergeGroupMetadata(txn, localGroup.getId(),
|
||||||
}
|
newMeta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -180,11 +189,11 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
|
|
||||||
public void setup(Transaction txn, List<ContactId> wipers)
|
public void setup(Transaction txn, List<ContactId> wipers)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
// If we already have a set of wipers do nothing
|
// If we already have a set of wipers do nothing
|
||||||
// TODO revoke existing wipers who are not present in the new list
|
// TODO revoke existing wipers who are not present in the new list
|
||||||
if (remoteWipeIsSetup(txn)) throw new FormatException();
|
if (remoteWipeIsSetup(txn)) throw new FormatException();
|
||||||
|
|
||||||
if (wipers.size() < 2) throw new FormatException();
|
if (wipers.size() < 2) throw new FormatException();
|
||||||
|
|
||||||
BdfList wipersMetadata = new BdfList();
|
BdfList wipersMetadata = new BdfList();
|
||||||
|
|
||||||
@@ -254,7 +263,8 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
|
|
||||||
public boolean amWiper(Transaction txn, ContactId contactId) {
|
public boolean amWiper(Transaction txn, ContactId contactId) {
|
||||||
try {
|
try {
|
||||||
GroupId groupId = getContactGroup(db.getContact(txn, contactId)).getId();
|
GroupId groupId =
|
||||||
|
getContactGroup(db.getContact(txn, contactId)).getId();
|
||||||
return findMessage(txn, groupId, SETUP, false) != null;
|
return findMessage(txn, groupId, SETUP, false) != null;
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -380,8 +390,9 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
Group g = getContactGroup(c);
|
Group g = getContactGroup(c);
|
||||||
db.addGroup(txn, g);
|
db.addGroup(txn, g);
|
||||||
// Apply the client's visibility to the contact group
|
// Apply the client's visibility to the contact group
|
||||||
Group.Visibility client = clientVersioningManager.getClientVisibility(txn,
|
Group.Visibility client =
|
||||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
clientVersioningManager.getClientVisibility(txn,
|
||||||
|
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||||
// Attach the contact ID to the group
|
// Attach the contact ID to the group
|
||||||
setContactId(txn, g.getId(), c.getId());
|
setContactId(txn, g.getId(), c.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user