Search in sources :

Example 51 with INode

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

the class NodeMgrTest method testMoveOutboundToActive.

@Test(timeout = 30_000)
public void testMoveOutboundToActive() {
    INode node = nMgr.allocNode(ip2, 1);
    addNodetoOutbound(node, UUID.fromString(nodeId1));
    nMgr.movePeerToActive(node.getIdHash(), "outbound");
    assertNull(nMgr.getOutboundNode(node.getIdHash()));
    INode activeNode = nMgr.getActiveNode(node.getIdHash());
    assertNotNull(activeNode);
    assertEquals(node, activeNode);
}
Also used : INode(org.aion.p2p.INode) Test(org.junit.Test)

Example 52 with INode

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

the class NodeMgrTest method addActiveNode.

private void addActiveNode() {
    INode node = nMgr.allocNode(ip1, 1);
    byte[] rHash = new byte[32];
    r.nextBytes(rHash);
    node.updateStatus(r.nextLong(), rHash, BigInteger.valueOf(r.nextLong()), (byte) r.nextInt(), (short) r.nextInt(), r.nextInt(), r.nextInt());
    addNodetoOutbound(node, UUID.randomUUID());
    nMgr.movePeerToActive(node.getIdHash(), "outbound");
}
Also used : INode(org.aion.p2p.INode)

Example 53 with INode

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

the class NodeMgr method dropActive.

public void dropActive(int nodeIdHash, String _reason) {
    INode node = null;
    try {
        node = activeNodes.remove(nodeIdHash);
    } catch (Exception e) {
        p2pLOG.info("<dropActive exception>", e);
    }
    if (node == null) {
        return;
    }
    p2pMgr.closeSocket(node.getChannel(), _reason);
}
Also used : INode(org.aion.p2p.INode)

Example 54 with INode

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

the class NodeMgr method dumpNodeInfo.

/**
 * @param selfShortId String
 */
@Override
public String dumpNodeInfo(String selfShortId, boolean completeInfo) {
    StringBuilder sb = new StringBuilder();
    sb.append("\n");
    sb.append(String.format("=========================================================================== p2p-status-%6s =============================================================================\n", selfShortId));
    sb.append(String.format(" temp[%3d] inbound[%3d] outbound[%3d] active[%3d]                           id - node short id, s - seed node, td - total difficulty, # - block number, bv - binary version\n", tempNodesSize(), inboundNodes.size(), outboundNodes.size(), activeNodes.size()));
    sb.append(appendColumnFormat());
    if (myNode != null) {
        sb.append(appendNodeInfo(myNode)).append("\n");
    }
    List<INode> sorted = new ArrayList<>(activeNodes.values());
    if (sorted.size() > 0) {
        sorted.sort((n1, n2) -> {
            int tdCompare = n2.getTotalDifficulty().compareTo(n1.getTotalDifficulty());
            if (tdCompare == 0) {
                Long n2Bn = n2.getBestBlockNumber();
                Long n1Bn = n1.getBestBlockNumber();
                return n2Bn.compareTo(n1Bn);
            } else {
                return tdCompare;
            }
        });
        for (INode n : sorted) {
            try {
                if (!completeInfo && !n.getIfFromBootList()) {
                    continue;
                }
                sb.append(appendNodeInfo(n));
            } catch (Exception ex) {
                p2pLOG.error("<NodeMgr dumpNodeInfo exception>", ex);
            }
        }
    }
    return sb.toString();
}
Also used : INode(org.aion.p2p.INode) ArrayList(java.util.ArrayList)

Example 55 with INode

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

the class ResActiveNodesTest method testMaxActive.

// Only 40 Active Nodes are returned at MAX
@Test
public void testMaxActive() {
    List<INode> srcNodes = new ArrayList<>();
    for (int i = 0; i < 50; i++) {
        srcNodes.add(randomNode());
    }
    ResActiveNodes res = ResActiveNodes.decode(new ResActiveNodes(p2pLOG, srcNodes).encode(), p2pLOG);
    assertEquals(40, res.getNodes().size());
    List<INode> tarNodes = res.getNodes();
    for (int i = 0; i < 40; i++) {
        INode srcNode = srcNodes.get(i);
        INode tarNode = tarNodes.get(i);
        assertArrayEquals(srcNode.getId(), tarNode.getId());
        assertEquals(srcNode.getIdHash(), tarNode.getIdHash());
        assertArrayEquals(srcNode.getIp(), tarNode.getIp());
        assertEquals(srcNode.getIpStr(), tarNode.getIpStr());
        assertEquals(srcNode.getPort(), tarNode.getPort());
    }
}
Also used : INode(org.aion.p2p.INode) ArrayList(java.util.ArrayList) 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