Search in sources :

Example 1 with ItemNotFound

use of org.tron.core.net.message.ItemNotFound 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());
    }
}
Also used : TransactionMessage(org.tron.core.net.message.TransactionMessage) InventoryMessage(org.tron.core.net.message.InventoryMessage) SyncBlockChainMessage(org.tron.core.net.message.SyncBlockChainMessage) BlockMessage(org.tron.core.net.message.BlockMessage) Message(org.tron.common.overlay.message.Message) BlockInventoryMessage(org.tron.core.net.message.BlockInventoryMessage) FetchInvDataMessage(org.tron.core.net.message.FetchInvDataMessage) ChainInventoryMessage(org.tron.core.net.message.ChainInventoryMessage) TronMessage(org.tron.core.net.message.TronMessage) ItemNotFound(org.tron.core.net.message.ItemNotFound) MessageTypes(org.tron.core.net.message.MessageTypes) BlockCapsule(org.tron.core.capsule.BlockCapsule)

Aggregations

Message (org.tron.common.overlay.message.Message)1 BlockCapsule (org.tron.core.capsule.BlockCapsule)1 BlockInventoryMessage (org.tron.core.net.message.BlockInventoryMessage)1 BlockMessage (org.tron.core.net.message.BlockMessage)1 ChainInventoryMessage (org.tron.core.net.message.ChainInventoryMessage)1 FetchInvDataMessage (org.tron.core.net.message.FetchInvDataMessage)1 InventoryMessage (org.tron.core.net.message.InventoryMessage)1 ItemNotFound (org.tron.core.net.message.ItemNotFound)1 MessageTypes (org.tron.core.net.message.MessageTypes)1 SyncBlockChainMessage (org.tron.core.net.message.SyncBlockChainMessage)1 TransactionMessage (org.tron.core.net.message.TransactionMessage)1 TronMessage (org.tron.core.net.message.TronMessage)1