use of io.nuls.core.chain.entity.Block 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