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:
akwizgran
2012-01-11 17:00:47 +00:00
parent 1499e061c1
commit 99caec9448
61 changed files with 505 additions and 515 deletions

View File

@@ -49,8 +49,8 @@ import net.sf.briar.crypto.CryptoModule;
import net.sf.briar.db.DatabaseModule;
import net.sf.briar.lifecycle.LifecycleModule;
import net.sf.briar.protocol.ProtocolModule;
import net.sf.briar.protocol.batch.ProtocolBatchModule;
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.transport.TransportModule;
@@ -85,8 +85,8 @@ public class ProtocolIntegrationTest extends BriarTestCase {
Injector i = Guice.createInjector(new CryptoModule(),
new DatabaseModule(), new LifecycleModule(),
new ProtocolModule(), new SerialModule(),
new TestDatabaseModule(), new ProtocolBatchModule(),
new TransportModule(), new ProtocolStreamModule());
new TestDatabaseModule(), new SimplexProtocolModule(),
new TransportModule(), new DuplexProtocolModule());
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
protocolReaderFactory = i.getInstance(ProtocolReaderFactory.class);

View File

@@ -44,8 +44,8 @@ import net.sf.briar.api.transport.ConnectionWindowFactory;
import net.sf.briar.crypto.CryptoModule;
import net.sf.briar.lifecycle.LifecycleModule;
import net.sf.briar.protocol.ProtocolModule;
import net.sf.briar.protocol.batch.ProtocolBatchModule;
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.transport.TransportModule;
@@ -96,8 +96,8 @@ public class H2DatabaseTest extends BriarTestCase {
Injector i = Guice.createInjector(new CryptoModule(),
new DatabaseModule(), new LifecycleModule(),
new ProtocolModule(), new SerialModule(),
new ProtocolBatchModule(), new TransportModule(),
new ProtocolStreamModule(), new TestDatabaseModule(testDir));
new SimplexProtocolModule(), new TransportModule(),
new DuplexProtocolModule(), new TestDatabaseModule(testDir));
connectionContextFactory =
i.getInstance(ConnectionContextFactory.class);
connectionWindowFactory = i.getInstance(ConnectionWindowFactory.class);

View File

@@ -6,10 +6,10 @@ import java.util.Map;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.plugins.StreamPluginCallback;
import net.sf.briar.api.transport.StreamTransportConnection;
import net.sf.briar.api.plugins.DuplexPluginCallback;
import net.sf.briar.api.plugins.DuplexTransportConnection;
public abstract class StreamClientTest extends StreamTest {
public abstract class DuplexClientTest extends DuplexTest {
protected ClientCallback callback = null;
@@ -20,37 +20,37 @@ public abstract class StreamClientTest extends StreamTest {
plugin.start();
// Try to connect to the server
System.out.println("Creating connection");
StreamTransportConnection s = plugin.createConnection(contactId);
if(s == null) {
DuplexTransportConnection d = plugin.createConnection(contactId);
if(d == null) {
System.out.println("Connection failed");
} else {
System.out.println("Connection created");
receiveChallengeSendResponse(s);
receiveChallengeSendResponse(d);
}
// Try to send an invitation
System.out.println("Sending invitation");
s = plugin.sendInvitation(123, INVITATION_TIMEOUT);
if(s == null) {
d = plugin.sendInvitation(123, INVITATION_TIMEOUT);
if(d == null) {
System.out.println("Connection failed");
} else {
System.out.println("Connection created");
receiveChallengeSendResponse(s);
receiveChallengeSendResponse(d);
}
// Try to accept an invitation
System.out.println("Accepting invitation");
s = plugin.acceptInvitation(456, INVITATION_TIMEOUT);
if(s == null) {
d = plugin.acceptInvitation(456, INVITATION_TIMEOUT);
if(d == null) {
System.out.println("Connection failed");
} else {
System.out.println("Connection created");
sendChallengeReceiveResponse(s);
sendChallengeReceiveResponse(d);
}
// Stop the plugin
System.out.println("Stopping plugin");
plugin.stop();
}
protected static class ClientCallback implements StreamPluginCallback {
protected static class ClientCallback implements DuplexPluginCallback {
private TransportConfig config = null;
private TransportProperties local = null;
@@ -93,9 +93,9 @@ public abstract class StreamClientTest extends StreamTest {
public void showMessage(String... message) {}
public void incomingConnectionCreated(StreamTransportConnection c) {}
public void incomingConnectionCreated(DuplexTransportConnection d) {}
public void outgoingConnectionCreated(ContactId contactId,
StreamTransportConnection c) {}
DuplexTransportConnection d) {}
}
}

View File

@@ -6,10 +6,10 @@ import java.util.concurrent.CountDownLatch;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.plugins.StreamPluginCallback;
import net.sf.briar.api.transport.StreamTransportConnection;
import net.sf.briar.api.plugins.DuplexPluginCallback;
import net.sf.briar.api.plugins.DuplexTransportConnection;
public abstract class StreamServerTest extends StreamTest {
public abstract class DuplexServerTest extends DuplexTest {
protected ServerCallback callback = null;
@@ -24,29 +24,29 @@ public abstract class StreamServerTest extends StreamTest {
callback.latch.await();
// Try to accept an invitation
System.out.println("Accepting invitation");
StreamTransportConnection s = plugin.acceptInvitation(123,
DuplexTransportConnection d = plugin.acceptInvitation(123,
INVITATION_TIMEOUT);
if(s == null) {
if(d == null) {
System.out.println("Connection failed");
} else {
System.out.println("Connection created");
sendChallengeReceiveResponse(s);
sendChallengeReceiveResponse(d);
}
// Try to send an invitation
System.out.println("Sending invitation");
s = plugin.sendInvitation(456, INVITATION_TIMEOUT);
if(s == null) {
d = plugin.sendInvitation(456, INVITATION_TIMEOUT);
if(d == null) {
System.out.println("Connection failed");
} else {
System.out.println("Connection created");
receiveChallengeSendResponse(s);
receiveChallengeSendResponse(d);
}
// Stop the plugin
System.out.println("Stopping plugin");
plugin.stop();
}
protected class ServerCallback implements StreamPluginCallback {
protected class ServerCallback implements DuplexPluginCallback {
private final CountDownLatch latch = new CountDownLatch(1);
@@ -91,13 +91,13 @@ public abstract class StreamServerTest extends StreamTest {
public void showMessage(String... message) {}
public void incomingConnectionCreated(StreamTransportConnection s) {
public void incomingConnectionCreated(DuplexTransportConnection d) {
System.out.println("Connection received");
sendChallengeReceiveResponse(s);
sendChallengeReceiveResponse(d);
latch.countDown();
}
public void outgoingConnectionCreated(ContactId contactId,
StreamTransportConnection c) {}
public void outgoingConnectionCreated(ContactId c,
DuplexTransportConnection d) {}
}
}

View File

@@ -5,10 +5,10 @@ import java.io.PrintStream;
import java.util.Scanner;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.StreamPlugin;
import net.sf.briar.api.transport.StreamTransportConnection;
import net.sf.briar.api.plugins.DuplexPlugin;
import net.sf.briar.api.plugins.DuplexTransportConnection;
abstract class StreamTest {
abstract class DuplexTest {
protected static final String CHALLENGE = "Carrots!";
protected static final String RESPONSE = "Potatoes!";
@@ -16,15 +16,15 @@ abstract class StreamTest {
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;
try {
PrintStream out = new PrintStream(s.getOutputStream());
PrintStream out = new PrintStream(d.getOutputStream());
out.println(CHALLENGE);
System.out.println("Sent challenge: " + CHALLENGE);
Scanner in = new Scanner(s.getInputStream());
Scanner in = new Scanner(d.getInputStream());
if(in.hasNextLine()) {
String response = in.nextLine();
System.out.println("Received response: " + response);
@@ -36,22 +36,22 @@ abstract class StreamTest {
} else {
System.out.println("No response");
}
s.dispose(false, true);
d.dispose(false, true);
} catch(IOException e) {
e.printStackTrace();
s.dispose(true, true);
d.dispose(true, true);
}
}
protected void receiveChallengeSendResponse(StreamTransportConnection s) {
protected void receiveChallengeSendResponse(DuplexTransportConnection d) {
assert plugin != null;
try {
Scanner in = new Scanner(s.getInputStream());
Scanner in = new Scanner(d.getInputStream());
if(in.hasNextLine()) {
String challenge = in.nextLine();
System.out.println("Received challenge: " + challenge);
if(CHALLENGE.equals(challenge)) {
PrintStream out = new PrintStream(s.getOutputStream());
PrintStream out = new PrintStream(d.getOutputStream());
out.println(RESPONSE);
System.out.println("Sent response: " + RESPONSE);
} else {
@@ -60,10 +60,10 @@ abstract class StreamTest {
} else {
System.out.println("No challenge");
}
s.dispose(false, true);
d.dispose(false, true);
} catch(IOException e) {
e.printStackTrace();
s.dispose(true, true);
d.dispose(true, true);
}
}
}

View File

@@ -9,11 +9,11 @@ import java.util.concurrent.Executors;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
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
// is running on another machine
public class BluetoothClientTest extends StreamClientTest {
public class BluetoothClientTest extends DuplexClientTest {
private BluetoothClientTest(Executor executor, String serverAddress) {
// Store the server's Bluetooth address and UUID

View File

@@ -7,11 +7,11 @@ import java.util.concurrent.Executors;
import net.sf.briar.api.TransportConfig;
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
// is running on another machine
public class BluetoothServerTest extends StreamServerTest {
public class BluetoothServerTest extends DuplexServerTest {
private BluetoothServerTest(Executor executor) {
// Store the UUID

View File

@@ -13,8 +13,8 @@ import java.util.concurrent.Executor;
import net.sf.briar.BriarTestCase;
import net.sf.briar.TestUtils;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.BatchPluginCallback;
import net.sf.briar.api.transport.BatchTransportWriter;
import net.sf.briar.api.plugins.SimplexPluginCallback;
import net.sf.briar.api.plugins.SimplexTransportWriter;
import net.sf.briar.api.transport.TransportConstants;
import net.sf.briar.plugins.ImmediateExecutor;
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
@@ -39,8 +39,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
public void testGetId() {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -61,8 +61,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -93,8 +93,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -130,8 +130,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -169,8 +169,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -208,8 +208,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -250,8 +250,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -271,7 +271,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
callback, finder, monitor);
plugin.start();
BatchTransportWriter writer = plugin.createWriter(contactId);
SimplexTransportWriter writer = plugin.createWriter(contactId);
assertNotNull(writer);
// The output file should exist and should be empty
File[] files = drive1.listFiles();
@@ -295,8 +295,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
public void testEmptyDriveIsIgnored() throws Exception {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -319,8 +319,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
public void testFilenames() {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
@@ -342,8 +342,8 @@ public class RemovableDrivePluginTest extends BriarTestCase {
@Test
public void testReaderIsCreated() throws Exception {
Mockery context = new Mockery();
final BatchPluginCallback callback =
context.mock(BatchPluginCallback.class);
final SimplexPluginCallback callback =
context.mock(SimplexPluginCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =

View File

@@ -9,11 +9,11 @@ import java.util.concurrent.Executor;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
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
// is running on another machine
public class LanSocketClientTest extends StreamClientTest {
public class LanSocketClientTest extends DuplexClientTest {
private LanSocketClientTest(Executor executor, String serverAddress,
String serverPort) {

View File

@@ -7,11 +7,11 @@ import java.util.concurrent.Executors;
import net.sf.briar.api.TransportConfig;
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
// is running on another machine
public class LanSocketServerTest extends StreamServerTest {
public class LanSocketServerTest extends DuplexServerTest {
private LanSocketServerTest(Executor executor) {
callback = new ServerCallback(new TransportConfig(),

View File

@@ -16,8 +16,8 @@ import net.sf.briar.BriarTestCase;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.plugins.StreamPluginCallback;
import net.sf.briar.api.transport.StreamTransportConnection;
import net.sf.briar.api.plugins.DuplexPluginCallback;
import net.sf.briar.api.plugins.DuplexTransportConnection;
import org.junit.Test;
@@ -27,7 +27,7 @@ public class SimpleSocketPluginTest extends BriarTestCase {
@Test
public void testIncomingConnection() throws Exception {
StreamCallback callback = new StreamCallback();
Callback callback = new Callback();
callback.local.put("internal", "127.0.0.1");
callback.local.put("port", "0");
Executor e = Executors.newCachedThreadPool();
@@ -63,7 +63,7 @@ public class SimpleSocketPluginTest extends BriarTestCase {
@Test
public void testOutgoingConnection() throws Exception {
StreamCallback callback = new StreamCallback();
Callback callback = new Callback();
Executor e = Executors.newCachedThreadPool();
SimpleSocketPlugin plugin = new SimpleSocketPlugin(e, callback, 0L);
plugin.start();
@@ -90,18 +90,18 @@ public class SimpleSocketPluginTest extends BriarTestCase {
p.put("port", String.valueOf(port));
callback.remote.put(contactId, p);
// Connect to the port
StreamTransportConnection conn = plugin.createConnection(contactId);
assertNotNull(conn);
DuplexTransportConnection d = plugin.createConnection(contactId);
assertNotNull(d);
// Check that the connection was accepted
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertFalse(error.get());
// Clean up
conn.dispose(false, true);
d.dispose(false, true);
ss.close();
plugin.stop();
}
private static class StreamCallback implements StreamPluginCallback {
private static class Callback implements DuplexPluginCallback {
private final Map<ContactId, TransportProperties> remote =
new HashMap<ContactId, TransportProperties>();
@@ -143,12 +143,11 @@ public class SimpleSocketPluginTest extends BriarTestCase {
public void showMessage(String... message) {}
public void incomingConnectionCreated(StreamTransportConnection c) {
public void incomingConnectionCreated(DuplexTransportConnection d) {
incomingConnections++;
}
public void outgoingConnectionCreated(ContactId contactId,
StreamTransportConnection c) {
}
public void outgoingConnectionCreated(ContactId c,
DuplexTransportConnection d) {}
}
}

View File

@@ -1,4 +1,4 @@
package net.sf.briar.protocol.batch;
package net.sf.briar.protocol.simplex;
import java.io.ByteArrayOutputStream;
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.crypto.CryptoModule;
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.transport.TransportModule;
@@ -37,7 +38,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
public class OutgoingBatchConnectionTest extends BriarTestCase {
public class OutgoingSimplexConnectionTest extends BriarTestCase {
private final Mockery context;
private final DatabaseComponent db;
@@ -49,7 +50,7 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
private final TransportIndex transportIndex;
private final byte[] secret;
public OutgoingBatchConnectionTest() {
public OutgoingSimplexConnectionTest() {
super();
context = new Mockery();
db = context.mock(DatabaseComponent.class);
@@ -64,8 +65,8 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
};
Injector i = Guice.createInjector(testModule, new CryptoModule(),
new SerialModule(), new TransportModule(),
new ProtocolBatchModule(), new ProtocolModule(),
new ProtocolStreamModule());
new SimplexProtocolModule(), new ProtocolModule(),
new DuplexProtocolModule());
connRegistry = i.getInstance(ConnectionRegistry.class);
connFactory = i.getInstance(ConnectionWriterFactory.class);
protoFactory = i.getInstance(ProtocolWriterFactory.class);
@@ -78,9 +79,9 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
@Test
public void testConnectionTooShort() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
ProtocolConstants.MAX_PACKET_LENGTH, true);
OutgoingBatchConnection connection = new OutgoingBatchConnection(db,
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, ProtocolConstants.MAX_PACKET_LENGTH, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
connRegistry, connFactory, protoFactory, contactId, transportId,
transportIndex, transport);
final ConnectionContext ctx = context.mock(ConnectionContext.class);
@@ -102,9 +103,9 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
@Test
public void testNothingToSend() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
TransportConstants.MIN_CONNECTION_LENGTH, true);
OutgoingBatchConnection connection = new OutgoingBatchConnection(db,
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, TransportConstants.MIN_CONNECTION_LENGTH, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
connRegistry, connFactory, protoFactory, contactId, transportId,
transportIndex, transport);
final ConnectionContext ctx = context.mock(ConnectionContext.class);
@@ -138,9 +139,9 @@ public class OutgoingBatchConnectionTest extends BriarTestCase {
@Test
public void testSomethingToSend() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
TransportConstants.MIN_CONNECTION_LENGTH, true);
OutgoingBatchConnection connection = new OutgoingBatchConnection(db,
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, TransportConstants.MIN_CONNECTION_LENGTH, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
connRegistry, connFactory, protoFactory, contactId, transportId,
transportIndex, transport);
final ConnectionContext ctx = context.mock(ConnectionContext.class);

View File

@@ -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;
@@ -35,7 +35,8 @@ import net.sf.briar.db.DatabaseModule;
import net.sf.briar.lifecycle.LifecycleModule;
import net.sf.briar.plugins.ImmediateExecutor;
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.transport.TransportModule;
@@ -46,7 +47,7 @@ import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class BatchConnectionReadWriteTest extends BriarTestCase {
public class SimplexConnectionReadWriteTest extends BriarTestCase {
private final File testDir = TestUtils.getTestDirectory();
private final File aliceDir = new File(testDir, "alice");
@@ -57,7 +58,7 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
private Injector alice, bob;
public BatchConnectionReadWriteTest() throws Exception {
public SimplexConnectionReadWriteTest() throws Exception {
super();
transportId = new TransportId(TestUtils.getRandomId());
transportIndex = new TransportIndex(1);
@@ -79,8 +80,8 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
private Injector createInjector(File dir) {
return Guice.createInjector(new CryptoModule(), new DatabaseModule(),
new LifecycleModule(), new ProtocolModule(), new SerialModule(),
new TestDatabaseModule(dir), new ProtocolBatchModule(),
new TransportModule(), new ProtocolStreamModule());
new TestDatabaseModule(dir), new SimplexProtocolModule(),
new TransportModule(), new DuplexProtocolModule());
}
@Test
@@ -114,9 +115,9 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
alice.getInstance(ConnectionWriterFactory.class);
ProtocolWriterFactory protoFactory =
alice.getInstance(ProtocolWriterFactory.class);
TestBatchTransportWriter transport = new TestBatchTransportWriter(out,
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(out,
Long.MAX_VALUE, false);
OutgoingBatchConnection batchOut = new OutgoingBatchConnection(db,
OutgoingSimplexConnection batchOut = new OutgoingSimplexConnection(db,
connRegistry, connFactory, protoFactory, contactId, transportId,
transportIndex, transport);
// Write whatever needs to be written
@@ -170,8 +171,8 @@ public class BatchConnectionReadWriteTest extends BriarTestCase {
bob.getInstance(ConnectionReaderFactory.class);
ProtocolReaderFactory protoFactory =
bob.getInstance(ProtocolReaderFactory.class);
TestBatchTransportReader transport = new TestBatchTransportReader(in);
IncomingBatchConnection batchIn = new IncomingBatchConnection(
TestSimplexTransportReader transport = new TestSimplexTransportReader(in);
IncomingSimplexConnection batchIn = new IncomingSimplexConnection(
new ImmediateExecutor(), new ImmediateExecutor(), db,
connRegistry, connFactory, protoFactory, ctx, transportId,
transport, tag);

View File

@@ -1,16 +1,16 @@
package net.sf.briar.protocol.batch;
package net.sf.briar.protocol.simplex;
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 boolean disposed = false, exception = false, recognised = false;
TestBatchTransportReader(InputStream in) {
TestSimplexTransportReader(InputStream in) {
this.in = in;
}

View File

@@ -1,11 +1,11 @@
package net.sf.briar.protocol.batch;
package net.sf.briar.protocol.simplex;
import java.io.ByteArrayOutputStream;
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 long capacity;
@@ -13,7 +13,7 @@ class TestBatchTransportWriter implements BatchTransportWriter {
private boolean disposed = false, exception = false;
TestBatchTransportWriter(ByteArrayOutputStream out, long capacity,
TestSimplexTransportWriter(ByteArrayOutputStream out, long capacity,
boolean flush) {
this.out = out;
this.capacity = capacity;

View File

@@ -14,8 +14,8 @@ import net.sf.briar.crypto.CryptoModule;
import net.sf.briar.db.DatabaseModule;
import net.sf.briar.lifecycle.LifecycleModule;
import net.sf.briar.protocol.ProtocolModule;
import net.sf.briar.protocol.batch.ProtocolBatchModule;
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 org.junit.Test;
@@ -33,8 +33,8 @@ public class ConnectionWriterTest extends BriarTestCase {
Injector i = Guice.createInjector(new CryptoModule(),
new DatabaseModule(), new LifecycleModule(),
new ProtocolModule(), new SerialModule(),
new TestDatabaseModule(), new ProtocolBatchModule(),
new TransportModule(), new ProtocolStreamModule());
new TestDatabaseModule(), new SimplexProtocolModule(),
new TransportModule(), new DuplexProtocolModule());
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
secret = new byte[32];
new Random().nextBytes(secret);