use of io.nuls.network.message.entity.VersionEvent in project nuls by nuls-io.
the class VersionEventHandler method process.
@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
VersionEvent event = (VersionEvent) networkEvent;
if (event.getBestBlockHeight() < 0) {
throw new NetworkMessageException(ErrorCode.NET_MESSAGE_ERROR);
}
node.setVersionMessage(event);
checkVersion(event.getNulsVersion());
if (!node.isHandShake()) {
node.setStatus(Node.HANDSHAKE);
node.setPort(event.getExternalPort());
node.setLastTime(TimeService.currentTimeMillis());
getNodeDao().saveChange(NodeTransferTool.toPojo(node));
}
return null;
}
use of io.nuls.network.message.entity.VersionEvent 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