The response to a BMP Offer is now an Ack and/or a Request.

The Request packet now contains a list of message IDs, rather than a
bitmap referring to the list of messages IDs in the Offer. This allows
the Request to be understood out of context, e.g. if the Offer and
Request are sent over separate connections or a connection is replayed.
This commit is contained in:
akwizgran
2013-11-19 22:13:26 +00:00
parent 2e472c1d16
commit 1a351535be
12 changed files with 128 additions and 302 deletions

View File

@@ -0,0 +1,27 @@
package net.sf.briar.api.db;
import net.sf.briar.api.messaging.Ack;
import net.sf.briar.api.messaging.Request;
/**
* A tuple of an {@link net.sf.briar.api.messaging.Ack} and a
* {@link net.sf.briar.api.messaging.Request}.
*/
public class AckAndRequest {
private final Ack ack;
private final Request request;
public AckAndRequest(Ack ack, Request request) {
this.ack = ack;
this.request = request;
}
public Ack getAck() {
return ack;
}
public Request getRequest() {
return request;
}
}

View File

@@ -20,7 +20,6 @@ import net.sf.briar.api.messaging.GroupStatus;
import net.sf.briar.api.messaging.Message;
import net.sf.briar.api.messaging.MessageId;
import net.sf.briar.api.messaging.Offer;
import net.sf.briar.api.messaging.Request;
import net.sf.briar.api.messaging.RetentionAck;
import net.sf.briar.api.messaging.RetentionUpdate;
import net.sf.briar.api.messaging.SubscriptionAck;
@@ -98,9 +97,9 @@ public interface DatabaseComponent {
* collection of requested messages, with a total length less than or equal
* to the given length, for transmission over a transport with the given
* maximum latency. Any messages that were either added to the batch, or
* were considered but are no longer sendable to the contact, are removed
* from the collection of requested messages before returning. Returns null
* if there are no sendable messages that fit in the given length.
* were considered but are not sendable to the contact, are removed from
* the collection of requested messages before returning. Returns null if
* there are no sendable messages that fit in the given length.
*/
Collection<byte[]> generateBatch(ContactId c, int maxLength,
long maxLatency, Collection<MessageId> requested)
@@ -259,14 +258,17 @@ public interface DatabaseComponent {
void receiveMessage(ContactId c, Message m) throws DbException;
/**
* Processes an offer from the given contact and generates a request for
* any messages in the offer that the contact should send. To prevent
* contacts from using offers to test for subscriptions that are not
* visible to them, any messages belonging to groups that are not visible
* to the contact are requested just as though they were not present in the
* database.
* Processes an offer from the given contact and generates an ack for any
* messages in the offer that are present in the database, and a request
* for any messages that are not. The ack or the request may be null if no
* messages meet the respective criteria.
* <p>
* To prevent contacts from using offers to test for subscriptions that are
* not visible to them, any messages belonging to groups that are not
* visible to the contact are requested just as though they were not
* present in the database.
*/
Request receiveOffer(ContactId c, Offer o) throws DbException;
AckAndRequest receiveOffer(ContactId c, Offer o) throws DbException;
/** Processes a retention ack from the given contact. */
void receiveRetentionAck(ContactId c, RetentionAck a) throws DbException;

View File

@@ -1,31 +1,18 @@
package net.sf.briar.api.messaging;
import java.util.BitSet;
import java.util.Collection;
/**
* A packet requesting some or all of the {@link Message}s from an
* {@link Offer}.
*/
/** A packet requesting one or more {@link Message}s from the recipient. */
public class Request {
private final BitSet requested;
private final int length;
private final Collection<MessageId> requested;
public Request(BitSet requested, int length) {
public Request(Collection<MessageId> requested) {
this.requested = requested;
this.length = length;
}
/**
* Returns a sequence of bits corresponding to the sequence of messages in
* the offer, where the i^th bit is set if the i^th message should be sent.
*/
public BitSet getBitmap() {
/** Returns the identifiers of the requested messages. */
public Collection<MessageId> getMessageIds() {
return requested;
}
/** Returns the length of the bitmap in bits. */
public int getLength() {
return length;
}
}