Search in sources :

Example 1 with DummySeedNode

use of io.bitsquare.p2p.DummySeedNode in project bitsquare by bitsquare.

the class PeerManagerTest method testAuthentication.

// @Test
public void testAuthentication() throws InterruptedException {
    log.debug("### start");
    LocalhostNetworkNode.setSimulateTorDelayTorNode(0);
    LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
    DummySeedNode seedNode1 = getAndStartSeedNode(8001);
    log.debug("### seedNode1");
    Thread.sleep(100);
    log.debug("### seedNode1 100");
    Thread.sleep(1000);
    DummySeedNode seedNode2 = getAndStartSeedNode(8002);
// authentication: 
// node2 -> node1 RequestAuthenticationMessage
// node1: close connection
// node1 -> node2 ChallengeMessage on new connection
// node2: authentication to node1 done if nonce ok
// node2 -> node1 GetPeersMessage
// node1: authentication to node2 done if nonce ok
// node1 -> node2 PeersMessage
// first authentication from seedNode2 to seedNode1, then from seedNode1 to seedNode2
//TODO
/* CountDownLatch latch1 = new CountDownLatch(2);
        AuthenticationListener routingListener1 = new AuthenticationListener() {
            @Override
            public void onConnectionAuthenticated(Connection connection) {
                log.debug("onConnectionAuthenticated " + connection);
                latch1.countDown();
            }
        };
        seedNode1.getP2PService().getPeerGroup().addPeerListener(routingListener1);

        AuthenticationListener routingListener2 = new AuthenticationListener() {
            @Override
            public void onConnectionAuthenticated(Connection connection) {
                log.debug("onConnectionAuthenticated " + connection);
                latch1.countDown();
            }
        };
        seedNode2.getP2PService().getPeerGroup().addPeerListener(routingListener2);
        latch1.await();
        seedNode1.getP2PService().getPeerGroup().removePeerListener(routingListener1);
        seedNode2.getP2PService().getPeerGroup().removePeerListener(routingListener2);

        // wait until Peers msg finished
        Thread.sleep(sleepTime);

        // authentication: 
        // authentication from seedNode3 to seedNode1, then from seedNode1 to seedNode3
        // authentication from seedNode3 to seedNode2, then from seedNode2 to seedNode3
        SeedNode seedNode3 = getAndStartSeedNode(8003);
        CountDownLatch latch2 = new CountDownLatch(3);
        seedNode1.getP2PService().getPeerGroup().addPeerListener(new AuthenticationListener() {
            @Override
            public void onConnectionAuthenticated(Connection connection) {
                log.debug("onConnectionAuthenticated " + connection);
                latch2.countDown();
            }
        });
        seedNode2.getP2PService().getPeerGroup().addPeerListener(new AuthenticationListener() {
            @Override
            public void onConnectionAuthenticated(Connection connection) {
                log.debug("onConnectionAuthenticated " + connection);
                latch2.countDown();
            }
        });
        seedNode3.getP2PService().getPeerGroup().addPeerListener(new AuthenticationListener() {
            @Override
            public void onConnectionAuthenticated(Connection connection) {
                log.debug("onConnectionAuthenticated " + connection);
                latch2.countDown();
            }
        });
        latch2.await();

        // wait until Peers msg finished
        Thread.sleep(sleepTime);


        CountDownLatch shutDownLatch = new CountDownLatch(3);
        seedNode1.shutDown(() -> shutDownLatch.countDown());
        seedNode2.shutDown(() -> shutDownLatch.countDown());
        seedNode3.shutDown(() -> shutDownLatch.countDown());
        shutDownLatch.await();*/
}
Also used : DummySeedNode(io.bitsquare.p2p.DummySeedNode)

Example 2 with DummySeedNode

use of io.bitsquare.p2p.DummySeedNode in project bitsquare by bitsquare.

the class PeerManagerTest method test2SeedNodes.

@Test
public void test2SeedNodes() throws InterruptedException {
    LocalhostNetworkNode.setSimulateTorDelayTorNode(0);
    LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
    seedNodes = new HashSet<>();
    NodeAddress nodeAddress1 = new NodeAddress("localhost:8001");
    seedNodes.add(nodeAddress1);
    NodeAddress nodeAddress2 = new NodeAddress("localhost:8002");
    seedNodes.add(nodeAddress2);
    latch = new CountDownLatch(6);
    seedNode1 = new DummySeedNode("test_dummy_dir");
    seedNode1.createAndStartP2PService(nodeAddress1, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
            latch.countDown();
        }

        @Override
        public void onHiddenServicePublished() {
            latch.countDown();
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    P2PService p2PService1 = seedNode1.getSeedNodeP2PService();
    Thread.sleep(500);
    seedNode2 = new DummySeedNode("test_dummy_dir");
    seedNode2.createAndStartP2PService(nodeAddress2, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
            latch.countDown();
        }

        @Override
        public void onHiddenServicePublished() {
            latch.countDown();
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    P2PService p2PService2 = seedNode2.getSeedNodeP2PService();
    latch.await();
// Assert.assertEquals(1, p2PService1.getPeerManager().getAuthenticatedAndReportedPeers().size());
// Assert.assertEquals(1, p2PService2.getPeerManager().getAuthenticatedAndReportedPeers().size());
}
Also used : P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) DummySeedNode(io.bitsquare.p2p.DummySeedNode) NodeAddress(io.bitsquare.p2p.NodeAddress) CountDownLatch(java.util.concurrent.CountDownLatch) P2PService(io.bitsquare.p2p.P2PService) Test(org.junit.Test)

Example 3 with DummySeedNode

use of io.bitsquare.p2p.DummySeedNode in project bitsquare by bitsquare.

the class PeerManagerTest method testSingleSeedNode.

// @Test
public void testSingleSeedNode() throws InterruptedException {
    LocalhostNetworkNode.setSimulateTorDelayTorNode(0);
    LocalhostNetworkNode.setSimulateTorDelayHiddenService(0);
    seedNodes = new HashSet<>();
    NodeAddress nodeAddress = new NodeAddress("localhost:8001");
    seedNodes.add(nodeAddress);
    seedNode1 = new DummySeedNode("test_dummy_dir");
    latch = new CountDownLatch(2);
    seedNode1.createAndStartP2PService(nodeAddress, MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
        }

        @Override
        public void onHiddenServicePublished() {
            latch.countDown();
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    P2PService p2PService1 = seedNode1.getSeedNodeP2PService();
    latch.await();
    Thread.sleep(500);
//Assert.assertEquals(0, p2PService1.getPeerManager().getAuthenticatedAndReportedPeers().size());
}
Also used : P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) DummySeedNode(io.bitsquare.p2p.DummySeedNode) NodeAddress(io.bitsquare.p2p.NodeAddress) CountDownLatch(java.util.concurrent.CountDownLatch) P2PService(io.bitsquare.p2p.P2PService)

Example 4 with DummySeedNode

use of io.bitsquare.p2p.DummySeedNode in project bitsquare by bitsquare.

the class PeerManagerTest method getAndStartSeedNode.

private DummySeedNode getAndStartSeedNode(int port) throws InterruptedException {
    DummySeedNode seedNode = new DummySeedNode("test_dummy_dir");
    latch = new CountDownLatch(1);
    seedNode.createAndStartP2PService(new NodeAddress("localhost", port), MAX_CONNECTIONS, useLocalhost, 2, true, seedNodes, new P2PServiceListener() {

        @Override
        public void onRequestingDataCompleted() {
            latch.countDown();
        }

        @Override
        public void onNoSeedNodeAvailable() {
        }

        @Override
        public void onTorNodeReady() {
        }

        @Override
        public void onNoPeersAvailable() {
        }

        @Override
        public void onBootstrapComplete() {
        }

        @Override
        public void onHiddenServicePublished() {
        }

        @Override
        public void onSetupFailed(Throwable throwable) {
        }
    });
    latch.await();
    Thread.sleep(sleepTime);
    return seedNode;
}
Also used : P2PServiceListener(io.bitsquare.p2p.P2PServiceListener) DummySeedNode(io.bitsquare.p2p.DummySeedNode) NodeAddress(io.bitsquare.p2p.NodeAddress) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

DummySeedNode (io.bitsquare.p2p.DummySeedNode)4 NodeAddress (io.bitsquare.p2p.NodeAddress)3 P2PServiceListener (io.bitsquare.p2p.P2PServiceListener)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 P2PService (io.bitsquare.p2p.P2PService)2 Test (org.junit.Test)1