use of neo.model.network.VersionPayload in project neo-java by coranos.
the class LocalControllerNode method onVersion.
/**
* when a "version" message is received, update the peer's connection phase to
* be "acknowledged" and set it's version to be the user agent in the payload.
*
* @param peer
* the peer that sent the message.
* @param message
* the message.
*/
private void onVersion(final RemoteNodeControllerRunnable peer, final Message message) {
if (stopped) {
return;
}
final RemoteNodeData data = peer.getData();
synchronized (data) {
final VersionPayload payload = message.getPayload(VersionPayload.class);
data.setVersion(payload.userAgent);
final long blockHeight = payload.startHeight.asLong();
data.setBlockHeight(blockHeight);
data.setLastMessageTimestamp(System.currentTimeMillis());
if (blockHeight > localNodeData.getBlockchainBlockHeight()) {
localNodeData.setBlockchainBlockHeight(blockHeight);
}
}
synchronized (RemoteNodeData.class) {
data.setConnectionPhase(NodeConnectionPhaseEnum.ACKNOWLEDGED);
}
final boolean stalledBlockchain = isStalledBlockchain(data);
if (stalledBlockchain) {
if (LOG.isDebugEnabled()) {
final String errorMessage = "recycling node {} with version {}" + " and stalled blockheight {} where our blockheight is {}";
final long blockCount = localNodeData.getBlockDb().getBlockCount();
LOG.debug(errorMessage, data.getHostAddress(), data.getVersion(), data.getBlockHeight(), blockCount);
}
data.setGoodPeer(false);
}
notifyNodeDataChangeListeners();
}
Aggregations