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); } }
public override void Handle(IDhtEngine engine, Node node) { base.Handle(engine, node); PingResponse m = new PingResponse(engine.GetNeighborId(Id), TransactionId); engine.Send(m, node.EndPoint); }
public override void Handle(IDhtEngine engine, Node node) { base.Handle(engine, node); FindNodeResponse response = new FindNodeResponse(engine.LocalId, TransactionId); var result = engine.QueryFindNode(Target); response.Nodes = Node.CompactNode(result.Nodes); engine.Send(response, node.EndPoint); }
public override void Handle(IDhtEngine engine, Node node) { base.Handle(engine, node); DhtMessage response; if (engine.TokenManager.VerifyToken(node, Token)) { engine.GetAnnounced(new InfoHash(InfoHash.Bytes), new IPEndPoint(node.EndPoint.Address, (int)Port.Number)); response = new AnnouncePeerResponse(engine.GetNeighborId(Id), TransactionId); } else { response = new ErrorMessage(ErrorCode.ProtocolError, "Invalid or expired token received"); } engine.Send(response, node.EndPoint); }