tor-browser

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

trendline_estimator.h (4191B)


      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 #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_TRENDLINE_ESTIMATOR_H_
     11 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_TRENDLINE_ESTIMATOR_H_
     12 
     13 #include <stddef.h>
     14 #include <stdint.h>
     15 
     16 #include <deque>
     17 #include <memory>
     18 
     19 #include "api/field_trials_view.h"
     20 #include "api/network_state_predictor.h"
     21 #include "api/transport/bandwidth_usage.h"
     22 #include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h"
     23 #include "rtc_base/experiments/struct_parameters_parser.h"
     24 
     25 namespace webrtc {
     26 
     27 struct TrendlineEstimatorSettings {
     28  static constexpr char kKey[] = "WebRTC-Bwe-TrendlineEstimatorSettings";
     29  static constexpr unsigned kDefaultTrendlineWindowSize = 20;
     30 
     31  TrendlineEstimatorSettings() = delete;
     32  explicit TrendlineEstimatorSettings(const FieldTrialsView& key_value_config);
     33 
     34  // Sort the packets in the window. Should be redundant,
     35  // but then almost no cost.
     36  bool enable_sort = false;
     37 
     38  // Cap the trendline slope based on the minimum delay seen
     39  // in the beginning_packets and end_packets respectively.
     40  bool enable_cap = false;
     41  unsigned beginning_packets = 7;
     42  unsigned end_packets = 7;
     43  double cap_uncertainty = 0.0;
     44 
     45  // Size (in packets) of the window.
     46  unsigned window_size = kDefaultTrendlineWindowSize;
     47 
     48  std::unique_ptr<StructParametersParser> Parser();
     49 };
     50 
     51 class TrendlineEstimator : public DelayIncreaseDetectorInterface {
     52 public:
     53  TrendlineEstimator(const FieldTrialsView& key_value_config,
     54                     NetworkStatePredictor* network_state_predictor);
     55 
     56  ~TrendlineEstimator() override;
     57 
     58  TrendlineEstimator(const TrendlineEstimator&) = delete;
     59  TrendlineEstimator& operator=(const TrendlineEstimator&) = delete;
     60 
     61  // Update the estimator with a new sample. The deltas should represent deltas
     62  // between timestamp groups as defined by the InterArrival class.
     63  void Update(double recv_delta_ms,
     64              double send_delta_ms,
     65              int64_t send_time_ms,
     66              int64_t arrival_time_ms,
     67              size_t packet_size,
     68              bool calculated_deltas) override;
     69 
     70  void UpdateTrendline(double recv_delta_ms,
     71                       double send_delta_ms,
     72                       int64_t send_time_ms,
     73                       int64_t arrival_time_ms,
     74                       size_t packet_size);
     75 
     76  BandwidthUsage State() const override;
     77 
     78  struct PacketTiming {
     79    PacketTiming(double arrival_time_ms,
     80                 double smoothed_delay_ms,
     81                 double raw_delay_ms)
     82        : arrival_time_ms(arrival_time_ms),
     83          smoothed_delay_ms(smoothed_delay_ms),
     84          raw_delay_ms(raw_delay_ms) {}
     85    double arrival_time_ms;
     86    double smoothed_delay_ms;
     87    double raw_delay_ms;
     88  };
     89 
     90 private:
     91  friend class GoogCcStatePrinter;
     92  void Detect(double trend, double ts_delta, int64_t now_ms);
     93 
     94  void UpdateThreshold(double modified_trend, int64_t now_ms);
     95 
     96  // Parameters.
     97  TrendlineEstimatorSettings settings_;
     98  const double smoothing_coef_;
     99  const double threshold_gain_;
    100  // Used by the existing threshold.
    101  int num_of_deltas_;
    102  // Keep the arrival times small by using the change from the first packet.
    103  int64_t first_arrival_time_ms_;
    104  // Exponential backoff filtering.
    105  double accumulated_delay_;
    106  double smoothed_delay_;
    107  // Linear least squares regression.
    108  std::deque<PacketTiming> delay_hist_;
    109 
    110  const double k_up_;
    111  const double k_down_;
    112  double overusing_time_threshold_;
    113  double threshold_;
    114  double prev_modified_trend_;
    115  int64_t last_update_ms_;
    116  double prev_trend_;
    117  double time_over_using_;
    118  int overuse_counter_;
    119  BandwidthUsage hypothesis_;
    120  BandwidthUsage hypothesis_predicted_;
    121  NetworkStatePredictor* network_state_predictor_;
    122 };
    123 }  // namespace webrtc
    124 
    125 #endif  // MODULES_CONGESTION_CONTROLLER_GOOG_CC_TRENDLINE_ESTIMATOR_H_