use of org.tron.core.net.message.MessageTypes in project java-tron by tronprotocol.
the class NodeImpl method onHandleFetchDataMessage.
private void onHandleFetchDataMessage(PeerConnection peer, FetchInvDataMessage fetchInvDataMsg) {
logger.info("on handle fetch block message");
MessageTypes type = fetchInvDataMsg.getInvMessageType();
// TODO:maybe can use message cache here
final BlockCapsule[] blocks = { del.getGenesisBlock() };
// get data and send it one by one
fetchInvDataMsg.getHashList().forEach(hash -> {
if (del.contain(hash, type)) {
Message msg = del.getData(hash, type);
if (type.equals(MessageTypes.BLOCK)) {
blocks[0] = ((BlockMessage) msg).getBlockCapsule();
}
peer.sendMessage(msg);
} else {
peer.sendMessage(new ItemNotFound());
}
});
if (blocks[0] != null) {
peer.setHeadBlockWeBothHave(blocks[0].getBlockId());
peer.setHeadBlockTimeWeBothHave(blocks[0].getTimeStamp());
}
}
Aggregations