예제 #1
0
        public override void Handle(IDhtEngine engine, Node node)
        {
            base.Handle(engine, node);

            BEncodedString   token    = engine.TokenManager.GenerateToken(node);
            GetPeersResponse response = new GetPeersResponse(engine.LocalId, TransactionId, token);

            var result = engine.QueryGetPeers(InfoHash);

            if (result.HasHash)
            {
                BEncodedList list = new BEncodedList();
                foreach (Node n in result.Values)
                {
                    list.Add(n.CompactPort());
                }
                response.Values = list;
            }
            else
            {
                // Is this right?
                response.Nodes = Node.CompactNode(result.Nodes);
            }

            if (Hook == null || Hook(response))
            {
                engine.Send(response, node.EndPoint);
            }
        }