use of io.nuls.network.message.entity.GetNodeEvent in project nuls by nuls-io.
the class GetNodeEventHandler method process.
@Override
public NetworkEventResult process(BaseEvent event, Node node) {
GetNodeEvent getNodeEvent = (GetNodeEvent) event;
// String key = event.getHeader().getEventType() + "-" + node.getIp();
// if (cacheService.existEvent(key)) {
// getNetworkService().removeNode(node.getId());
// return null;
// }
// cacheService.putEvent(key, event, false);
List<Node> list = getAvailableNodes(getNodeEvent.getLength(), node.getId());
NodeEvent replyEvent = new NodeEvent(list);
return new NetworkEventResult(true, replyEvent);
}
use of io.nuls.network.message.entity.GetNodeEvent in project nuls by nuls-io.
the class NodeDiscoverHandler method findOtherNode.
/**
* Inquire more of the other nodes to the connected nodes
*
* @param size
*/
public void findOtherNode(int size) {
GetNodeEvent event = new GetNodeEvent(size);
NodeGroup group = nodesManager.getNodeGroup(NetworkConstant.NETWORK_NODE_IN_GROUP);
if (group.getNodes().size() > 0) {
List<Node> nodeList = new ArrayList<>(group.getNodes().values());
Collections.shuffle(nodeList);
for (Node node : nodeList) {
if (node.isHandShake()) {
broadcaster.broadcastToNode(event, node, true);
break;
}
}
}
group = nodesManager.getNodeGroup(NetworkConstant.NETWORK_NODE_OUT_GROUP);
if (group.getNodes().size() > 0) {
List<Node> nodeList = new ArrayList<>(group.getNodes().values());
Collections.shuffle(nodeList);
for (Node node : nodeList) {
if (node.isHandShake()) {
broadcaster.broadcastToNode(event, node, true);
break;
}
}
}
}
Aggregations