Search in sources :

Example 1 with NetworkEventResult

use of io.nuls.network.model.NetworkEventResult in project nuls by nuls-io.

the class GetNodesMessageHandler method process.

@Override
public NetworkEventResult process(BaseMessage message, Node node) {
    List<Node> nodeList = getAvailableNodes();
    NodeMessageBody body = new NodeMessageBody();
    body.setNodeList(nodeList);
    NodesMessage nodesMessage = new NodesMessage(body);
    return new NetworkEventResult(true, nodesMessage);
}
Also used : NodesMessage(io.nuls.network.protocol.message.NodesMessage) Node(io.nuls.network.model.Node) NodeMessageBody(io.nuls.network.protocol.message.NodeMessageBody) NetworkEventResult(io.nuls.network.model.NetworkEventResult)

Example 2 with NetworkEventResult

use of io.nuls.network.model.NetworkEventResult in project nuls by nuls-io.

the class GetVersionMessageHandler method process.

@Override
public NetworkEventResult process(BaseMessage message, Node node) {
    GetVersionMessage getVersionMessage = (GetVersionMessage) message;
    NetworkMessageBody body = getVersionMessage.getMsgBody();
    if (body.getBestBlockHeight() < 0) {
        // node.setStatus(Node.BAD);
        nodeManager.removeNode(node.getId());
        return null;
    }
    node.setBestBlockHeight(body.getBestBlockHeight());
    node.setBestBlockHash(body.getBestBlockHash());
    NetworkMessageBody myVersionBody = new NetworkMessageBody(NetworkConstant.HANDSHAKE_CLIENT_TYPE, networkParam.getPort(), NulsContext.getInstance().getBestHeight(), NulsContext.getInstance().getBestBlock().getHeader().getHash());
    return new NetworkEventResult(true, new VersionMessage(myVersionBody));
}
Also used : NetworkMessageBody(io.nuls.network.protocol.message.NetworkMessageBody) VersionMessage(io.nuls.network.protocol.message.VersionMessage) GetVersionMessage(io.nuls.network.protocol.message.GetVersionMessage) GetVersionMessage(io.nuls.network.protocol.message.GetVersionMessage) NetworkEventResult(io.nuls.network.model.NetworkEventResult)

Aggregations

NetworkEventResult (io.nuls.network.model.NetworkEventResult)2 Node (io.nuls.network.model.Node)1 GetVersionMessage (io.nuls.network.protocol.message.GetVersionMessage)1 NetworkMessageBody (io.nuls.network.protocol.message.NetworkMessageBody)1 NodeMessageBody (io.nuls.network.protocol.message.NodeMessageBody)1 NodesMessage (io.nuls.network.protocol.message.NodesMessage)1 VersionMessage (io.nuls.network.protocol.message.VersionMessage)1