Esempio n. 1
0
        internal void RemoveFromKademliaWhenRequestTimeout()
        {
            var id = KademliaId.RandomId;
            var ni = new NodeInformation(new IPEndPoint(IPAddress.Loopback, 65432), id);
            var message = new UdpMessage();
            kademlia.HandleIncomingRequest(ni, message);
            var response = new UdpMessage();
            response.ResponseId = message.RequestId;
            response.SenderNodeId = id;

            message.ResponseCallback(response);
            Assert.AreEqual(1, kademlia.CurrentContactCount);

            // actual test

            bool noResponse = false;
            message = new UdpMessage();
            message.PingRequest = new PingRequest();
            message.ResponseCallback = udpMessage => Assert.Fail("The response callback should not be called in this test");
            message.NoResponseCallback = () => noResponse = true;

            node.SendUdpMessage(message, ni.EndPoint, id);

            for (int i = 0; i < Node.TimeoutTicks; i++)
                node.TimerElapsed();
            Assert.AreEqual(1, kademlia.CurrentContactCount);

            for (int i = 0; i < Node.TimeoutTicks; i++)
                node.TimerElapsed();
            Assert.IsTrue(noResponse, "The no-response callback should be called in this test");
            Assert.AreEqual(0, kademlia.CurrentContactCount);
        }
Esempio n. 2
0
        internal void KademliaContactsAfterNewContact()
        {
            for (int i = 0; i < 10; i++)
            {
                var id = KademliaId.RandomId;
                var ni = new NodeInformation(new IPEndPoint(i + 1, i + 1), id);
                var message = new UdpMessage();
                kademlia.HandleIncomingRequest(ni, message);

                Assert.AreEqual(i, kademlia.CurrentContactCount);
                Assert.IsNotNull(message.PingRequest);

                var response = new UdpMessage();
                response.ResponseId = message.RequestId;
                response.SenderNodeId = id;
                message.ResponseCallback(response);

                Assert.AreEqual(i + 1, kademlia.CurrentContactCount);
            }
        }
Esempio n. 3
0
        internal static void RegisterFakeContact(Kademlia kademlia, NodeInformation ni)
        {
            var message = new UdpMessage();
            kademlia.HandleIncomingRequest(ni, message);

            if (message.ResponseCallback == null)
                return;

            var response = new UdpMessage();
            response.ResponseId = message.RequestId;
            response.SenderNodeId = ni.NodeId;
            message.ResponseCallback(response);
        }