Example #1
0
        public void StoreValue()
        {
            KadNode node1 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55555));
            KadNode node2 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55556));

            KadValue val = new KadValue(KadId.GenerateRandom(), DateTime.Now, new byte[20]);

            node1.BucketList.Put(new KadContactNode(node2.Id, node2.EndPoint));
            Assert.IsTrue(node1.StoreValue(node2.Id, val));

            KadValue node2Val = node2.Storage.Get(val.Id);

            Assert.IsTrue(val.Id.GetNumericValue() == node2Val.Id.GetNumericValue());

            node1.Shutdown();
            node2.Shutdown();
        }
Example #2
0
        public void StoreValue_CantStore()
        {
            KadNode node1 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55555));
            KadNode node2 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55556));

            for (int i = 0; i < 20; i++)
            {
                var value = new KadValue(kademlia_dht.Base.KadId.GenerateRandom(), DateTime.UtcNow, new byte[20]);
                node2.Storage.Put(value);
                Thread.Sleep(500);
            }

            KadValue val = new KadValue(KadId.GenerateRandom(), DateTime.UtcNow, new byte[20]);

            node1.BucketList.Put(new KadContactNode(node2.Id, node2.EndPoint));
            Assert.IsFalse(node1.StoreValue(node2.Id, val));

            node1.Shutdown();
            node2.Shutdown();
        }