Esempio n. 1
0
        public void AddSame()
        {
            table.Clear();
            for (int i = 0; i < Bucket.MaxCapacity; i++)
            {
                byte[] id = (byte[])this.id.Clone();
                table.Add(new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0)));
            }

            Assert.AreEqual(1, addedCount, "#a");
            Assert.AreEqual(1, table.Buckets.Count, "#1");
            Assert.AreEqual(1, table.Buckets[0].Nodes.Count, "#2");

            CheckBuckets();
        }
        internal static void ManyNodes(out RoutingTable routingTable, out List <NodeId> nodes)
        {
            // Generate our local id
            byte[] id = new byte[20];
            id[19] = 7;

            nodes = new List <NodeId>();
            RoutingTable table = new RoutingTable(new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0)));

            for (int i = 0; i <= 30; i++)
            {
                if (i == 7)
                {
                    continue;
                }

                id     = new byte[20];
                id[19] = (byte)i;
                nodes.Add(new NodeId(id));
                table.Add(new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0)));
            }

            nodes.Sort(delegate(NodeId left, NodeId right)
            {
                NodeId dLeft  = left.Xor(table.LocalNode.Id);
                NodeId dRight = right.Xor(table.LocalNode.Id);
                return(dLeft.CompareTo(dRight));
            });

            nodes.RemoveAll(delegate(NodeId n) { return(table.FindNode(n) == null); });
            routingTable = table;
        }
Esempio n. 3
0
 public void Setup()
 {
     id               = new byte[20];
     id[1]            = 128;
     n                = new Node(new NodeId(id), new System.Net.IPEndPoint(IPAddress.Any, 0));
     table            = new RoutingTable(n);
     table.NodeAdded += delegate { addedCount++; };
     table.Add(n);//the local node is no more in routing table so add it to show test is still ok
     addedCount = 0;
 }