private void FindNode() { var ct = new CallbackTimeout<List<NodeInformation>>(); var node = nodes[NodeCount - 1]; node.Kademlia.NodeLookup(nodes[0].Id, ct.Done); if (!ct.Block(TestParameters.LocalhostCommunicationTimeout * 120)) { Assert.Fail("Not completed within timeout"); } Assert.AreNotEqual(0, nodes.Count); Assert.AreEqual(nodes[0].Port, ct.Result[0].EndPoint.Port); Assert.AreEqual(nodes[0].Id, (KademliaId)ct.Result[0].NodeId); }
internal void Test() { var objectId = KademliaId.RandomId; var chunkId = KademliaId.RandomId; var user = new User(); user.ObjectId = objectId; var userFile = new UserFile(); userFile.ChunkList.Add(chunkId); user.Add(userFile); var ms = new MemoryStream(); Serializer.Serialize(ms, user); var bytes = ms.ToArray(); // store the object var ct1 = new CallbackTimeout<Error>(); nodeA.StoreObject(nodeBInfo, objectId, bytes, ct1.Done); if (!ct1.Block(TestParameters.LocalhostCommunicationTimeout)) { Assert.Fail("No response within timeout"); } Assert.AreEqual(Error.Success, ct1.Result); // now retrieve it var ct2 = new CallbackTimeout<Error, byte[]>(); nodeC.GetObjectFromNode(new List<NodeInformation>{nodeBInfo}, objectId, ct2.Done); if (!ct2.Block(TestParameters.LocalhostCommunicationTimeout)) { Assert.Fail("No response within timeout"); } Assert.AreEqual(Error.Success, ct2.Result1); Assert.AreElementsEqual(bytes, ct2.Result2); }
private void RetrieveObject() { StoreTestObject(); var node = nodes[NodeCount - 1]; var ct = new CallbackTimeout<Error, byte[]>(); node.GetObjectFromNetwork(objectId, ct.Done); if (!ct.Block(TestParameters.LocalhostCommunicationTimeout * 100)) { Assert.Fail("Not completed within timeout"); } Assert.AreEqual(Error.Success, ct.Result1); Assert.AreElementsEqual(bytes, ct.Result2); }
private void StoreTestObject() { // create the test object objectId = KademliaId.RandomId; var chunkId = KademliaId.RandomId; var user = new User(); user.ObjectId = objectId; var userFile = new UserFile(); userFile.ChunkList.Add(chunkId); user.Add(userFile); var ms = new MemoryStream(); Serializer.Serialize(ms, user); bytes = ms.ToArray(); // store it var ct = new CallbackTimeout<Error>(); var ni = new NodeInformation(new IPEndPoint(IPAddress.Loopback, nodes[1].Port), nodes[1].Id); nodes[0].StoreObject(ni, objectId, bytes, ct.Done); if (!ct.Block(TestParameters.LocalhostCommunicationTimeout)) { Assert.Fail("No response within timeout"); } Assert.AreEqual(Error.Success, ct.Result); }