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);
}
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);
}
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);
}
}
});
}
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);
}
Aggregations