Beispiel #1
0
        public void GetPeersResponseDecode()
        {
            GetPeersEncode();
            MessageFactory.RegisterSend(message);

            string           text = "d1:rd2:id20:abcdefghij01234567895:token8:aoeusnth6:valuesl6:axje.u6:idhtnmee1:t2:aa1:y1:re";
            GetPeersResponse m    = (GetPeersResponse)Decode(text);

            Assert.AreEqual(token, m.Token, "#1");
            Assert.AreEqual(id, m.Id, "#2");

            BEncodedList l = new BEncodedList();

            l.Add((BEncodedString)"axje.u");
            l.Add((BEncodedString)"idhtnm");
            Assert.AreEqual(l, m.Values, "#3");

            Compare(m, text);
        }
Beispiel #2
0
        public override void Handle(DhtEngine engine, Node node)
        {
            base.Handle(engine, node);

            var token    = engine.TokenManager.GenerateToken(node);
            var response = new GetPeersResponse(engine.RoutingTable.LocalNode.Id, TransactionId, token);

            if (engine.Torrents.ContainsKey(InfoHash))
            {
                var list = new BEncodedList();
                foreach (var n in engine.Torrents[InfoHash])
                {
                    list.Add(n.CompactPort());
                }
                response.Values = list;
            }
            else
            {
                // Is this right?
                response.Nodes = Node.CompactNode(engine.RoutingTable.GetClosest(InfoHash));
            }

            engine.MessageLoop.EnqueueSend(response, node.EndPoint);
        }
Beispiel #3
0
 public void GetPeersResponseEncode()
 {
     var m = new GetPeersResponse(_id, _transactionId, _token)
                 {
                     Values = new BEncodedList
                                  {
                                      (BEncodedString) "axje.u",
                                      (BEncodedString) "idhtnm"
                                  }
                 };
     Compare(m, "d1:rd2:id20:abcdefghij01234567895:token8:aoeusnth6:valuesl6:axje.u6:idhtnmee1:t2:aa1:y1:re");
 }