diff --git a/api/net/sf/briar/api/transport/batch/BatchTransportCallback.java b/api/net/sf/briar/api/transport/batch/BatchTransportCallback.java index 44387029f696fc461a8a6a9457c14460fc919fcf..33423e3b72afef1750f237d72a07ac2eab12ed9c 100644 --- a/api/net/sf/briar/api/transport/batch/BatchTransportCallback.java +++ b/api/net/sf/briar/api/transport/batch/BatchTransportCallback.java @@ -10,8 +10,7 @@ import net.sf.briar.api.transport.TransportCallback; */ public interface BatchTransportCallback extends TransportCallback { - void readerCreated(ContactId contactId, byte[] encryptedIv, - BatchTransportReader r); + void readerCreated(BatchTransportReader r); void writerCreated(ContactId contactId, TransportId t, long connection, BatchTransportWriter w); diff --git a/api/net/sf/briar/api/transport/stream/StreamTransportCallback.java b/api/net/sf/briar/api/transport/stream/StreamTransportCallback.java index fe741b8c2af8c4a5a0cb4db24070c6cb4da66b1a..f244160de75b966cce26eeae9bd7a6242aff0a88 100644 --- a/api/net/sf/briar/api/transport/stream/StreamTransportCallback.java +++ b/api/net/sf/briar/api/transport/stream/StreamTransportCallback.java @@ -10,8 +10,7 @@ import net.sf.briar.api.transport.TransportCallback; */ public interface StreamTransportCallback extends TransportCallback { - void incomingConnectionCreated(ContactId contactId, byte[] encryptedIv, - StreamTransportConnection c); + void incomingConnectionCreated(StreamTransportConnection c); void outgoingConnectionCreated(ContactId contactId, TransportId t, long connection, StreamTransportConnection c); diff --git a/components/net/sf/briar/plugins/file/FilePlugin.java b/components/net/sf/briar/plugins/file/FilePlugin.java index abe37fac527cd659dde2413ee13962ab2f1715cb..20191a930d1c84effe724eea0c88c93959ea8649 100644 --- a/components/net/sf/briar/plugins/file/FilePlugin.java +++ b/components/net/sf/briar/plugins/file/FilePlugin.java @@ -9,8 +9,6 @@ import java.util.Map; import java.util.concurrent.Executor; import net.sf.briar.api.ContactId; -import net.sf.briar.api.db.DbException; -import net.sf.briar.api.transport.ConnectionRecogniser; import net.sf.briar.api.transport.InvalidConfigException; import net.sf.briar.api.transport.InvalidTransportException; import net.sf.briar.api.transport.TransportConstants; @@ -23,7 +21,6 @@ import org.apache.commons.io.FileSystemUtils; abstract class FilePlugin implements BatchTransportPlugin { - private final ConnectionRecogniser recogniser; private final Executor executor; protected Map<String, String> localProperties = null; @@ -36,8 +33,7 @@ abstract class FilePlugin implements BatchTransportPlugin { protected abstract File chooseOutputDirectory(); protected abstract void writerFinished(File f); - FilePlugin(ConnectionRecogniser recogniser, Executor executor) { - this.recogniser = recogniser; + FilePlugin(Executor executor) { this.executor = executor; } @@ -142,31 +138,8 @@ abstract class FilePlugin implements BatchTransportPlugin { if(f.length() < TransportConstants.MIN_CONNECTION_LENGTH) return; try { FileInputStream in = new FileInputStream(f); - byte[] iv = new byte[TransportConstants.IV_LENGTH]; - int offset = 0; - while(offset < iv.length) { - int read = in.read(iv, offset, iv.length - offset); - if(read == -1) break; - offset += read; - } - if(offset < iv.length) { - // The file was truncated - in.close(); - return; - } - ContactId c = recogniser.acceptConnection(iv); - if(c == null) { - // Nobody there - in.close(); - return; - } - FileTransportReader reader = new FileTransportReader(f, in); - callback.readerCreated(c, iv, reader); - } catch(DbException e) { - // FIXME: At least log it - return; + callback.readerCreated(new FileTransportReader(f, in)); } catch(IOException e) { - // FIXME: At least log it return; } } diff --git a/components/net/sf/briar/plugins/file/RemovableDrivePlugin.java b/components/net/sf/briar/plugins/file/RemovableDrivePlugin.java index 29041633eb2e5174b6a714adca1d9733e28518ed..e0f3523ae6e6c75daae6a05f908bebba18092d4f 100644 --- a/components/net/sf/briar/plugins/file/RemovableDrivePlugin.java +++ b/components/net/sf/briar/plugins/file/RemovableDrivePlugin.java @@ -8,7 +8,6 @@ import java.util.concurrent.Executor; import net.sf.briar.api.ContactId; import net.sf.briar.api.TransportId; -import net.sf.briar.api.transport.ConnectionRecogniser; import net.sf.briar.api.transport.InvalidConfigException; import net.sf.briar.api.transport.InvalidTransportException; import net.sf.briar.api.transport.batch.BatchTransportCallback; @@ -23,9 +22,9 @@ implements RemovableDriveMonitor.Callback { private final RemovableDriveFinder finder; private final RemovableDriveMonitor monitor; - RemovableDrivePlugin(ConnectionRecogniser recogniser, Executor executor, - RemovableDriveFinder finder, RemovableDriveMonitor monitor) { - super(recogniser, executor); + RemovableDrivePlugin(Executor executor, RemovableDriveFinder finder, + RemovableDriveMonitor monitor) { + super(executor); this.finder = finder; this.monitor = monitor; } diff --git a/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java b/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java index 0792589ccfdf31151e21bb2715eca271058d05a5..52869a27aba3a43a7867e7551f97bc010a03e500 100644 --- a/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java +++ b/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java @@ -11,10 +11,8 @@ import java.util.concurrent.Executor; import junit.framework.TestCase; import net.sf.briar.TestUtils; import net.sf.briar.api.ContactId; -import net.sf.briar.api.transport.ConnectionRecogniser; import net.sf.briar.api.transport.TransportConstants; import net.sf.briar.api.transport.batch.BatchTransportCallback; -import net.sf.briar.api.transport.batch.BatchTransportReader; import net.sf.briar.api.transport.batch.BatchTransportWriter; import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback; @@ -38,15 +36,13 @@ public class RemovableDrivePluginTest extends TestCase { public void testGetId() { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = context.mock(RemovableDriveMonitor.class); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); assertEquals(RemovableDrivePlugin.TRANSPORT_ID, plugin.getId().getInt()); @@ -60,8 +56,6 @@ public class RemovableDrivePluginTest extends TestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -75,8 +69,8 @@ public class RemovableDrivePluginTest extends TestCase { will(returnValue(drives)); }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); plugin.start(null, null, null, callback); assertNull(plugin.createWriter(contactId)); @@ -94,8 +88,6 @@ public class RemovableDrivePluginTest extends TestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -112,8 +104,8 @@ public class RemovableDrivePluginTest extends TestCase { will(returnValue(-1)); // The user cancelled the choice }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); plugin.start(null, null, null, callback); assertNull(plugin.createWriter(contactId)); @@ -133,8 +125,6 @@ public class RemovableDrivePluginTest extends TestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -151,8 +141,8 @@ public class RemovableDrivePluginTest extends TestCase { will(returnValue(0)); // The user chose drive1 but it doesn't exist }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); plugin.start(null, null, null, callback); assertNull(plugin.createWriter(contactId)); @@ -174,8 +164,6 @@ public class RemovableDrivePluginTest extends TestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -192,8 +180,8 @@ public class RemovableDrivePluginTest extends TestCase { will(returnValue(0)); // The user chose drive1 but it's not a dir }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); plugin.start(null, null, null, callback); assertNull(plugin.createWriter(contactId)); @@ -215,8 +203,6 @@ public class RemovableDrivePluginTest extends TestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -233,8 +219,8 @@ public class RemovableDrivePluginTest extends TestCase { will(returnValue(0)); // The user chose drive1 }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); plugin.start(null, null, null, callback); assertNotNull(plugin.createWriter(contactId)); @@ -259,8 +245,6 @@ public class RemovableDrivePluginTest extends TestCase { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -278,8 +262,8 @@ public class RemovableDrivePluginTest extends TestCase { oneOf(callback).showMessage(with(any(String.class))); }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); plugin.start(null, null, null, callback); BatchTransportWriter writer = plugin.createWriter(contactId); @@ -308,8 +292,6 @@ public class RemovableDrivePluginTest extends TestCase { public void testEmptyDriveIsIgnored() throws Exception { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -321,8 +303,8 @@ public class RemovableDrivePluginTest extends TestCase { oneOf(monitor).start(with(any(Callback.class))); }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); plugin.start(null, null, null, callback); plugin.driveInserted(testDir); @@ -334,15 +316,13 @@ public class RemovableDrivePluginTest extends TestCase { public void testFilenames() { Mockery context = new Mockery(); final Executor executor = context.mock(Executor.class); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = context.mock(RemovableDriveMonitor.class); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - executor, finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, + finder, monitor); assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat")); assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat")); @@ -357,8 +337,6 @@ public class RemovableDrivePluginTest extends TestCase { @Test public void testSmallFileIsIgnored() throws Exception { Mockery context = new Mockery(); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -370,8 +348,8 @@ public class RemovableDrivePluginTest extends TestCase { oneOf(monitor).start(with(any(Callback.class))); }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - new ImmediateExecutor(), finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(new ImmediateExecutor(), + finder, monitor); plugin.start(null, null, null, callback); File f = new File(testDir, "abcdefgh.dat"); @@ -385,44 +363,9 @@ public class RemovableDrivePluginTest extends TestCase { context.assertIsSatisfied(); } - @Test - public void testIvIsChecked() throws Exception { - Mockery context = new Mockery(); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); - final RemovableDriveFinder finder = - context.mock(RemovableDriveFinder.class); - final RemovableDriveMonitor monitor = - context.mock(RemovableDriveMonitor.class); - final BatchTransportCallback callback = - context.mock(BatchTransportCallback.class); - - context.checking(new Expectations() {{ - oneOf(monitor).start(with(any(Callback.class))); - oneOf(recogniser).acceptConnection(with(any(byte[].class))); - will(returnValue(null)); - }}); - - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - new ImmediateExecutor(), finder, monitor); - plugin.start(null, null, null, callback); - - File f = new File(testDir, "abcdefgh.dat"); - OutputStream out = new FileOutputStream(f); - out.write(new byte[TransportConstants.MIN_CONNECTION_LENGTH]); - out.flush(); - out.close(); - assertEquals(TransportConstants.MIN_CONNECTION_LENGTH, f.length()); - plugin.driveInserted(testDir); - - context.assertIsSatisfied(); - } - @Test public void testReaderIsCreated() throws Exception { Mockery context = new Mockery(); - final ConnectionRecogniser recogniser = - context.mock(ConnectionRecogniser.class); final RemovableDriveFinder finder = context.mock(RemovableDriveFinder.class); final RemovableDriveMonitor monitor = @@ -432,15 +375,11 @@ public class RemovableDrivePluginTest extends TestCase { context.checking(new Expectations() {{ oneOf(monitor).start(with(any(Callback.class))); - oneOf(recogniser).acceptConnection(with(any(byte[].class))); - will(returnValue(contactId)); - oneOf(callback).readerCreated(with(contactId), - with(any(byte[].class)), - with(any(BatchTransportReader.class))); + oneOf(callback).readerCreated(with(any(FileTransportReader.class))); }}); - RemovableDrivePlugin plugin = new RemovableDrivePlugin(recogniser, - new ImmediateExecutor(), finder, monitor); + RemovableDrivePlugin plugin = new RemovableDrivePlugin(new ImmediateExecutor(), + finder, monitor); plugin.start(null, null, null, callback); File f = new File(testDir, "abcdefgh.dat");