mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +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;
|
||||||
@@ -127,32 +126,41 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
// 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 =
|
||||||
|
clientHelper.getGroupMetadataAsDictionary(txn,
|
||||||
localGroup.getId());
|
localGroup.getId());
|
||||||
BdfList receivedWipeMessages = existingMeta.getOptionalList(GROUP_KEY_RECEIVED_WIPE);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,7 +179,8 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,7 +390,8 @@ 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 =
|
||||||
|
clientVersioningManager.getClientVisibility(txn,
|
||||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user