Libtorrent setting download_limit/upload_limit is

2019-08-14 20:59发布

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条回答
我只想做你的唯一
2楼-- · 2019-08-14 21:37

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);
查看更多
登录 后发表回答