Esempio n. 1
0
 public void Handle(GetBlockHeadersMessage getBlockHeaders)
 {
     Eth.V62.BlockHeadersMessage ethBlockHeadersMessage = FulfillBlockHeadersRequest(getBlockHeaders.EthMessage);
     // todo - implement cost tracking
     Send(new BlockHeadersMessage(ethBlockHeadersMessage, getBlockHeaders.RequestId, int.MaxValue));
 }
Esempio n. 2
0
        public override void HandleMessage(ZeroPacket message)
        {
            if (message.PacketType != LesMessageCode.Status && !_statusReceived)
            {
                throw new SubprotocolException($"No {nameof(StatusMessage)} received prior to communication with {Session.Node:c}.");
            }

            int size = message.Content.ReadableBytes;

            switch (message.PacketType)
            {
            case LesMessageCode.Status:
                StatusMessage statusMessage = Deserialize <StatusMessage>(message.Content);
                if (NetworkDiagTracer.IsEnabled)
                {
                    NetworkDiagTracer.ReportIncomingMessage(Session.Node.Address, Name, statusMessage.ToString());
                }
                Handle(statusMessage);
                break;

            case LesMessageCode.GetBlockHeaders:
                GetBlockHeadersMessage getBlockHeadersMessage = Deserialize <GetBlockHeadersMessage>(message.Content);
                if (NetworkDiagTracer.IsEnabled)
                {
                    NetworkDiagTracer.ReportIncomingMessage(Session.Node.Address, Name, getBlockHeadersMessage.ToString());
                }
                Handle(getBlockHeadersMessage);
                break;

            case LesMessageCode.GetBlockBodies:
                GetBlockBodiesMessage getBlockBodiesMessage = Deserialize <GetBlockBodiesMessage>(message.Content);
                if (NetworkDiagTracer.IsEnabled)
                {
                    NetworkDiagTracer.ReportIncomingMessage(Session.Node.Address, Name, getBlockBodiesMessage.ToString());
                }
                Handle(getBlockBodiesMessage);
                break;

            case LesMessageCode.GetReceipts:
                GetReceiptsMessage getReceiptsMessage = Deserialize <GetReceiptsMessage>(message.Content);
                if (NetworkDiagTracer.IsEnabled)
                {
                    NetworkDiagTracer.ReportIncomingMessage(Session.Node.Address, Name, getReceiptsMessage.ToString());
                }
                Handle(getReceiptsMessage);
                break;

            case LesMessageCode.GetContractCodes:
                GetContractCodesMessage getContractCodesMessage = Deserialize <GetContractCodesMessage>(message.Content);
                if (NetworkDiagTracer.IsEnabled)
                {
                    NetworkDiagTracer.ReportIncomingMessage(Session.Node.Address, Name, getContractCodesMessage.ToString());
                }
                Handle(getContractCodesMessage);
                break;

            case LesMessageCode.GetHelperTrieProofs:
                GetHelperTrieProofsMessage getHelperTrieProofsMessage = Deserialize <GetHelperTrieProofsMessage>(message.Content);
                if (NetworkDiagTracer.IsEnabled)
                {
                    NetworkDiagTracer.ReportIncomingMessage(Session.Node.Address, Name, getHelperTrieProofsMessage.ToString());
                }
                Handle(getHelperTrieProofsMessage);
                break;
            }
        }