diff --git a/congestion_control.cpp b/congestion_control.cpp index 89c70e7..e3f9225 100644 --- a/congestion_control.cpp +++ b/congestion_control.cpp @@ -7,7 +7,9 @@ CongestionController::CongestionController(const VpnPeer& peer): _last_seqno = _peer.get_loss_logger().get_cur_seqno(); _loss_based.bandwidth = 3e5; // 300kBps seems a good value to start with _loss_based.prev_tot_sent = _peer.get_tot_bytes_sent(); - _loss_based.prev_time = std::chrono::steady_clock::now(); + _last_bucket_update = _loss_based.prev_time = + std::chrono::steady_clock::now(); + update_params(); } void CongestionController::update_lossbased() { @@ -35,8 +37,12 @@ void CongestionController::update_lossbased() { } else if(loss_rate >= 0.1) _loss_based.bandwidth *= (1 - 0.5 * loss_rate); + + update_params(); } -uint64_t CongestionController::get_bandwidth() const { - return _loss_based.bandwidth; +void CongestionController::update_params() { + _bandwidth = _loss_based.bandwidth; // meant to integrate other controllers + _bucket_max_level = _bandwidth * _peer.get_rtt().avg_rtt(); + _bucket_level = std::min(_bucket_level, _bucket_max_level); } diff --git a/congestion_control.hpp b/congestion_control.hpp index ca8d9a5..63de53e 100644 --- a/congestion_control.hpp +++ b/congestion_control.hpp @@ -18,14 +18,22 @@ class CongestionController { void update_lossbased(); - uint64_t get_bandwidth() const; + uint64_t get_bandwidth() const { return _bandwidth; } uint64_t get_lossbased_bandwidth() const { return _loss_based.bandwidth; } + private: // meth + void update_params(); ///< called after an update + private: const VpnPeer& _peer; LossBased _loss_based; + uint64_t _bandwidth; // Bps uint32_t _last_seqno; // seqno at the last update time + + uint64_t _bucket_level, ///< implements a leaky bucket + _bucket_max_level; // bandwidth * RTT + std::chrono::steady_clock::time_point _last_bucket_update; };