Merge branch 'aggressive-polling' into 'master'

Try harder to connect to contacts

* When an outgoing connection is lost, try to reconnect to the contact straight away
* Use periodic polling for Tor, regardless of whether our hidden service descriptor has been published
* Reduce polling intervals for all plugins (this can be reverted if we solve the connectivity issues)

Closes #262, #314. Hopefully helps with #361.

See merge request !177
This commit is contained in:
akwizgran
2016-05-10 14:47:04 +00:00
18 changed files with 230 additions and 127 deletions

View File

@@ -3,6 +3,8 @@ package org.briarproject.plugins;
import org.briarproject.BriarTestCase;
import org.briarproject.api.TransportId;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.event.ConnectionClosedEvent;
import org.briarproject.api.event.ConnectionOpenedEvent;
import org.briarproject.api.event.ContactConnectedEvent;
import org.briarproject.api.event.ContactDisconnectedEvent;
import org.briarproject.api.event.EventBus;
@@ -35,6 +37,10 @@ public class ConnectionRegistryImplTest extends BriarTestCase {
Mockery context = new Mockery();
final EventBus eventBus = context.mock(EventBus.class);
context.checking(new Expectations() {{
exactly(5).of(eventBus).broadcast(with(any(
ConnectionOpenedEvent.class)));
exactly(2).of(eventBus).broadcast(with(any(
ConnectionClosedEvent.class)));
exactly(3).of(eventBus).broadcast(with(any(
ContactConnectedEvent.class)));
oneOf(eventBus).broadcast(with(any(
@@ -49,43 +55,46 @@ public class ConnectionRegistryImplTest extends BriarTestCase {
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
// Check that a registered connection shows up - this should
// broadcast a ContactConnectedEvent
c.registerConnection(contactId, transportId);
// broadcast a ConnectionOpenedEvent and a ContactConnectedEvent
c.registerConnection(contactId, transportId, true);
assertEquals(Collections.singletonList(contactId),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
// Register an identical connection - lookup should be unaffected
c.registerConnection(contactId, transportId);
// Register an identical connection - this should broadcast a
// ConnectionOpenedEvent and lookup should be unaffected
c.registerConnection(contactId, transportId, true);
assertEquals(Collections.singletonList(contactId),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
// Unregister one of the connections - lookup should be unaffected
c.unregisterConnection(contactId, transportId);
// Unregister one of the connections - this should broadcast a
// ConnectionClosedEvent and lookup should be unaffected
c.unregisterConnection(contactId, transportId, true);
assertEquals(Collections.singletonList(contactId),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
// Unregister the other connection - lookup should be affected -
// this should broadcast a ContactDisconnectedEvent
c.unregisterConnection(contactId, transportId);
// Unregister the other connection - this should broadcast a
// ConnectionClosedEvent and a ContactDisconnectedEvent
c.unregisterConnection(contactId, transportId, true);
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId));
assertEquals(Collections.emptyList(),
c.getConnectedContacts(transportId1));
// Try to unregister the connection again - exception should be thrown
try {
c.unregisterConnection(contactId, transportId);
c.unregisterConnection(contactId, transportId, true);
fail();
} catch (IllegalArgumentException expected) {
// Expected
}
// Register both contacts with one transport, one contact with both -
// this should broadcast two ContactConnectedEvents
c.registerConnection(contactId, transportId);
c.registerConnection(contactId1, transportId);
c.registerConnection(contactId1, transportId1);
// this should broadcast three ConnectionOpenedEvents and two
// ContactConnectedEvents
c.registerConnection(contactId, transportId, true);
c.registerConnection(contactId1, transportId, true);
c.registerConnection(contactId1, transportId1, true);
Collection<ContactId> connected = c.getConnectedContacts(transportId);
assertEquals(2, connected.size());
assertTrue(connected.contains(contactId));

View File

@@ -84,9 +84,6 @@ public class PluginManagerImplTest extends BriarTestCase {
will(returnValue(simplexPlugin)); // Created
oneOf(simplexPlugin).start();
will(returnValue(true)); // Started
oneOf(simplexPlugin).shouldPoll();
will(returnValue(true));
oneOf(poller).addPlugin(simplexPlugin);
// Second simplex plugin
oneOf(simplexFailFactory).getId();
will(returnValue(simplexFailId));
@@ -105,8 +102,6 @@ public class PluginManagerImplTest extends BriarTestCase {
will(returnValue(duplexPlugin)); // Created
oneOf(duplexPlugin).start();
will(returnValue(true)); // Started
oneOf(duplexPlugin).shouldPoll();
will(returnValue(false));
// Second duplex plugin
oneOf(duplexFailFactory).getId();
will(returnValue(duplexFailId));
@@ -193,9 +188,6 @@ public class PluginManagerImplTest extends BriarTestCase {
will(returnValue(simplexPlugin)); // Created
oneOf(simplexPlugin).start();
will(returnValue(true)); // Started
oneOf(simplexPlugin).shouldPoll();
will(returnValue(true)); // Should poll
oneOf(poller).addPlugin(simplexPlugin);
// Second simplex plugin
oneOf(simplexFactory1).getId();
will(returnValue(simplexId1));
@@ -204,8 +196,6 @@ public class PluginManagerImplTest extends BriarTestCase {
will(returnValue(simplexPlugin1)); // Created
oneOf(simplexPlugin1).start();
will(returnValue(true)); // Started
oneOf(simplexPlugin1).shouldPoll();
will(returnValue(false)); // Should not poll
// First duplex plugin
oneOf(pluginConfig).getDuplexFactories();
will(returnValue(Arrays.asList(duplexFactory, duplexFactory1)));
@@ -216,9 +206,6 @@ public class PluginManagerImplTest extends BriarTestCase {
will(returnValue(duplexPlugin)); // Created
oneOf(duplexPlugin).start();
will(returnValue(true)); // Started
oneOf(duplexPlugin).shouldPoll();
will(returnValue(true)); // Should poll
oneOf(poller).addPlugin(duplexPlugin);
// Second duplex plugin
oneOf(duplexFactory1).getId();
will(returnValue(duplexId1));
@@ -227,8 +214,6 @@ public class PluginManagerImplTest extends BriarTestCase {
will(returnValue(duplexPlugin1)); // Created
oneOf(duplexPlugin1).start();
will(returnValue(true)); // Started
oneOf(duplexPlugin1).shouldPoll();
will(returnValue(false)); // Should not poll
// Start listening for events
oneOf(eventBus).addListener(with(any(EventListener.class)));
// eventOccurred()