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;
            }
        }
Esempio n. 2
0
        public string HttpAction(BlockChainNode Node, String data)
        {
            Console.WriteLine("Http host has received a request to count chain size.");

            int i = Node.GetBlockChain().Count;

            return(i.ToString());
        }
Esempio n. 3
0
        public string HttpAction(BlockChainNode Node, String data)
        {
            Console.WriteLine($"Http host has received a request get block number {data}");

            int BlockNumber;

            if (int.TryParse(data, out BlockNumber) != true)
            {
                return("Invalid block number. Block number must be integer");
            }

            if (Node.GetBlockChain().Count < BlockNumber)
            {
                return("Invalid Block. Block number doesn't exist");
            }

            return(Node.GetBlockChain()[BlockNumber].Data);
        }