Exemple #1
0
 private void QueryNode(Node node)
 {
     _node            = node;
     _message         = new FindNode(_engine.LocalId, node.Id);
     _task            = new SendQueryTask(_engine, _message, node);
     _task.Completed += TaskComplete;
     _task.Execute();
 }
Exemple #2
0
 private void SendFindNode(IEnumerable <Node> newNodes)
 {
     foreach (var node in Node.CloserNodes(_engine.LocalId, _nodes, newNodes, Bucket.MaxCapacity))
     {
         _activeRequests++;
         var request = new FindNode(_engine.LocalId, _engine.LocalId);
         var task    = new SendQueryTask(_engine, request, node);
         task.Completed += FindNodeComplete;
         task.Execute();
     }
 }
        private void SendGetPeers(Node n)
        {
            var distance = n.Id.Xor(_infoHash);
            if (ClosestActiveNodes.ContainsKey(distance))
                return;
            ClosestActiveNodes.Add(distance, n);

            _activeQueries++;
            var m = new GetPeers(_engine.LocalId, _infoHash);
            var task = new SendQueryTask(_engine, m, n);
            task.Completed += GetPeersCompleted;
            task.Execute();
        }
Exemple #4
0
        private void SendGetPeers(Node n)
        {
            var distance = n.Id.Xor(_infoHash);

            if (ClosestActiveNodes.ContainsKey(distance))
            {
                return;
            }
            ClosestActiveNodes.Add(distance, n);

            _activeQueries++;
            var m    = new GetPeers(_engine.LocalId, _infoHash);
            var task = new SendQueryTask(_engine, m, n);

            task.Completed += GetPeersCompleted;
            task.Execute();
        }
        private void SendPingToOldest()
        {
            _bucket.LastChanged = DateTime.UtcNow;
            _bucket.SortBySeen();

            if ((DateTime.UtcNow - _bucket.Nodes[0].LastSeen) < TimeSpan.FromMinutes(3))
            {
                RaiseComplete(new TaskCompleteEventArgs(this));
            }
            else
            {
                var oldest = _bucket.Nodes[0];
                var task = new SendQueryTask(_engine, new Ping(_engine.LocalId), oldest);
                task.Completed += TaskComplete;
                task.Execute();
            }
        }
Exemple #6
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
            {
                var oldest = _bucket.Nodes[0];
                var task   = new SendQueryTask(_engine, new Ping(_engine.LocalId), oldest);
                task.Completed += TaskComplete;
                task.Execute();
            }
        }
 private void SendFindNode(IEnumerable<Node> newNodes)
 {
     foreach (var node in Node.CloserNodes(_engine.LocalId, _nodes, newNodes, Bucket.MaxCapacity))
     {
         _activeRequests++;
         var request = new FindNode(_engine.LocalId, _engine.LocalId);
         var task = new SendQueryTask(_engine, request, node);
         task.Completed += FindNodeComplete;
         task.Execute();
     }
 }
        internal void Add(Node node)
        {
            if (node == null)
                throw new ArgumentNullException(nameof(node));

            var task = new SendQueryTask(this, new Ping(RoutingTable.LocalNode.Id), node);
            task.Execute();
        }