Esempio n. 1
0
        public void Test_CreateGetPeersResponse()
        {
            var        tid      = DHTTransactions.GetNextId();
            var        nodeId   = DHTId.CreateRandom();
            var        infoHash = DHTId.CreateRandom();
            var        peers    = new List <IDHTPeer>();
            var        nodes    = new List <DHTNode>();
            DHTMessage msg      = DHTMessage.CreateGetPeersResponse(tid, nodeId, infoHash, peers, nodes);

            Assert.IsNotNull(msg);
            Assert.AreEqual(MessageType.Response, msg.Type);
            // TODO: test contents
        }
Esempio n. 2
0
        private void OnRecvGetPeersQuery(IPEndPoint ipinfo, BDictionary data)
        {
            var t    = data.Get <BString>("t");
            var args = data.Get <BDictionary>("a");

            var id       = args.Get <BString>("id");
            var infoHash = args.Get <BString>("info_hash");

            fLogger.WriteDebug("Receive `get_peers` query from {0} [{1}] for {2}", ipinfo.ToString(), id.Value.ToHexString(), infoHash.Value.ToHexString());

            fRoutingTable.UpdateNode(new DHTNode(id.Value, ipinfo));

            var neighbor  = DHTHelper.GetNeighbor(infoHash.Value, fLocalID);
            var peersList = (Algorithms.ArraysEqual(infoHash.Value, fSearchInfoHash)) ? fPeersHolder.GetPeersList() : null;
            var nodesList = fRoutingTable.FindNodes(infoHash.Value);

            Send(ipinfo, DHTMessage.CreateGetPeersResponse(t, neighbor, infoHash.Value, peersList, nodesList));
        }
Esempio n. 3
0
        private void OnRecvGetPeersQuery(IPEndPoint ipinfo, BDictionary data)
        {
            var t    = data.Get <BString>("t");
            var args = data.Get <BDictionary>("a");

            var id       = args.Get <BString>("id");
            var infoHash = new DHTId(args.Get <BString>("info_hash"));

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

            UpdateRoutingTable(remoteNode);

#if DEBUG_DHT_INTERNALS
            fLogger.WriteDebug("Receive `get_peers` query from {0} for {1}", remoteNode.ToString(), infoHash.ToString());
#endif

            var neighbor  = DHTNode.GetNeighbor(infoHash.Data, fLocalID.Data);
            var peersList = (infoHash == fSearchInfoHash) ? fPeersHolder.GetPeersList() : null;
            var nodesList = fRoutingTable.GetClosest(infoHash.Data);
            Send(ipinfo, DHTMessage.CreateGetPeersResponse(t, neighbor, infoHash, peersList, nodesList));
        }