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);
}
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");
}
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);
}
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();
}
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());
}
}
Aggregations