Added a connection registry to avoid creating redundant connections.

This commit is contained in:
akwizgran
2011-12-09 17:34:58 +00:00
parent 9abe920edb
commit f9f41acde9
69 changed files with 435 additions and 182 deletions

View File

@@ -1,7 +1,9 @@
package net.sf.briar.api.plugins;
import java.io.IOException;
import java.util.Collection;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportId;
public interface Plugin {
@@ -28,10 +30,11 @@ public interface Plugin {
long getPollingInterval();
/**
* Attempts to establish connections to all contacts, passing any created
* connections to the callback.
* Attempts to establish connections to contacts, passing any created
* connections to the callback. To avoid creating redundant connections,
* the plugin may exclude the given contacts from polling.
*/
void poll();
void poll(Collection<ContactId> connected);
/** Returns true if the plugin supports exchanging invitations. */
boolean supportsInvitations();

View File

@@ -1,6 +1,7 @@
package net.sf.briar.api.protocol.batch;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.BatchTransportReader;
import net.sf.briar.api.transport.BatchTransportWriter;
@@ -8,9 +9,9 @@ import net.sf.briar.api.transport.ConnectionContext;
public interface BatchConnectionFactory {
void createIncomingConnection(ConnectionContext ctx,
void createIncomingConnection(ConnectionContext ctx, TransportId t,
BatchTransportReader r, byte[] tag);
void createOutgoingConnection(ContactId c, TransportIndex i,
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
BatchTransportWriter w);
}

View File

@@ -1,15 +1,16 @@
package net.sf.briar.api.protocol.stream;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.ConnectionContext;
import net.sf.briar.api.transport.StreamTransportConnection;
public interface StreamConnectionFactory {
void createIncomingConnection(ConnectionContext ctx,
void createIncomingConnection(ConnectionContext ctx, TransportId t,
StreamTransportConnection s, byte[] tag);
void createOutgoingConnection(ContactId c, TransportIndex i,
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
StreamTransportConnection s);
}

View File

@@ -8,10 +8,11 @@ public interface ConnectionDispatcher {
void dispatchReader(TransportId t, BatchTransportReader r);
void dispatchWriter(ContactId c, TransportIndex i, BatchTransportWriter w);
void dispatchWriter(ContactId c, TransportId t, TransportIndex i,
BatchTransportWriter w);
void dispatchIncomingConnection(TransportId t, StreamTransportConnection s);
void dispatchOutgoingConnection(ContactId c, TransportIndex i,
StreamTransportConnection s);
void dispatchOutgoingConnection(ContactId c, TransportId t,
TransportIndex i, StreamTransportConnection s);
}

View File

@@ -0,0 +1,18 @@
package net.sf.briar.api.transport;
import java.util.Collection;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportId;
/**
* Keeps track of which contacts are currently connected by which transports.
*/
public interface ConnectionRegistry {
void registerConnection(ContactId c, TransportId t);
void unregisterConnection(ContactId c, TransportId t);
Collection<ContactId> getConnectedContacts(TransportId t);
}