mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
acceptable timestamp of subscribed messages. For a new subscription, the timestamp is initialised to the current time, so a new subscriber to a group will not immediately receive any messages. (Subscribing to a group is therefore more like joining a mailing list than joining a Usenet group - you only receive messages written after you joined.) Once the database fills up and starts expiring messages, the timestamps of subscriptions are updated so that contacts need not send messages that would expire immediately. This is done using the *approximate* timestamp of the oldest message in the database, to avoid revealing the presence or absence of any particular message.
42 lines
1.3 KiB
Java
42 lines
1.3 KiB
Java
package net.sf.briar.protocol;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Map;
|
|
|
|
import net.sf.briar.api.protocol.Group;
|
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
|
import net.sf.briar.api.protocol.Tags;
|
|
import net.sf.briar.api.serial.Consumer;
|
|
import net.sf.briar.api.serial.ObjectReader;
|
|
import net.sf.briar.api.serial.Reader;
|
|
|
|
import com.google.inject.Inject;
|
|
|
|
class SubscriptionReader implements ObjectReader<SubscriptionUpdate> {
|
|
|
|
private final ObjectReader<Group> groupReader;
|
|
private final SubscriptionFactory subscriptionFactory;
|
|
|
|
@Inject
|
|
SubscriptionReader(ObjectReader<Group> groupReader,
|
|
SubscriptionFactory subscriptionFactory) {
|
|
this.groupReader = groupReader;
|
|
this.subscriptionFactory = subscriptionFactory;
|
|
}
|
|
|
|
public SubscriptionUpdate readObject(Reader r) throws IOException {
|
|
// Initialise the consumer
|
|
Consumer counting = new CountingConsumer(SubscriptionUpdate.MAX_SIZE);
|
|
// Read the data
|
|
r.addConsumer(counting);
|
|
r.readUserDefinedTag(Tags.SUBSCRIPTIONS);
|
|
r.addObjectReader(Tags.GROUP, groupReader);
|
|
Map<Group, Long> subs = r.readMap(Group.class, Long.class);
|
|
r.removeObjectReader(Tags.GROUP);
|
|
long timestamp = r.readInt64();
|
|
r.removeConsumer(counting);
|
|
// Build and return the subscription update
|
|
return subscriptionFactory.createSubscriptions(subs, timestamp);
|
|
}
|
|
}
|