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