use of io.nuls.network.model.Node in project nuls by nuls-io.
the class GetNodeVersionTask method process.
private void process() {
Collection<Node> connectedNodes = nodeManager.getAvailableNodes();
if (connectedNodes == null) {
return;
}
NetworkMessageBody body = new NetworkMessageBody(NetworkConstant.HANDSHAKE_CLIENT_TYPE, networkParam.getPort(), NulsContext.getInstance().getBestHeight(), NulsContext.getInstance().getBestBlock().getHeader().getHash());
GetVersionMessage getVersionMessage = new GetVersionMessage(body);
Iterator<Node> it = connectedNodes.iterator();
while (it.hasNext()) {
Node node = it.next();
if (node.getType() == Node.OUT) {
if (!checkIsSurvive(node)) {
it.remove();
continue;
}
node.setLastTime(TimeService.currentTimeMillis());
broadcastHandler.broadcastToNode(getVersionMessage, node, true);
}
}
}
use of io.nuls.network.model.Node in project nuls by nuls-io.
the class NodeMaintenanceTask method process.
private void process() {
List<Node> needConnectNodes = getNeedConnectNodes();
if (needConnectNodes == null || needConnectNodes.size() == 0) {
return;
}
for (Node node : needConnectNodes) {
node.setType(Node.OUT);
connectionNode(node);
}
}
use of io.nuls.network.model.Node in project nuls by nuls-io.
the class NetworkStorageServiceImpl method getNodeList.
@Override
public List<Node> getNodeList(int size, Set<String> ipSet) {
List<Node> nodeList = new ArrayList<>();
List<NodePo> poList = getDbService().values(NetworkStorageConstant.DB_NAME_NETWORK_NODE, NodePo.class);
if (poList == null) {
return nodeList;
}
int count = 0;
for (int i = poList.size() - 1; i >= 0; i--) {
NodePo po = poList.get(i);
if (ipSet.contains(po.getIp())) {
continue;
}
nodeList.add(NetworkTransferTool.toNode(po));
count++;
if (count >= size) {
break;
}
}
return nodeList;
}
Aggregations