Retransmit messages based on maximum latency of transport.

This commit is contained in:
akwizgran
2013-02-06 15:11:55 +00:00
parent 5150737476
commit 9558bd88df
25 changed files with 134 additions and 76 deletions

View File

@@ -503,12 +503,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
} catch(NoSuchContactException expected) {}
try {
db.generateBatch(contactId, 123);
db.generateBatch(contactId, 123, 456);
fail();
} catch(NoSuchContactException expected) {}
try {
db.generateBatch(contactId, 123, Arrays.asList(messageId));
db.generateBatch(contactId, 123, 456, Arrays.asList(messageId));
fail();
} catch(NoSuchContactException expected) {}
@@ -696,14 +696,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
oneOf(database).getRawMessage(txn, messageId1);
will(returnValue(raw1));
// Record the outstanding messages
// FIXME: Calculate the expiry time
oneOf(database).addOutstandingMessages(txn, contactId, sendable,
Long.MAX_VALUE);
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner,
shutdown);
assertEquals(messages, db.generateBatch(contactId, size * 2));
assertEquals(messages, db.generateBatch(contactId, size * 2,
Long.MAX_VALUE));
context.assertIsSatisfied();
}
@@ -733,16 +733,15 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
will(returnValue(raw1)); // Message is sendable
oneOf(database).getRawMessageIfSendable(txn, contactId, messageId2);
will(returnValue(null)); // Message is not sendable
// Record the outstanding messages
// FIXME: Calculate the expiry time
// Record the outstanding message
oneOf(database).addOutstandingMessages(txn, contactId,
Collections.singletonList(messageId1), Long.MAX_VALUE);
Arrays.asList(messageId1), Long.MAX_VALUE);
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner,
shutdown);
assertEquals(messages, db.generateBatch(contactId, size * 3,
requested));
Long.MAX_VALUE, requested));
context.assertIsSatisfied();
}

View File

@@ -524,9 +524,8 @@ public class H2DatabaseTest extends BriarTestCase {
assertTrue(it.hasNext());
assertEquals(messageId, it.next());
assertFalse(it.hasNext());
// FIXME: Calculate the expiry time
db.addOutstandingMessages(txn, contactId,
Collections.singletonList(messageId), Long.MAX_VALUE);
db.addOutstandingMessages(txn, contactId, Arrays.asList(messageId),
Long.MAX_VALUE);
// The message should no longer be sendable
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();

View File

@@ -87,7 +87,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
public void testConnectionTooShort() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, MAX_PACKET_LENGTH, true);
out, MAX_PACKET_LENGTH, Long.MAX_VALUE, true);
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
secret, 0, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
@@ -105,7 +105,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
public void testNothingToSend() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, MIN_CONNECTION_LENGTH, true);
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE, true);
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
secret, 0, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
@@ -134,7 +134,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
oneOf(db).generateAck(with(contactId), with(any(int.class)));
will(returnValue(null));
// No messages to send
oneOf(db).generateBatch(with(contactId), with(any(int.class)));
oneOf(db).generateBatch(with(contactId), with(any(int.class)),
with(any(long.class)));
will(returnValue(null));
}});
connection.write();
@@ -150,7 +151,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
public void testSomethingToSend() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, MIN_CONNECTION_LENGTH, true);
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE, true);
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
secret, 0, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
@@ -183,10 +184,12 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
oneOf(db).generateAck(with(contactId), with(any(int.class)));
will(returnValue(null));
// One message to send
oneOf(db).generateBatch(with(contactId), with(any(int.class)));
oneOf(db).generateBatch(with(contactId), with(any(int.class)),
with(any(long.class)));
will(returnValue(Collections.singletonList(raw)));
// No more messages
oneOf(db).generateBatch(with(contactId), with(any(int.class)));
oneOf(db).generateBatch(with(contactId), with(any(int.class)),
with(any(long.class)));
will(returnValue(null));
}});
connection.write();

View File

@@ -126,7 +126,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
PacketWriterFactory packetWriterFactory =
alice.getInstance(PacketWriterFactory.class);
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, Long.MAX_VALUE, false);
out, Long.MAX_VALUE, Long.MAX_VALUE, false);
ConnectionContext ctx = km.getConnectionContext(contactId, transportId);
assertNotNull(ctx);
OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db,

View File

@@ -8,15 +8,16 @@ import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
class TestSimplexTransportWriter implements SimplexTransportWriter {
private final ByteArrayOutputStream out;
private final long capacity;
private final long capacity, maxLatency;
private final boolean flush;
private boolean disposed = false, exception = false;
TestSimplexTransportWriter(ByteArrayOutputStream out, long capacity,
boolean flush) {
long maxLatency, boolean flush) {
this.out = out;
this.capacity = capacity;
this.maxLatency = maxLatency;
this.flush = flush;
}
@@ -24,6 +25,10 @@ class TestSimplexTransportWriter implements SimplexTransportWriter {
return capacity;
}
public long getMaxLatency() {
return maxLatency;
}
public OutputStream getOutputStream() {
return out;
}