Beispiel #1
0
        public void ParallelValueStoredGetsPropagatedTest()
        {
            VirtualProtocol vp1    = new VirtualProtocol();
            VirtualProtocol vp2    = new VirtualProtocol();
            VirtualStorage  store1 = new VirtualStorage();
            VirtualStorage  store2 = new VirtualStorage();

            // Ensures that all nodes are closer, because ID.Max ^ n < ID.Max when n > 0.
            Dht dht = new Dht(ID.Max, vp1, new ParallelRouter(), store1, store1, new VirtualStorage());

            vp1.Node = dht.Router.Node;

            ID      contactID    = ID.Mid; // a closer contact.
            Contact otherContact = new Contact(vp2, contactID);
            Node    otherNode    = new Node(otherContact, store2);

            vp2.Node = otherNode;

            // Add this other contact to our peer list.
            dht.Router.Node.BucketList.AddContact(otherContact);

            // We want an integer distance, not an XOR distance.
            ID     key = ID.Zero;
            string val = "Test";

            Assert.IsFalse(store1.Contains(key), "Obviously we don't have the key-value yet.");
            Assert.IsFalse(store2.Contains(key), "And equally obvious, the other peer doesn't have the key-value yet either.");

            dht.Store(key, val);

            Assert.IsTrue(store1.Contains(key), "Expected our peer to have stored the key-value.");
            Assert.IsTrue(store2.Contains(key), "Expected the other peer to have stored the key-value.");
        }
Beispiel #2
0
        public void DhtSerializationTest()
        {
            TcpSubnetProtocol p1     = new TcpSubnetProtocol("http://127.0.0.1", 2720, 1);
            TcpSubnetProtocol p2     = new TcpSubnetProtocol("http://127.0.0.1", 2720, 2);
            VirtualStorage    store1 = new VirtualStorage();
            VirtualStorage    store2 = new VirtualStorage();

            // Ensures that all nodes are closer, because ID.Max ^ n < ID.Max when n > 0.
            Dht dht = new Dht(ID.Max, p1, new Router(), store1, store1, new VirtualStorage());

            ID      contactID    = ID.Mid; // a closer contact.
            Contact otherContact = new Contact(p2, contactID);
            Node    otherNode    = new Node(otherContact, store2);

            // Add this other contact to our peer list.
            dht.Node.BucketList.AddContact(otherContact);

            string json = dht.Save();

            Dht newDht = Dht.Load(json);

            Assert.IsTrue(newDht.Node.BucketList.Buckets.Sum(b => b.Contacts.Count) == 1, "Expected our node to have 1 contact.");
            Assert.IsTrue(newDht.Node.BucketList.ContactExists(otherContact), "Expected our contact to have the other contact.");
            Assert.IsTrue(newDht.Router.Node == newDht.Node, "Router node not initialized.");
        }
Beispiel #3
0
        public void ParallelGetValuePropagatesToCloserNodeTest()
        {
            VirtualProtocol vp1    = new VirtualProtocol();
            VirtualProtocol vp2    = new VirtualProtocol();
            VirtualProtocol vp3    = new VirtualProtocol();
            VirtualStorage  store1 = new VirtualStorage();
            VirtualStorage  store2 = new VirtualStorage();
            VirtualStorage  store3 = new VirtualStorage();
            VirtualStorage  cache3 = new VirtualStorage();

            // Ensures that all nodes are closer, because ID.Max ^ n < ID.Max when n > 0.
            Dht dht = new Dht(ID.Max, vp1, new ParallelRouter(), store1, store1, new VirtualStorage());

            vp1.Node = dht.Router.Node;

            // Setup node 2:

            ID      contactID2    = ID.Mid; // a closer contact.
            Contact otherContact2 = new Contact(vp2, contactID2);
            Node    otherNode2    = new Node(otherContact2, store2);

            vp2.Node = otherNode2;

            // Add the second contact to our peer list.
            dht.Router.Node.BucketList.AddContact(otherContact2);

            // Node 2 has the value.
            // We want an integer distance, not an XOR distance.
            ID     key = ID.Zero;
            string val = "Test";

            otherNode2.Storage.Set(key, val);

            // Setup node 3:

            ID      contactID3    = ID.Zero.SetBit(158); // 01000.... -- a farther contact.
            Contact otherContact3 = new Contact(vp3, contactID3);
            Node    otherNode3    = new Node(otherContact3, store3, cache3);

            vp3.Node = otherNode3;

            // Add the third contact to our peer list.
            dht.Router.Node.BucketList.AddContact(otherContact3);

            Assert.IsFalse(store1.Contains(key), "Obviously we don't have the key-value yet.");
            Assert.IsFalse(store3.Contains(key), "And equally obvious, the third peer doesn't have the key-value yet either.");

            var ret = dht.FindValue(key);

            Assert.IsTrue(ret.found, "Expected value to be found.");
            Assert.IsFalse(store3.Contains(key), "Key should not be in the republish store.");
            Assert.IsTrue(cache3.Contains(key), "Key should be in the cache store.");
            Assert.IsTrue(cache3.GetExpirationTimeSec(key.Value) == Constants.EXPIRATION_TIME_SECONDS / 2, "Expected 12 hour expiration.");
        }
Beispiel #4
0
        public void ParallelValueStoredInFartherNodeTest()
        {
            VirtualProtocol vp1    = new VirtualProtocol();
            VirtualProtocol vp2    = new VirtualProtocol();
            VirtualStorage  store1 = new VirtualStorage();
            VirtualStorage  store2 = new VirtualStorage();

            // Ensures that all nodes are closer, because ID.Max ^ n < ID.Max when n > 0.
            Dht dht = new Dht(ID.Zero, vp1, new ParallelRouter(), store1, store1, new VirtualStorage());

            vp1.Node = dht.Router.Node;

            ID      contactID    = ID.Max; // a farther contact.
            Contact otherContact = new Contact(vp2, contactID);
            Node    otherNode    = new Node(otherContact, store2);

            vp2.Node = otherNode;

            // Add this other contact to our peer list.
            dht.Router.Node.BucketList.AddContact(otherContact);

            // We want an integer distance, not an XOR distance.
            ID key = ID.One;

            // Set the value in the other node, to be discovered by the lookup process.
            string val = "Test";

            otherNode.SimpleStore(key, val);

            Assert.IsFalse(store1.Contains(key), "Expected our peer to NOT have cached the key-value.");
            Assert.IsTrue(store2.Contains(key), "Expected other node to HAVE cached the key-value.");

            // Try and find the value, given our Dht knows about the other contact.
            string retval = dht.FindValue(key).val;

            Assert.IsTrue(retval == val, "Expected to get back what we stored");
        }