Exemple #1
0
        private void OnRecvResponseX(IPEndPoint ipinfo, DHTResponseMessage msg)
        {
            if (msg == null)
            {
                return;
            }

            BDictionary data = msg.Data;

            var tid = data.Get <BString>("t");

            var returnValues = data.Get <BDictionary>("r");

            if (returnValues == null)
            {
                // response is invalid
                return;
            }

            BString id         = returnValues.Get <BString>("id");
            BString tokStr     = returnValues.Get <BString>("token");
            BList   valuesList = returnValues.Get <BList>("values");
            BString nodesStr   = returnValues.Get <BString>("nodes");

            var remoteNode = new DHTNode(id.Value, ipinfo);

            UpdateRoutingTable(remoteNode);

            // define type of response by transactionId of query/response
            QueryType queryType = fTransactions.CheckQuery(tid);

            switch (queryType)
            {
            case QueryType.Ping:
                OnRecvPingResponse(remoteNode);
                break;

            case QueryType.FindNode:
                OnRecvFindNodeResponse(remoteNode, nodesStr);
                break;

            case QueryType.GetPeers:
                OnRecvGetPeersResponse(remoteNode, nodesStr, valuesList, tokStr);
                break;

            case QueryType.AnnouncePeer:
                OnRecvAnnouncePeerResponse(remoteNode);
                break;

            case QueryType.None:
                // TransactionId bad or unknown
                OnRecvCustomResponse(remoteNode, data);
                break;
            }
        }
Exemple #2
0
        public void Test_DHTTransactions_class()
        {
            var instance = new DHTTransactions();

            Assert.IsNotNull(instance);

            var tid = DHTTransactions.GetNextId();
            var msg = new DHTMessage(MessageType.Query, QueryType.Ping, null);

            instance.SetQuery(tid, msg);
            Assert.AreEqual(QueryType.Ping, instance.CheckQuery(tid));
        }