예제 #1
0
        public void AddSame()
        {
            _table.Clear();
            for (int i = 0; i < Config.MaxBucketCapacity; i++)
            {
                byte[] id = (byte[])_id.Clone();
                _table.Add(new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0)));
            }

            Assert.Equal(1, _addedCount);
            Assert.Equal(1, _table.Buckets.Count);
            Assert.Equal(1, _table.Buckets[0].Nodes.Count);

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

            nodes = new List <NodeId>();
            RoutingTable.RoutingTable table = new RoutingTable.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(n => table.FindNode(n) == null);
            routingTable = table;
        }
예제 #3
0
 public RoutingTableTests()
 {
     _id               = new byte[20];
     _id[1]            = 128;
     _n                = new Node(new NodeId(_id), new IPEndPoint(IPAddress.Any, 0));
     _table            = new RoutingTable.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;
 }