Libtorrent setting download_limit/upload_limit is not working

馋奶兔 提交于 2019-12-11 07:34:42

问题


I want to rate limit my download/upload speed in my libtorrent client. I am using the following code for this.

params = { 'save_path': '.', \
           'storage_mode': lt.storage_mode_t.storage_mode_sparse, \
           'ti': info, 'flags': 0x020 }

h = ses.add_torrent(params)
h.set_download_limit(100)
h.set_upload_limit(100)
h.resume()

It should download the data at 0.1 kb/sec, but still it is downloading the data at the speed of around 1500 kb/sec.

100.00% complete (down: 1576.0 kb/s up: 55.0 kB/s)

Anything I am missing ?


回答1:


Perhaps your peers are on the same local network as yourself. By default, local peers are not subject to the rate limit (as documented here).

Unfortunately the documentation on how to make rate limits apply to local peers is a bit lacking. I've tried to remedy that in this pull request.

Basically, to make the global rate limit apply to all peers, regardless of which IP they have, do this:

std::uint32_t const mask = 1 << lt::session::global_peer_class_id;
ip_filter f;

// for every IPv4 address, assign the global peer class
f.add_rule(address_v4::from_string("0.0.0.0")
    , address_v4::from_string("255.255.255.255")
    , mask);

// for every IPv6 address, assign the global peer class
f.add_rule(address_v6::from_string("::")
    , address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
    , mask);
ses.set_peer_class_filter(f);


来源:https://stackoverflow.com/questions/43045564/libtorrent-setting-download-limit-upload-limit-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!