コード例 #1
0
        public int Compare(object x, object y)
        {
            if (x == y)
            {
                //This is trivial, but we need to deal with it:
                return(0);
            }
            NodeRankInformation x1 = (NodeRankInformation)x;
            NodeRankInformation y1 = (NodeRankInformation)y;

            if (x1.Equals(y1) && x1.Count == y1.Count)
            {
                /*
                 * Since each Address is in our list at most once,
                 * this is an Error, so lets print it out and hope
                 * someone sees it.
                 */
                return(0);
            }
            else if (x1.Count <= y1.Count)
            {
                return(1);
            }
            else if (x1.Count > y1.Count)
            {
                return(-1);
            }
            return(-1);
        }
コード例 #2
0
        override public bool Equals(Object other)
        {
            if (Object.ReferenceEquals(other, this))
            {
                return(true);
            }

            NodeRankInformation other1 = other as NodeRankInformation;

            if (Object.ReferenceEquals(other1, null))
            {
                return(false);
            }
            else if (_addr.Equals(other1.Addr))
            {
                return(true);
            }
            return(false);
        }
コード例 #3
0
        public void Increment(Address dest)
        {
            // Sample every 1 / SAMPLE_SIZE
            if (_rand.Next(SAMPLE_SIZE) != 0)
            {
                return;
            }


            lock (_sync) {
                NodeRankInformation node_rank =
                    (NodeRankInformation)_dest_to_node_rank[dest];
                if (node_rank == null)
                {
                    node_rank = new NodeRankInformation(dest);
                    _node_rank_list.Add(node_rank);
                    _dest_to_node_rank[dest] = node_rank;
                }
                // Increment by SAMPLE_SIZE
                node_rank.Count += SAMPLE_SIZE;
            }
        }
コード例 #4
0
    public void Increment(Address dest) {
      // Sample every 1 / SAMPLE_SIZE
      if( _rand.Next(SAMPLE_SIZE) != 0 ) {
        return;
      }


      lock(_sync) {
        NodeRankInformation node_rank =
          (NodeRankInformation) _dest_to_node_rank[dest];
        if( node_rank == null ) {
          node_rank = new NodeRankInformation(dest);
          _node_rank_list.Add( node_rank );
          _dest_to_node_rank[dest] = node_rank;
        }
        // Increment by SAMPLE_SIZE
        node_rank.Count += SAMPLE_SIZE;
      }
    }
コード例 #5
0
        /**
         * On every activation, the ChotaConnectionOverlord trims any connections
         * that are unused, and also creates any new connections of needed
         */
        override public void Activate()
        {
            if (!_active)
            {
                return;
            }

            ConnectionList cons = _node.ConnectionTable.GetConnections(Connection.StringToMainType(struc_chota));

            // Trim and add OUTSIDE of the lock!
            List <Edge>    to_trim = new List <Edge>();
            List <Address> to_add  = new List <Address>();

            lock (_sync) {
                _node_rank_list.Sort(_cmp);
                // Find the guys to trim....
                for (int i = _node_rank_list.Count - 1; i >= MAX_CHOTA && i > 0; i--)
                {
                    NodeRankInformation node_rank = (NodeRankInformation)_node_rank_list[i];
                    // Must remove from _dest_to_node_rank to prevent memory leak
                    _dest_to_node_rank.Remove(node_rank.Addr);
                    // Now check to see if ChotaCO owns this connections and add to_trim if it does
                    int idx = cons.IndexOf(node_rank.Addr);
                    if (idx >= 0 && cons[idx].ConType.Equals(struc_chota))
                    {
                        to_trim.Add(cons[idx].Edge);
                    }
                }

                // Don't keep around stale state
                if (_node_rank_list.Count > MAX_CHOTA)
                {
                    _node_rank_list.RemoveRange(MAX_CHOTA, _node_rank_list.Count - MAX_CHOTA);
                }

                // Find guys to connect to!
                for (int i = 0; i < _node_rank_list.Count && i < MAX_CHOTA; i++)
                {
                    //we are traversing the list in descending order of
                    NodeRankInformation node_rank = (NodeRankInformation)_node_rank_list[i];
                    if (node_rank.Count < MIN_SCORE_THRESHOLD)
                    {
                        //too low score to create a connection
                        continue;
                    }
                    else if (cons.IndexOf(node_rank.Addr) >= 0)
                    {
                        // already have a connection to that node!
                        continue;
                    }
                    to_add.Add(node_rank.Addr);
                }
            }

            foreach (Edge e in to_trim)
            {
                _node.GracefullyClose(e, "From Chota, low score trim.");
            }

            foreach (Address addr in to_add)
            {
                ConnectTo(addr, struc_chota);
            }
        }