Example #1
0
        public void HandleTasks()
        {
            while (true)
            {
                if (DataServer.Tasks.Count == 0)
                {
                    continue;
                }

                DataTcpClient client = DataServer.Tasks.Dequeue();

                try
                {
                    Thread requestTh = new Thread(() => this.HandleRequests(client))
                    {
                        IsBackground = true
                    };
                    requestTh.Start();
                }
                catch (Exception e)
                {
                    client.IsQueued = false;
                    Console.WriteLine(e.Message);
                    throw;
                }
            }
            return;
        }
Example #2
0
        public static void LogRequest(MessageType type, DataTcpClient client)
        {
            ConsoleColor c;
            string       stype = "";

            if (type == null)
            {
                stype = "Unknown";
                c     = ConsoleColor.Red;
            }
            else if (type == MessageType.Error)
            {
                c     = ConsoleColor.Red;
                stype = type.ToString();
            }
            else
            {
                c     = ConsoleColor.Green;
                stype = type.ToString();
            }
            Log(c, "[", "SINFO", "][" + stype + "] request from " + client.Client.Client.RemoteEndPoint.ToString());
        }
Example #3
0
        public void HandleRequests(DataTcpClient client)
        {
            Protocol msg = Receive(client.Client);
            Protocol resp;

            if (msg != null)
            {
                switch (msg.Type)
                {
                case MessageType.AskBlocknumber:
                    resp = RequestServer.AskBlockNumber(msg);
                    break;

                case MessageType.AskBlockToMine:
                    resp = RequestServer.AskBlockToMine(msg);
                    break;

                case MessageType.AskChain:
                    resp = RequestServer.AskChain(msg);
                    break;

                case MessageType.AskLastestBlock:
                    resp = RequestServer.AskLastestBlock(msg);
                    break;

                case MessageType.AskPeer:
                    resp = RequestServer.AskPeer(msg);
                    break;

                case MessageType.MinedBlock:
                    resp = RequestServer.MinedBlock(msg);
                    break;

                case MessageType.Transaction:
                    resp = RequestServer.Transaction(msg);
                    break;

                case MessageType.AskChainStats:
                    resp = RequestServer.AskChainStats(msg);
                    break;

                default:
                    resp = new Protocol(MessageType.Error)
                    {
                        Message = "You did something, but I don't know what."
                    };
                    break;
                }
            }
            else
            {
                resp = new Protocol(MessageType.Error)
                {
                    Message = "You did something, but I don't know what."
                };
            }
            LogRequest(msg.Type, client);

            Send(client.Client, resp);
            client.IsQueued = false;
            return;
        }