Пример #1
0
		public override void Handle(DhtEngine engine, Node node)
		{
			base.Handle(engine, node);

			if (!engine.Torrents.ContainsKey(InfoHash))
				engine.Torrents.Add(InfoHash, new List<Node>());

			Message response;
			if (engine.TokenManager.VerifyToken(node, Token))
			{
				engine.Torrents[InfoHash].Add(node);
				response = new AnnouncePeerResponse(engine.RoutingTable.LocalNode.Id, TransactionId);
			}
			else
				response = new ErrorMessage(ErrorCode.ProtocolError, "Invalid or expired token received");

			engine.MessageLoop.EnqueueSend(response, node.EndPoint);
		}
        public override void Handle(DhtEngine engine, Node node)
        {
            base.Handle(engine, node);

            if (!engine.Torrents.ContainsKey(InfoHash))
            {
                engine.Torrents.Add(InfoHash, new List <Node> ());
            }

            DhtMessage response;

            if (engine.TokenManager.VerifyToken(node, Token))
            {
                engine.Torrents[InfoHash].Add(node);
                response = new AnnouncePeerResponse(engine.RoutingTable.LocalNode.Id, TransactionId);
            }
            else
            {
                response = new ErrorMessage(TransactionId, ErrorCode.ProtocolError, "Invalid or expired token received");
            }

            engine.MessageLoop.EnqueueSend(response, node, node.EndPoint);
        }
Пример #3
0
        public void AnnouncePeerResponseEncode()
        {
            AnnouncePeerResponse m = new AnnouncePeerResponse(infohash, transactionId);

            Compare(m, "d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re");
        }