Search in sources :

Example 41 with INode

use of org.aion.p2p.INode in project aion by aionnetwork.

the class P2pMgr method acceptConnection.

private void acceptConnection(ServerSocketChannel _channel) throws IOException {
    if (this.nodeMgr.activeNodesSize() >= getMaxActiveNodes()) {
        return;
    }
    SocketChannel channel = _channel.accept();
    if (channel != null) {
        configChannel(channel);
        String ip = channel.socket().getInetAddress().getHostAddress();
        if (isSyncSeedsOnly() && this.nodeMgr.isSeedIp(ip)) {
            channel.close();
            return;
        }
        int port = channel.socket().getPort();
        INode node;
        try {
            node = this.nodeMgr.allocNode(ip, port);
        } catch (IllegalArgumentException e) {
            p2pLOG.error("illegal ip / port : {} {}", ip, port);
            channel.close();
            return;
        }
        p2pLOG.trace("new-node : {}", node.toString());
        node.setChannel(channel);
        SelectionKey sk = channel.register(this.selector, SelectionKey.OP_READ);
        sk.attach(new ChannelBuffer(p2pLOG));
        this.nodeMgr.addInboundNode(node);
        p2pLOG.debug("new-connection {}:{}", ip, port);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) SelectionKey(java.nio.channels.SelectionKey) INode(org.aion.p2p.INode)

Example 42 with INode

use of org.aion.p2p.INode in project aion by aionnetwork.

the class NodeMgrTest method testTimeoutOutbound.

@Test
public void testTimeoutOutbound() {
    INode node = nMgr.allocNode(ip2, 1);
    addNodetoOutbound(node, UUID.fromString(nodeId1));
    nMgr.timeoutCheck(System.currentTimeMillis() + NodeMgr.TIMEOUT_OUTBOUND_NODES + 1);
    assertNull(nMgr.getOutboundNode(node.getIdHash()));
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 43 with INode

use of org.aion.p2p.INode in project aion by aionnetwork.

the class NodeMgrTest method testTempNodesTake.

@Test
public void testTempNodesTake() {
    String ip = "127.0.0.1";
    String[] nodes = new String[] { "p2p://" + UUID.randomUUID() + "@127.0.0.1:30123", "p2p://" + UUID.randomUUID() + "@127.0.0.1:30321" };
    for (String nodeL : nodes) {
        Node node = Node.parseP2p(nodeL);
        assertNotNull(node);
        nMgr.addTempNode(node);
        nMgr.seedIpAdd(node.getIpStr());
    }
    assertEquals(2, nMgr.tempNodesSize());
    INode node;
    while (nMgr.tempNodesSize() != 0) {
        node = nMgr.tempNodesTake();
        assertEquals(ip, node.getIpStr());
        assertTrue(node.getIfFromBootList());
        assertTrue(nMgr.isSeedIp(ip));
    }
    assertEquals(0, nMgr.tempNodesSize());
}
Also used : INode(org.aion.p2p.INode) INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 44 with INode

use of org.aion.p2p.INode in project aion by aionnetwork.

the class NodeMgrTest method testDropActive.

@Test(timeout = 30_000)
public void testDropActive() {
    INode node = nMgr.allocNode(ip2, 1);
    node.setChannel(channel);
    node.setId(nodeId2.getBytes(StandardCharsets.UTF_8));
    nMgr.addInboundNode(node);
    assertEquals(0, nMgr.activeNodesSize());
    nMgr.movePeerToActive(channel.hashCode(), "inbound");
    assertEquals(1, nMgr.activeNodesSize());
    // will not drop
    nMgr.dropActive(node.getIdHash() - 1, "close");
    assertEquals(1, nMgr.activeNodesSize());
    // will drop
    nMgr.dropActive(node.getIdHash(), "close");
    assertEquals(0, nMgr.activeNodesSize());
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 45 with INode

use of org.aion.p2p.INode in project aion by aionnetwork.

the class NodeMgrTest method testGetActiveNodesMap.

@Test(timeout = 30_000)
public void testGetActiveNodesMap() {
    INode node = nMgr.allocNode(ip2, 1);
    addNodetoInbound(node, UUID.fromString(nodeId1));
    nMgr.movePeerToActive(node.getChannel().hashCode(), "inbound");
    Map activeMap = nMgr.getActiveNodesMap();
    assertNotNull(activeMap);
    assertEquals(1, activeMap.size());
}
Also used : INode(org.aion.p2p.INode) Map(java.util.Map) Test(org.junit.Test)

Aggregations

INode (org.aion.p2p.INode)55 Test (org.junit.Test)30 BigInteger (java.math.BigInteger)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ECKey (org.aion.crypto.ECKey)4 IP2pMgr (org.aion.p2p.IP2pMgr)4 Msg (org.aion.p2p.Msg)4 NetworkBestBlockCallback (org.aion.zero.impl.blockchain.AionImpl.NetworkBestBlockCallback)4 PendingTxCallback (org.aion.zero.impl.blockchain.AionImpl.PendingTxCallback)4 TransactionBroadcastCallback (org.aion.zero.impl.blockchain.AionImpl.TransactionBroadcastCallback)4 StandaloneBlockchain (org.aion.zero.impl.blockchain.StandaloneBlockchain)4 AionPendingStateImpl (org.aion.zero.impl.pendingState.AionPendingStateImpl)4 BlockHeader (org.aion.zero.impl.types.BlockHeader)4 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 SelectionKey (java.nio.channels.SelectionKey)3 ServerSocketChannel (java.nio.channels.ServerSocketChannel)3