use of io.nuls.network.protocol.message.NetworkMessageBody in project nuls by nuls-io.
the class VersionMessageHandler method process.
@Override
public NetworkEventResult process(BaseMessage message, Node node) {
VersionMessage versionMessage = (VersionMessage) message;
NetworkMessageBody body = versionMessage.getMsgBody();
// Log.info("receive a version message : {}", body);
if (body.getBestBlockHeight() < 0) {
// node.setStatus(Node.BAD);
nodeManager.removeNode(node.getId());
return null;
}
node.setBestBlockHeight(body.getBestBlockHeight());
node.setBestBlockHash(body.getBestBlockHash());
node.setTimeOffset((TimeService.currentTimeMillis() - node.getLastTime()) / 2);
return null;
}
use of io.nuls.network.protocol.message.NetworkMessageBody in project nuls by nuls-io.
the class NodeManager method sendHandshakeMessage.
private void sendHandshakeMessage(Node node, int type) {
NetworkMessageBody body = new NetworkMessageBody(type, networkParam.getPort(), NulsContext.getInstance().getBestHeight(), NulsContext.getInstance().getBestBlock().getHeader().getHash(), node.getIp());
broadcastHandler.broadcastToNode(new HandshakeMessage(body), node, true);
}
use of io.nuls.network.protocol.message.NetworkMessageBody in project nuls by nuls-io.
the class HandshakeMessageHandler method process.
@Override
public NetworkEventResult process(BaseMessage message, Node node) {
HandshakeMessage handshakeMessage = (HandshakeMessage) message;
NetworkMessageBody body = handshakeMessage.getMsgBody();
// Log.info("receive message from node {}, message : {}", node.getId(), body);
node.setBestBlockHash(body.getBestBlockHash());
node.setBestBlockHeight(body.getBestBlockHeight());
node.setExternalIp(body.getNodeIp());
node.setRemoteVersion(body.getVersion());
node.setConnectStatus(NodeConnectStatusEnum.AVAILABLE);
return null;
}
use of io.nuls.network.protocol.message.NetworkMessageBody in project nuls by nuls-io.
the class GetVersionMessageHandler method process.
@Override
public NetworkEventResult process(BaseMessage message, Node node) {
GetVersionMessage getVersionMessage = (GetVersionMessage) message;
NetworkMessageBody body = getVersionMessage.getMsgBody();
if (body.getBestBlockHeight() < 0) {
// node.setStatus(Node.BAD);
nodeManager.removeNode(node.getId());
return null;
}
node.setBestBlockHeight(body.getBestBlockHeight());
node.setBestBlockHash(body.getBestBlockHash());
NetworkMessageBody myVersionBody = new NetworkMessageBody(NetworkConstant.HANDSHAKE_CLIENT_TYPE, networkParam.getPort(), NulsContext.getInstance().getBestHeight(), NulsContext.getInstance().getBestBlock().getHeader().getHash());
return new NetworkEventResult(true, new VersionMessage(myVersionBody));
}
use of io.nuls.network.protocol.message.NetworkMessageBody in project nuls by nuls-io.
the class GetNodeVersionTask method process.
private void process() {
Collection<Node> connectedNodes = nodeManager.getAvailableNodes();
if (connectedNodes == null) {
return;
}
NetworkMessageBody body = new NetworkMessageBody(NetworkConstant.HANDSHAKE_CLIENT_TYPE, networkParam.getPort(), NulsContext.getInstance().getBestHeight(), NulsContext.getInstance().getBestBlock().getHeader().getHash());
GetVersionMessage getVersionMessage = new GetVersionMessage(body);
Iterator<Node> it = connectedNodes.iterator();
while (it.hasNext()) {
Node node = it.next();
if (node.getType() == Node.OUT) {
if (!checkIsSurvive(node)) {
it.remove();
continue;
}
node.setLastTime(TimeService.currentTimeMillis());
broadcastHandler.broadcastToNode(getVersionMessage, node, true);
}
}
}
Aggregations