コード例 #1
0
        public void FindValueRouteTest()
        {
            TcpSubnetProtocol p1 = new TcpSubnetProtocol(localIP, port, 1);
            TcpSubnetProtocol p2 = new TcpSubnetProtocol(localIP, port, 2);
            ID      ourID        = ID.RandomID;
            Contact c1           = new Contact(p1, ourID);
            Node    n1           = new Node(c1, new VirtualStorage());
            Node    n2           = new Node(new Contact(p2, ID.RandomID), new VirtualStorage());

            server.RegisterProtocol(p1.Subnet, n1);
            server.RegisterProtocol(p2.Subnet, n2);
            server.Start();

            ID     testID    = ID.RandomID;
            string testValue = "Test";

            p2.Store(c1, testID, testValue);

            Assert.IsTrue(n2.Storage.Contains(testID), "Expected remote peer to have value.");
            Assert.IsTrue(n2.Storage.Get(testID) == testValue, "Expected remote peer to contain stored value.");

            var ret = p2.FindValue(c1, testID);

            Assert.IsTrue(ret.contacts == null, "Expected to find value.");
            Assert.IsTrue(ret.val == testValue, "Value does not match expected value from peer.");
        }
コード例 #2
0
ファイル: TcpSubnetTests.cs プロジェクト: mitacha/Kademlia-1
        public void UnresponsiveNodeTest()
        {
            TcpSubnetProtocol p1 = new TcpSubnetProtocol(localIP, port, 1);
            TcpSubnetProtocol p2 = new TcpSubnetProtocol(localIP, port, 2);

            p2.Responds = false;
            ID      ourID = ID.RandomID;
            Contact c1    = new Contact(p1, ourID);
            Node    n1    = new Node(c1, new VirtualStorage());
            Node    n2    = new Node(new Contact(p2, ID.RandomID), new VirtualStorage());

            server.RegisterProtocol(p1.Subnet, n1);
            server.RegisterProtocol(p2.Subnet, n2);
            server.Start();

            ID     testID    = ID.RandomID;
            string testValue = "Test";

            RestCall.RequestTimeout = 1;
            RpcError error = p2.Store(c1, testID, testValue);

            System.Threading.Thread.Sleep(10);

            Assert.IsTrue(error.TimeoutError, "Expected timeout.");
        }
コード例 #3
0
        public void StoreRouteTest()
        {
            TcpSubnetProtocol p1 = new TcpSubnetProtocol(localIP, port, 1);
            TcpSubnetProtocol p2 = new TcpSubnetProtocol(localIP, port, 2);
            ID      ourID        = ID.RandomID;
            Contact c1           = new Contact(p1, ourID);
            Node    n1           = new Node(c1, new VirtualStorage());
            Node    n2           = new Node(new Contact(p2, ID.RandomID), new VirtualStorage());

            server.RegisterProtocol(p1.Subnet, n1);
            server.RegisterProtocol(p2.Subnet, n2);
            server.Start();

            Contact sender    = new Contact(p1, ID.RandomID);
            ID      testID    = ID.RandomID;
            string  testValue = "Test";

            p2.Store(sender, testID, testValue);
            Assert.IsTrue(n2.Storage.Contains(testID), "Expected remote peer to have value.");
            Assert.IsTrue(n2.Storage.Get(testID) == testValue, "Expected remote peer to contain stored value.");
        }