use of io.nuls.network.model.Node in project nuls by nuls-io.
the class RunOnceAfterStartupTask method getMostSameIp.
private String getMostSameIp(Collection<Node> nodes) {
Map<String, Integer> ipMaps = new HashMap<>();
for (Node node : nodes) {
String ip = node.getExternalIp();
if (ip == null) {
continue;
}
Integer count = ipMaps.get(ip);
if (count == null) {
ipMaps.put(ip, 1);
} else {
ipMaps.put(ip, count + 1);
}
}
int maxCount = 0;
String ip = null;
for (Map.Entry<String, Integer> entry : ipMaps.entrySet()) {
if (entry.getValue() > maxCount) {
maxCount = entry.getValue();
ip = entry.getKey();
}
}
return ip;
}
use of io.nuls.network.model.Node in project nuls by nuls-io.
the class ConnectionManager method connection.
public Node connection(String ip, int port) {
Node node = new Node(ip, port, Node.OUT);
boolean success = connection(node);
return success ? node : null;
}
use of io.nuls.network.model.Node in project nuls by nuls-io.
the class NodesMessageHandler method process.
@Override
public NetworkEventResult process(BaseMessage message, Node node) {
NodesMessage nodesMessage = (NodesMessage) message;
NodeMessageBody body = nodesMessage.getMsgBody();
for (Node newNode : body.getNodeList()) {
if (!IpUtil.isboolIp(newNode.getIp())) {
continue;
}
nodeManager.addNeedCheckNode(newNode);
}
return null;
}
use of io.nuls.network.model.Node in project nuls by nuls-io.
the class RequestThread method run.
@Override
public void run() {
this.running = true;
this.success = false;
while (running) {
try {
if (startHeight > endHeight) {
this.init();
this.success = true;
break;
}
if (this.nodeList == null || this.nodeList.isEmpty()) {
break;
}
if (startHeight - NulsContext.getInstance().getBestHeight() < 1000) {
downloadRound();
continue;
} else {
for (int i = nodeList.size() - 1; i >= 0; i--) {
Node node = nodeList.get(i);
if (!node.isHandShake()) {
nodeList.remove(i);
}
}
}
Thread.sleep(10L);
} catch (Exception e) {
Log.error(e);
}
}
this.running = false;
}
use of io.nuls.network.model.Node in project nuls by nuls-io.
the class RequestThread method retryDownload.
public boolean retryDownload(long start, int size) {
if (nodeList.isEmpty()) {
return false;
}
Node node = nodeList.get(randomIndex++ % nodeList.size());
request(node, start, size);
return true;
}
Aggregations