c0re100 / qBittorrent-Enhanced-Edition

[Unofficial] qBittorrent Enhanced, based on qBittorrent
https://github.com/c0re100/qBittorrent-Enhanced-Edition
Other
18.64k stars 1.24k forks source link

limit uploaded size to downloaded torrent size for every peer #444

Closed Kolcha closed 1 year ago

Kolcha commented 1 year ago

implemented new libtorrent plugin to limit upload size per peer to torrent downloaded size. when peer tries to download more than that size - its address is banned (using libtorrent api) for current session. peer id and reported progress are not taken into account in any way, only amount of data uploaded to the peer. check is performed about every second (according to libtorrent documentation, and this looks true), it is very lightweight - just compare to integers, so it should not have a significant impact on performance. another commit included into this pr is just small refactoring - moved libtorrent versions compatibility stuff into its own file, and used it where it is required (not just a ramdom "common" place as it was before). not well tested, but added check seems not causing any issues with upload, and changing "allowed size" to for example 1 MB or 10 MB drops peers very quickly and they seems not appear anymore (at least until app restart). so, should be fine. but any testing is welcome. closes #432

escape0707 commented 1 year ago

Humm, not sure whether this is a good feature or not. For example sometimes I upload recent Ubuntu iso and sometimes I do redownload it on my other devices or dual booted system on the same device. If this will cause me to get banned by the whole qbee community, it will be quite weird.

Kolcha commented 1 year ago

yes, this is downside of that... but in case of such widespread and popular torrents like Ubuntu image it is unlikely to be banned by all seeders, even all of them would run qbee. you download from dozens of peers, every will upload only some part of torrent, and even more, that counter should be reset when peer reconnects (aka another handshake is made, don't know torrent protocol or its implementation details, but it is very unlikely that libtorrent keeps some "global" counters for every peer, but I'll check), so it is very unlikely that you will reach the torrent size limit for some seed, even in case of redownload. and I opened this pr mostly "for curious" and "brave enough" people just to try it in real world, as so as it is not well-tested by me. and I agree that it is good question is it worth merging or not.

c0re100 commented 1 year ago

In my opinion, just make a option for "brave enough" people to enable this feature🤔

Kolcha commented 1 year ago

tested with 2 computers behind VPN (2 different external addresses) and own created torrent (one of my computers the only seed), so it seems libtorrent keeps peer statistics, at least for some (un)reasonable time (I waited ~7 min before re-downloading). very unexpected... even client restart (on downloading side) doesn't reset these counters. so, it will not work as intended, closing PR. sorry for disturbing you.

c0re100 commented 1 year ago

even client restart (on downloading side) doesn't reset these counters. Maybe libtorrent keeps peer statistics with fastresume. (need to check libtorrent source code to confirm it)

Kolcha commented 1 year ago

fastresume keeps only per-torrent statistics. but some per-peer (and maybe even "peer-per-torrent") statistics (aka data in peer_info struct) is kept.