Ejemplo 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();
        }
Ejemplo n.º 2
0
        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 ^ table.LocalNode.Id;
                NodeId dRight = right ^ table.LocalNode.Id;
                return(dLeft.CompareTo(dRight));
            });

            nodes.RemoveAll(delegate(NodeId n) { return(table.FindNode(n) == null); });
            routingTable = table;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 public void Setup()
 {
     id    = new byte[20];
     id[1] = 128;
     n     = new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0));
     table = new RoutingTable(n);
     table.Add(n);
 }
Ejemplo n.º 5
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;
 }
 public RoutingTableTests()
 {
     id = new byte[20];
     id[1] = 128;
     n = new Node(new NodeId(id), new 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;
 }