public StructuredConnectionOverlord(Node n)
    {
      _sync = new Object();
      lock( _sync ) {
        _node = n;
        _rand = new Random();
        _connectors = new Hashtable();
        _last_connection_time = DateTime.UtcNow;
      /**
       * Every heartbeat we assess the trimming situation.
       * If we have excess edges and it has been more than
       * _trim_wait_time heartbeats then we trim.
       */
        _last_retry_time = DateTime.UtcNow;
        _current_retry_interval = _DEFAULT_RETRY_INTERVAL;

        /**
         * Information related to the target selector feature.
         * Includes statistics such as trim rate and connection lifetimes.
         */
        
        _target_selector = new DefaultTargetSelector();
        _last_optimize_time = DateTime.UtcNow;
        _sum_con_lifetime = 0.0;
        _start_time = DateTime.UtcNow;
        _trim_count = 0;

        
        /*
         * Register event handlers after everything else is set
         */
        //Listen for connection events:
        _node.ConnectionTable.DisconnectionEvent +=
          new EventHandler(this.DisconnectHandler);
        _node.ConnectionTable.ConnectionEvent +=
          new EventHandler(this.ConnectHandler);     
        _node.ConnectionTable.StatusChangedEvent += 
          new EventHandler(this.StatusChangedHandler);
        
        _node.HeartBeatEvent += new EventHandler(this.CheckState);
        _node.HeartBeatEvent += new EventHandler(this.CheckConnectionOptimality);
      }
    }
示例#2
0
    public void Test() {
      RandomNumberGenerator rng = new RNGCryptoServiceProvider();
      TargetSelector ts = new DefaultTargetSelector();
      //in this case we set the current to an address in our list
      for (int i = 0; i < _addr_list.Length; i++ ) {
        AHAddress tmp_addr = new AHAddress(rng);
        _addr_list[i] = tmp_addr;
      }
      _idx = 0;
      for (int i = 0; i < _addr_list.Length; i++ ) {
        ts.ComputeCandidates(new AHAddress(rng), 10, TargetSelectorCallback, _addr_list[i]);
      }

      //in this case we set the current address to null
      for (int i = 0; i < _addr_list.Length; i++ ) {
        AHAddress tmp_addr = new AHAddress(rng);
        _addr_list[i] = tmp_addr;
      }
      _idx = 0;
      for (int i = 0; i < _addr_list.Length; i++ ) {
        ts.ComputeCandidates(_addr_list[i], 10, TargetSelectorCallback, null);
      }
    }