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