tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

alr_detector.h (2637B)


      1 /*
      2 *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_ALR_DETECTOR_H_
     12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_ALR_DETECTOR_H_
     13 
     14 #include <optional>
     15 
     16 #include "api/environment/environment.h"
     17 #include "api/field_trials_view.h"
     18 #include "api/units/data_rate.h"
     19 #include "api/units/data_size.h"
     20 #include "api/units/timestamp.h"
     21 #include "modules/pacing/interval_budget.h"
     22 
     23 namespace webrtc {
     24 
     25 // Application limited region detector is a class that utilizes signals of
     26 // elapsed time and bytes sent to estimate whether network traffic is
     27 // currently limited by the application's ability to generate traffic.
     28 //
     29 // AlrDetector provides a signal that can be utilized to adjust
     30 // estimate bandwidth.
     31 // Note: This class is not thread-safe.
     32 class AlrDetector {
     33 public:
     34  explicit AlrDetector(const Environment& env);
     35 
     36  AlrDetector(const AlrDetector&) = delete;
     37  AlrDetector& operator=(const AlrDetector&) = delete;
     38 
     39  ~AlrDetector();
     40 
     41  void OnBytesSent(DataSize bytes_sent, Timestamp send_time);
     42 
     43  // Set current estimated bandwidth.
     44  void SetEstimatedBitrate(DataRate bitrate);
     45 
     46  // Returns time when the current application-limited region started or empty
     47  // result if the sender is currently not application-limited.
     48  std::optional<Timestamp> GetApplicationLimitedRegionStartTime() const;
     49 
     50 private:
     51  friend class GoogCcStatePrinter;
     52  struct AlrDetectorConfig {
     53    explicit AlrDetectorConfig(const FieldTrialsView& key_value_config);
     54 
     55    // Sent traffic ratio as a function of network capacity used to determine
     56    // application-limited region. ALR region start when bandwidth usage drops
     57    // below kAlrStartUsageRatio and ends when it raises above
     58    // kAlrEndUsageRatio. NOTE: This is intentionally conservative at the moment
     59    // until BW adjustments of application limited region is fine tuned.
     60    double bandwidth_usage_ratio = 0.65;
     61    double start_budget_level_ratio = 0.80;
     62    double stop_budget_level_ratio = 0.50;
     63  };
     64 
     65  const Environment env_;
     66  const AlrDetectorConfig conf_;
     67 
     68  std::optional<Timestamp> last_send_time_;
     69 
     70  IntervalBudget alr_budget_;
     71  std::optional<Timestamp> alr_started_time_;
     72 };
     73 }  // namespace webrtc
     74 
     75 #endif  // MODULES_CONGESTION_CONTROLLER_GOOG_CC_ALR_DETECTOR_H_