Browse Source
Still lacks an outbound bandwidth limiter and outbound actual emission bitrate, to avoid increasing the available bandwidth when the bandwidth is not saturated.master
10 changed files with 188 additions and 6 deletions
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
#include "congestion_control.hpp" |
||||
#include "VpnPeer.hpp" |
||||
|
||||
CongestionController::CongestionController(const VpnPeer& peer): |
||||
_peer(peer) |
||||
{ |
||||
_last_seqno = _peer.get_loss_logger().get_cur_seqno(); |
||||
_loss_based.bandwidth = 3e5; // 300kBps seems a good value to start with
|
||||
} |
||||
|
||||
void CongestionController::update_lossbased() { |
||||
const VpnPeer::LossReports& loss_rep = _peer.get_loss_reports(); |
||||
|
||||
uint32_t delta_seqno = loss_rep.last_seqno - loss_rep.prev_seqno; |
||||
unsigned int delta_losses = loss_rep.last_losses - loss_rep.prev_losses; |
||||
|
||||
double loss_rate = (double)delta_losses / (double)delta_seqno; |
||||
|
||||
if(loss_rate < 0.02) // FIXME only if the bandwidth is used
|
||||
_loss_based.bandwidth *= 1.05; |
||||
else if(loss_rate >= 0.1) |
||||
_loss_based.bandwidth *= (1 - 0.5 * loss_rate); |
||||
} |
||||
|
||||
uint64_t CongestionController::get_bandwidth() const { |
||||
return _loss_based.bandwidth; |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
#pragma once |
||||
#include <stdint.h> |
||||
|
||||
class VpnPeer; |
||||
|
||||
class CongestionController { |
||||
public: |
||||
struct LossBased { |
||||
uint64_t bandwidth; // bytes per second
|
||||
}; |
||||
|
||||
CongestionController(const VpnPeer& peer); |
||||
|
||||
const VpnPeer& get_peer() const { return _peer; } |
||||
|
||||
void update_lossbased(); |
||||
|
||||
uint64_t get_bandwidth() const; |
||||
uint64_t get_lossbased_bandwidth() const { |
||||
return _loss_based.bandwidth; } |
||||
|
||||
private: |
||||
const VpnPeer& _peer; |
||||
|
||||
LossBased _loss_based; |
||||
uint32_t _last_seqno; // seqno at the last update time
|
||||
}; |
||||
|
Loading…
Reference in new issue