congestvpn/congestion_control.hpp

40 lines
1.1 KiB
C++

#pragma once
#include <stdint.h>
#include <chrono>
class VpnPeer;
class CongestionController {
public:
struct LossBased {
uint64_t bandwidth; // bytes per second
uint64_t prev_tot_sent; // tot bytes sent during last update
std::chrono::steady_clock::time_point prev_time; // last update time
};
CongestionController(const VpnPeer& peer);
const VpnPeer& get_peer() const { return _peer; }
void update_lossbased();
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;
};