diff --git a/api/net/sf/briar/api/protocol/writers/SubscriptionWriter.java b/api/net/sf/briar/api/protocol/writers/SubscriptionWriter.java index e3f81b917f77cf2494e3db95437693704960696d..fe88229a9dc3fa5a5f63fbc2b74aeceb46fdad16 100644 --- a/api/net/sf/briar/api/protocol/writers/SubscriptionWriter.java +++ b/api/net/sf/briar/api/protocol/writers/SubscriptionWriter.java @@ -9,5 +9,6 @@ import net.sf.briar.api.protocol.Group; public interface SubscriptionWriter { /** Writes the contents of the update. */ - void writeSubscriptions(Map<Group, Long> subs) throws IOException; + void writeSubscriptionUpdate(Map<Group, Long> subs, long timestamp) + throws IOException; } diff --git a/api/net/sf/briar/api/protocol/writers/TransportWriter.java b/api/net/sf/briar/api/protocol/writers/TransportWriter.java index a8e7f9f76a3e8d86c6a09285967878750b3d83fd..70fb8251cf3c4d09d35be7de345d25cad28570ff 100644 --- a/api/net/sf/briar/api/protocol/writers/TransportWriter.java +++ b/api/net/sf/briar/api/protocol/writers/TransportWriter.java @@ -7,6 +7,6 @@ import java.util.Map; public interface TransportWriter { /** Writes the contents of the update. */ - void writeTransports(Map<String, Map<String, String>> transports) - throws IOException; + void writeTransportUpdate(Map<String, Map<String, String>> transports, + long timestamp) throws IOException; } diff --git a/components/net/sf/briar/db/ReadWriteLockDatabaseComponent.java b/components/net/sf/briar/db/ReadWriteLockDatabaseComponent.java index eb8e93375e0425c26e2fa318685f3a8b09c736be..adc1e64a4668d340049afd4a1c5968e75f4fcb73 100644 --- a/components/net/sf/briar/db/ReadWriteLockDatabaseComponent.java +++ b/components/net/sf/briar/db/ReadWriteLockDatabaseComponent.java @@ -445,7 +445,7 @@ class ReadWriteLockDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> { Txn txn = db.startTransaction(); try { Map<Group, Long> subs = db.getVisibleSubscriptions(txn, c); - s.writeSubscriptions(subs); + s.writeSubscriptionUpdate(subs, System.currentTimeMillis()); if(LOG.isLoggable(Level.FINE)) LOG.fine("Added " + subs.size() + " subscriptions"); db.commitTransaction(txn); @@ -475,7 +475,8 @@ class ReadWriteLockDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> { try { Map<String, Map<String, String>> transports = db.getTransports(txn); - t.writeTransports(transports); + long timestamp = System.currentTimeMillis(); + t.writeTransportUpdate(transports, timestamp); if(LOG.isLoggable(Level.FINE)) LOG.fine("Added " + transports.size() + " transports"); db.commitTransaction(txn); diff --git a/components/net/sf/briar/db/SynchronizedDatabaseComponent.java b/components/net/sf/briar/db/SynchronizedDatabaseComponent.java index 466efead756b2c75674443ed1fe9316cf4cdef00..5bc52fd67bc08f3966a167caedf812829a03b7f4 100644 --- a/components/net/sf/briar/db/SynchronizedDatabaseComponent.java +++ b/components/net/sf/briar/db/SynchronizedDatabaseComponent.java @@ -339,7 +339,7 @@ class SynchronizedDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> { Txn txn = db.startTransaction(); try { Map<Group, Long> subs = db.getVisibleSubscriptions(txn, c); - s.writeSubscriptions(subs); + s.writeSubscriptionUpdate(subs, System.currentTimeMillis()); if(LOG.isLoggable(Level.FINE)) LOG.fine("Added " + subs.size() + " subscriptions"); db.commitTransaction(txn); @@ -363,7 +363,8 @@ class SynchronizedDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> { try { Map<String, Map<String, String>> transports = db.getTransports(txn); - t.writeTransports(transports); + long timestamp = System.currentTimeMillis(); + t.writeTransportUpdate(transports, timestamp); if(LOG.isLoggable(Level.FINE)) LOG.fine("Added " + transports.size() + " transports"); db.commitTransaction(txn); diff --git a/components/net/sf/briar/protocol/writers/SubscriptionWriterImpl.java b/components/net/sf/briar/protocol/writers/SubscriptionWriterImpl.java index b8f080e27ba640e46ace381ba2d2796ecc8f24e1..9e7d5c6329618e639caeb5f68d2b58aa6393dd8e 100644 --- a/components/net/sf/briar/protocol/writers/SubscriptionWriterImpl.java +++ b/components/net/sf/briar/protocol/writers/SubscriptionWriterImpl.java @@ -20,10 +20,11 @@ class SubscriptionWriterImpl implements SubscriptionWriter { w = writerFactory.createWriter(out); } - public void writeSubscriptions(Map<Group, Long> subs) throws IOException { + public void writeSubscriptionUpdate(Map<Group, Long> subs, long timestamp) + throws IOException { w.writeUserDefinedTag(Tags.SUBSCRIPTION_UPDATE); w.writeMap(subs); - w.writeInt64(System.currentTimeMillis()); + w.writeInt64(timestamp); out.flush(); } } diff --git a/components/net/sf/briar/protocol/writers/TransportWriterImpl.java b/components/net/sf/briar/protocol/writers/TransportWriterImpl.java index 8381f4d0648ce52f10ecc69bf2d11e8633cd7b4a..aeb74c5e6bac88a457ab41ed5006913a75be23cf 100644 --- a/components/net/sf/briar/protocol/writers/TransportWriterImpl.java +++ b/components/net/sf/briar/protocol/writers/TransportWriterImpl.java @@ -20,7 +20,8 @@ class TransportWriterImpl implements TransportWriter { w = writerFactory.createWriter(out); } - public void writeTransports(Map<String, Map<String, String>> transports) + public void writeTransportUpdate( + Map<String, Map<String, String>> transports, long timestamp) throws IOException { w.writeUserDefinedTag(Tags.TRANSPORT_UPDATE); w.writeListStart(); @@ -30,7 +31,7 @@ class TransportWriterImpl implements TransportWriter { w.writeMap(e.getValue()); } w.writeListEnd(); - w.writeInt64(System.currentTimeMillis()); + w.writeInt64(timestamp); out.flush(); } } diff --git a/test/net/sf/briar/FileReadWriteTest.java b/test/net/sf/briar/FileReadWriteTest.java index 363710f53ba5c94c1b4bc7563cfa0bd9518efd25..64725290bbd40470d1dbffdadd427b3b5b57452e 100644 --- a/test/net/sf/briar/FileReadWriteTest.java +++ b/test/net/sf/briar/FileReadWriteTest.java @@ -64,7 +64,7 @@ public class FileReadWriteTest extends TestCase { private final File file = new File(testDir, "foo"); private final BatchId ack = new BatchId(TestUtils.getRandomId()); - private final long start = System.currentTimeMillis(); + private final long timestamp = System.currentTimeMillis(); private final PacketReaderFactory packetReaderFactory; private final PacketWriterFactory packetWriterFactory; @@ -172,11 +172,11 @@ public class FileReadWriteTest extends TestCase { Map<Group, Long> subs = new LinkedHashMap<Group, Long>(); subs.put(group, 0L); subs.put(group1, 0L); - s.writeSubscriptions(subs); + s.writeSubscriptionUpdate(subs, timestamp); packetWriter.finishPacket(); TransportWriter t = protocolWriterFactory.createTransportWriter(out); - t.writeTransports(transports); + t.writeTransportUpdate(transports, timestamp); packetWriter.finishPacket(); out.flush(); @@ -257,16 +257,14 @@ public class FileReadWriteTest extends TestCase { assertEquals(2, subs.size()); assertEquals(Long.valueOf(0L), subs.get(group)); assertEquals(Long.valueOf(0L), subs.get(group1)); - assertTrue(s.getTimestamp() > start); - assertTrue(s.getTimestamp() <= System.currentTimeMillis()); + assertTrue(s.getTimestamp() == timestamp); // Read the transport update assertTrue(protocolReader.hasTransportUpdate()); TransportUpdate t = protocolReader.readTransportUpdate(); packetReader.finishPacket(); assertEquals(transports, t.getTransports()); - assertTrue(t.getTimestamp() > start); - assertTrue(t.getTimestamp() <= System.currentTimeMillis()); + assertTrue(t.getTimestamp() == timestamp); in.close(); } diff --git a/test/net/sf/briar/db/DatabaseComponentTest.java b/test/net/sf/briar/db/DatabaseComponentTest.java index f49ce59077b5458545c7e4cd47b9b228564fcbf4..f1d6eef22551f294f0ef5cb060ae5c65276afba3 100644 --- a/test/net/sf/briar/db/DatabaseComponentTest.java +++ b/test/net/sf/briar/db/DatabaseComponentTest.java @@ -779,8 +779,9 @@ public abstract class DatabaseComponentTest extends TestCase { oneOf(database).getVisibleSubscriptions(txn, contactId); will(returnValue(Collections.singletonMap(group, 0L))); // Add the subscriptions to the writer - oneOf(subscriptionWriter).writeSubscriptions( - Collections.singletonMap(group, 0L)); + oneOf(subscriptionWriter).writeSubscriptionUpdate( + with(Collections.singletonMap(group, 0L)), + with(any(long.class))); }}); DatabaseComponent db = createDatabaseComponent(database, cleaner); @@ -811,7 +812,8 @@ public abstract class DatabaseComponentTest extends TestCase { oneOf(database).getTransports(txn); will(returnValue(transports)); // Add the properties to the writer - oneOf(transportWriter).writeTransports(transports); + oneOf(transportWriter).writeTransportUpdate(with(transports), + with(any(long.class))); }}); DatabaseComponent db = createDatabaseComponent(database, cleaner); diff --git a/test/net/sf/briar/protocol/ProtocolReadWriteTest.java b/test/net/sf/briar/protocol/ProtocolReadWriteTest.java index 3757ad9f04f19b04a7fd47e8ff24ca79031f2417..e4cbc879f9f0dbdd15c8cfe97800738c16e01cd6 100644 --- a/test/net/sf/briar/protocol/ProtocolReadWriteTest.java +++ b/test/net/sf/briar/protocol/ProtocolReadWriteTest.java @@ -51,6 +51,7 @@ public class ProtocolReadWriteTest extends TestCase { private final BitSet bitSet; private final Map<Group, Long> subscriptions; private final Map<String, Map<String, String>> transports; + private final long timestamp = System.currentTimeMillis(); public ProtocolReadWriteTest() throws Exception { super(); @@ -75,8 +76,6 @@ public class ProtocolReadWriteTest extends TestCase { @Test public void testWriteAndRead() throws Exception { - long start = System.currentTimeMillis(); - // Write ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -96,10 +95,10 @@ public class ProtocolReadWriteTest extends TestCase { r.writeRequest(offerId, bitSet, 10); SubscriptionWriter s = writerFactory.createSubscriptionWriter(out); - s.writeSubscriptions(subscriptions); + s.writeSubscriptionUpdate(subscriptions, timestamp); TransportWriter t = writerFactory.createTransportWriter(out); - t.writeTransports(transports); + t.writeTransportUpdate(transports, timestamp); // Read ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); @@ -120,10 +119,10 @@ public class ProtocolReadWriteTest extends TestCase { SubscriptionUpdate subscriptionUpdate = reader.readSubscriptionUpdate(); assertEquals(subscriptions, subscriptionUpdate.getSubscriptions()); - assertTrue(subscriptionUpdate.getTimestamp() >= start); + assertTrue(subscriptionUpdate.getTimestamp() == timestamp); TransportUpdate transportUpdate = reader.readTransportUpdate(); assertEquals(transports, transportUpdate.getTransports()); - assertTrue(transportUpdate.getTimestamp() >= start); + assertTrue(transportUpdate.getTimestamp() == timestamp); } }