Search in sources :

Example 1 with NetworkEventResult

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

the class GetNodeEventHandler method process.

@Override
public NetworkEventResult process(BaseEvent event, Node node) {
    GetNodeEvent getNodeEvent = (GetNodeEvent) event;
    // String key = event.getHeader().getEventType() + "-" + node.getIp();
    // if (cacheService.existEvent(key)) {
    // getNetworkService().removeNode(node.getId());
    // return null;
    // }
    // cacheService.putEvent(key, event, false);
    List<Node> list = getAvailableNodes(getNodeEvent.getLength(), node.getId());
    NodeEvent replyEvent = new NodeEvent(list);
    return new NetworkEventResult(true, replyEvent);
}
Also used : GetNodeEvent(io.nuls.network.message.entity.GetNodeEvent) NodeEvent(io.nuls.network.message.entity.NodeEvent) Node(io.nuls.network.entity.Node) GetNodeEvent(io.nuls.network.message.entity.GetNodeEvent) NetworkEventResult(io.nuls.network.message.NetworkEventResult)

Example 2 with NetworkEventResult

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

the class GetNodesIpEventHandler method process.

@Override
public NetworkEventResult process(BaseEvent event, Node node) {
    List<Node> availableNodes = getNetworkService().getAvailableNodes();
    List<String> ipList = new ArrayList<>();
    for (Node n : availableNodes) {
        ipList.add(n.getIp());
    }
    NodesIpEvent ipEvent = new NodesIpEvent(ipList);
    return new NetworkEventResult(true, ipEvent);
}
Also used : Node(io.nuls.network.entity.Node) ArrayList(java.util.ArrayList) NodesIpEvent(io.nuls.network.message.entity.NodesIpEvent) GetNodesIpEvent(io.nuls.network.message.entity.GetNodesIpEvent) NetworkEventResult(io.nuls.network.message.NetworkEventResult)

Example 3 with NetworkEventResult

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

the class ConnectionManager method asynExecute.

private void asynExecute(BaseEvent networkEvent, Node node) {
    NetWorkEventHandler handler = messageHandlerFactory.getHandler(networkEvent);
    TaskManager.asynExecuteRunnable(new Runnable() {

        @Override
        public void run() {
            try {
                NetworkEventResult messageResult = handler.process(networkEvent, node);
                processMessageResult(messageResult, node);
            } catch (Exception e) {
                Log.error(e);
            }
        }
    });
}
Also used : NetWorkEventHandler(io.nuls.network.message.handler.NetWorkEventHandler) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NetworkEventResult(io.nuls.network.message.NetworkEventResult)

Example 4 with NetworkEventResult

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

the class GetVersionEventHandler method process.

@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
    GetVersionEvent event = (GetVersionEvent) networkEvent;
    // String key = event.getHeader().getEventType() + "-" + node.getId();
    // if (cacheService.existEvent(key)) {
    // Log.info("----------GetVersionEventHandler  cacheService  existEvent--------");
    // getNetworkService().removeNode(node.getId());
    // return null;
    // }
    // cacheService.putEvent(key, event, true);
    Block block = NulsContext.getInstance().getBestBlock();
    while (block == null) {
        try {
            Thread.sleep(1000);
            block = NulsContext.getInstance().getBestBlock();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    VersionEvent replyMessage = new VersionEvent(getNetworkService().getNetworkParam().getExternalPort(), block.getHeader().getHeight(), block.getHeader().getHash().getDigestHex());
    node.setPort(event.getExternalPort());
    return new NetworkEventResult(true, replyMessage);
}
Also used : GetVersionEvent(io.nuls.network.message.entity.GetVersionEvent) VersionEvent(io.nuls.network.message.entity.VersionEvent) GetVersionEvent(io.nuls.network.message.entity.GetVersionEvent) Block(io.nuls.core.chain.entity.Block) NetworkEventResult(io.nuls.network.message.NetworkEventResult)

Aggregations

NetworkEventResult (io.nuls.network.message.NetworkEventResult)4 Node (io.nuls.network.entity.Node)2 Block (io.nuls.core.chain.entity.Block)1 NulsException (io.nuls.core.exception.NulsException)1 GetNodeEvent (io.nuls.network.message.entity.GetNodeEvent)1 GetNodesIpEvent (io.nuls.network.message.entity.GetNodesIpEvent)1 GetVersionEvent (io.nuls.network.message.entity.GetVersionEvent)1 NodeEvent (io.nuls.network.message.entity.NodeEvent)1 NodesIpEvent (io.nuls.network.message.entity.NodesIpEvent)1 VersionEvent (io.nuls.network.message.entity.VersionEvent)1 NetWorkEventHandler (io.nuls.network.message.handler.NetWorkEventHandler)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1