Search in sources :

Example 16 with INode

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

the class NodeMgrTest method testAllocate.

@Test(timeout = 30_000)
public void testAllocate() {
    INode node = nMgr.allocNode(ip2, 1);
    assertNotNull(node);
    assertFalse(node.getIfFromBootList());
    nMgr.seedIpAdd(ip2);
    node = nMgr.allocNode(ip2, 1);
    assertNotNull(node);
    assertTrue(node.getIfFromBootList());
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 17 with INode

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

the class NodeMgrTest method testTimeoutInbound.

@Test
public void testTimeoutInbound() {
    INode node = nMgr.allocNode(ip2, 1);
    addNodetoInbound(node, UUID.fromString(nodeId1));
    nMgr.timeoutCheck(System.currentTimeMillis() + NodeMgr.TIMEOUT_INBOUND_NODES + 1);
    assertNull(nMgr.getInboundNode(channel.hashCode()));
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 18 with INode

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

the class NodeMgrTest method testBan.

@Test(timeout = 30_000)
public void testBan() {
    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());
    assertTrue(node.getPeerMetric().notBan());
    nMgr.ban(node.getIdHash());
    assertFalse(node.getPeerMetric().notBan());
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 19 with INode

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

the class NodeMgrTest method testShutDown.

@Test(timeout = 30_000)
public void testShutDown() {
    INode node = nMgr.allocNode(ip2, 1);
    addNodetoOutbound(node, UUID.randomUUID());
    node = nMgr.allocNode(ip1, 1);
    addNodetoOutbound(node, UUID.randomUUID());
    nMgr.movePeerToActive(node.getIdHash(), "outbound");
    node = nMgr.allocNode("1.1.1.1", 1);
    addNodetoInbound(node, UUID.randomUUID());
    assertEquals(1, nMgr.activeNodesSize());
    nMgr.shutdown();
    assertTrue(nMgr.getActiveNodesMap().isEmpty());
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 20 with INode

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

the class NodeMgrTest method testMovePeerToActiveFromInbound.

@Test
public void testMovePeerToActiveFromInbound() {
    INode node = nMgr.allocNode(ip2, 1);
    node.setChannel(channel);
    nMgr.movePeerToActive(node.getChannel().hashCode(), "inbound");
    assertTrue(nMgr.getActiveNodesMap().isEmpty());
    nMgr.addInboundNode(node);
    // wrong type & key
    nMgr.movePeerToActive(node.getChannel().hashCode(), "outbound");
    assertTrue(nMgr.getActiveNodesMap().isEmpty());
    // move from inbound
    nMgr.movePeerToActive(node.getChannel().hashCode(), "inbound");
    assertEquals(1, nMgr.getActiveNodesMap().size());
    // move same node again
    nMgr.movePeerToActive(node.getChannel().hashCode(), "inbound");
    assertEquals(1, 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