@Test public void timoutOnConnection() throws Exception { StreamConnector sca = new StreamConnector(); BitrustedConnector connector = new BitrustedConnector( TestKeys.privateKey(0), sca.getInputStream(), new ByteArrayOutputStream() ); connector.setHandshakeTimeoutMillis(10); try { connector.connect(null); fail("must throw TimeoutException"); } catch (TimeoutException x) { // all ok } }
@Override public void send(Map<String, Object> data) throws IOException { checkConnected(); byte[] packed = mySessionKey.etaEncrypt(Boss.pack(data)); if (!connection.isClosed()) connection.sendParams("block", packed); else throw new EOFException("connection closed"); }
/** * The handshake and transport command processing * * @param command * * @return * * @throws Exception */ @Override public Object onCommand(Command command) throws Exception { // log.d(toString()+" cmd "+command.getName()); switch (command.getName()) { case "hello": return onHello(Binder.from(command.getKeyParams())); case "block": return decryptBlock(command); } return null; }
StreamConnector sca = new StreamConnector(); StreamConnector scb = new StreamConnector(); BitrustedConnector ca = new BitrustedConnector( TestKeys.privateKey(0), sca.getInputStream(), scb.getOutputStream() ); BitrustedConnector cb = new BitrustedConnector( TestKeys.privateKey(1), scb.getInputStream(), ); Future<Object> connectA = pool.submit(() -> { ca.connect(null); return null; }); cb.connect(null); assertTrue(cb.isConnected()); connectA.get(); assertTrue(ca.isConnected()); assertEquals(ca.getMySessionKey(), cb.getRemoteSessionKey()); assertEquals(cb.getMySessionKey(), ca.getRemoteSessionKey()); cb.send(Binder.fromKeysValues("hello", "world")); cb.send(Binder.fromKeysValues("hello", "world2")); Binder res = Binder.from(cb.receive()); assertEquals("bar", res.getStringOrThrow("foo")); res = Binder.from(cb.receive());
StreamConnector sca = new StreamConnector(); StreamConnector scb = new StreamConnector(); BitrustedConnector ca = new BitrustedConnector( TestKeys.privateKey(0), sca.getInputStream(), scb.getOutputStream() ); BitrustedConnector cb = new BitrustedConnector( TestKeys.privateKey(1), scb.getInputStream(), ); Future<Object> connectA = pool.submit(() -> { ca.connect(null); return null; }); cb.connect(null); assertTrue(cb.isConnected()); connectA.get(); assertTrue(ca.isConnected());
try { Socket in = ss.accept(); BitrustedConnector bc = new BitrustedConnector(TestKeys.privateKey(0), in.getInputStream(), in.getOutputStream() ); bc.connect(null); Farcall f = new Farcall(bc); f.start(cmd -> { Farcall f = new Farcall(new BitrustedConnector( TestKeys.privateKey(1), s.getInputStream(), s.getOutputStream() ).connect(null)); f.start(); assertEquals(f.send("ping").waitSuccess(), "pong");
); try { processHelloAnswer(result);
StreamConnector sca = new StreamConnector(); StreamConnector scb = new StreamConnector(); BitrustedConnector ca = new BitrustedConnector( TestKeys.privateKey(0), sca.getInputStream(), scb.getOutputStream() ); BitrustedConnector cb = new BitrustedConnector( TestKeys.privateKey(1), scb.getInputStream(), ); Future<Object> connectA = pool.submit(() -> { ca.connect(null); return null; }); cb.connect(null); assertTrue(cb.isConnected()); connectA.get(); assertTrue(ca.isConnected());