Search in sources :

Example 46 with Node

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

Example 47 with Node

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

Example 48 with 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;
}
Also used : NodePo(io.nuls.network.storage.po.NodePo) 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