Esempio n. 1
0
        /// <summary>
        /// All incoming messages from other peers are passed to this function for processing
        /// </summary>
        /// <param name="responseData"></param>
        private void ProcessInboundP2PCommand(P2Pmessage responseData)
        {
            Console.WriteLine($"Processing {responseData.Command.ToString()} command");

            switch (responseData.Command)
            {
            case P2Pcommand.GetBlockChain:

                //todo: get chain from {MyNode} and return to response peer

                SendMesage(new Connection(System.Net.IPAddress.Parse(responseData.ResponsePeerIp), responseData.ResponsePeerPort), new P2Pmessage()
                {
                    Command          = P2Pcommand.GetBlockChainResponse,
                    ResponseRequired = false,
                    Data             = MyNode.GetBlockChain()
                });

                break;

            case P2Pcommand.GetBlockChainResponse:

                MyNode.SetBlockChain((List <Block>)responseData.Data);

                break;

            case P2Pcommand.PutBlock:

                MyNode.PutBroadcastedBlock((Block)responseData.Data);

                break;
            }
        }