Exemple #1
0
        public void SendQueryTaskTimeout()
        {
            engine.TimeOut = TimeSpan.FromMilliseconds(25);

            Ping ping = new Ping(engine.LocalId);

            ping.TransactionId            = transactionId;
            engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e) {
                if (e.TimedOut)
                {
                    counter++;
                }
            };

            SendQueryTask task = new SendQueryTask(engine, ping, node);

            task.Completed += delegate { handle.Set(); };
            task.Execute();
#if NETSTANDARD1_5
            Assert.True(handle.WaitOne(3000), "#1");
#else
            Assert.True(handle.WaitOne(3000, false), "#1");
#endif
            Assert.Equal(task.Retries, counter);
        }
Exemple #2
0
        public void SendQueryTaskSucceed()
        {
            engine.TimeOut = TimeSpan.FromMilliseconds(25);

            Ping ping = new Ping(engine.LocalId);

            ping.TransactionId            = transactionId;
            engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e)
            {
                if (e.TimedOut)
                {
                    counter++;
                    PingResponse response = new PingResponse(node.Id, transactionId);
                    listener.RaiseMessageReceived(response, node.EndPoint);
                }
            };

            SendQueryTask task = new SendQueryTask(engine, ping, node);

            task.Completed += delegate { handle.Set(); };
            task.Execute();

#if NETSTANDARD1_5
            Assert.True(handle.WaitOne(3000), "#1");
#else
            Assert.True(handle.WaitOne(3000, false), "#1");
#endif
            System.Threading.Thread.Sleep(200);
            Assert.Equal(1, counter);
            Node n = engine.RoutingTable.FindNode(this.node.Id);
            Assert.NotNull(n);
            Assert.True(n.LastSeen > DateTime.UtcNow.AddSeconds(-2));
        }
Exemple #3
0
        public void SendQueryTaskSucceed()
        {
            _engine.TimeOut = TimeSpan.FromMilliseconds(25);

            Ping ping = new Ping(_engine.LocalId);

            ping.TransactionId             = _transactionId;
            _engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e)
            {
                if (e.TimedOut)
                {
                    _counter++;
                    PingResponse response = new PingResponse(_node.Id, _transactionId);
                    _listener.RaiseMessageReceived(response, _node.EndPoint);
                }
            };

            SendQueryTask task = new SendQueryTask(_engine, ping, _node);

            task.Completed += delegate { _handle.Set(); };
            task.Execute();

            Assert.True(_handle.WaitOne(3000));
            Thread.Sleep(200);
            Assert.Equal(1, _counter);
            Node n = _engine.RoutingTable.FindNode(_node.Id);

            Assert.NotNull(n);
            Assert.True(n.LastSeen > DateTime.UtcNow.AddSeconds(-2));
        }
Exemple #4
0
        public void SendQueryTaskSucceed()
        {
            _engine.TimeOut = TimeSpan.FromMilliseconds(25);

            var ping = new Ping(_engine.LocalId)
            {
                TransactionId = _transactionId
            };

            _engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e)
            {
                if (!e.TimedOut)
                {
                    return;
                }

                _counter++;
                var response = new PingResponse(_node.Id, _transactionId);
                _listener.RaiseMessageReceived(response, _node.EndPoint);
            };

            var task = new SendQueryTask(_engine, ping, _node);

            task.Completed += delegate { _handle.Set(); };
            task.Execute();

            Assert.IsTrue(_handle.WaitOne(3000, false), "#1");
            Thread.Sleep(200);
            Assert.AreEqual(1, _counter, "#2");
            var n = _engine.RoutingTable.FindNode(_node.Id);

            Assert.IsNotNull(n, "#3");
            Assert.IsTrue(n.LastSeen > DateTime.UtcNow.AddSeconds(-2));
        }
Exemple #5
0
 private void QueryNode(Node node)
 {
     this.node       = node;
     message         = new FindNode(engine.LocalId, node.Id);
     task            = new SendQueryTask(engine, message, node);
     task.Completed += TaskComplete;
     task.Execute();
 }
Exemple #6
0
        internal void Add(Node node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

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

            task.Execute();
        }
Exemple #7
0
 private static void SendFindNode(IEnumerable <Node> knonwn, NodeId nodeId)
 {
     foreach (Node node in knonwn)
     {
         FindNode      request = new FindNode(engine.LocalId, nodeId);
         SendQueryTask task    = new SendQueryTask(engine, request, node);
         task.Completed += FindNodeComplete;
         task.Execute();
         lock (engine)
             activities++;
     }
 }
Exemple #8
0
        public void PingTimeout()
        {
            engine.TimeOut = TimeSpan.FromHours(1);
            // Send ping
            Ping ping = new Ping(node.Id);

            ping.TransactionId = transactionId;

            ManualResetEvent handle = new ManualResetEvent(false);
            SendQueryTask    task   = new SendQueryTask(engine, ping, node);

            task.Completed += delegate {
                handle.Set();
            };
            task.Execute();

            // Receive response
            PingResponse response = new PingResponse(node.Id, transactionId);

            listener.RaiseMessageReceived(response, node.EndPoint);

#if NETSTANDARD1_5
            Assert.True(handle.WaitOne(1000), "#0");
#else
            Assert.True(handle.WaitOne(1000, true), "#0");
#endif

            engine.TimeOut = TimeSpan.FromMilliseconds(75);
            DateTime lastSeen = node.LastSeen;

            // Time out a ping
            ping = new Ping(node.Id);
            ping.TransactionId = (BEncodedString)"ab";

            task            = new SendQueryTask(engine, ping, node, 4);
            task.Completed += delegate { handle.Set(); };

            handle.Reset();
            task.Execute();
            handle.WaitOne();

            Assert.Equal(4, node.FailedCount);
            Assert.Equal(NodeState.Bad, node.State);
            Assert.Equal(lastSeen, node.LastSeen);
        }
Exemple #9
0
        public void SendQueryTaskTimeout()
        {
            _engine.TimeOut = TimeSpan.FromMilliseconds(25);

            Ping ping = new Ping(_engine.LocalId);

            ping.TransactionId             = _transactionId;
            _engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e)
            {
                if (e.TimedOut)
                {
                    _counter++;
                }
            };

            SendQueryTask task = new SendQueryTask(_engine, ping, _node);

            task.Completed += delegate { _handle.Set(); };
            task.Execute();
            Assert.True(_handle.WaitOne(3000));
            Assert.Equal(task.Retries, _counter);
        }
Exemple #10
0
        public void SendQueryTaskTimeout()
        {
            _engine.TimeOut = TimeSpan.FromMilliseconds(25);

            var ping = new Ping(_engine.LocalId)
            {
                TransactionId = _transactionId
            };

            _engine.MessageLoop.QuerySent += (o, e) =>
            {
                if (e.TimedOut)
                {
                    _counter++;
                }
            };

            var task = new SendQueryTask(_engine, ping, _node);

            task.Completed += (sender, args) => _handle.Set();
            task.Execute();
            Assert.IsTrue(_handle.WaitOne(3000, false), "#1");
            Assert.AreEqual(task.Retries, _counter);
        }