Associate a timestamp with every subscription, indicating the earliest

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.
This commit is contained in:
akwizgran
2011-08-05 13:34:58 +01:00
parent 6c5ce05c5d
commit c2045296eb
15 changed files with 283 additions and 130 deletions

View File

@@ -37,6 +37,7 @@ public interface DatabaseComponent {
static final int MAX_BYTES_BETWEEN_SPACE_CHECKS = 5 * MEGABYTES;
static final long MAX_MS_BETWEEN_SPACE_CHECKS = 60L * 1000L; // 1 min
static final int BYTES_PER_SWEEP = 5 * MEGABYTES;
static final long EXPIRY_MODULUS = 60L * 60L * 1000L; // 1 hour
/**
* Opens the database.

View File

@@ -1,6 +1,6 @@
package net.sf.briar.api.protocol;
import java.util.Collection;
import java.util.Map;
/** A packet updating the sender's subscriptions. */
public interface SubscriptionUpdate {
@@ -12,7 +12,7 @@ public interface SubscriptionUpdate {
static final int MAX_SIZE = (1024 * 1024) - 100;
/** Returns the subscriptions contained in the update. */
Collection<Group> getSubscriptions();
Map<Group, Long> getSubscriptions();
/**
* Returns the update's timestamp. Updates that are older than the newest

View File

@@ -1,7 +1,7 @@
package net.sf.briar.api.protocol.writers;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import net.sf.briar.api.protocol.Group;
@@ -9,5 +9,5 @@ import net.sf.briar.api.protocol.Group;
public interface SubscriptionWriter {
/** Writes the contents of the update. */
void writeSubscriptions(Collection<Group> subs) throws IOException;
void writeSubscriptions(Map<Group, Long> subs) throws IOException;
}