Search in sources :

Example 1 with GetNodeEvent

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);
}
Also used : GetNodeEvent(io.nuls.network.message.entity.GetNodeEvent) NodeEvent(io.nuls.network.message.entity.NodeEvent) Node(io.nuls.network.entity.Node) GetNodeEvent(io.nuls.network.message.entity.GetNodeEvent) NetworkEventResult(io.nuls.network.message.NetworkEventResult)

Example 2 with GetNodeEvent

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;
            }
        }
    }
}
Also used : Node(io.nuls.network.entity.Node) GetNodeEvent(io.nuls.network.message.entity.GetNodeEvent) NodeGroup(io.nuls.network.entity.NodeGroup)

Aggregations

Node (io.nuls.network.entity.Node)2 GetNodeEvent (io.nuls.network.message.entity.GetNodeEvent)2 NodeGroup (io.nuls.network.entity.NodeGroup)1 NetworkEventResult (io.nuls.network.message.NetworkEventResult)1 NodeEvent (io.nuls.network.message.entity.NodeEvent)1