public void RetrieveValues_NoValuesInStorage() { KadNode node1 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55555)); KadNode node2 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55556)); List <KadContactNode> nodes = new List <KadContactNode>(20); for (int i = 0; i < 20; i++) { var contact = new kademlia_dht.Base.KadContactNode(kademlia_dht.Base.KadId.GenerateRandom(), new System.Net.IPEndPoint(IPAddress.Loopback, 20000)); nodes.Add(contact); node2.BucketList.Put(contact); Thread.Sleep(500); } nodes = nodes.OrderBy((n) => n.Id.GetNumericValue()).ToList(); node1.BucketList.Put(new KadContactNode(node2.Id, node2.EndPoint)); var foundNodes = node1.FindValue(node2.Id, KadId.GenerateRandom()).Contacts; CollectionAssert.AreEqual(foundNodes.Select((n) => n.Id.GetNumericValue()).OrderBy((n) => n).ToList(), nodes.Select((n) => n.Id.GetNumericValue()).OrderBy((n) => n).ToList()); node1.Shutdown(); node2.Shutdown(); }
public void RetrieveValues() { KadNode node1 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55555)); KadNode node2 = new KadNode(new System.Net.IPEndPoint(IPAddress.Loopback, 55556)); List <KadValue> values = new List <KadValue>(20); for (int i = 0; i < 20; i++) { var value = new KadValue(kademlia_dht.Base.KadId.GenerateRandom(), DateTime.UtcNow, new byte[20]); values.Add(value); node2.Storage.Put(value); Thread.Sleep(500); } values = values.OrderBy((v) => v.Id.GetNumericValue()).ToList(); node1.BucketList.Put(new KadContactNode(node2.Id, node2.EndPoint)); var foundVal = node1.FindValue(node2.Id, values.First().Id); Assert.AreEqual(values.First().Id.GetNumericValue(), foundVal.Value.Id.GetNumericValue()); node1.Shutdown(); node2.Shutdown(); }