Search in sources :

Example 41 with Node

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;
}
Also used : HashMap(java.util.HashMap) Node(io.nuls.network.model.Node) HashMap(java.util.HashMap) Map(java.util.Map)

Example 42 with Node

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;
}
Also used : Node(io.nuls.network.model.Node)

Example 43 with Node

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;
}
Also used : NodesMessage(io.nuls.network.protocol.message.NodesMessage) NodeMessageBody(io.nuls.network.protocol.message.NodeMessageBody) Node(io.nuls.network.model.Node)

Example 44 with Node

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;
}
Also used : Node(io.nuls.network.model.Node)

Example 45 with Node

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;
}
Also used : Node(io.nuls.network.model.Node)

Aggregations

Node (io.nuls.network.model.Node)48 Result (io.nuls.kernel.model.Result)4 NodesContainer (io.nuls.network.netty.container.NodesContainer)4 Block (io.nuls.kernel.model.Block)3 NulsDigestData (io.nuls.kernel.model.NulsDigestData)3 RpcClientResult (io.nuls.kernel.model.RpcClientResult)3 BroadcastResult (io.nuls.network.model.BroadcastResult)3 BlockMessage (io.nuls.protocol.message.BlockMessage)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Test (org.junit.Test)3 ByteBuf (io.netty.buffer.ByteBuf)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)2 NodeMessageBody (io.nuls.network.protocol.message.NodeMessageBody)2 NodesMessage (io.nuls.network.protocol.message.NodesMessage)2