mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Record when the latest subscription/transport update was sent.
This commit is contained in:
@@ -452,6 +452,15 @@ interface Database<T> {
|
|||||||
void setSubscriptions(T txn, ContactId c, Map<Group, Long> subs,
|
void setSubscriptions(T txn, ContactId c, Map<Group, Long> subs,
|
||||||
long timestamp) throws DbException;
|
long timestamp) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records the time at which a subscription update was last sent to the
|
||||||
|
* given contact.
|
||||||
|
* <p>
|
||||||
|
* Locking: contacts read, subscriptions write.
|
||||||
|
*/
|
||||||
|
void setSubscriptionTimestamp(T txn, ContactId c, long timestamp)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the configuration for the transport with the given name, replacing
|
* Sets the configuration for the transport with the given name, replacing
|
||||||
* any existing configuration for that transport.
|
* any existing configuration for that transport.
|
||||||
@@ -481,6 +490,15 @@ interface Database<T> {
|
|||||||
Map<String, Map<String, String>> transports, long timestamp)
|
Map<String, Map<String, String>> transports, long timestamp)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records the time at which a transport update was last sent to the given
|
||||||
|
* contact.
|
||||||
|
* <p>
|
||||||
|
* Locking: contacts read, transports write.
|
||||||
|
*/
|
||||||
|
void setTransportTimestamp(T txn, ContactId c, long timestamp)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the given group visible to the given set of contacts and invisible
|
* Makes the given group visible to the given set of contacts and invisible
|
||||||
* to any other contacts.
|
* to any other contacts.
|
||||||
|
|||||||
@@ -596,26 +596,29 @@ DatabaseCleaner.Callback {
|
|||||||
public void generateSubscriptionUpdate(ContactId c, SubscriptionWriter s)
|
public void generateSubscriptionUpdate(ContactId c, SubscriptionWriter s)
|
||||||
throws DbException, IOException {
|
throws DbException, IOException {
|
||||||
Map<Group, Long> subs;
|
Map<Group, Long> subs;
|
||||||
|
long timestamp;
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
if(!containsContact(c)) throw new NoSuchContactException();
|
if(!containsContact(c)) throw new NoSuchContactException();
|
||||||
subscriptionLock.readLock().lock();
|
subscriptionLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
subs = db.getVisibleSubscriptions(txn, c);
|
subs = db.getVisibleSubscriptions(txn, c);
|
||||||
|
timestamp = System.currentTimeMillis();
|
||||||
|
db.setSubscriptionTimestamp(txn, c, timestamp);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
subscriptionLock.readLock().unlock();
|
subscriptionLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
contactLock.readLock().unlock();
|
contactLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
s.writeSubscriptions(subs, System.currentTimeMillis());
|
s.writeSubscriptions(subs, timestamp);
|
||||||
if(LOG.isLoggable(Level.FINE))
|
if(LOG.isLoggable(Level.FINE))
|
||||||
LOG.fine("Added " + subs.size() + " subscriptions to update");
|
LOG.fine("Added " + subs.size() + " subscriptions to update");
|
||||||
}
|
}
|
||||||
@@ -623,26 +626,29 @@ DatabaseCleaner.Callback {
|
|||||||
public void generateTransportUpdate(ContactId c, TransportWriter t)
|
public void generateTransportUpdate(ContactId c, TransportWriter t)
|
||||||
throws DbException, IOException {
|
throws DbException, IOException {
|
||||||
Map<String, Map<String, String>> transports;
|
Map<String, Map<String, String>> transports;
|
||||||
|
long timestamp;
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
if(!containsContact(c)) throw new NoSuchContactException();
|
if(!containsContact(c)) throw new NoSuchContactException();
|
||||||
transportLock.readLock().lock();
|
transportLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
transports = db.getTransports(txn);
|
transports = db.getTransports(txn);
|
||||||
|
timestamp = System.currentTimeMillis();
|
||||||
|
db.setTransportTimestamp(txn, c, timestamp);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
transportLock.readLock().unlock();
|
transportLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
contactLock.readLock().unlock();
|
contactLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
t.writeTransports(transports, System.currentTimeMillis());
|
t.writeTransports(transports, timestamp);
|
||||||
if(LOG.isLoggable(Level.FINE))
|
if(LOG.isLoggable(Level.FINE))
|
||||||
LOG.fine("Added " + transports.size() + " transports to update");
|
LOG.fine("Added " + transports.size() + " transports to update");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -753,6 +753,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
// Get the visible subscriptions
|
// Get the visible subscriptions
|
||||||
oneOf(database).getVisibleSubscriptions(txn, contactId);
|
oneOf(database).getVisibleSubscriptions(txn, contactId);
|
||||||
will(returnValue(Collections.singletonMap(group, 0L)));
|
will(returnValue(Collections.singletonMap(group, 0L)));
|
||||||
|
oneOf(database).setSubscriptionTimestamp(with(txn), with(contactId),
|
||||||
|
with(any(long.class)));
|
||||||
// Add the subscriptions to the writer
|
// Add the subscriptions to the writer
|
||||||
oneOf(subscriptionWriter).writeSubscriptions(
|
oneOf(subscriptionWriter).writeSubscriptions(
|
||||||
with(Collections.singletonMap(group, 0L)),
|
with(Collections.singletonMap(group, 0L)),
|
||||||
@@ -786,6 +788,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
// Get the local transport properties
|
// Get the local transport properties
|
||||||
oneOf(database).getTransports(txn);
|
oneOf(database).getTransports(txn);
|
||||||
will(returnValue(transports));
|
will(returnValue(transports));
|
||||||
|
oneOf(database).setTransportTimestamp(with(txn), with(contactId),
|
||||||
|
with(any(long.class)));
|
||||||
// Add the properties to the writer
|
// Add the properties to the writer
|
||||||
oneOf(transportWriter).writeTransports(with(transports),
|
oneOf(transportWriter).writeTransports(with(transports),
|
||||||
with(any(long.class)));
|
with(any(long.class)));
|
||||||
|
|||||||
Reference in New Issue
Block a user