takes IP and TCP headers into account for rate limits as well
This commit is contained in:
parent
e09457e4ab
commit
f7ef315438
|
@ -143,16 +143,21 @@ namespace libtorrent
|
|||
// calculate ip protocol overhead
|
||||
void calc_ip_overhead()
|
||||
{
|
||||
// traffic balance is the number of bytes we downloaded
|
||||
// more than we uploaded
|
||||
int traffic_balance = m_stat[download_protocol].counter()
|
||||
+ m_stat[download_payload].counter()
|
||||
- m_stat[upload_protocol].counter()
|
||||
- m_stat[upload_payload].counter();
|
||||
if (traffic_balance > 0)
|
||||
m_stat[upload_ip_protocol].add(traffic_balance / 20);
|
||||
else
|
||||
m_stat[download_ip_protocol].add(-traffic_balance / 20);
|
||||
int uploaded = m_stat[upload_protocol].counter()
|
||||
+ m_stat[upload_payload].counter();
|
||||
int downloaded = m_stat[download_protocol].counter()
|
||||
+ m_stat[download_payload].counter();
|
||||
|
||||
// IP + TCP headers are 40 bytes per MTU (1460)
|
||||
// bytes of payload, but at least 40 bytes
|
||||
m_stat[upload_ip_protocol].add((std::max)(uploaded / 1460, 40));
|
||||
m_stat[download_ip_protocol].add((std::max)(downloaded / 1460, 40));
|
||||
|
||||
// also account for ACK traffic. That adds to the transfers
|
||||
// in the opposite direction. Even on connections with symmetric
|
||||
// transfer rates, it seems to add a penalty.
|
||||
m_stat[upload_ip_protocol].add((std::max)(downloaded / 20, 40));
|
||||
m_stat[download_ip_protocol].add((std::max)(uploaded / 20, 40));
|
||||
}
|
||||
|
||||
int upload_ip_overhead() const { return m_stat[upload_ip_protocol].counter(); }
|
||||
|
|
Loading…
Reference in New Issue