Exemplo n.º 1
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.");
        }
Exemplo n.º 2
0
        private void btnRetrieve_Click(object sender, EventArgs e)
        {
            var ret = dht.FindValue(ID.FromString(tbRetrieveKey.Text));

            if (ret.found)
            {
                tbRetrieveValue.Text = ret.val;
            }
            else
            {
                tbRetrieveValue.Text = String.Empty;
                MessageBox.Show("Key not found", "No Results", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 3
0
        public void ParallelLocalStoreFoundValueTest()
        {
            VirtualProtocol vp  = new VirtualProtocol();
            Dht             dht = new Dht(ID.RandomID, vp, () => new VirtualStorage(), new ParallelRouter());

            vp.Node = dht.Router.Node;
            ID     key = ID.RandomID;
            string val = "Test";

            dht.Store(key, val);
            string retval = dht.FindValue(key).val;

            Assert.IsTrue(retval == val, "Expected to get back what we stored");
        }
Exemplo n.º 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");
        }