private void SendFindNode(IEnumerable <Node> newNodes)
 {
     foreach (Node node in Node.CloserNodes(engine.LocalId, nodes, newNodes, Bucket.MaxCapacity))
     {
         activeRequests++;
         FindNode      request = new FindNode(engine.LocalId, engine.LocalId);
         SendQueryTask task    = new SendQueryTask(engine, request, node);
         task.Completed += FindNodeComplete;
         task.Execute();
     }
 }
Beispiel #2
0
        private void SendGetPeers(Node n)
        {
            NodeId distance = n.Id.Xor(infoHash);

            queriedNodes.Add(distance, n);

            activeQueries++;
            GetPeers      m    = new GetPeers(engine.LocalId, infoHash);
            SendQueryTask task = new SendQueryTask(engine, m, n);

            task.Completed += GetPeersCompleted;
            task.Execute();
        }
Beispiel #3
0
        private void SendPingToOldest()
        {
            bucket.LastChanged = DateTime.UtcNow;
            bucket.SortBySeen();

            if ((DateTime.UtcNow - bucket.Nodes[0].LastSeen) < TimeSpan.FromMinutes(3))
            {
                RaiseComplete(new TaskCompleteEventArgs(this));
            }
            else
            {
                Node          oldest = bucket.Nodes[0];
                SendQueryTask task   = new SendQueryTask(engine, new Ping(engine.LocalId), oldest);
                task.Completed += TaskComplete;
                task.Execute();
            }
        }
        private void GotPeers(object o, TaskCompleteEventArgs e)
        {
            e.Task.Completed -= GotPeers;
            GetPeersTask getpeers = (GetPeersTask)e.Task;

            foreach (Node n in getpeers.ClosestActiveNodes.Values)
            {
                if (n.Token == null)
                {
                    continue;
                }
                AnnouncePeer  query = new AnnouncePeer(engine.LocalId, infoHash, port, n.Token);
                SendQueryTask task  = new SendQueryTask(engine, query, n);
                task.Completed += SentAnnounce;
                task.Execute();
                activeAnnounces++;
            }

            if (activeAnnounces == 0)
            {
                RaiseComplete(new TaskCompleteEventArgs(this));
            }
        }