mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Add Message Dependencies to Database
This adds a new table to the database to hold message dependencies. It introduces two more message states: pending and delivered The valid column in the database was renamed to state to better reflect its new extended meaning. The DatabaseComponent was extended with three methods for: * adding dependencies * getting dependencies of a message * getting messages that depend on a message (dependents) * getting messages to be delivered (by startup hook) * getting pending messages to be possibly delivered (by startup hook) In order to reflect the new states, things that were previously true for VALID messages have been changed to now be true for DELIVERED messages. Since pending messages should not be available to clients, many database queries have been modified to only return results for delivered messages. All added methods and changes should come with updated unit tests. Please note that the database version was bumped in this commit.
This commit is contained in:
@@ -22,6 +22,8 @@ import org.briarproject.api.transport.TransportKeys;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.briarproject.api.sync.ValidationManager.State;
|
||||
|
||||
/**
|
||||
* Encapsulates the database implementation and exposes high-level operations
|
||||
* to other components.
|
||||
@@ -233,6 +235,24 @@ public interface DatabaseComponent {
|
||||
Collection<MessageId> getMessagesToValidate(Transaction txn, ClientId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the IDs of any messages that need to be delivered to the given
|
||||
* client.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<MessageId> getMessagesToDeliver(Transaction txn, ClientId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the IDs of any messages that are still pending due to
|
||||
* dependencies to other messages for the given client.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<MessageId> getPendingMessages(Transaction txn, ClientId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the message with the given ID, in serialised form, or null if
|
||||
* the message has been deleted.
|
||||
@@ -276,6 +296,22 @@ public interface DatabaseComponent {
|
||||
Collection<MessageStatus> getMessageStatus(Transaction txn, ContactId c,
|
||||
GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the dependencies of the given message.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Map<MessageId, State> getMessageDependencies(Transaction txn, MessageId m)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all IDs of messages that depend on the given message.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Map<MessageId, State> getMessageDependents(Transaction txn, MessageId m)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the status of the given message with respect to the given
|
||||
* contact.
|
||||
@@ -391,11 +427,17 @@ public interface DatabaseComponent {
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the given message as valid or invalid.
|
||||
* Sets the state of the message with respect to validation and delivery.
|
||||
*/
|
||||
void setMessageValid(Transaction txn, Message m, ClientId c, boolean valid)
|
||||
void setMessageState(Transaction txn, Message m, ClientId c, State valid)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Adds dependencies for a message
|
||||
*/
|
||||
void addMessageDependencies(Transaction txn, Message dependent,
|
||||
Collection<MessageId> dependencies) throws DbException;
|
||||
|
||||
/**
|
||||
* Sets the reordering window for the given contact and transport in the
|
||||
* given rotation period.
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.ValidationManager;
|
||||
import static org.briarproject.api.sync.ValidationManager.State;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a message state changed.
|
||||
*/
|
||||
public class MessageStateChangedEvent extends Event {
|
||||
|
||||
private final Message message;
|
||||
private final ClientId clientId;
|
||||
private final boolean local;
|
||||
private final State state;
|
||||
|
||||
public MessageStateChangedEvent(Message message, ClientId clientId,
|
||||
boolean local, State state) {
|
||||
this.message = message;
|
||||
this.clientId = clientId;
|
||||
this.local = local;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public ClientId getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.db.Metadata;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a message has passed or failed validation.
|
||||
*/
|
||||
public class MessageValidatedEvent extends Event {
|
||||
|
||||
private final Message message;
|
||||
private final ClientId clientId;
|
||||
private final boolean local, valid;
|
||||
|
||||
public MessageValidatedEvent(Message message, ClientId clientId,
|
||||
boolean local, boolean valid) {
|
||||
this.message = message;
|
||||
this.clientId = clientId;
|
||||
this.local = local;
|
||||
this.valid = valid;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public ClientId getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,13 @@ import org.briarproject.api.db.Transaction;
|
||||
*/
|
||||
public interface ValidationManager {
|
||||
|
||||
enum Validity {
|
||||
enum State {
|
||||
|
||||
UNKNOWN(0), INVALID(1), VALID(2);
|
||||
UNKNOWN(0), INVALID(1), PENDING(2), VALID(3), DELIVERED(4);
|
||||
|
||||
private final int value;
|
||||
|
||||
Validity(int value) {
|
||||
State(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public interface ValidationManager {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Validity fromValue(int value) {
|
||||
for (Validity s : values()) if (s.value == value) return s;
|
||||
public static State fromValue(int value) {
|
||||
for (State s : values()) if (s.value == value) return s;
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user