Search in sources :

Example 11 with INode

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

the class NodeMgrTest method testTempNodeMax.

@Test
public void testTempNodeMax() {
    String[] nodes_max = new String[MAX_TEMP_NODES];
    int ip = 0;
    int port = 10000;
    for (int i = 0; i < nodes_max.length; i++) {
        nodes_max[i] = "p2p://" + UUID.randomUUID() + "@255.255.255." + ip++ + ":" + port++;
    }
    for (String nodeL : nodes_max) {
        INode node = Node.parseP2p(nodeL);
        assertNotNull(node);
        nMgr.addTempNode(node);
        nMgr.seedIpAdd(node.getIpStr());
    }
    assertEquals(MAX_TEMP_NODES, nMgr.tempNodesSize());
    // future nodes will be rejected due to the reached limit
    ip = 0;
    for (int i = 0; i < nodes_max.length; i++) {
        nodes_max[i] = "p2p://" + UUID.randomUUID() + "@255.255.254." + ip++ + ":" + port++;
    }
    for (String nodeL : nodes_max) {
        INode node = Node.parseP2p(nodeL);
        assertNotNull(node);
        nMgr.addTempNode(node);
        nMgr.seedIpAdd(node.getIpStr());
        assertEquals(MAX_TEMP_NODES, nMgr.tempNodesSize());
    }
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 12 with INode

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

the class NodeMgrTest method testGetRandom.

@Test(timeout = 30_000)
public void testGetRandom() {
    assertNull(nMgr.getRandom());
    INode node = nMgr.allocNode(ip2, 1);
    addNodetoInbound(node, UUID.fromString(nodeId1));
    nMgr.movePeerToActive(node.getChannel().hashCode(), "inbound");
    INode nodeRandom = nMgr.getRandom();
    assertNotNull(node);
    assertEquals(node, nodeRandom);
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 13 with INode

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

the class NodeMgrTest method testGetActiveNodesList.

@Test(timeout = 30_000)
public void testGetActiveNodesList() {
    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());
    List<INode> active = nMgr.getActiveNodesList();
    for (INode activeN : active) {
        assertEquals(ip2, activeN.getIpStr());
    }
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 14 with INode

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

the class NodeMgrTest method testDumpNodeInfo2.

@Test(timeout = 30_000)
public void testDumpNodeInfo2() {
    String dump = nMgr.dumpNodeInfo("testId", false);
    assertNotNull(dump);
    nMgr.seedIpAdd(ip1);
    INode node = nMgr.allocNode(ip1, 1);
    byte[] rHash = new byte[32];
    r.nextBytes(rHash);
    node.updateStatus(r.nextLong(), rHash, BigInteger.ONE, (byte) r.nextInt(), (short) r.nextInt(), r.nextInt(), r.nextInt());
    addNodetoOutbound(node, UUID.randomUUID());
    nMgr.movePeerToActive(node.getIdHash(), "outbound");
    String dump2 = nMgr.dumpNodeInfo("testId", false);
    assertTrue(dump2.length() > dump.length());
    String dump3 = nMgr.dumpNodeInfo("testId", true);
    assertEquals(dump3.length(), dump2.length());
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 15 with INode

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

the class NodeMgrTest method testMovePeerToActiveFromOutbound.

@Test
public void testMovePeerToActiveFromOutbound() {
    INode node = nMgr.allocNode(ip2, 1);
    node.setChannel(channel);
    addNodetoOutbound(node, UUID.fromString(nodeId1));
    // wrong type & key
    nMgr.movePeerToActive(node.getIdHash(), "inbound");
    assertTrue(nMgr.getActiveNodesMap().isEmpty());
    // move first node
    nMgr.movePeerToActive(node.getIdHash(), "outbound");
    assertEquals(1, nMgr.getActiveNodesMap().size());
    // move different node
    node = nMgr.allocNode(ip1, 1);
    addNodetoOutbound(node, UUID.fromString(nodeId2));
    nMgr.movePeerToActive(node.getIdHash(), "outbound");
    assertEquals(2, nMgr.getActiveNodesMap().size());
    // move same node again
    nMgr.movePeerToActive(node.getIdHash(), "outbound");
    assertEquals(2, nMgr.getActiveNodesMap().size());
}
Also used : INode(org.aion.p2p.INode) 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