From a665179377c1a727546499b8819b55afc2e9295b Mon Sep 17 00:00:00 2001 From: ameba23 Date: Thu, 24 Feb 2022 13:01:39 +0100 Subject: [PATCH] Confirm messages method in remote wipe manager --- .../remotewipe/RemoteWipeManagerImpl.java | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java b/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java index ec7902b16..2ef216ba8 100644 --- a/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java @@ -14,6 +14,8 @@ import org.briarproject.bramble.api.data.MetadataParser; import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.Transaction; +import org.briarproject.bramble.api.event.Event; +import org.briarproject.bramble.api.event.EventListener; import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.lifecycle.LifecycleManager; import org.briarproject.bramble.api.sync.Group; @@ -48,7 +50,6 @@ import javax.annotation.Nullable; import javax.inject.Inject; import static java.util.logging.Logger.getLogger; -import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING; 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.SETUP; @@ -197,15 +198,12 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl LOG.warning("Threshold number of remote wipe signals reached - panic!"); // Send a CONFIRM message to each wiper - sendConfirmMessages(txn); +// sendConfirmMessages(txn); if (observer != null) { observer.onPanic(); } txn.attach(new RemoteWipeActivatedEvent()); - - // we could here clear the metadata to allow us to send - // the wipe messages several times when testing } else { BdfList newReceivedWipeMessage = new BdfList(); newReceivedWipeMessage.add(contactId.getInt()); @@ -329,31 +327,36 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl messageTracker.trackOutgoingMessage(txn, m); } - private void sendConfirmMessages(Transaction txn) + public void sendConfirmMessages(Transaction txn) throws DbException, FormatException { List wipers = getWiperContactIds(txn); - List confirmMessages = new ArrayList<>(); for (ContactId c : wipers) { Contact contact = contactManager.getContact(txn, c); - confirmMessages.add(sendConfirmMessage(txn, contact)); + sendConfirmMessage(txn, contact); } - boolean allSent = true; - do { - for (MessageId confirmMessage: confirmMessages) { - if (db.getMessageState(txn, confirmMessage) == PENDING) allSent = false; - } - if (!allSent) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - allSent = true; - } - } - } while(allSent == false); +// boolean allSent = true; +// do { +// for (MessageId confirmMessage: confirmMessages) { +// if (db.getMessageState(txn, confirmMessage) == PENDING) allSent = false; +// } +// if (!allSent) { +// try { +// Thread.sleep(100); +// } catch (InterruptedException e) { +// allSent = true; +// } +// } +// } while(allSent == false); } - private MessageId sendConfirmMessage(Transaction txn, Contact contact) + public void sleep() { + try { + Thread.sleep(5000); + } catch (InterruptedException ignored) {} + } + + private void sendConfirmMessage(Transaction txn, Contact contact) throws DbException, FormatException { Group group = getContactGroup(contact); GroupId g = group.getId(); @@ -372,15 +375,15 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl messageTracker.trackOutgoingMessage(txn, m); // Find the id of this message - List messageIds = (List) db.getMessageIds(txn, g); - Message newestMsg = null; - for (MessageId id : messageIds) { - Message msg = db.getMessage(txn, id); - if (newestMsg == null || msg.getTimestamp() > newestMsg.getTimestamp()) { - newestMsg = msg; - } - } - return newestMsg.getId(); +// List messageIds = (List) db.getMessageIds(txn, g); +// Message newestMsg = null; +// for (MessageId id : messageIds) { +// Message msg = db.getMessage(txn, id); +// if (newestMsg == null || msg.getTimestamp() > newestMsg.getTimestamp()) { +// newestMsg = msg; +// } +// } +// return newestMsg.getId(); } public void wipe(Transaction txn, Contact contact)