mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Refactoring.
Unidirectional transports and connections are now called simplex rather than batch. Bidirectional transports and connections are now called duplex rather than stream.
This commit is contained in:
@@ -1,50 +0,0 @@
|
|||||||
package net.sf.briar.api.plugins;
|
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface for transport plugins that do not support bidirectional,
|
|
||||||
* reliable, ordered, timely delivery of data.
|
|
||||||
*/
|
|
||||||
public interface BatchPlugin extends Plugin {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to create and return a BatchTransportReader for the given
|
|
||||||
* contact using the current transport and configuration properties.
|
|
||||||
* Returns null if a reader could not be created.
|
|
||||||
*/
|
|
||||||
BatchTransportReader createReader(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to create and return a BatchTransportWriter for the given
|
|
||||||
* contact using the current transport and configuration properties.
|
|
||||||
* Returns null if a writer could not be created.
|
|
||||||
*/
|
|
||||||
BatchTransportWriter createWriter(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the invitation process from the inviter's side. Returns null if
|
|
||||||
* no connection can be established within the given timeout.
|
|
||||||
*/
|
|
||||||
BatchTransportWriter sendInvitation(int code, long timeout);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the invitation process from the invitee's side. Returns null if
|
|
||||||
* no connection can be established within the given timeout.
|
|
||||||
*/
|
|
||||||
BatchTransportReader acceptInvitation(int code, long timeout);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Continues the invitation process from the invitee's side. Returns null
|
|
||||||
* if no connection can be established within the given timeout.
|
|
||||||
*/
|
|
||||||
BatchTransportWriter sendInvitationResponse(int code, long timeout);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Continues the invitation process from the inviter's side. Returns null
|
|
||||||
* if no connection can be established within the given timeout.
|
|
||||||
*/
|
|
||||||
BatchTransportReader acceptInvitationResponse(int code, long timeout);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package net.sf.briar.api.plugins;
|
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface for receiving readers and writers created by a batch-mode
|
|
||||||
* transport plugin.
|
|
||||||
*/
|
|
||||||
public interface BatchPluginCallback extends PluginCallback {
|
|
||||||
|
|
||||||
void readerCreated(BatchTransportReader r);
|
|
||||||
|
|
||||||
void writerCreated(ContactId c, BatchTransportWriter w);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package net.sf.briar.api.plugins;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
public interface BatchPluginFactory {
|
|
||||||
|
|
||||||
BatchPlugin createPlugin(Executor pluginExecutor,
|
|
||||||
BatchPluginCallback callback);
|
|
||||||
}
|
|
||||||
26
api/net/sf/briar/api/plugins/DuplexPlugin.java
Normal file
26
api/net/sf/briar/api/plugins/DuplexPlugin.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
|
import net.sf.briar.api.ContactId;
|
||||||
|
|
||||||
|
/** An interface for transport plugins that support duplex communication. */
|
||||||
|
public interface DuplexPlugin extends Plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to create and return a connection to the given contact using
|
||||||
|
* the current transport and configuration properties. Returns null if a
|
||||||
|
* connection could not be created.
|
||||||
|
*/
|
||||||
|
DuplexTransportConnection createConnection(ContactId c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the invitation process from the inviter's side. Returns null if
|
||||||
|
* no connection can be established within the given timeout.
|
||||||
|
*/
|
||||||
|
DuplexTransportConnection sendInvitation(int code, long timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the invitation process from the invitee's side. Returns null if
|
||||||
|
* no connection can be established within the given timeout.
|
||||||
|
*/
|
||||||
|
DuplexTransportConnection acceptInvitation(int code, long timeout);
|
||||||
|
}
|
||||||
13
api/net/sf/briar/api/plugins/DuplexPluginCallback.java
Normal file
13
api/net/sf/briar/api/plugins/DuplexPluginCallback.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
|
import net.sf.briar.api.ContactId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for receiving connections created by a duplex transport plugin.
|
||||||
|
*/
|
||||||
|
public interface DuplexPluginCallback extends PluginCallback {
|
||||||
|
|
||||||
|
void incomingConnectionCreated(DuplexTransportConnection d);
|
||||||
|
|
||||||
|
void outgoingConnectionCreated(ContactId c, DuplexTransportConnection d);
|
||||||
|
}
|
||||||
9
api/net/sf/briar/api/plugins/DuplexPluginFactory.java
Normal file
9
api/net/sf/briar/api/plugins/DuplexPluginFactory.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
public interface DuplexPluginFactory {
|
||||||
|
|
||||||
|
DuplexPlugin createPlugin(Executor pluginExecutor,
|
||||||
|
DuplexPluginCallback callback);
|
||||||
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package net.sf.briar.api.transport;
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for reading and writing data over a stream-mode transport. The
|
* An interface for reading and writing data over a duplex transport. The
|
||||||
* connection is not responsible for encrypting/decrypting or authenticating
|
* connection is not responsible for encrypting/decrypting or authenticating
|
||||||
* the data.
|
* the data.
|
||||||
*/
|
*/
|
||||||
public interface StreamTransportConnection {
|
public interface DuplexTransportConnection {
|
||||||
|
|
||||||
/** Returns an input stream for reading from the connection. */
|
/** Returns an input stream for reading from the connection. */
|
||||||
InputStream getInputStream() throws IOException;
|
InputStream getInputStream() throws IOException;
|
||||||
45
api/net/sf/briar/api/plugins/SimplexPlugin.java
Normal file
45
api/net/sf/briar/api/plugins/SimplexPlugin.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
|
import net.sf.briar.api.ContactId;
|
||||||
|
|
||||||
|
/** An interface for transport plugins that support simplex communication. */
|
||||||
|
public interface SimplexPlugin extends Plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to create and return a reader for the given contact using the
|
||||||
|
* current transport and configuration properties. Returns null if a reader
|
||||||
|
* could not be created.
|
||||||
|
*/
|
||||||
|
SimplexTransportReader createReader(ContactId c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to create and return a writer for the given contact using the
|
||||||
|
* current transport and configuration properties. Returns null if a writer
|
||||||
|
* could not be created.
|
||||||
|
*/
|
||||||
|
SimplexTransportWriter createWriter(ContactId c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the invitation process from the inviter's side. Returns null if
|
||||||
|
* no connection can be established within the given timeout.
|
||||||
|
*/
|
||||||
|
SimplexTransportWriter sendInvitation(int code, long timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the invitation process from the invitee's side. Returns null if
|
||||||
|
* no connection can be established within the given timeout.
|
||||||
|
*/
|
||||||
|
SimplexTransportReader acceptInvitation(int code, long timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Continues the invitation process from the invitee's side. Returns null
|
||||||
|
* if no connection can be established within the given timeout.
|
||||||
|
*/
|
||||||
|
SimplexTransportWriter sendInvitationResponse(int code, long timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Continues the invitation process from the inviter's side. Returns null
|
||||||
|
* if no connection can be established within the given timeout.
|
||||||
|
*/
|
||||||
|
SimplexTransportReader acceptInvitationResponse(int code, long timeout);
|
||||||
|
}
|
||||||
13
api/net/sf/briar/api/plugins/SimplexPluginCallback.java
Normal file
13
api/net/sf/briar/api/plugins/SimplexPluginCallback.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
|
import net.sf.briar.api.ContactId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for receiving readers and writers created by a simplex plugin.
|
||||||
|
*/
|
||||||
|
public interface SimplexPluginCallback extends PluginCallback {
|
||||||
|
|
||||||
|
void readerCreated(SimplexTransportReader r);
|
||||||
|
|
||||||
|
void writerCreated(ContactId c, SimplexTransportWriter w);
|
||||||
|
}
|
||||||
9
api/net/sf/briar/api/plugins/SimplexPluginFactory.java
Normal file
9
api/net/sf/briar/api/plugins/SimplexPluginFactory.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
public interface SimplexPluginFactory {
|
||||||
|
|
||||||
|
SimplexPlugin createPlugin(Executor pluginExecutor,
|
||||||
|
SimplexPluginCallback callback);
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package net.sf.briar.api.transport;
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for reading data from a batch-mode transport. The reader is not
|
* An interface for reading data from a simplex transport. The reader is not
|
||||||
* responsible for decrypting or authenticating the data before returning it.
|
* responsible for decrypting or authenticating the data before returning it.
|
||||||
*/
|
*/
|
||||||
public interface BatchTransportReader {
|
public interface SimplexTransportReader {
|
||||||
|
|
||||||
/** Returns an input stream for reading from the transport. */
|
/** Returns an input stream for reading from the transport. */
|
||||||
InputStream getInputStream();
|
InputStream getInputStream();
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package net.sf.briar.api.transport;
|
package net.sf.briar.api.plugins;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for writing data to a batch-mode transport. The writer is not
|
* An interface for writing data to a simplex transport. The writer is not
|
||||||
* responsible for authenticating or encrypting the data before writing it.
|
* responsible for authenticating or encrypting the data before writing it.
|
||||||
*/
|
*/
|
||||||
public interface BatchTransportWriter {
|
public interface SimplexTransportWriter {
|
||||||
|
|
||||||
/** Returns the capacity of the transport in bytes. */
|
/** Returns the capacity of the transport in bytes. */
|
||||||
long getCapacity();
|
long getCapacity();
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package net.sf.briar.api.plugins;
|
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface for transport plugins that support bidirectional, reliable,
|
|
||||||
* ordered, timely delivery of data.
|
|
||||||
*/
|
|
||||||
public interface StreamPlugin extends Plugin {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to create and return a StreamTransportConnection to the given
|
|
||||||
* contact using the current transport and configuration properties.
|
|
||||||
* Returns null if a connection could not be created.
|
|
||||||
*/
|
|
||||||
StreamTransportConnection createConnection(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the invitation process from the inviter's side. Returns null if
|
|
||||||
* no connection can be established within the given timeout.
|
|
||||||
*/
|
|
||||||
StreamTransportConnection sendInvitation(int code, long timeout);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the invitation process from the invitee's side. Returns null if
|
|
||||||
* no connection can be established within the given timeout.
|
|
||||||
*/
|
|
||||||
StreamTransportConnection acceptInvitation(int code, long timeout);
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package net.sf.briar.api.plugins;
|
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface for receiving connections created by a stream-mode transport
|
|
||||||
* plugin.
|
|
||||||
*/
|
|
||||||
public interface StreamPluginCallback extends PluginCallback {
|
|
||||||
|
|
||||||
void incomingConnectionCreated(StreamTransportConnection s);
|
|
||||||
|
|
||||||
void outgoingConnectionCreated(ContactId c, StreamTransportConnection s);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package net.sf.briar.api.plugins;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
public interface StreamPluginFactory {
|
|
||||||
|
|
||||||
StreamPlugin createPlugin(Executor pluginExecutor,
|
|
||||||
StreamPluginCallback callback);
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package net.sf.briar.api.protocol.stream;
|
package net.sf.briar.api.protocol.duplex;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
|
|
||||||
public interface StreamConnectionFactory {
|
public interface DuplexConnectionFactory {
|
||||||
|
|
||||||
void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
||||||
StreamTransportConnection s, byte[] tag);
|
DuplexTransportConnection d, byte[] tag);
|
||||||
|
|
||||||
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
|
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
|
||||||
StreamTransportConnection s);
|
DuplexTransportConnection d);
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package net.sf.briar.api.protocol.batch;
|
package net.sf.briar.api.protocol.simplex;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
|
|
||||||
public interface BatchConnectionFactory {
|
public interface SimplexConnectionFactory {
|
||||||
|
|
||||||
void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
||||||
BatchTransportReader r, byte[] tag);
|
SimplexTransportReader r, byte[] tag);
|
||||||
|
|
||||||
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
|
void createOutgoingConnection(ContactId c, TransportId t, TransportIndex i,
|
||||||
BatchTransportWriter w);
|
SimplexTransportWriter w);
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
package net.sf.briar.api.transport;
|
package net.sf.briar.api.transport;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
|
|
||||||
public interface ConnectionDispatcher {
|
public interface ConnectionDispatcher {
|
||||||
|
|
||||||
void dispatchReader(TransportId t, BatchTransportReader r);
|
void dispatchReader(TransportId t, SimplexTransportReader r);
|
||||||
|
|
||||||
void dispatchWriter(ContactId c, TransportId t, TransportIndex i,
|
void dispatchWriter(ContactId c, TransportId t, TransportIndex i,
|
||||||
BatchTransportWriter w);
|
SimplexTransportWriter w);
|
||||||
|
|
||||||
void dispatchIncomingConnection(TransportId t, StreamTransportConnection s);
|
void dispatchIncomingConnection(TransportId t, DuplexTransportConnection d);
|
||||||
|
|
||||||
void dispatchOutgoingConnection(ContactId c, TransportId t,
|
void dispatchOutgoingConnection(ContactId c, TransportId t,
|
||||||
TransportIndex i, StreamTransportConnection s);
|
TransportIndex i, DuplexTransportConnection d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,23 +16,23 @@ import net.sf.briar.api.TransportConfig;
|
|||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.plugins.BatchPlugin;
|
import net.sf.briar.api.plugins.SimplexPlugin;
|
||||||
import net.sf.briar.api.plugins.BatchPluginCallback;
|
import net.sf.briar.api.plugins.SimplexPluginCallback;
|
||||||
import net.sf.briar.api.plugins.BatchPluginFactory;
|
import net.sf.briar.api.plugins.SimplexPluginFactory;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
import net.sf.briar.api.plugins.Plugin;
|
import net.sf.briar.api.plugins.Plugin;
|
||||||
import net.sf.briar.api.plugins.PluginCallback;
|
import net.sf.briar.api.plugins.PluginCallback;
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.PluginManager;
|
import net.sf.briar.api.plugins.PluginManager;
|
||||||
import net.sf.briar.api.plugins.StreamPlugin;
|
import net.sf.briar.api.plugins.DuplexPlugin;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.plugins.StreamPluginFactory;
|
import net.sf.briar.api.plugins.DuplexPluginFactory;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
import net.sf.briar.api.transport.ConnectionDispatcher;
|
import net.sf.briar.api.transport.ConnectionDispatcher;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
import net.sf.briar.api.ui.UiCallback;
|
import net.sf.briar.api.ui.UiCallback;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -42,11 +42,11 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(PluginManagerImpl.class.getName());
|
Logger.getLogger(PluginManagerImpl.class.getName());
|
||||||
|
|
||||||
private static final String[] BATCH_FACTORIES = new String[] {
|
private static final String[] SIMPLEX_PLUGIN_FACTORIES = new String[] {
|
||||||
"net.sf.briar.plugins.file.RemovableDrivePluginFactory"
|
"net.sf.briar.plugins.file.RemovableDrivePluginFactory"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] STREAM_FACTORIES = new String[] {
|
private static final String[] DUPLEX_PLUGIN_FACTORIES = new String[] {
|
||||||
"net.sf.briar.plugins.bluetooth.BluetoothPluginFactory",
|
"net.sf.briar.plugins.bluetooth.BluetoothPluginFactory",
|
||||||
"net.sf.briar.plugins.socket.SimpleSocketPluginFactory"
|
"net.sf.briar.plugins.socket.SimpleSocketPluginFactory"
|
||||||
};
|
};
|
||||||
@@ -56,8 +56,8 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
private final Poller poller;
|
private final Poller poller;
|
||||||
private final ConnectionDispatcher dispatcher;
|
private final ConnectionDispatcher dispatcher;
|
||||||
private final UiCallback uiCallback;
|
private final UiCallback uiCallback;
|
||||||
private final List<BatchPlugin> batchPlugins; // Locking: this
|
private final List<SimplexPlugin> simplexPlugins; // Locking: this
|
||||||
private final List<StreamPlugin> streamPlugins; // Locking: this
|
private final List<DuplexPlugin> duplexPlugins; // Locking: this
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PluginManagerImpl(@PluginExecutor ExecutorService pluginExecutor,
|
PluginManagerImpl(@PluginExecutor ExecutorService pluginExecutor,
|
||||||
@@ -68,24 +68,24 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
this.poller = poller;
|
this.poller = poller;
|
||||||
this.dispatcher = dispatcher;
|
this.dispatcher = dispatcher;
|
||||||
this.uiCallback = uiCallback;
|
this.uiCallback = uiCallback;
|
||||||
batchPlugins = new ArrayList<BatchPlugin>();
|
simplexPlugins = new ArrayList<SimplexPlugin>();
|
||||||
streamPlugins = new ArrayList<StreamPlugin>();
|
duplexPlugins = new ArrayList<DuplexPlugin>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int getPluginCount() {
|
public synchronized int getPluginCount() {
|
||||||
return batchPlugins.size() + streamPlugins.size();
|
return simplexPlugins.size() + duplexPlugins.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int start() {
|
public synchronized int start() {
|
||||||
Set<TransportId> ids = new HashSet<TransportId>();
|
Set<TransportId> ids = new HashSet<TransportId>();
|
||||||
// Instantiate and start the batch plugins
|
// Instantiate and start the simplex plugins
|
||||||
for(String s : BATCH_FACTORIES) {
|
for(String s : SIMPLEX_PLUGIN_FACTORIES) {
|
||||||
try {
|
try {
|
||||||
Class<?> c = Class.forName(s);
|
Class<?> c = Class.forName(s);
|
||||||
BatchPluginFactory factory =
|
SimplexPluginFactory factory =
|
||||||
(BatchPluginFactory) c.newInstance();
|
(SimplexPluginFactory) c.newInstance();
|
||||||
BatchCallback callback = new BatchCallback();
|
SimplexCallback callback = new SimplexCallback();
|
||||||
BatchPlugin plugin = factory.createPlugin(pluginExecutor,
|
SimplexPlugin plugin = factory.createPlugin(pluginExecutor,
|
||||||
callback);
|
callback);
|
||||||
if(plugin == null) {
|
if(plugin == null) {
|
||||||
if(LOG.isLoggable(Level.INFO)) {
|
if(LOG.isLoggable(Level.INFO)) {
|
||||||
@@ -109,7 +109,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
}
|
}
|
||||||
callback.init(id, index);
|
callback.init(id, index);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
batchPlugins.add(plugin);
|
simplexPlugins.add(plugin);
|
||||||
} catch(ClassCastException e) {
|
} catch(ClassCastException e) {
|
||||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||||
continue;
|
continue;
|
||||||
@@ -118,14 +118,14 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Instantiate and start the stream plugins
|
// Instantiate and start the duplex plugins
|
||||||
for(String s : STREAM_FACTORIES) {
|
for(String s : DUPLEX_PLUGIN_FACTORIES) {
|
||||||
try {
|
try {
|
||||||
Class<?> c = Class.forName(s);
|
Class<?> c = Class.forName(s);
|
||||||
StreamPluginFactory factory =
|
DuplexPluginFactory factory =
|
||||||
(StreamPluginFactory) c.newInstance();
|
(DuplexPluginFactory) c.newInstance();
|
||||||
StreamCallback callback = new StreamCallback();
|
DuplexCallback callback = new DuplexCallback();
|
||||||
StreamPlugin plugin = factory.createPlugin(pluginExecutor,
|
DuplexPlugin plugin = factory.createPlugin(pluginExecutor,
|
||||||
callback);
|
callback);
|
||||||
if(plugin == null) {
|
if(plugin == null) {
|
||||||
if(LOG.isLoggable(Level.INFO)) {
|
if(LOG.isLoggable(Level.INFO)) {
|
||||||
@@ -149,7 +149,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
}
|
}
|
||||||
callback.init(id, index);
|
callback.init(id, index);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
streamPlugins.add(plugin);
|
duplexPlugins.add(plugin);
|
||||||
} catch(ClassCastException e) {
|
} catch(ClassCastException e) {
|
||||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||||
continue;
|
continue;
|
||||||
@@ -160,17 +160,17 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
}
|
}
|
||||||
// Start the poller
|
// Start the poller
|
||||||
List<Plugin> plugins = new ArrayList<Plugin>();
|
List<Plugin> plugins = new ArrayList<Plugin>();
|
||||||
plugins.addAll(batchPlugins);
|
plugins.addAll(simplexPlugins);
|
||||||
plugins.addAll(streamPlugins);
|
plugins.addAll(duplexPlugins);
|
||||||
poller.start(Collections.unmodifiableList(plugins));
|
poller.start(Collections.unmodifiableList(plugins));
|
||||||
// Return the number of plugins successfully started
|
// Return the number of plugins successfully started
|
||||||
return batchPlugins.size() + streamPlugins.size();
|
return simplexPlugins.size() + duplexPlugins.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int stop() {
|
public synchronized int stop() {
|
||||||
int stopped = 0;
|
int stopped = 0;
|
||||||
// Stop the batch plugins
|
// Stop the simplex plugins
|
||||||
for(BatchPlugin plugin : batchPlugins) {
|
for(SimplexPlugin plugin : simplexPlugins) {
|
||||||
try {
|
try {
|
||||||
plugin.stop();
|
plugin.stop();
|
||||||
stopped++;
|
stopped++;
|
||||||
@@ -178,9 +178,9 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
batchPlugins.clear();
|
simplexPlugins.clear();
|
||||||
// Stop the stream plugins
|
// Stop the duplex plugins
|
||||||
for(StreamPlugin plugin : streamPlugins) {
|
for(DuplexPlugin plugin : duplexPlugins) {
|
||||||
try {
|
try {
|
||||||
plugin.stop();
|
plugin.stop();
|
||||||
stopped++;
|
stopped++;
|
||||||
@@ -188,7 +188,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
streamPlugins.clear();
|
duplexPlugins.clear();
|
||||||
// Stop the poller
|
// Stop the poller
|
||||||
poller.stop();
|
poller.stop();
|
||||||
// Shut down the executor service
|
// Shut down the executor service
|
||||||
@@ -289,32 +289,32 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BatchCallback extends PluginCallbackImpl
|
private class SimplexCallback extends PluginCallbackImpl
|
||||||
implements BatchPluginCallback {
|
implements SimplexPluginCallback {
|
||||||
|
|
||||||
public void readerCreated(BatchTransportReader r) {
|
public void readerCreated(SimplexTransportReader r) {
|
||||||
assert id != null;
|
assert id != null;
|
||||||
dispatcher.dispatchReader(id, r);
|
dispatcher.dispatchReader(id, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writerCreated(ContactId c, BatchTransportWriter w) {
|
public void writerCreated(ContactId c, SimplexTransportWriter w) {
|
||||||
assert index != null;
|
assert index != null;
|
||||||
dispatcher.dispatchWriter(c, id, index, w);
|
dispatcher.dispatchWriter(c, id, index, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class StreamCallback extends PluginCallbackImpl
|
private class DuplexCallback extends PluginCallbackImpl
|
||||||
implements StreamPluginCallback {
|
implements DuplexPluginCallback {
|
||||||
|
|
||||||
public void incomingConnectionCreated(StreamTransportConnection s) {
|
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
||||||
assert id != null;
|
assert id != null;
|
||||||
dispatcher.dispatchIncomingConnection(id, s);
|
dispatcher.dispatchIncomingConnection(id, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoingConnectionCreated(ContactId c,
|
public void outgoingConnectionCreated(ContactId c,
|
||||||
StreamTransportConnection s) {
|
DuplexTransportConnection d) {
|
||||||
assert index != null;
|
assert index != null;
|
||||||
dispatcher.dispatchOutgoingConnection(c, id, index, s);
|
dispatcher.dispatchOutgoingConnection(c, id, index, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,14 +26,14 @@ import javax.microedition.io.StreamConnectionNotifier;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.StreamPlugin;
|
import net.sf.briar.api.plugins.DuplexPlugin;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
import net.sf.briar.util.OsUtils;
|
import net.sf.briar.util.OsUtils;
|
||||||
import net.sf.briar.util.StringUtils;
|
import net.sf.briar.util.StringUtils;
|
||||||
|
|
||||||
class BluetoothPlugin implements StreamPlugin {
|
class BluetoothPlugin implements DuplexPlugin {
|
||||||
|
|
||||||
public static final byte[] TRANSPORT_ID =
|
public static final byte[] TRANSPORT_ID =
|
||||||
StringUtils.fromHexString("d99c9313c04417dcf22fc60d12a187ea"
|
StringUtils.fromHexString("d99c9313c04417dcf22fc60d12a187ea"
|
||||||
@@ -44,7 +44,7 @@ class BluetoothPlugin implements StreamPlugin {
|
|||||||
Logger.getLogger(BluetoothPlugin.class.getName());
|
Logger.getLogger(BluetoothPlugin.class.getName());
|
||||||
|
|
||||||
private final Executor pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final StreamPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long pollingInterval;
|
||||||
private final Object discoveryLock = new Object();
|
private final Object discoveryLock = new Object();
|
||||||
private final Object localPropertiesLock = new Object();
|
private final Object localPropertiesLock = new Object();
|
||||||
@@ -56,7 +56,7 @@ class BluetoothPlugin implements StreamPlugin {
|
|||||||
private StreamConnectionNotifier socket = null; // Locking: this
|
private StreamConnectionNotifier socket = null; // Locking: this
|
||||||
|
|
||||||
BluetoothPlugin(@PluginExecutor Executor pluginExecutor,
|
BluetoothPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
StreamPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
@@ -228,8 +228,8 @@ class BluetoothPlugin implements StreamPlugin {
|
|||||||
// Don't create redundant connections
|
// Don't create redundant connections
|
||||||
if(connected.contains(c)) continue;
|
if(connected.contains(c)) continue;
|
||||||
String url = e.getValue();
|
String url = e.getValue();
|
||||||
StreamTransportConnection s = connect(c, url);
|
DuplexTransportConnection d = connect(c, url);
|
||||||
if(s != null) callback.outgoingConnectionCreated(c, s);
|
if(d != null) callback.outgoingConnectionCreated(c, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ class BluetoothPlugin implements StreamPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StreamTransportConnection connect(ContactId c, String url) {
|
private DuplexTransportConnection connect(ContactId c, String url) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
}
|
}
|
||||||
@@ -287,7 +287,7 @@ class BluetoothPlugin implements StreamPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTransportConnection createConnection(ContactId c) {
|
public DuplexTransportConnection createConnection(ContactId c) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
}
|
}
|
||||||
@@ -303,15 +303,15 @@ class BluetoothPlugin implements StreamPlugin {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTransportConnection sendInvitation(int code, long timeout) {
|
public DuplexTransportConnection sendInvitation(int code, long timeout) {
|
||||||
return createInvitationConnection(code, timeout);
|
return createInvitationConnection(code, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTransportConnection acceptInvitation(int code, long timeout) {
|
public DuplexTransportConnection acceptInvitation(int code, long timeout) {
|
||||||
return createInvitationConnection(code, timeout);
|
return createInvitationConnection(code, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StreamTransportConnection createInvitationConnection(int code,
|
private DuplexTransportConnection createInvitationConnection(int code,
|
||||||
long timeout) {
|
long timeout) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package net.sf.briar.plugins.bluetooth;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.StreamPlugin;
|
import net.sf.briar.api.plugins.DuplexPlugin;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.plugins.StreamPluginFactory;
|
import net.sf.briar.api.plugins.DuplexPluginFactory;
|
||||||
|
|
||||||
public class BluetoothPluginFactory implements StreamPluginFactory {
|
public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 mins
|
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 mins
|
||||||
|
|
||||||
public StreamPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
StreamPluginCallback callback) {
|
DuplexPluginCallback callback) {
|
||||||
return new BluetoothPlugin(pluginExecutor, callback, POLLING_INTERVAL);
|
return new BluetoothPlugin(pluginExecutor, callback, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.microedition.io.StreamConnection;
|
import javax.microedition.io.StreamConnection;
|
||||||
|
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
|
|
||||||
class BluetoothTransportConnection implements StreamTransportConnection {
|
class BluetoothTransportConnection implements DuplexTransportConnection {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BluetoothTransportConnection.class.getName());
|
Logger.getLogger(BluetoothTransportConnection.class.getName());
|
||||||
|
|||||||
@@ -11,22 +11,22 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.plugins.BatchPlugin;
|
import net.sf.briar.api.plugins.SimplexPlugin;
|
||||||
import net.sf.briar.api.plugins.BatchPluginCallback;
|
import net.sf.briar.api.plugins.SimplexPluginCallback;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
import net.sf.briar.api.transport.TransportConstants;
|
import net.sf.briar.api.transport.TransportConstants;
|
||||||
|
|
||||||
import org.apache.commons.io.FileSystemUtils;
|
import org.apache.commons.io.FileSystemUtils;
|
||||||
|
|
||||||
abstract class FilePlugin implements BatchPlugin {
|
abstract class FilePlugin implements SimplexPlugin {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(FilePlugin.class.getName());
|
Logger.getLogger(FilePlugin.class.getName());
|
||||||
|
|
||||||
protected final Executor pluginExecutor;
|
protected final Executor pluginExecutor;
|
||||||
protected final BatchPluginCallback callback;
|
protected final SimplexPluginCallback callback;
|
||||||
|
|
||||||
protected volatile boolean running = false;
|
protected volatile boolean running = false;
|
||||||
|
|
||||||
@@ -40,16 +40,16 @@ abstract class FilePlugin implements BatchPlugin {
|
|||||||
protected abstract void readerFinished(File f);
|
protected abstract void readerFinished(File f);
|
||||||
|
|
||||||
protected FilePlugin(@PluginExecutor Executor pluginExecutor,
|
protected FilePlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
BatchPluginCallback callback) {
|
SimplexPluginCallback callback) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchTransportReader createReader(ContactId c) {
|
public SimplexTransportReader createReader(ContactId c) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchTransportWriter createWriter(ContactId c) {
|
public SimplexTransportWriter createWriter(ContactId c) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
return createWriter(createConnectionFilename());
|
return createWriter(createConnectionFilename());
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ abstract class FilePlugin implements BatchPlugin {
|
|||||||
return filename.toLowerCase().matches("[a-z]{8}\\.dat");
|
return filename.toLowerCase().matches("[a-z]{8}\\.dat");
|
||||||
}
|
}
|
||||||
|
|
||||||
private BatchTransportWriter createWriter(String filename) {
|
private SimplexTransportWriter createWriter(String filename) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
File dir = chooseOutputDirectory();
|
File dir = chooseOutputDirectory();
|
||||||
if(dir == null || !dir.exists() || !dir.isDirectory()) return null;
|
if(dir == null || !dir.exists() || !dir.isDirectory()) return null;
|
||||||
@@ -92,30 +92,30 @@ abstract class FilePlugin implements BatchPlugin {
|
|||||||
pluginExecutor.execute(new ReaderCreator(f));
|
pluginExecutor.execute(new ReaderCreator(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchTransportWriter sendInvitation(int code, long timeout) {
|
public SimplexTransportWriter sendInvitation(int code, long timeout) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
return createWriter(createInvitationFilename(code, false));
|
return createWriter(createInvitationFilename(code, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchTransportReader acceptInvitation(int code, long timeout) {
|
public SimplexTransportReader acceptInvitation(int code, long timeout) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
String filename = createInvitationFilename(code, false);
|
String filename = createInvitationFilename(code, false);
|
||||||
return createInvitationReader(filename, timeout);
|
return createInvitationReader(filename, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchTransportWriter sendInvitationResponse(int code, long timeout) {
|
public SimplexTransportWriter sendInvitationResponse(int code, long timeout) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
return createWriter(createInvitationFilename(code, true));
|
return createWriter(createInvitationFilename(code, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BatchTransportReader acceptInvitationResponse(int code,
|
public SimplexTransportReader acceptInvitationResponse(int code,
|
||||||
long timeout) {
|
long timeout) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
String filename = createInvitationFilename(code, true);
|
String filename = createInvitationFilename(code, true);
|
||||||
return createInvitationReader(filename, timeout);
|
return createInvitationReader(filename, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BatchTransportReader createInvitationReader(String filename,
|
private SimplexTransportReader createInvitationReader(String filename,
|
||||||
long timeout) {
|
long timeout) {
|
||||||
Collection<File> files;
|
Collection<File> files;
|
||||||
// FIXME: Avoid making alien calls with a lock held
|
// FIXME: Avoid making alien calls with a lock held
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import java.io.InputStream;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
|
||||||
class FileTransportReader implements BatchTransportReader {
|
class FileTransportReader implements SimplexTransportReader {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(FileTransportReader.class.getName());
|
Logger.getLogger(FileTransportReader.class.getName());
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import java.io.OutputStream;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
|
|
||||||
class FileTransportWriter implements BatchTransportWriter {
|
class FileTransportWriter implements SimplexTransportWriter {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(FileTransportWriter.class.getName());
|
Logger.getLogger(FileTransportWriter.class.getName());
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.plugins.BatchPluginCallback;
|
import net.sf.briar.api.plugins.SimplexPluginCallback;
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.util.StringUtils;
|
import net.sf.briar.util.StringUtils;
|
||||||
@@ -31,7 +31,7 @@ implements RemovableDriveMonitor.Callback {
|
|||||||
private final RemovableDriveMonitor monitor;
|
private final RemovableDriveMonitor monitor;
|
||||||
|
|
||||||
RemovableDrivePlugin(@PluginExecutor Executor pluginExecutor,
|
RemovableDrivePlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
BatchPluginCallback callback, RemovableDriveFinder finder,
|
SimplexPluginCallback callback, RemovableDriveFinder finder,
|
||||||
RemovableDriveMonitor monitor) {
|
RemovableDriveMonitor monitor) {
|
||||||
super(pluginExecutor, callback);
|
super(pluginExecutor, callback);
|
||||||
this.finder = finder;
|
this.finder = finder;
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ package net.sf.briar.plugins.file;
|
|||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.plugins.BatchPlugin;
|
import net.sf.briar.api.plugins.SimplexPlugin;
|
||||||
import net.sf.briar.api.plugins.BatchPluginCallback;
|
import net.sf.briar.api.plugins.SimplexPluginCallback;
|
||||||
import net.sf.briar.api.plugins.BatchPluginFactory;
|
import net.sf.briar.api.plugins.SimplexPluginFactory;
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.util.OsUtils;
|
import net.sf.briar.util.OsUtils;
|
||||||
|
|
||||||
public class RemovableDrivePluginFactory implements BatchPluginFactory {
|
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||||
|
|
||||||
private static final long POLLING_INTERVAL = 10L * 1000L; // 10 seconds
|
private static final long POLLING_INTERVAL = 10L * 1000L; // 10 seconds
|
||||||
|
|
||||||
public BatchPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
public SimplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
BatchPluginCallback callback) {
|
SimplexPluginCallback callback) {
|
||||||
RemovableDriveFinder finder;
|
RemovableDriveFinder finder;
|
||||||
RemovableDriveMonitor monitor;
|
RemovableDriveMonitor monitor;
|
||||||
if(OsUtils.isLinux()) {
|
if(OsUtils.isLinux()) {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.util.ByteUtils;
|
import net.sf.briar.util.ByteUtils;
|
||||||
|
|
||||||
/** A socket plugin that supports exchanging invitations over a LAN. */
|
/** A socket plugin that supports exchanging invitations over a LAN. */
|
||||||
@@ -26,7 +26,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
|
|||||||
Logger.getLogger(LanSocketPlugin.class.getName());
|
Logger.getLogger(LanSocketPlugin.class.getName());
|
||||||
|
|
||||||
LanSocketPlugin(@PluginExecutor Executor pluginExecutor,
|
LanSocketPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
StreamPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long pollingInterval) {
|
||||||
super(pluginExecutor, callback, pollingInterval);
|
super(pluginExecutor, callback, pollingInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamTransportConnection sendInvitation(int code, long timeout) {
|
public DuplexTransportConnection sendInvitation(int code, long timeout) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamTransportConnection acceptInvitation(int code, long timeout) {
|
public DuplexTransportConnection acceptInvitation(int code, long timeout) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import java.util.logging.Logger;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
import net.sf.briar.util.StringUtils;
|
import net.sf.briar.util.StringUtils;
|
||||||
|
|
||||||
class SimpleSocketPlugin extends SocketPlugin {
|
class SimpleSocketPlugin extends SocketPlugin {
|
||||||
@@ -32,7 +32,7 @@ class SimpleSocketPlugin extends SocketPlugin {
|
|||||||
Logger.getLogger(SimpleSocketPlugin.class.getName());
|
Logger.getLogger(SimpleSocketPlugin.class.getName());
|
||||||
|
|
||||||
SimpleSocketPlugin(@PluginExecutor Executor pluginExecutor,
|
SimpleSocketPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
StreamPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long pollingInterval) {
|
||||||
super(pluginExecutor, callback, pollingInterval);
|
super(pluginExecutor, callback, pollingInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,11 +138,11 @@ class SimpleSocketPlugin extends SocketPlugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTransportConnection sendInvitation(int code, long timeout) {
|
public DuplexTransportConnection sendInvitation(int code, long timeout) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTransportConnection acceptInvitation(int code, long timeout) {
|
public DuplexTransportConnection acceptInvitation(int code, long timeout) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package net.sf.briar.plugins.socket;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.StreamPlugin;
|
import net.sf.briar.api.plugins.DuplexPlugin;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.plugins.StreamPluginFactory;
|
import net.sf.briar.api.plugins.DuplexPluginFactory;
|
||||||
|
|
||||||
public class SimpleSocketPluginFactory implements StreamPluginFactory {
|
public class SimpleSocketPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 mins
|
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 mins
|
||||||
|
|
||||||
public StreamPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
StreamPluginCallback callback) {
|
DuplexPluginCallback callback) {
|
||||||
return new SimpleSocketPlugin(pluginExecutor, callback,
|
return new SimpleSocketPlugin(pluginExecutor, callback,
|
||||||
POLLING_INTERVAL);
|
POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,17 +13,17 @@ import java.util.logging.Logger;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.StreamPlugin;
|
import net.sf.briar.api.plugins.DuplexPlugin;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
|
|
||||||
abstract class SocketPlugin implements StreamPlugin {
|
abstract class SocketPlugin implements DuplexPlugin {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(SocketPlugin.class.getName());
|
Logger.getLogger(SocketPlugin.class.getName());
|
||||||
|
|
||||||
protected final Executor pluginExecutor;
|
protected final Executor pluginExecutor;
|
||||||
protected final StreamPluginCallback callback;
|
protected final DuplexPluginCallback callback;
|
||||||
|
|
||||||
private final long pollingInterval;
|
private final long pollingInterval;
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ abstract class SocketPlugin implements StreamPlugin {
|
|||||||
protected abstract SocketAddress getRemoteSocketAddress(ContactId c);
|
protected abstract SocketAddress getRemoteSocketAddress(ContactId c);
|
||||||
|
|
||||||
protected SocketPlugin(@PluginExecutor Executor pluginExecutor,
|
protected SocketPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
StreamPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long pollingInterval) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
@@ -148,11 +148,11 @@ abstract class SocketPlugin implements StreamPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void connectAndCallBack(ContactId c) {
|
private void connectAndCallBack(ContactId c) {
|
||||||
StreamTransportConnection conn = createConnection(c);
|
DuplexTransportConnection d = createConnection(c);
|
||||||
if(conn != null) callback.outgoingConnectionCreated(c, conn);
|
if(d != null) callback.outgoingConnectionCreated(c, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTransportConnection createConnection(ContactId c) {
|
public DuplexTransportConnection createConnection(ContactId c) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(!running) return null;
|
if(!running) return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import java.net.Socket;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
|
|
||||||
class SocketTransportConnection implements StreamTransportConnection {
|
class SocketTransportConnection implements DuplexTransportConnection {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(SocketTransportConnection.class.getName());
|
Logger.getLogger(SocketTransportConnection.class.getName());
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.batch.BatchConnectionFactory;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
public class ProtocolBatchModule extends AbstractModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(BatchConnectionFactory.class).to(
|
|
||||||
BatchConnectionFactoryImpl.class).in(Singleton.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.protocol.stream;
|
package net.sf.briar.protocol.duplex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -29,6 +29,7 @@ import net.sf.briar.api.db.event.DatabaseListener;
|
|||||||
import net.sf.briar.api.db.event.LocalTransportsUpdatedEvent;
|
import net.sf.briar.api.db.event.LocalTransportsUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.MessagesAddedEvent;
|
import net.sf.briar.api.db.event.MessagesAddedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionsUpdatedEvent;
|
import net.sf.briar.api.db.event.SubscriptionsUpdatedEvent;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.Batch;
|
import net.sf.briar.api.protocol.Batch;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
@@ -49,12 +50,11 @@ import net.sf.briar.api.transport.ConnectionReaderFactory;
|
|||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
|
|
||||||
abstract class StreamConnection implements DatabaseListener {
|
abstract class DuplexConnection implements DatabaseListener {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(StreamConnection.class.getName());
|
Logger.getLogger(DuplexConnection.class.getName());
|
||||||
|
|
||||||
private static final Runnable CLOSE = new Runnable() {
|
private static final Runnable CLOSE = new Runnable() {
|
||||||
public void run() {}
|
public void run() {}
|
||||||
@@ -68,7 +68,7 @@ abstract class StreamConnection implements DatabaseListener {
|
|||||||
protected final ProtocolWriterFactory protoWriterFactory;
|
protected final ProtocolWriterFactory protoWriterFactory;
|
||||||
protected final ContactId contactId;
|
protected final ContactId contactId;
|
||||||
protected final TransportId transportId;
|
protected final TransportId transportId;
|
||||||
protected final StreamTransportConnection transport;
|
protected final DuplexTransportConnection transport;
|
||||||
|
|
||||||
private final Executor dbExecutor, verificationExecutor;
|
private final Executor dbExecutor, verificationExecutor;
|
||||||
private final AtomicBoolean canSendOffer, disposed;
|
private final AtomicBoolean canSendOffer, disposed;
|
||||||
@@ -78,14 +78,14 @@ abstract class StreamConnection implements DatabaseListener {
|
|||||||
|
|
||||||
private volatile ProtocolWriter writer = null;
|
private volatile ProtocolWriter writer = null;
|
||||||
|
|
||||||
StreamConnection(@DatabaseExecutor Executor dbExecutor,
|
DuplexConnection(@DatabaseExecutor Executor dbExecutor,
|
||||||
@VerificationExecutor Executor verificationExecutor,
|
@VerificationExecutor Executor verificationExecutor,
|
||||||
DatabaseComponent db, ConnectionRegistry connRegistry,
|
DatabaseComponent db, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
ConnectionReaderFactory connReaderFactory,
|
||||||
ConnectionWriterFactory connWriterFactory,
|
ConnectionWriterFactory connWriterFactory,
|
||||||
ProtocolReaderFactory protoReaderFactory,
|
ProtocolReaderFactory protoReaderFactory,
|
||||||
ProtocolWriterFactory protoWriterFactory, ContactId contactId,
|
ProtocolWriterFactory protoWriterFactory, ContactId contactId,
|
||||||
TransportId transportId, StreamTransportConnection transport) {
|
TransportId transportId, DuplexTransportConnection transport) {
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
this.verificationExecutor = verificationExecutor;
|
this.verificationExecutor = verificationExecutor;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package net.sf.briar.protocol.duplex;
|
||||||
|
|
||||||
|
import net.sf.briar.api.protocol.duplex.DuplexConnectionFactory;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
public class DuplexProtocolModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(DuplexConnectionFactory.class).to(
|
||||||
|
StreamConnectionFactoryImpl.class).in(Singleton.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package net.sf.briar.protocol.stream;
|
package net.sf.briar.protocol.duplex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseExecutor;
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||||
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
@@ -15,14 +16,13 @@ import net.sf.briar.api.transport.ConnectionReaderFactory;
|
|||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
|
|
||||||
class IncomingStreamConnection extends StreamConnection {
|
class IncomingDuplexConnection extends DuplexConnection {
|
||||||
|
|
||||||
private final ConnectionContext ctx;
|
private final ConnectionContext ctx;
|
||||||
private final byte[] tag;
|
private final byte[] tag;
|
||||||
|
|
||||||
IncomingStreamConnection(@DatabaseExecutor Executor dbExecutor,
|
IncomingDuplexConnection(@DatabaseExecutor Executor dbExecutor,
|
||||||
@VerificationExecutor Executor verificationExecutor,
|
@VerificationExecutor Executor verificationExecutor,
|
||||||
DatabaseComponent db, ConnectionRegistry connRegistry,
|
DatabaseComponent db, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
ConnectionReaderFactory connReaderFactory,
|
||||||
@@ -30,7 +30,7 @@ class IncomingStreamConnection extends StreamConnection {
|
|||||||
ProtocolReaderFactory protoReaderFactory,
|
ProtocolReaderFactory protoReaderFactory,
|
||||||
ProtocolWriterFactory protoWriterFactory,
|
ProtocolWriterFactory protoWriterFactory,
|
||||||
ConnectionContext ctx, TransportId transportId,
|
ConnectionContext ctx, TransportId transportId,
|
||||||
StreamTransportConnection transport, byte[] tag) {
|
DuplexTransportConnection transport, byte[] tag) {
|
||||||
super(dbExecutor, verificationExecutor, db, connRegistry,
|
super(dbExecutor, verificationExecutor, db, connRegistry,
|
||||||
connReaderFactory, connWriterFactory, protoReaderFactory,
|
connReaderFactory, connWriterFactory, protoReaderFactory,
|
||||||
protoWriterFactory, ctx.getContactId(), transportId, transport);
|
protoWriterFactory, ctx.getContactId(), transportId, transport);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.protocol.stream;
|
package net.sf.briar.protocol.duplex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@@ -7,6 +7,7 @@ import net.sf.briar.api.ContactId;
|
|||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseExecutor;
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||||
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
@@ -18,15 +19,14 @@ import net.sf.briar.api.transport.ConnectionReaderFactory;
|
|||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
|
|
||||||
class OutgoingStreamConnection extends StreamConnection {
|
class OutgoingDuplexConnection extends DuplexConnection {
|
||||||
|
|
||||||
private final TransportIndex transportIndex;
|
private final TransportIndex transportIndex;
|
||||||
|
|
||||||
private ConnectionContext ctx = null; // Locking: this
|
private ConnectionContext ctx = null; // Locking: this
|
||||||
|
|
||||||
OutgoingStreamConnection(@DatabaseExecutor Executor dbExecutor,
|
OutgoingDuplexConnection(@DatabaseExecutor Executor dbExecutor,
|
||||||
@VerificationExecutor Executor verificationExecutor,
|
@VerificationExecutor Executor verificationExecutor,
|
||||||
DatabaseComponent db, ConnectionRegistry connRegistry,
|
DatabaseComponent db, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
ConnectionReaderFactory connReaderFactory,
|
||||||
@@ -34,7 +34,7 @@ class OutgoingStreamConnection extends StreamConnection {
|
|||||||
ProtocolReaderFactory protoReaderFactory,
|
ProtocolReaderFactory protoReaderFactory,
|
||||||
ProtocolWriterFactory protoWriterFactory, ContactId contactId,
|
ProtocolWriterFactory protoWriterFactory, ContactId contactId,
|
||||||
TransportId transportId, TransportIndex transportIndex,
|
TransportId transportId, TransportIndex transportIndex,
|
||||||
StreamTransportConnection transport) {
|
DuplexTransportConnection transport) {
|
||||||
super(dbExecutor, verificationExecutor, db, connRegistry,
|
super(dbExecutor, verificationExecutor, db, connRegistry,
|
||||||
connReaderFactory, connWriterFactory, protoReaderFactory,
|
connReaderFactory, connWriterFactory, protoReaderFactory,
|
||||||
protoWriterFactory, contactId, transportId, transport);
|
protoWriterFactory, contactId, transportId, transport);
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
package net.sf.briar.protocol.stream;
|
package net.sf.briar.protocol.duplex;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseExecutor;
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||||
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
import net.sf.briar.api.protocol.VerificationExecutor;
|
import net.sf.briar.api.protocol.VerificationExecutor;
|
||||||
import net.sf.briar.api.protocol.stream.StreamConnectionFactory;
|
import net.sf.briar.api.protocol.duplex.DuplexConnectionFactory;
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
class StreamConnectionFactoryImpl implements StreamConnectionFactory {
|
class StreamConnectionFactoryImpl implements DuplexConnectionFactory {
|
||||||
|
|
||||||
private final Executor dbExecutor, verificationExecutor;
|
private final Executor dbExecutor, verificationExecutor;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
@@ -48,11 +48,11 @@ class StreamConnectionFactoryImpl implements StreamConnectionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
public void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
||||||
StreamTransportConnection s, byte[] tag) {
|
DuplexTransportConnection d, byte[] tag) {
|
||||||
final StreamConnection conn = new IncomingStreamConnection(dbExecutor,
|
final DuplexConnection conn = new IncomingDuplexConnection(dbExecutor,
|
||||||
verificationExecutor, db, connRegistry, connReaderFactory,
|
verificationExecutor, db, connRegistry, connReaderFactory,
|
||||||
connWriterFactory, protoReaderFactory, protoWriterFactory,
|
connWriterFactory, protoReaderFactory, protoWriterFactory,
|
||||||
ctx, t, s, tag);
|
ctx, t, d, tag);
|
||||||
Runnable write = new Runnable() {
|
Runnable write = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
conn.write();
|
conn.write();
|
||||||
@@ -68,11 +68,11 @@ class StreamConnectionFactoryImpl implements StreamConnectionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createOutgoingConnection(ContactId c, TransportId t,
|
public void createOutgoingConnection(ContactId c, TransportId t,
|
||||||
TransportIndex i, StreamTransportConnection s) {
|
TransportIndex i, DuplexTransportConnection d) {
|
||||||
final StreamConnection conn = new OutgoingStreamConnection(dbExecutor,
|
final DuplexConnection conn = new OutgoingDuplexConnection(dbExecutor,
|
||||||
verificationExecutor, db, connRegistry, connReaderFactory,
|
verificationExecutor, db, connRegistry, connReaderFactory,
|
||||||
connWriterFactory, protoReaderFactory, protoWriterFactory,
|
connWriterFactory, protoReaderFactory, protoWriterFactory,
|
||||||
c, t, i, s);
|
c, t, i, d);
|
||||||
Runnable write = new Runnable() {
|
Runnable write = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
conn.write();
|
conn.write();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -12,6 +12,7 @@ import net.sf.briar.api.FormatException;
|
|||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseExecutor;
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.Batch;
|
import net.sf.briar.api.protocol.Batch;
|
||||||
import net.sf.briar.api.protocol.ProtocolReader;
|
import net.sf.briar.api.protocol.ProtocolReader;
|
||||||
@@ -21,16 +22,15 @@ import net.sf.briar.api.protocol.TransportId;
|
|||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.protocol.UnverifiedBatch;
|
import net.sf.briar.api.protocol.UnverifiedBatch;
|
||||||
import net.sf.briar.api.protocol.VerificationExecutor;
|
import net.sf.briar.api.protocol.VerificationExecutor;
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
import net.sf.briar.api.transport.ConnectionReader;
|
import net.sf.briar.api.transport.ConnectionReader;
|
||||||
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
|
|
||||||
class IncomingBatchConnection {
|
class IncomingSimplexConnection {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(IncomingBatchConnection.class.getName());
|
Logger.getLogger(IncomingSimplexConnection.class.getName());
|
||||||
|
|
||||||
private final Executor dbExecutor, verificationExecutor;
|
private final Executor dbExecutor, verificationExecutor;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
@@ -39,16 +39,16 @@ class IncomingBatchConnection {
|
|||||||
private final ProtocolReaderFactory protoFactory;
|
private final ProtocolReaderFactory protoFactory;
|
||||||
private final ConnectionContext ctx;
|
private final ConnectionContext ctx;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final BatchTransportReader transport;
|
private final SimplexTransportReader transport;
|
||||||
private final byte[] tag;
|
private final byte[] tag;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
|
|
||||||
IncomingBatchConnection(@DatabaseExecutor Executor dbExecutor,
|
IncomingSimplexConnection(@DatabaseExecutor Executor dbExecutor,
|
||||||
@VerificationExecutor Executor verificationExecutor,
|
@VerificationExecutor Executor verificationExecutor,
|
||||||
DatabaseComponent db, ConnectionRegistry connRegistry,
|
DatabaseComponent db, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connFactory,
|
ConnectionReaderFactory connFactory,
|
||||||
ProtocolReaderFactory protoFactory, ConnectionContext ctx,
|
ProtocolReaderFactory protoFactory, ConnectionContext ctx,
|
||||||
TransportId transportId, BatchTransportReader transport,
|
TransportId transportId, SimplexTransportReader transport,
|
||||||
byte[] tag) {
|
byte[] tag) {
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
this.verificationExecutor = verificationExecutor;
|
this.verificationExecutor = verificationExecutor;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@ import java.util.logging.Logger;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.ProtocolWriter;
|
import net.sf.briar.api.protocol.ProtocolWriter;
|
||||||
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
||||||
@@ -19,16 +20,15 @@ import net.sf.briar.api.protocol.SubscriptionUpdate;
|
|||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
|
|
||||||
class OutgoingBatchConnection {
|
class OutgoingSimplexConnection {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(OutgoingBatchConnection.class.getName());
|
Logger.getLogger(OutgoingSimplexConnection.class.getName());
|
||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ConnectionRegistry connRegistry;
|
private final ConnectionRegistry connRegistry;
|
||||||
@@ -37,14 +37,14 @@ class OutgoingBatchConnection {
|
|||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final TransportIndex transportIndex;
|
private final TransportIndex transportIndex;
|
||||||
private final BatchTransportWriter transport;
|
private final SimplexTransportWriter transport;
|
||||||
|
|
||||||
OutgoingBatchConnection(DatabaseComponent db,
|
OutgoingSimplexConnection(DatabaseComponent db,
|
||||||
ConnectionRegistry connRegistry,
|
ConnectionRegistry connRegistry,
|
||||||
ConnectionWriterFactory connFactory,
|
ConnectionWriterFactory connFactory,
|
||||||
ProtocolWriterFactory protoFactory, ContactId contactId,
|
ProtocolWriterFactory protoFactory, ContactId contactId,
|
||||||
TransportId transportId, TransportIndex transportIndex,
|
TransportId transportId, TransportIndex transportIndex,
|
||||||
BatchTransportWriter transport) {
|
SimplexTransportWriter transport) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.connRegistry = connRegistry;
|
this.connRegistry = connRegistry;
|
||||||
this.connFactory = connFactory;
|
this.connFactory = connFactory;
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseExecutor;
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||||
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
import net.sf.briar.api.protocol.ProtocolWriterFactory;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
import net.sf.briar.api.protocol.VerificationExecutor;
|
import net.sf.briar.api.protocol.VerificationExecutor;
|
||||||
import net.sf.briar.api.protocol.batch.BatchConnectionFactory;
|
import net.sf.briar.api.protocol.simplex.SimplexConnectionFactory;
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
@@ -20,7 +20,7 @@ import net.sf.briar.api.transport.ConnectionWriterFactory;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
class BatchConnectionFactoryImpl implements BatchConnectionFactory {
|
class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
|
||||||
|
|
||||||
private final Executor dbExecutor, verificationExecutor;
|
private final Executor dbExecutor, verificationExecutor;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
@@ -31,7 +31,7 @@ class BatchConnectionFactoryImpl implements BatchConnectionFactory {
|
|||||||
private final ProtocolWriterFactory protoWriterFactory;
|
private final ProtocolWriterFactory protoWriterFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BatchConnectionFactoryImpl(@DatabaseExecutor Executor dbExecutor,
|
SimplexConnectionFactoryImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
@VerificationExecutor Executor verificationExecutor,
|
@VerificationExecutor Executor verificationExecutor,
|
||||||
DatabaseComponent db, ConnectionRegistry connRegistry,
|
DatabaseComponent db, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
ConnectionReaderFactory connReaderFactory,
|
||||||
@@ -49,8 +49,8 @@ class BatchConnectionFactoryImpl implements BatchConnectionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
public void createIncomingConnection(ConnectionContext ctx, TransportId t,
|
||||||
BatchTransportReader r, byte[] tag) {
|
SimplexTransportReader r, byte[] tag) {
|
||||||
final IncomingBatchConnection conn = new IncomingBatchConnection(
|
final IncomingSimplexConnection conn = new IncomingSimplexConnection(
|
||||||
dbExecutor, verificationExecutor, db, connRegistry,
|
dbExecutor, verificationExecutor, db, connRegistry,
|
||||||
connReaderFactory, protoReaderFactory, ctx, t, r, tag);
|
connReaderFactory, protoReaderFactory, ctx, t, r, tag);
|
||||||
Runnable read = new Runnable() {
|
Runnable read = new Runnable() {
|
||||||
@@ -62,8 +62,8 @@ class BatchConnectionFactoryImpl implements BatchConnectionFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createOutgoingConnection(ContactId c, TransportId t,
|
public void createOutgoingConnection(ContactId c, TransportId t,
|
||||||
TransportIndex i, BatchTransportWriter w) {
|
TransportIndex i, SimplexTransportWriter w) {
|
||||||
final OutgoingBatchConnection conn = new OutgoingBatchConnection(db,
|
final OutgoingSimplexConnection conn = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, protoWriterFactory,
|
connRegistry, connWriterFactory, protoWriterFactory,
|
||||||
c, t, i, w);
|
c, t, i, w);
|
||||||
Runnable write = new Runnable() {
|
Runnable write = new Runnable() {
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
|
import net.sf.briar.api.protocol.simplex.SimplexConnectionFactory;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
|
public class SimplexProtocolModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(SimplexConnectionFactory.class).to(
|
||||||
|
SimplexConnectionFactoryImpl.class).in(Singleton.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package net.sf.briar.protocol.stream;
|
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.stream.StreamConnectionFactory;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
public class ProtocolStreamModule extends AbstractModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(StreamConnectionFactory.class).to(
|
|
||||||
StreamConnectionFactoryImpl.class).in(Singleton.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,17 +9,17 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
import net.sf.briar.api.protocol.TransportId;
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
import net.sf.briar.api.protocol.TransportIndex;
|
||||||
import net.sf.briar.api.protocol.batch.BatchConnectionFactory;
|
import net.sf.briar.api.protocol.duplex.DuplexConnectionFactory;
|
||||||
import net.sf.briar.api.protocol.stream.StreamConnectionFactory;
|
import net.sf.briar.api.protocol.simplex.SimplexConnectionFactory;
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
import net.sf.briar.api.transport.ConnectionDispatcher;
|
import net.sf.briar.api.transport.ConnectionDispatcher;
|
||||||
import net.sf.briar.api.transport.ConnectionRecogniser;
|
import net.sf.briar.api.transport.ConnectionRecogniser;
|
||||||
import net.sf.briar.api.transport.IncomingConnectionExecutor;
|
import net.sf.briar.api.transport.IncomingConnectionExecutor;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
|
||||||
import net.sf.briar.api.transport.TransportConstants;
|
import net.sf.briar.api.transport.TransportConstants;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -31,37 +31,37 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
|||||||
|
|
||||||
private final Executor connExecutor;
|
private final Executor connExecutor;
|
||||||
private final ConnectionRecogniser recogniser;
|
private final ConnectionRecogniser recogniser;
|
||||||
private final BatchConnectionFactory batchConnFactory;
|
private final SimplexConnectionFactory batchConnFactory;
|
||||||
private final StreamConnectionFactory streamConnFactory;
|
private final DuplexConnectionFactory streamConnFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ConnectionDispatcherImpl(@IncomingConnectionExecutor Executor connExecutor,
|
ConnectionDispatcherImpl(@IncomingConnectionExecutor Executor connExecutor,
|
||||||
ConnectionRecogniser recogniser,
|
ConnectionRecogniser recogniser,
|
||||||
BatchConnectionFactory batchConnFactory,
|
SimplexConnectionFactory batchConnFactory,
|
||||||
StreamConnectionFactory streamConnFactory) {
|
DuplexConnectionFactory streamConnFactory) {
|
||||||
this.connExecutor = connExecutor;
|
this.connExecutor = connExecutor;
|
||||||
this.recogniser = recogniser;
|
this.recogniser = recogniser;
|
||||||
this.batchConnFactory = batchConnFactory;
|
this.batchConnFactory = batchConnFactory;
|
||||||
this.streamConnFactory = streamConnFactory;
|
this.streamConnFactory = streamConnFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchReader(TransportId t, BatchTransportReader r) {
|
public void dispatchReader(TransportId t, SimplexTransportReader r) {
|
||||||
connExecutor.execute(new DispatchBatchConnection(t, r));
|
connExecutor.execute(new DispatchSimplexConnection(t, r));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchWriter(ContactId c, TransportId t, TransportIndex i,
|
public void dispatchWriter(ContactId c, TransportId t, TransportIndex i,
|
||||||
BatchTransportWriter w) {
|
SimplexTransportWriter w) {
|
||||||
batchConnFactory.createOutgoingConnection(c, t, i, w);
|
batchConnFactory.createOutgoingConnection(c, t, i, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchIncomingConnection(TransportId t,
|
public void dispatchIncomingConnection(TransportId t,
|
||||||
StreamTransportConnection s) {
|
DuplexTransportConnection d) {
|
||||||
connExecutor.execute(new DispatchStreamConnection(t, s));
|
connExecutor.execute(new DispatchDuplexConnection(t, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchOutgoingConnection(ContactId c, TransportId t,
|
public void dispatchOutgoingConnection(ContactId c, TransportId t,
|
||||||
TransportIndex i, StreamTransportConnection s) {
|
TransportIndex i, DuplexTransportConnection d) {
|
||||||
streamConnFactory.createOutgoingConnection(c, t, i, s);
|
streamConnFactory.createOutgoingConnection(c, t, i, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] readTag(InputStream in) throws IOException {
|
private byte[] readTag(InputStream in) throws IOException {
|
||||||
@@ -75,13 +75,13 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DispatchBatchConnection implements Runnable {
|
private class DispatchSimplexConnection implements Runnable {
|
||||||
|
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final BatchTransportReader transport;
|
private final SimplexTransportReader transport;
|
||||||
|
|
||||||
private DispatchBatchConnection(TransportId transportId,
|
private DispatchSimplexConnection(TransportId transportId,
|
||||||
BatchTransportReader transport) {
|
SimplexTransportReader transport) {
|
||||||
this.transportId = transportId;
|
this.transportId = transportId;
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
}
|
}
|
||||||
@@ -104,13 +104,13 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DispatchStreamConnection implements Runnable {
|
private class DispatchDuplexConnection implements Runnable {
|
||||||
|
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final StreamTransportConnection transport;
|
private final DuplexTransportConnection transport;
|
||||||
|
|
||||||
private DispatchStreamConnection(TransportId transportId,
|
private DispatchDuplexConnection(TransportId transportId,
|
||||||
StreamTransportConnection transport) {
|
DuplexTransportConnection transport) {
|
||||||
this.transportId = transportId;
|
this.transportId = transportId;
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,8 @@
|
|||||||
<test name='net.sf.briar.protocol.ProtocolWriterImplTest'/>
|
<test name='net.sf.briar.protocol.ProtocolWriterImplTest'/>
|
||||||
<test name='net.sf.briar.protocol.RequestReaderTest'/>
|
<test name='net.sf.briar.protocol.RequestReaderTest'/>
|
||||||
<test name='net.sf.briar.protocol.UnverifiedBatchImplTest'/>
|
<test name='net.sf.briar.protocol.UnverifiedBatchImplTest'/>
|
||||||
<test name='net.sf.briar.protocol.batch.BatchConnectionReadWriteTest'/>
|
<test name='net.sf.briar.protocol.simplex.OutgoingSimplexConnectionTest'/>
|
||||||
<test name='net.sf.briar.protocol.batch.OutgoingBatchConnectionTest'/>
|
<test name='net.sf.briar.protocol.simplex.SimplexConnectionReadWriteTest'/>
|
||||||
<test name='net.sf.briar.serial.ReaderImplTest'/>
|
<test name='net.sf.briar.serial.ReaderImplTest'/>
|
||||||
<test name='net.sf.briar.serial.WriterImplTest'/>
|
<test name='net.sf.briar.serial.WriterImplTest'/>
|
||||||
<test name='net.sf.briar.setup.SetupWorkerTest'/>
|
<test name='net.sf.briar.setup.SetupWorkerTest'/>
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ import net.sf.briar.crypto.CryptoModule;
|
|||||||
import net.sf.briar.db.DatabaseModule;
|
import net.sf.briar.db.DatabaseModule;
|
||||||
import net.sf.briar.lifecycle.LifecycleModule;
|
import net.sf.briar.lifecycle.LifecycleModule;
|
||||||
import net.sf.briar.protocol.ProtocolModule;
|
import net.sf.briar.protocol.ProtocolModule;
|
||||||
import net.sf.briar.protocol.batch.ProtocolBatchModule;
|
import net.sf.briar.protocol.duplex.DuplexProtocolModule;
|
||||||
import net.sf.briar.protocol.stream.ProtocolStreamModule;
|
import net.sf.briar.protocol.simplex.SimplexProtocolModule;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
import net.sf.briar.transport.TransportModule;
|
import net.sf.briar.transport.TransportModule;
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
Injector i = Guice.createInjector(new CryptoModule(),
|
Injector i = Guice.createInjector(new CryptoModule(),
|
||||||
new DatabaseModule(), new LifecycleModule(),
|
new DatabaseModule(), new LifecycleModule(),
|
||||||
new ProtocolModule(), new SerialModule(),
|
new ProtocolModule(), new SerialModule(),
|
||||||
new TestDatabaseModule(), new ProtocolBatchModule(),
|
new TestDatabaseModule(), new SimplexProtocolModule(),
|
||||||
new TransportModule(), new ProtocolStreamModule());
|
new TransportModule(), new DuplexProtocolModule());
|
||||||
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
||||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||||
protocolReaderFactory = i.getInstance(ProtocolReaderFactory.class);
|
protocolReaderFactory = i.getInstance(ProtocolReaderFactory.class);
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ import net.sf.briar.api.transport.ConnectionWindowFactory;
|
|||||||
import net.sf.briar.crypto.CryptoModule;
|
import net.sf.briar.crypto.CryptoModule;
|
||||||
import net.sf.briar.lifecycle.LifecycleModule;
|
import net.sf.briar.lifecycle.LifecycleModule;
|
||||||
import net.sf.briar.protocol.ProtocolModule;
|
import net.sf.briar.protocol.ProtocolModule;
|
||||||
import net.sf.briar.protocol.batch.ProtocolBatchModule;
|
import net.sf.briar.protocol.duplex.DuplexProtocolModule;
|
||||||
import net.sf.briar.protocol.stream.ProtocolStreamModule;
|
import net.sf.briar.protocol.simplex.SimplexProtocolModule;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
import net.sf.briar.transport.TransportModule;
|
import net.sf.briar.transport.TransportModule;
|
||||||
|
|
||||||
@@ -96,8 +96,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Injector i = Guice.createInjector(new CryptoModule(),
|
Injector i = Guice.createInjector(new CryptoModule(),
|
||||||
new DatabaseModule(), new LifecycleModule(),
|
new DatabaseModule(), new LifecycleModule(),
|
||||||
new ProtocolModule(), new SerialModule(),
|
new ProtocolModule(), new SerialModule(),
|
||||||
new ProtocolBatchModule(), new TransportModule(),
|
new SimplexProtocolModule(), new TransportModule(),
|
||||||
new ProtocolStreamModule(), new TestDatabaseModule(testDir));
|
new DuplexProtocolModule(), new TestDatabaseModule(testDir));
|
||||||
connectionContextFactory =
|
connectionContextFactory =
|
||||||
i.getInstance(ConnectionContextFactory.class);
|
i.getInstance(ConnectionContextFactory.class);
|
||||||
connectionWindowFactory = i.getInstance(ConnectionWindowFactory.class);
|
connectionWindowFactory = i.getInstance(ConnectionWindowFactory.class);
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import java.util.Map;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
|
|
||||||
public abstract class StreamClientTest extends StreamTest {
|
public abstract class DuplexClientTest extends DuplexTest {
|
||||||
|
|
||||||
protected ClientCallback callback = null;
|
protected ClientCallback callback = null;
|
||||||
|
|
||||||
@@ -20,37 +20,37 @@ public abstract class StreamClientTest extends StreamTest {
|
|||||||
plugin.start();
|
plugin.start();
|
||||||
// Try to connect to the server
|
// Try to connect to the server
|
||||||
System.out.println("Creating connection");
|
System.out.println("Creating connection");
|
||||||
StreamTransportConnection s = plugin.createConnection(contactId);
|
DuplexTransportConnection d = plugin.createConnection(contactId);
|
||||||
if(s == null) {
|
if(d == null) {
|
||||||
System.out.println("Connection failed");
|
System.out.println("Connection failed");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Connection created");
|
System.out.println("Connection created");
|
||||||
receiveChallengeSendResponse(s);
|
receiveChallengeSendResponse(d);
|
||||||
}
|
}
|
||||||
// Try to send an invitation
|
// Try to send an invitation
|
||||||
System.out.println("Sending invitation");
|
System.out.println("Sending invitation");
|
||||||
s = plugin.sendInvitation(123, INVITATION_TIMEOUT);
|
d = plugin.sendInvitation(123, INVITATION_TIMEOUT);
|
||||||
if(s == null) {
|
if(d == null) {
|
||||||
System.out.println("Connection failed");
|
System.out.println("Connection failed");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Connection created");
|
System.out.println("Connection created");
|
||||||
receiveChallengeSendResponse(s);
|
receiveChallengeSendResponse(d);
|
||||||
}
|
}
|
||||||
// Try to accept an invitation
|
// Try to accept an invitation
|
||||||
System.out.println("Accepting invitation");
|
System.out.println("Accepting invitation");
|
||||||
s = plugin.acceptInvitation(456, INVITATION_TIMEOUT);
|
d = plugin.acceptInvitation(456, INVITATION_TIMEOUT);
|
||||||
if(s == null) {
|
if(d == null) {
|
||||||
System.out.println("Connection failed");
|
System.out.println("Connection failed");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Connection created");
|
System.out.println("Connection created");
|
||||||
sendChallengeReceiveResponse(s);
|
sendChallengeReceiveResponse(d);
|
||||||
}
|
}
|
||||||
// Stop the plugin
|
// Stop the plugin
|
||||||
System.out.println("Stopping plugin");
|
System.out.println("Stopping plugin");
|
||||||
plugin.stop();
|
plugin.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class ClientCallback implements StreamPluginCallback {
|
protected static class ClientCallback implements DuplexPluginCallback {
|
||||||
|
|
||||||
private TransportConfig config = null;
|
private TransportConfig config = null;
|
||||||
private TransportProperties local = null;
|
private TransportProperties local = null;
|
||||||
@@ -93,9 +93,9 @@ public abstract class StreamClientTest extends StreamTest {
|
|||||||
|
|
||||||
public void showMessage(String... message) {}
|
public void showMessage(String... message) {}
|
||||||
|
|
||||||
public void incomingConnectionCreated(StreamTransportConnection c) {}
|
public void incomingConnectionCreated(DuplexTransportConnection d) {}
|
||||||
|
|
||||||
public void outgoingConnectionCreated(ContactId contactId,
|
public void outgoingConnectionCreated(ContactId contactId,
|
||||||
StreamTransportConnection c) {}
|
DuplexTransportConnection d) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
|
|
||||||
public abstract class StreamServerTest extends StreamTest {
|
public abstract class DuplexServerTest extends DuplexTest {
|
||||||
|
|
||||||
protected ServerCallback callback = null;
|
protected ServerCallback callback = null;
|
||||||
|
|
||||||
@@ -24,29 +24,29 @@ public abstract class StreamServerTest extends StreamTest {
|
|||||||
callback.latch.await();
|
callback.latch.await();
|
||||||
// Try to accept an invitation
|
// Try to accept an invitation
|
||||||
System.out.println("Accepting invitation");
|
System.out.println("Accepting invitation");
|
||||||
StreamTransportConnection s = plugin.acceptInvitation(123,
|
DuplexTransportConnection d = plugin.acceptInvitation(123,
|
||||||
INVITATION_TIMEOUT);
|
INVITATION_TIMEOUT);
|
||||||
if(s == null) {
|
if(d == null) {
|
||||||
System.out.println("Connection failed");
|
System.out.println("Connection failed");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Connection created");
|
System.out.println("Connection created");
|
||||||
sendChallengeReceiveResponse(s);
|
sendChallengeReceiveResponse(d);
|
||||||
}
|
}
|
||||||
// Try to send an invitation
|
// Try to send an invitation
|
||||||
System.out.println("Sending invitation");
|
System.out.println("Sending invitation");
|
||||||
s = plugin.sendInvitation(456, INVITATION_TIMEOUT);
|
d = plugin.sendInvitation(456, INVITATION_TIMEOUT);
|
||||||
if(s == null) {
|
if(d == null) {
|
||||||
System.out.println("Connection failed");
|
System.out.println("Connection failed");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Connection created");
|
System.out.println("Connection created");
|
||||||
receiveChallengeSendResponse(s);
|
receiveChallengeSendResponse(d);
|
||||||
}
|
}
|
||||||
// Stop the plugin
|
// Stop the plugin
|
||||||
System.out.println("Stopping plugin");
|
System.out.println("Stopping plugin");
|
||||||
plugin.stop();
|
plugin.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class ServerCallback implements StreamPluginCallback {
|
protected class ServerCallback implements DuplexPluginCallback {
|
||||||
|
|
||||||
private final CountDownLatch latch = new CountDownLatch(1);
|
private final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
@@ -91,13 +91,13 @@ public abstract class StreamServerTest extends StreamTest {
|
|||||||
|
|
||||||
public void showMessage(String... message) {}
|
public void showMessage(String... message) {}
|
||||||
|
|
||||||
public void incomingConnectionCreated(StreamTransportConnection s) {
|
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
||||||
System.out.println("Connection received");
|
System.out.println("Connection received");
|
||||||
sendChallengeReceiveResponse(s);
|
sendChallengeReceiveResponse(d);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoingConnectionCreated(ContactId contactId,
|
public void outgoingConnectionCreated(ContactId c,
|
||||||
StreamTransportConnection c) {}
|
DuplexTransportConnection d) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ import java.io.PrintStream;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.plugins.StreamPlugin;
|
import net.sf.briar.api.plugins.DuplexPlugin;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
|
|
||||||
abstract class StreamTest {
|
abstract class DuplexTest {
|
||||||
|
|
||||||
protected static final String CHALLENGE = "Carrots!";
|
protected static final String CHALLENGE = "Carrots!";
|
||||||
protected static final String RESPONSE = "Potatoes!";
|
protected static final String RESPONSE = "Potatoes!";
|
||||||
@@ -16,15 +16,15 @@ abstract class StreamTest {
|
|||||||
|
|
||||||
protected final ContactId contactId = new ContactId(0);
|
protected final ContactId contactId = new ContactId(0);
|
||||||
|
|
||||||
protected StreamPlugin plugin = null;
|
protected DuplexPlugin plugin = null;
|
||||||
|
|
||||||
protected void sendChallengeReceiveResponse(StreamTransportConnection s) {
|
protected void sendChallengeReceiveResponse(DuplexTransportConnection d) {
|
||||||
assert plugin != null;
|
assert plugin != null;
|
||||||
try {
|
try {
|
||||||
PrintStream out = new PrintStream(s.getOutputStream());
|
PrintStream out = new PrintStream(d.getOutputStream());
|
||||||
out.println(CHALLENGE);
|
out.println(CHALLENGE);
|
||||||
System.out.println("Sent challenge: " + CHALLENGE);
|
System.out.println("Sent challenge: " + CHALLENGE);
|
||||||
Scanner in = new Scanner(s.getInputStream());
|
Scanner in = new Scanner(d.getInputStream());
|
||||||
if(in.hasNextLine()) {
|
if(in.hasNextLine()) {
|
||||||
String response = in.nextLine();
|
String response = in.nextLine();
|
||||||
System.out.println("Received response: " + response);
|
System.out.println("Received response: " + response);
|
||||||
@@ -36,22 +36,22 @@ abstract class StreamTest {
|
|||||||
} else {
|
} else {
|
||||||
System.out.println("No response");
|
System.out.println("No response");
|
||||||
}
|
}
|
||||||
s.dispose(false, true);
|
d.dispose(false, true);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
s.dispose(true, true);
|
d.dispose(true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void receiveChallengeSendResponse(StreamTransportConnection s) {
|
protected void receiveChallengeSendResponse(DuplexTransportConnection d) {
|
||||||
assert plugin != null;
|
assert plugin != null;
|
||||||
try {
|
try {
|
||||||
Scanner in = new Scanner(s.getInputStream());
|
Scanner in = new Scanner(d.getInputStream());
|
||||||
if(in.hasNextLine()) {
|
if(in.hasNextLine()) {
|
||||||
String challenge = in.nextLine();
|
String challenge = in.nextLine();
|
||||||
System.out.println("Received challenge: " + challenge);
|
System.out.println("Received challenge: " + challenge);
|
||||||
if(CHALLENGE.equals(challenge)) {
|
if(CHALLENGE.equals(challenge)) {
|
||||||
PrintStream out = new PrintStream(s.getOutputStream());
|
PrintStream out = new PrintStream(d.getOutputStream());
|
||||||
out.println(RESPONSE);
|
out.println(RESPONSE);
|
||||||
System.out.println("Sent response: " + RESPONSE);
|
System.out.println("Sent response: " + RESPONSE);
|
||||||
} else {
|
} else {
|
||||||
@@ -60,10 +60,10 @@ abstract class StreamTest {
|
|||||||
} else {
|
} else {
|
||||||
System.out.println("No challenge");
|
System.out.println("No challenge");
|
||||||
}
|
}
|
||||||
s.dispose(false, true);
|
d.dispose(false, true);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
s.dispose(true, true);
|
d.dispose(true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,11 +9,11 @@ import java.util.concurrent.Executors;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.plugins.StreamClientTest;
|
import net.sf.briar.plugins.DuplexClientTest;
|
||||||
|
|
||||||
// This is not a JUnit test - it has to be run manually while the server test
|
// This is not a JUnit test - it has to be run manually while the server test
|
||||||
// is running on another machine
|
// is running on another machine
|
||||||
public class BluetoothClientTest extends StreamClientTest {
|
public class BluetoothClientTest extends DuplexClientTest {
|
||||||
|
|
||||||
private BluetoothClientTest(Executor executor, String serverAddress) {
|
private BluetoothClientTest(Executor executor, String serverAddress) {
|
||||||
// Store the server's Bluetooth address and UUID
|
// Store the server's Bluetooth address and UUID
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.plugins.StreamServerTest;
|
import net.sf.briar.plugins.DuplexServerTest;
|
||||||
|
|
||||||
// This is not a JUnit test - it has to be run manually while the client test
|
// This is not a JUnit test - it has to be run manually while the client test
|
||||||
// is running on another machine
|
// is running on another machine
|
||||||
public class BluetoothServerTest extends StreamServerTest {
|
public class BluetoothServerTest extends DuplexServerTest {
|
||||||
|
|
||||||
private BluetoothServerTest(Executor executor) {
|
private BluetoothServerTest(Executor executor) {
|
||||||
// Store the UUID
|
// Store the UUID
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import java.util.concurrent.Executor;
|
|||||||
import net.sf.briar.BriarTestCase;
|
import net.sf.briar.BriarTestCase;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.plugins.BatchPluginCallback;
|
import net.sf.briar.api.plugins.SimplexPluginCallback;
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
import net.sf.briar.api.transport.TransportConstants;
|
import net.sf.briar.api.transport.TransportConstants;
|
||||||
import net.sf.briar.plugins.ImmediateExecutor;
|
import net.sf.briar.plugins.ImmediateExecutor;
|
||||||
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
|
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
|
||||||
@@ -39,8 +39,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
public void testGetId() {
|
public void testGetId() {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -61,8 +61,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -93,8 +93,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -130,8 +130,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -169,8 +169,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -208,8 +208,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -250,8 +250,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -271,7 +271,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
callback, finder, monitor);
|
callback, finder, monitor);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
|
|
||||||
BatchTransportWriter writer = plugin.createWriter(contactId);
|
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
||||||
assertNotNull(writer);
|
assertNotNull(writer);
|
||||||
// The output file should exist and should be empty
|
// The output file should exist and should be empty
|
||||||
File[] files = drive1.listFiles();
|
File[] files = drive1.listFiles();
|
||||||
@@ -295,8 +295,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
public void testEmptyDriveIsIgnored() throws Exception {
|
public void testEmptyDriveIsIgnored() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -319,8 +319,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
public void testFilenames() {
|
public void testFilenames() {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final Executor executor = context.mock(Executor.class);
|
final Executor executor = context.mock(Executor.class);
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
@@ -342,8 +342,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testReaderIsCreated() throws Exception {
|
public void testReaderIsCreated() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final BatchPluginCallback callback =
|
final SimplexPluginCallback callback =
|
||||||
context.mock(BatchPluginCallback.class);
|
context.mock(SimplexPluginCallback.class);
|
||||||
final RemovableDriveFinder finder =
|
final RemovableDriveFinder finder =
|
||||||
context.mock(RemovableDriveFinder.class);
|
context.mock(RemovableDriveFinder.class);
|
||||||
final RemovableDriveMonitor monitor =
|
final RemovableDriveMonitor monitor =
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import java.util.concurrent.Executor;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.plugins.StreamClientTest;
|
import net.sf.briar.plugins.DuplexClientTest;
|
||||||
|
|
||||||
// This is not a JUnit test - it has to be run manually while the server test
|
// This is not a JUnit test - it has to be run manually while the server test
|
||||||
// is running on another machine
|
// is running on another machine
|
||||||
public class LanSocketClientTest extends StreamClientTest {
|
public class LanSocketClientTest extends DuplexClientTest {
|
||||||
|
|
||||||
private LanSocketClientTest(Executor executor, String serverAddress,
|
private LanSocketClientTest(Executor executor, String serverAddress,
|
||||||
String serverPort) {
|
String serverPort) {
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.plugins.StreamServerTest;
|
import net.sf.briar.plugins.DuplexServerTest;
|
||||||
|
|
||||||
// This is not a JUnit test - it has to be run manually while the client test
|
// This is not a JUnit test - it has to be run manually while the client test
|
||||||
// is running on another machine
|
// is running on another machine
|
||||||
public class LanSocketServerTest extends StreamServerTest {
|
public class LanSocketServerTest extends DuplexServerTest {
|
||||||
|
|
||||||
private LanSocketServerTest(Executor executor) {
|
private LanSocketServerTest(Executor executor) {
|
||||||
callback = new ServerCallback(new TransportConfig(),
|
callback = new ServerCallback(new TransportConfig(),
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import net.sf.briar.BriarTestCase;
|
|||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.plugins.StreamPluginCallback;
|
import net.sf.briar.api.plugins.DuplexPluginCallback;
|
||||||
import net.sf.briar.api.transport.StreamTransportConnection;
|
import net.sf.briar.api.plugins.DuplexTransportConnection;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIncomingConnection() throws Exception {
|
public void testIncomingConnection() throws Exception {
|
||||||
StreamCallback callback = new StreamCallback();
|
Callback callback = new Callback();
|
||||||
callback.local.put("internal", "127.0.0.1");
|
callback.local.put("internal", "127.0.0.1");
|
||||||
callback.local.put("port", "0");
|
callback.local.put("port", "0");
|
||||||
Executor e = Executors.newCachedThreadPool();
|
Executor e = Executors.newCachedThreadPool();
|
||||||
@@ -63,7 +63,7 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOutgoingConnection() throws Exception {
|
public void testOutgoingConnection() throws Exception {
|
||||||
StreamCallback callback = new StreamCallback();
|
Callback callback = new Callback();
|
||||||
Executor e = Executors.newCachedThreadPool();
|
Executor e = Executors.newCachedThreadPool();
|
||||||
SimpleSocketPlugin plugin = new SimpleSocketPlugin(e, callback, 0L);
|
SimpleSocketPlugin plugin = new SimpleSocketPlugin(e, callback, 0L);
|
||||||
plugin.start();
|
plugin.start();
|
||||||
@@ -90,18 +90,18 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
p.put("port", String.valueOf(port));
|
p.put("port", String.valueOf(port));
|
||||||
callback.remote.put(contactId, p);
|
callback.remote.put(contactId, p);
|
||||||
// Connect to the port
|
// Connect to the port
|
||||||
StreamTransportConnection conn = plugin.createConnection(contactId);
|
DuplexTransportConnection d = plugin.createConnection(contactId);
|
||||||
assertNotNull(conn);
|
assertNotNull(d);
|
||||||
// Check that the connection was accepted
|
// Check that the connection was accepted
|
||||||
assertTrue(latch.await(1, TimeUnit.SECONDS));
|
assertTrue(latch.await(1, TimeUnit.SECONDS));
|
||||||
assertFalse(error.get());
|
assertFalse(error.get());
|
||||||
// Clean up
|
// Clean up
|
||||||
conn.dispose(false, true);
|
d.dispose(false, true);
|
||||||
ss.close();
|
ss.close();
|
||||||
plugin.stop();
|
plugin.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class StreamCallback implements StreamPluginCallback {
|
private static class Callback implements DuplexPluginCallback {
|
||||||
|
|
||||||
private final Map<ContactId, TransportProperties> remote =
|
private final Map<ContactId, TransportProperties> remote =
|
||||||
new HashMap<ContactId, TransportProperties>();
|
new HashMap<ContactId, TransportProperties>();
|
||||||
@@ -143,12 +143,11 @@ public class SimpleSocketPluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
public void showMessage(String... message) {}
|
public void showMessage(String... message) {}
|
||||||
|
|
||||||
public void incomingConnectionCreated(StreamTransportConnection c) {
|
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
||||||
incomingConnections++;
|
incomingConnections++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outgoingConnectionCreated(ContactId contactId,
|
public void outgoingConnectionCreated(ContactId c,
|
||||||
StreamTransportConnection c) {
|
DuplexTransportConnection d) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -24,7 +24,8 @@ import net.sf.briar.api.transport.ConnectionWriterFactory;
|
|||||||
import net.sf.briar.api.transport.TransportConstants;
|
import net.sf.briar.api.transport.TransportConstants;
|
||||||
import net.sf.briar.crypto.CryptoModule;
|
import net.sf.briar.crypto.CryptoModule;
|
||||||
import net.sf.briar.protocol.ProtocolModule;
|
import net.sf.briar.protocol.ProtocolModule;
|
||||||
import net.sf.briar.protocol.stream.ProtocolStreamModule;
|
import net.sf.briar.protocol.duplex.DuplexProtocolModule;
|
||||||
|
import net.sf.briar.protocol.simplex.SimplexProtocolModule;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
import net.sf.briar.transport.TransportModule;
|
import net.sf.briar.transport.TransportModule;
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
public class OutgoingBatchConnectionTest extends BriarTestCase {
|
public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||||
|
|
||||||
private final Mockery context;
|
private final Mockery context;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
@@ -49,7 +50,7 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
|
|||||||
private final TransportIndex transportIndex;
|
private final TransportIndex transportIndex;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
|
|
||||||
public OutgoingBatchConnectionTest() {
|
public OutgoingSimplexConnectionTest() {
|
||||||
super();
|
super();
|
||||||
context = new Mockery();
|
context = new Mockery();
|
||||||
db = context.mock(DatabaseComponent.class);
|
db = context.mock(DatabaseComponent.class);
|
||||||
@@ -64,8 +65,8 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
|
|||||||
};
|
};
|
||||||
Injector i = Guice.createInjector(testModule, new CryptoModule(),
|
Injector i = Guice.createInjector(testModule, new CryptoModule(),
|
||||||
new SerialModule(), new TransportModule(),
|
new SerialModule(), new TransportModule(),
|
||||||
new ProtocolBatchModule(), new ProtocolModule(),
|
new SimplexProtocolModule(), new ProtocolModule(),
|
||||||
new ProtocolStreamModule());
|
new DuplexProtocolModule());
|
||||||
connRegistry = i.getInstance(ConnectionRegistry.class);
|
connRegistry = i.getInstance(ConnectionRegistry.class);
|
||||||
connFactory = i.getInstance(ConnectionWriterFactory.class);
|
connFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||||
protoFactory = i.getInstance(ProtocolWriterFactory.class);
|
protoFactory = i.getInstance(ProtocolWriterFactory.class);
|
||||||
@@ -78,9 +79,9 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testConnectionTooShort() throws Exception {
|
public void testConnectionTooShort() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
ProtocolConstants.MAX_PACKET_LENGTH, true);
|
out, ProtocolConstants.MAX_PACKET_LENGTH, true);
|
||||||
OutgoingBatchConnection connection = new OutgoingBatchConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, contactId, transportId,
|
connRegistry, connFactory, protoFactory, contactId, transportId,
|
||||||
transportIndex, transport);
|
transportIndex, transport);
|
||||||
final ConnectionContext ctx = context.mock(ConnectionContext.class);
|
final ConnectionContext ctx = context.mock(ConnectionContext.class);
|
||||||
@@ -102,9 +103,9 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testNothingToSend() throws Exception {
|
public void testNothingToSend() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
TransportConstants.MIN_CONNECTION_LENGTH, true);
|
out, TransportConstants.MIN_CONNECTION_LENGTH, true);
|
||||||
OutgoingBatchConnection connection = new OutgoingBatchConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, contactId, transportId,
|
connRegistry, connFactory, protoFactory, contactId, transportId,
|
||||||
transportIndex, transport);
|
transportIndex, transport);
|
||||||
final ConnectionContext ctx = context.mock(ConnectionContext.class);
|
final ConnectionContext ctx = context.mock(ConnectionContext.class);
|
||||||
@@ -138,9 +139,9 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testSomethingToSend() throws Exception {
|
public void testSomethingToSend() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
TransportConstants.MIN_CONNECTION_LENGTH, true);
|
out, TransportConstants.MIN_CONNECTION_LENGTH, true);
|
||||||
OutgoingBatchConnection connection = new OutgoingBatchConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, contactId, transportId,
|
connRegistry, connFactory, protoFactory, contactId, transportId,
|
||||||
transportIndex, transport);
|
transportIndex, transport);
|
||||||
final ConnectionContext ctx = context.mock(ConnectionContext.class);
|
final ConnectionContext ctx = context.mock(ConnectionContext.class);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
|
|
||||||
@@ -35,7 +35,8 @@ import net.sf.briar.db.DatabaseModule;
|
|||||||
import net.sf.briar.lifecycle.LifecycleModule;
|
import net.sf.briar.lifecycle.LifecycleModule;
|
||||||
import net.sf.briar.plugins.ImmediateExecutor;
|
import net.sf.briar.plugins.ImmediateExecutor;
|
||||||
import net.sf.briar.protocol.ProtocolModule;
|
import net.sf.briar.protocol.ProtocolModule;
|
||||||
import net.sf.briar.protocol.stream.ProtocolStreamModule;
|
import net.sf.briar.protocol.duplex.DuplexProtocolModule;
|
||||||
|
import net.sf.briar.protocol.simplex.SimplexProtocolModule;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
import net.sf.briar.transport.TransportModule;
|
import net.sf.briar.transport.TransportModule;
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ import org.junit.Test;
|
|||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
public class BatchConnectionReadWriteTest extends BriarTestCase {
|
public class SimplexConnectionReadWriteTest extends BriarTestCase {
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
private final File aliceDir = new File(testDir, "alice");
|
private final File aliceDir = new File(testDir, "alice");
|
||||||
@@ -57,7 +58,7 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
|
|||||||
|
|
||||||
private Injector alice, bob;
|
private Injector alice, bob;
|
||||||
|
|
||||||
public BatchConnectionReadWriteTest() throws Exception {
|
public SimplexConnectionReadWriteTest() throws Exception {
|
||||||
super();
|
super();
|
||||||
transportId = new TransportId(TestUtils.getRandomId());
|
transportId = new TransportId(TestUtils.getRandomId());
|
||||||
transportIndex = new TransportIndex(1);
|
transportIndex = new TransportIndex(1);
|
||||||
@@ -79,8 +80,8 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
|
|||||||
private Injector createInjector(File dir) {
|
private Injector createInjector(File dir) {
|
||||||
return Guice.createInjector(new CryptoModule(), new DatabaseModule(),
|
return Guice.createInjector(new CryptoModule(), new DatabaseModule(),
|
||||||
new LifecycleModule(), new ProtocolModule(), new SerialModule(),
|
new LifecycleModule(), new ProtocolModule(), new SerialModule(),
|
||||||
new TestDatabaseModule(dir), new ProtocolBatchModule(),
|
new TestDatabaseModule(dir), new SimplexProtocolModule(),
|
||||||
new TransportModule(), new ProtocolStreamModule());
|
new TransportModule(), new DuplexProtocolModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -114,9 +115,9 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
|
|||||||
alice.getInstance(ConnectionWriterFactory.class);
|
alice.getInstance(ConnectionWriterFactory.class);
|
||||||
ProtocolWriterFactory protoFactory =
|
ProtocolWriterFactory protoFactory =
|
||||||
alice.getInstance(ProtocolWriterFactory.class);
|
alice.getInstance(ProtocolWriterFactory.class);
|
||||||
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(out,
|
||||||
Long.MAX_VALUE, false);
|
Long.MAX_VALUE, false);
|
||||||
OutgoingBatchConnection batchOut = new OutgoingBatchConnection(db,
|
OutgoingSimplexConnection batchOut = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, contactId, transportId,
|
connRegistry, connFactory, protoFactory, contactId, transportId,
|
||||||
transportIndex, transport);
|
transportIndex, transport);
|
||||||
// Write whatever needs to be written
|
// Write whatever needs to be written
|
||||||
@@ -170,8 +171,8 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
|
|||||||
bob.getInstance(ConnectionReaderFactory.class);
|
bob.getInstance(ConnectionReaderFactory.class);
|
||||||
ProtocolReaderFactory protoFactory =
|
ProtocolReaderFactory protoFactory =
|
||||||
bob.getInstance(ProtocolReaderFactory.class);
|
bob.getInstance(ProtocolReaderFactory.class);
|
||||||
TestBatchTransportReader transport = new TestBatchTransportReader(in);
|
TestSimplexTransportReader transport = new TestSimplexTransportReader(in);
|
||||||
IncomingBatchConnection batchIn = new IncomingBatchConnection(
|
IncomingSimplexConnection batchIn = new IncomingSimplexConnection(
|
||||||
new ImmediateExecutor(), new ImmediateExecutor(), db,
|
new ImmediateExecutor(), new ImmediateExecutor(), db,
|
||||||
connRegistry, connFactory, protoFactory, ctx, transportId,
|
connRegistry, connFactory, protoFactory, ctx, transportId,
|
||||||
transport, tag);
|
transport, tag);
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.sf.briar.api.transport.BatchTransportReader;
|
import net.sf.briar.api.plugins.SimplexTransportReader;
|
||||||
|
|
||||||
class TestBatchTransportReader implements BatchTransportReader {
|
class TestSimplexTransportReader implements SimplexTransportReader {
|
||||||
|
|
||||||
private final InputStream in;
|
private final InputStream in;
|
||||||
|
|
||||||
private boolean disposed = false, exception = false, recognised = false;
|
private boolean disposed = false, exception = false, recognised = false;
|
||||||
|
|
||||||
TestBatchTransportReader(InputStream in) {
|
TestSimplexTransportReader(InputStream in) {
|
||||||
this.in = in;
|
this.in = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package net.sf.briar.protocol.batch;
|
package net.sf.briar.protocol.simplex;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import net.sf.briar.api.transport.BatchTransportWriter;
|
import net.sf.briar.api.plugins.SimplexTransportWriter;
|
||||||
|
|
||||||
class TestBatchTransportWriter implements BatchTransportWriter {
|
class TestSimplexTransportWriter implements SimplexTransportWriter {
|
||||||
|
|
||||||
private final ByteArrayOutputStream out;
|
private final ByteArrayOutputStream out;
|
||||||
private final long capacity;
|
private final long capacity;
|
||||||
@@ -13,7 +13,7 @@ class TestBatchTransportWriter implements BatchTransportWriter {
|
|||||||
|
|
||||||
private boolean disposed = false, exception = false;
|
private boolean disposed = false, exception = false;
|
||||||
|
|
||||||
TestBatchTransportWriter(ByteArrayOutputStream out, long capacity,
|
TestSimplexTransportWriter(ByteArrayOutputStream out, long capacity,
|
||||||
boolean flush) {
|
boolean flush) {
|
||||||
this.out = out;
|
this.out = out;
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
@@ -14,8 +14,8 @@ import net.sf.briar.crypto.CryptoModule;
|
|||||||
import net.sf.briar.db.DatabaseModule;
|
import net.sf.briar.db.DatabaseModule;
|
||||||
import net.sf.briar.lifecycle.LifecycleModule;
|
import net.sf.briar.lifecycle.LifecycleModule;
|
||||||
import net.sf.briar.protocol.ProtocolModule;
|
import net.sf.briar.protocol.ProtocolModule;
|
||||||
import net.sf.briar.protocol.batch.ProtocolBatchModule;
|
import net.sf.briar.protocol.duplex.DuplexProtocolModule;
|
||||||
import net.sf.briar.protocol.stream.ProtocolStreamModule;
|
import net.sf.briar.protocol.simplex.SimplexProtocolModule;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -33,8 +33,8 @@ public class ConnectionWriterTest extends BriarTestCase {
|
|||||||
Injector i = Guice.createInjector(new CryptoModule(),
|
Injector i = Guice.createInjector(new CryptoModule(),
|
||||||
new DatabaseModule(), new LifecycleModule(),
|
new DatabaseModule(), new LifecycleModule(),
|
||||||
new ProtocolModule(), new SerialModule(),
|
new ProtocolModule(), new SerialModule(),
|
||||||
new TestDatabaseModule(), new ProtocolBatchModule(),
|
new TestDatabaseModule(), new SimplexProtocolModule(),
|
||||||
new TransportModule(), new ProtocolStreamModule());
|
new TransportModule(), new DuplexProtocolModule());
|
||||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||||
secret = new byte[32];
|
secret = new byte[32];
|
||||||
new Random().nextBytes(secret);
|
new Random().nextBytes(secret);
|
||||||
|
|||||||
Reference in New Issue
Block a user