Ejemplo n.º 1
0
        public IntKadNetwork CreateIntKadNetwork()
        {
            var result = new IntKadNetwork();

            IntKadNode node2 = result.Add(2);
            IntKadNode node3 = result.Add(3);
            IntKadNode node4 = result.Add(4);

            // all nodes knows about all others
            for (int i = 0; i < result.Count; i++)
            {
                for (int j = 0; j < result.Count; j++)
                {
                    if (j != i)
                    {
                        result[i].KadCore.RoutingTable.Add(result[j].KadCore.NodeIdentifier);
                    }
                }
            }

            // add node 5 only connected with node 2
            IntKadNode node5 = result.Add(5);

            node3.KadCore.RoutingTable.Add(node5.KadCore.NodeIdentifier);
            node5.KadCore.RoutingTable.Add(node3.KadCore.NodeIdentifier);

            return(result);
        }
Ejemplo n.º 2
0
        public void node_lookup_returns_all_nodes_in_network(int nodeKey, IEnumerable <int> expectedResult)
        {
            IntKadNetwork network = CreateIntKadNetwork();
            IntKadNode    node1   = network[0];

            IEnumerable <int> result = node1.KadCore.NodeLookUp(nodeKey).Select(n => n.NodeId);

            CollectionAssert.AreEquivalent(expectedResult, result);
        }
        public void knows_other_nodes_after_joining_the_network()
        {
            IntKadNetwork network = CreateIntKadNetwork();
            IntKadNode    node1   = network[0];
            IntKadNode    node2   = network[1];

            IntKadNode extraNode = network.ExtraNode;

            // join extra node to the network
            extraNode.JoinToNetwork(new[] { node1.KadCore.NodeIdentifier, node2.KadCore.NodeIdentifier });

            CollectionAssert.Contains(extraNode.KadCore.RoutingTable, node1.KadCore.NodeIdentifier);
            CollectionAssert.Contains(extraNode.KadCore.RoutingTable, node2.KadCore.NodeIdentifier);
        }
        public virtual void find_value_after_joining_the_network(int key, String value)
        {
            IntKadNetwork network = CreateIntKadNetwork();
            IntKadNode    node1   = network[0];
            IntKadNode    node2   = network[1];

            IntKadNode extraNode = network.ExtraNode;

            // store a value
            node1.Store(key, value, node2.KadCore.NodeIdentifier);
            // join extra node to the network
            extraNode.JoinToNetwork(new[] { node1.KadCore.NodeIdentifier, node2.KadCore.NodeIdentifier });

            // the value should exist now
            string result = extraNode.KadCore.ValueLookUp(key);

            Assert.NotNull(result);
            Assert.AreEqual(value, result);
        }
        public override KadNetwork <int, string, IntKadNode> CreateKadNetwork()
        {
            var result = new IntKadNetwork();

            IntKadNode node1 = result.Add(2);
            IntKadNode node2 = result.Add(3);
            IntKadNode node3 = result.Add(4);
            IntKadNode node4 = result.Add(5);

            // all nodes knows about all others
            for (int i = 0; i < result.Count; i++)
            {
                for (int j = 0; j < result.Count; j++)
                {
                    if (j != i)
                    {
                        result[i].KadCore.RoutingTable.Add(result[j].KadCore.NodeIdentifier);
                    }
                }
            }

            return(result);
        }