Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.Write("Enter port number to use: ");
            int selfPort = Int32.Parse(Console.ReadLine());

            //UdpClient selfSocket = new UdpClient(selfPort);

            Console.Write("Enter port number to connect to: ");
            int        remotePort       = Int32.Parse(Console.ReadLine());
            IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), remotePort);

            //debug code
            Blockchain.Blocks = new List <Block> {
                new Block()
            };
            //debug code end


            Client.InitClient(selfPort);
            ConnectToNode.Connect(remotePort);
            ConnectToNode.GetNodes(remotePort, selfPort);
            Task.Factory.StartNew(() => Functionality.RunFunctionality());
            //Functionality func = new Functionality(remoteIpEndPoint, selfPort);

            while (true)
            {
            }
        }
Esempio n. 2
0
        public void Receive()
        {
            byte[] receiveBytes = Client.GetClient().Receive(ref _endPoint);
            string receivedData = Encoding.ASCII.GetString(receiveBytes);

            Console.WriteLine("MESSAGE: " + receivedData);
            string[] messageWords     = receivedData.Split(' ');
            string   messageFirstWord = messageWords[0];
            string   messageArguments = String.Join(" ", messageWords, 1, messageWords.Count() - 2);

            switch (messageFirstWord)
            {
            case "transactionprotocol":
                //process transaction if mining
                if (Client.IsMining)
                {
                    Transaction t = new Transaction(messageWords[1], messageWords[2], messageWords[3], messageWords[4]);
                    Functionality.ProcessTransaction(t);
                }
                break;

            case "getnodeports":
                List <string> nodePorts = new List <string>();
                foreach (Node n in NodeList.GetNodes())
                {
                    nodePorts.Add(n._endPoint.Port.ToString());
                }
                string nodesString = String.Join(",", nodePorts);
                Send("nodeportlist" + nodesString);
                break;

            case "nodeportlist":
                if (messageWords.Length == 1)
                {
                    break;
                }
                ConnectToNode.ConnectToNodeList(messageWords[1]);
                break;
            }
        }