use of org.aion.p2p.impl.zero.msg.ResHandshake1 in project aion by aionnetwork.
the class P2pMgr method handleP2pMessage.
private void handleP2pMessage(final SelectionKey sk, byte act, final byte[] msgBytes) {
ChannelBuffer rb = (ChannelBuffer) sk.attachment();
switch(act) {
case Act.REQ_HANDSHAKE:
if (msgBytes.length > ReqHandshake.LEN) {
ReqHandshake1 reqHandshake1 = ReqHandshake1.decode(msgBytes, p2pLOG);
if (reqHandshake1 != null) {
handleHandshakeRequest(rb, sk.channel().hashCode(), reqHandshake1.getNodeId(), reqHandshake1.getNetId(), reqHandshake1.getPort(), reqHandshake1.getRevision());
}
}
break;
case Act.RES_HANDSHAKE:
if (rb.getNodeIdHash() != 0) {
if (msgBytes.length > ResHandshake.LEN) {
ResHandshake1 resHandshake1 = ResHandshake1.decode(msgBytes, p2pLOG);
if (resHandshake1 != null && resHandshake1.getSuccess()) {
handleHandshakeResponse(rb.getNodeIdHash(), resHandshake1.getBinaryVersion());
}
}
}
break;
case Act.REQ_ACTIVE_NODES:
if (rb.getNodeIdHash() != 0) {
INode node = nodeMgr.getActiveNode(rb.getNodeIdHash());
if (node != null) {
ResActiveNodes resActiveNodes = new ResActiveNodes(p2pLOG, nodeMgr.getActiveNodesList());
send(node.getIdHash(), node.getIdShort(), resActiveNodes);
}
}
break;
case Act.RES_ACTIVE_NODES:
if (isSyncSeedsOnly() || rb.getNodeIdHash() == 0) {
break;
}
INode node = nodeMgr.getActiveNode(rb.getNodeIdHash());
if (node != null) {
node.refreshTimestamp();
ResActiveNodes resActiveNodes = ResActiveNodes.decode(msgBytes, p2pLOG);
if (resActiveNodes != null) {
List<INode> incomingNodes = resActiveNodes.getNodes();
for (INode incomingNode : incomingNodes) {
if (nodeMgr.tempNodesSize() >= getMaxTempNodes()) {
return;
}
if (validateNode(incomingNode)) {
nodeMgr.addTempNode(incomingNode);
}
}
}
}
break;
default:
p2pLOG.debug("unknown-route act={}", act);
break;
}
}
Aggregations