use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class GetNodeEventHandler method getAvailableNodes.
private List<Node> getAvailableNodes(int length, String nodeId) {
List<Node> nodes = new ArrayList<>();
int count = 0;
List<Node> availableNodes = getNetworkService().getAvailableNodes();
Collections.shuffle(availableNodes);
for (Node node : availableNodes) {
if (node.getId().equals(nodeId)) {
continue;
}
nodes.add(node);
count++;
if (count == length || count > 20) {
break;
}
}
return nodes;
}
use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class GetNodesIpEventHandler method process.
@Override
public NetworkEventResult process(BaseEvent event, Node node) {
List<Node> availableNodes = getNetworkService().getAvailableNodes();
List<String> ipList = new ArrayList<>();
for (Node n : availableNodes) {
ipList.add(n.getIp());
}
NodesIpEvent ipEvent = new NodesIpEvent(ipList);
return new NetworkEventResult(true, ipEvent);
}
use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class BroadcastHandler method broadcastToGroup.
public BroadcastResult broadcastToGroup(BaseEvent event, String groupName, String excludeNodeId, boolean asyn) {
NodeGroup group = nodesManager.getNodeGroup(groupName);
if (group == null) {
return new BroadcastResult(false, "NodeGroup not found");
}
if (group.size() == 0) {
return new BroadcastResult(false, "no node can be broadcast");
}
List<Node> nodeList = new ArrayList<>(group.getNodes().values());
return broadcastToList(nodeList, event, excludeNodeId, asyn);
}
use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class NetworkMessageResource method getInfo.
@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getInfo() {
RpcResult result = RpcResult.getSuccess();
InfoDto info = new InfoDto(NulsContext.getInstance().getBestBlock().getHeader().getHeight(), NulsContext.getInstance().getNetBestBlockHeight(), TimeService.getNetTimeOffset());
NodeGroup inGroup = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_IN_GROUP);
NodeGroup outGroup = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_OUT_GROUP);
int count = 0;
for (Node node : inGroup.getNodes().values()) {
if (node.getStatus() == Node.HANDSHAKE) {
count += 1;
}
}
info.setInCount(count);
count = 0;
for (Node node : outGroup.getNodes().values()) {
if (node.getStatus() == Node.HANDSHAKE) {
count += 1;
}
}
info.setOutCount(count);
result.setData(info);
return result;
}
use of io.nuls.network.entity.Node 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