mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Massive refactoring to merge handling of simplex and duplex connections.
This commit is contained in:
@@ -7,6 +7,8 @@ import java.util.Scanner;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.crypto.PseudoRandom;
|
||||
import org.briarproject.api.plugins.TransportConnectionReader;
|
||||
import org.briarproject.api.plugins.TransportConnectionWriter;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||
|
||||
@@ -21,12 +23,14 @@ abstract class DuplexTest {
|
||||
|
||||
protected void sendChallengeReceiveResponse(DuplexTransportConnection d) {
|
||||
assert plugin != null;
|
||||
TransportConnectionReader r = d.getReader();
|
||||
TransportConnectionWriter w = d.getWriter();
|
||||
try {
|
||||
PrintStream out = new PrintStream(d.getOutputStream());
|
||||
PrintStream out = new PrintStream(w.getOutputStream());
|
||||
out.println(CHALLENGE);
|
||||
out.flush();
|
||||
System.out.println("Sent challenge: " + CHALLENGE);
|
||||
Scanner in = new Scanner(d.getInputStream());
|
||||
Scanner in = new Scanner(r.getInputStream());
|
||||
if(in.hasNextLine()) {
|
||||
String response = in.nextLine();
|
||||
System.out.println("Received response: " + response);
|
||||
@@ -38,11 +42,13 @@ abstract class DuplexTest {
|
||||
} else {
|
||||
System.out.println("No response");
|
||||
}
|
||||
d.dispose(false, true);
|
||||
r.dispose(false, true);
|
||||
w.dispose(false);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
d.dispose(true, true);
|
||||
r.dispose(true, true);
|
||||
w.dispose(true);
|
||||
} catch(IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@@ -51,13 +57,16 @@ abstract class DuplexTest {
|
||||
|
||||
protected void receiveChallengeSendResponse(DuplexTransportConnection d) {
|
||||
assert plugin != null;
|
||||
TransportConnectionReader r = d.getReader();
|
||||
TransportConnectionWriter w = d.getWriter();
|
||||
try {
|
||||
Scanner in = new Scanner(d.getInputStream());
|
||||
Scanner in = new Scanner(r.getInputStream());
|
||||
if(in.hasNextLine()) {
|
||||
String challenge = in.nextLine();
|
||||
System.out.println("Received challenge: " + challenge);
|
||||
if(CHALLENGE.equals(challenge)) {
|
||||
PrintStream out = new PrintStream(d.getOutputStream());
|
||||
|
||||
PrintStream out = new PrintStream(w.getOutputStream());
|
||||
out.println(RESPONSE);
|
||||
out.flush();
|
||||
System.out.println("Sent response: " + RESPONSE);
|
||||
@@ -67,11 +76,13 @@ abstract class DuplexTest {
|
||||
} else {
|
||||
System.out.println("No challenge");
|
||||
}
|
||||
d.dispose(false, true);
|
||||
r.dispose(false, true);
|
||||
w.dispose(false);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
d.dispose(true, true);
|
||||
r.dispose(true, true);
|
||||
w.dispose(true);
|
||||
} catch(IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestFileUtils;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.plugins.TransportConnectionWriter;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.plugins.ImmediateExecutor;
|
||||
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
||||
@@ -32,6 +32,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
private final ContactId contactId = new ContactId(234);
|
||||
private final FileUtils fileUtils = new TestFileUtils();
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
testDir.mkdirs();
|
||||
@@ -253,7 +254,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0);
|
||||
plugin.start();
|
||||
|
||||
SimplexTransportWriter writer = plugin.createWriter(contactId);
|
||||
TransportConnectionWriter writer = plugin.createWriter(contactId);
|
||||
assertNotNull(writer);
|
||||
// The output file should exist and should be empty
|
||||
File[] files = drive1.listFiles();
|
||||
@@ -352,6 +353,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() {
|
||||
TestUtils.deleteTestDirectory(testDir);
|
||||
|
||||
@@ -278,7 +278,8 @@ public class ModemPluginTest extends BriarTestCase {
|
||||
public Object invoke(Invocation invocation) throws Throwable {
|
||||
DuplexTransportConnection conn =
|
||||
(DuplexTransportConnection) invocation.getParameter(1);
|
||||
conn.dispose(false, true);
|
||||
conn.getReader().dispose(false, true);
|
||||
conn.getWriter().dispose(false);
|
||||
invoked.countDown();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,8 @@ public class LanTcpPluginTest extends BriarTestCase {
|
||||
assertTrue(latch.await(5, SECONDS));
|
||||
assertFalse(error.get());
|
||||
// Clean up
|
||||
d.dispose(false, true);
|
||||
d.getReader().dispose(false, true);
|
||||
d.getWriter().dispose(false);
|
||||
ss.close();
|
||||
plugin.stop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user