|
|
|
|
|
|
|
|
// limit for now... |
|
|
// limit for now... |
|
|
static const unsigned MAXIMUM_WINDOW = 4194304; |
|
|
static const unsigned MAXIMUM_WINDOW = 4194304; |
|
|
|
|
|
|
|
|
|
|
|
// Compare position even when wrapped around |
|
|
|
|
|
static inline bool isAfter(unsigned a, unsigned b) { |
|
|
|
|
|
return (int)a - (int)b > 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static LogWriter vlog("Congestion"); |
|
|
static LogWriter vlog("Congestion"); |
|
|
|
|
|
|
|
|
Congestion::Congestion() : |
|
|
Congestion::Congestion() : |
|
|
|
|
|
|
|
|
targetAcked = lastPosition - congWindow; |
|
|
targetAcked = lastPosition - congWindow; |
|
|
|
|
|
|
|
|
// Simple case? |
|
|
// Simple case? |
|
|
if (lastPong.pos > targetAcked) |
|
|
|
|
|
|
|
|
if (isAfter(lastPong.pos, targetAcked)) |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
// No measurements yet? |
|
|
// No measurements yet? |
|
|
|
|
|
|
|
|
etaNext -= delay; |
|
|
etaNext -= delay; |
|
|
|
|
|
|
|
|
// Found it? |
|
|
// Found it? |
|
|
if (curPing.pos > targetAcked) { |
|
|
|
|
|
|
|
|
if (isAfter(curPing.pos, targetAcked)) { |
|
|
eta += etaNext * (curPing.pos - targetAcked) / (curPing.pos - prevPing->pos); |
|
|
eta += etaNext * (curPing.pos - targetAcked) / (curPing.pos - prevPing->pos); |
|
|
if (elapsed > eta) |
|
|
if (elapsed > eta) |
|
|
return 0; |
|
|
return 0; |