mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Add message header for confirm message. Await delivery before wiping
This commit is contained in:
@@ -21,6 +21,7 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.sync.MessageStatus;
|
import org.briarproject.bramble.api.sync.MessageStatus;
|
||||||
|
import org.briarproject.bramble.api.sync.validation.MessageState;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
@@ -47,6 +48,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.bramble.api.sync.validation.MessageState.PENDING;
|
||||||
import static org.briarproject.briar.api.remotewipe.MessageType.CONFIRM;
|
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;
|
||||||
@@ -197,10 +199,10 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
// Send a CONFIRM message to each wiper
|
// Send a CONFIRM message to each wiper
|
||||||
sendConfirmMessages(txn);
|
sendConfirmMessages(txn);
|
||||||
|
|
||||||
// if (observer != null) {
|
if (observer != null) {
|
||||||
// observer.onPanic();
|
observer.onPanic();
|
||||||
// }
|
}
|
||||||
// txn.attach(new RemoteWipeActivatedEvent());
|
txn.attach(new RemoteWipeActivatedEvent());
|
||||||
|
|
||||||
// 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
|
||||||
@@ -233,7 +235,6 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
clientHelper
|
clientHelper
|
||||||
.mergeGroupMetadata(txn, localGroup.getId(), localRecord);
|
.mergeGroupMetadata(txn, localGroup.getId(), localRecord);
|
||||||
} else if (type == CONFIRM) {
|
} else if (type == CONFIRM) {
|
||||||
LOG.info("*** Got confirm msg");
|
|
||||||
messageTracker.trackIncomingMessage(txn, m);
|
messageTracker.trackIncomingMessage(txn, m);
|
||||||
ContactId contactId = getContactId(txn, m.getGroupId());
|
ContactId contactId = getContactId(txn, m.getGroupId());
|
||||||
|
|
||||||
@@ -331,13 +332,28 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
private void sendConfirmMessages(Transaction txn)
|
private void sendConfirmMessages(Transaction txn)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
List<ContactId> wipers = getWiperContactIds(txn);
|
List<ContactId> wipers = getWiperContactIds(txn);
|
||||||
|
List<MessageId> confirmMessages = new ArrayList<>();
|
||||||
for (ContactId c : wipers) {
|
for (ContactId c : wipers) {
|
||||||
Contact contact = contactManager.getContact(txn, c);
|
Contact contact = contactManager.getContact(txn, c);
|
||||||
sendConfirmMessage(txn, contact);
|
confirmMessages.add(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendConfirmMessage(Transaction txn, Contact contact)
|
private MessageId sendConfirmMessage(Transaction txn, Contact contact)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
Group group = getContactGroup(contact);
|
Group group = getContactGroup(contact);
|
||||||
GroupId g = group.getId();
|
GroupId g = group.getId();
|
||||||
@@ -354,6 +370,17 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
);
|
);
|
||||||
clientHelper.addLocalMessage(txn, m, meta, true, false);
|
clientHelper.addLocalMessage(txn, m, meta, true, false);
|
||||||
messageTracker.trackOutgoingMessage(txn, m);
|
messageTracker.trackOutgoingMessage(txn, m);
|
||||||
|
|
||||||
|
// Find the id of this message
|
||||||
|
List<MessageId> messageIds = (List<MessageId>) 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)
|
public void wipe(Transaction txn, Contact contact)
|
||||||
@@ -480,6 +507,14 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
messageEntry.getKey());
|
messageEntry.getKey());
|
||||||
headers.add(
|
headers.add(
|
||||||
createMessageHeader(message, meta, status, REVOKE));
|
createMessageHeader(message, meta, status, REVOKE));
|
||||||
|
} else if (meta.getLong(MSG_KEY_MESSAGE_TYPE).intValue() ==
|
||||||
|
CONFIRM.getValue()) {
|
||||||
|
Message message = clientHelper
|
||||||
|
.getMessage(txn, messageEntry.getKey());
|
||||||
|
MessageStatus status = db.getMessageStatus(txn, contactId,
|
||||||
|
messageEntry.getKey());
|
||||||
|
headers.add(
|
||||||
|
createMessageHeader(message, meta, status, CONFIRM));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return headers;
|
return headers;
|
||||||
|
|||||||
Reference in New Issue
Block a user