tor-browser

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

inter_arrival_delta.h (3496B)


      1 /*
      2 *  Copyright (c) 2020 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_INTER_ARRIVAL_DELTA_H_
     12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_INTER_ARRIVAL_DELTA_H_
     13 
     14 #include <cstddef>
     15 
     16 #include "api/units/time_delta.h"
     17 #include "api/units/timestamp.h"
     18 
     19 namespace webrtc {
     20 
     21 // Helper class to compute the inter-arrival time delta and the size delta
     22 // between two send bursts. This code is branched from
     23 // modules/remote_bitrate_estimator/inter_arrival.
     24 class InterArrivalDelta {
     25 public:
     26  // After this many packet groups received out of order InterArrival will
     27  // reset, assuming that clocks have made a jump.
     28  static constexpr int kReorderedResetThreshold = 3;
     29  static constexpr TimeDelta kArrivalTimeOffsetThreshold =
     30      TimeDelta::Seconds(3);
     31 
     32  // A send time group is defined as all packets with a send time which are at
     33  // most send_time_group_length older than the first timestamp in that
     34  // group.
     35  explicit InterArrivalDelta(TimeDelta send_time_group_length);
     36 
     37  InterArrivalDelta() = delete;
     38  InterArrivalDelta(const InterArrivalDelta&) = delete;
     39  InterArrivalDelta& operator=(const InterArrivalDelta&) = delete;
     40 
     41  // This function returns true if a delta was computed, or false if the current
     42  // group is still incomplete or if only one group has been completed.
     43  // `send_time` is the send time.
     44  // `arrival_time` is the time at which the packet arrived.
     45  // `packet_size` is the size of the packet.
     46  // `timestamp_delta` (output) is the computed send time delta.
     47  // `arrival_time_delta` (output) is the computed arrival-time delta.
     48  // `packet_size_delta` (output) is the computed size delta.
     49  bool ComputeDeltas(Timestamp send_time,
     50                     Timestamp arrival_time,
     51                     Timestamp system_time,
     52                     size_t packet_size,
     53                     TimeDelta* send_time_delta,
     54                     TimeDelta* arrival_time_delta,
     55                     int* packet_size_delta);
     56 
     57 private:
     58  struct SendTimeGroup {
     59    SendTimeGroup()
     60        : size(0),
     61          first_send_time(Timestamp::MinusInfinity()),
     62          send_time(Timestamp::MinusInfinity()),
     63          first_arrival(Timestamp::MinusInfinity()),
     64          complete_time(Timestamp::MinusInfinity()),
     65          last_system_time(Timestamp::MinusInfinity()) {}
     66 
     67    bool IsFirstPacket() const { return complete_time.IsInfinite(); }
     68 
     69    size_t size;
     70    Timestamp first_send_time;
     71    Timestamp send_time;
     72    Timestamp first_arrival;
     73    Timestamp complete_time;
     74    Timestamp last_system_time;
     75  };
     76 
     77  // Returns true if the last packet was the end of the current batch and the
     78  // packet with `send_time` is the first of a new batch.
     79  bool NewTimestampGroup(Timestamp arrival_time, Timestamp send_time) const;
     80 
     81  bool BelongsToBurst(Timestamp arrival_time, Timestamp send_time) const;
     82 
     83  void Reset();
     84 
     85  const TimeDelta send_time_group_length_;
     86  SendTimeGroup current_timestamp_group_;
     87  SendTimeGroup prev_timestamp_group_;
     88  int num_consecutive_reordered_packets_;
     89 };
     90 }  // namespace webrtc
     91 
     92 #endif  // MODULES_CONGESTION_CONTROLLER_GOOG_CC_INTER_ARRIVAL_DELTA_H_