Search in sources :

Example 6 with NodeGroup

use of io.nuls.network.entity.NodeGroup 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)

Example 7 with NodeGroup

use of io.nuls.network.entity.NodeGroup in project nuls by nuls-io.

the class NodesManager method removeNodeFromGroup.

public void removeNodeFromGroup(String groupName, String nodeId) {
    if (!nodeGroups.containsKey(groupName)) {
        return;
    }
    NodeGroup group = nodeGroups.get(groupName);
    group.removeNode(nodeId);
}
Also used : NodeGroup(io.nuls.network.entity.NodeGroup)

Example 8 with NodeGroup

use of io.nuls.network.entity.NodeGroup in project nuls by nuls-io.

the class NodesManager method addNodeToGroup.

public void addNodeToGroup(String groupName, Node node) {
    if (!nodeGroups.containsKey(groupName)) {
        throw new NulsRuntimeException(ErrorCode.NET_NODE_GROUP_NOT_FOUND);
    }
    NodeGroup group = nodeGroups.get(groupName);
    if (groupName.equals(NetworkConstant.NETWORK_NODE_OUT_GROUP) && group.size() >= network.maxOutCount()) {
        return;
    }
    if (groupName.equals(NetworkConstant.NETWORK_NODE_IN_GROUP) && group.size() >= network.maxInCount()) {
        return;
    }
    node.getGroupSet().add(group.getName());
    addNode(node);
    group.addNode(node);
}
Also used : NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NodeGroup(io.nuls.network.entity.NodeGroup)

Aggregations

NodeGroup (io.nuls.network.entity.NodeGroup)8 Node (io.nuls.network.entity.Node)5 SocketChannel (io.netty.channel.socket.SocketChannel)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 BroadcastResult (io.nuls.network.entity.BroadcastResult)1 GetNodeEvent (io.nuls.network.message.entity.GetNodeEvent)1 InfoDto (io.nuls.rpc.entity.InfoDto)1 RpcResult (io.nuls.rpc.entity.RpcResult)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1