Brunet.Symphony.StructuredShortcutConnectionOverlord.CheckShortcutCallback C# (CSharp) Метод

CheckShortcutCallback() защищенный Метод

protected CheckShortcutCallback ( Address random_target, SortedList score_table, Address sc_address ) : void
random_target Address
score_table System.Collections.SortedList
sc_address Address
Результат void
    protected void CheckShortcutCallback(Address random_target, SortedList score_table, Address sc_address) {
#if TRACE
      if (ProtocolLog.SCO.Enabled) {
        ProtocolLog.Write(ProtocolLog.SCO, 
                          String.Format("SCO local: {0}, Checking shortcut optimality: {1}.", 
                                _node.Address, sc_address));
      }
#endif
      
      int max_rank = (int) Math.Ceiling(0.2*score_table.Count);
      if (!IsConnectionOptimal(sc_address, score_table, max_rank)) {
        Address min_target = (Address) score_table.GetByIndex(0);
        //find the connection and trim it.
        Connection to_trim = null;
        foreach(Connection c in _node.ConnectionTable.GetConnections(STRUC_SHORT) ) {
          string token = c.State.PeerLinkMessage.Token;
          if (token == null || token == String.Empty) {
            continue;
          }

          // First half of the token should be the connection initiator
          string initiator_address = token.Substring(0, token.Length/2);
          if (initiator_address == _node.Address.ToString() && c.Address.Equals(sc_address)) {
            to_trim = c;
            break;
          }
        }
        
        if (to_trim != null) {
#if TRACE
          if (ProtocolLog.SCO.Enabled) {
            ProtocolLog.Write(ProtocolLog.SCO, 
                              String.Format("SCO local: {0}, Trimming shortcut : {1}, min_target: {2}.",
                                            _node.Address, to_trim.Address, min_target));
          }
#endif
          lock(_sync) {
            double total_secs = (DateTime.UtcNow - to_trim.CreationTime).TotalSeconds;
            _sum_con_lifetime += total_secs;
            _trim_count++;
          }
          to_trim.Close(_node.Rpc, String.Empty);
        }
      } else {
#if TRACE
        if (ProtocolLog.SCO.Enabled) {
          ProtocolLog.Write(ProtocolLog.SCO,
                            String.Format("SCO local: {0}, Shortcut is optimal: {1}.", 
                                          _node.Address, sc_address));
        }
#endif
      }
    }