From f7ef315438a234c1324c96fd871c9be890542c87 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 6 May 2008 16:15:31 +0000 Subject: [PATCH] takes IP and TCP headers into account for rate limits as well --- include/libtorrent/stat.hpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 84daec3af..64ef64af0 100755 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -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(); }