takes IP and TCP headers into account for rate limits as well
This commit is contained in:
@@ -143,16 +143,21 @@ namespace libtorrent
|
|||||||
// calculate ip protocol overhead
|
// calculate ip protocol overhead
|
||||||
void calc_ip_overhead()
|
void calc_ip_overhead()
|
||||||
{
|
{
|
||||||
// traffic balance is the number of bytes we downloaded
|
int uploaded = m_stat[upload_protocol].counter()
|
||||||
// more than we uploaded
|
+ m_stat[upload_payload].counter();
|
||||||
int traffic_balance = m_stat[download_protocol].counter()
|
int downloaded = m_stat[download_protocol].counter()
|
||||||
+ m_stat[download_payload].counter()
|
+ m_stat[download_payload].counter();
|
||||||
- m_stat[upload_protocol].counter()
|
|
||||||
- m_stat[upload_payload].counter();
|
// IP + TCP headers are 40 bytes per MTU (1460)
|
||||||
if (traffic_balance > 0)
|
// bytes of payload, but at least 40 bytes
|
||||||
m_stat[upload_ip_protocol].add(traffic_balance / 20);
|
m_stat[upload_ip_protocol].add((std::max)(uploaded / 1460, 40));
|
||||||
else
|
m_stat[download_ip_protocol].add((std::max)(downloaded / 1460, 40));
|
||||||
m_stat[download_ip_protocol].add(-traffic_balance / 20);
|
|
||||||
|
// 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(); }
|
int upload_ip_overhead() const { return m_stat[upload_ip_protocol].counter(); }
|
||||||
|
Reference in New Issue
Block a user