Example #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.");
        }
Example #2
0
 /// <summary>
 /// Color the originator with yellow
 /// the immediate peer we're storing the value to in blue
 /// and the peers to which the value is republished in orange:
 /// </summary>
 private void btnPublish_Click(object sender, EventArgs e)
 {
     firstContacts = new List<Dht>();
     storeKey = ID.RandomID;
     originatorDht = dhts[(int)nudPeerNumber.Value];
     originatorDht.Store(storeKey, "Test");
     System.Threading.Thread.Sleep(500);
     dhts.Where(d => d.RepublishStorage.Contains(storeKey)).ForEach(d => firstContacts.Add(d));
     UpdatePeerColors();
     DrawDhts();
 }
Example #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");
        }
Example #4
0
 private void btnStore_Click(object sender, EventArgs e)
 {
     dht.Store(ID.FromString(tbStoreKey.Text), tbStoreValue.Text);
 }