Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Improvments
Browse files Browse the repository at this point in the history
- strip needless requests

- force check refused upload when anonymous

- decrease false positives of serious leech, need enable refused upload
check
  • Loading branch information
SeaHOH committed Oct 27, 2020
1 parent 2b92963 commit e92e2b6
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 177 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Network File:

```
$ ban_peers -h
Welcome using Ban-Peers 1.0.0
Welcome using Ban-Peers 1.0.1
usage: ban_peers [-H IP|DOMAIN] [-p PORT] [-a USERNAME:PASSWORD] [-e HOURS]
[-t MINUTES] [-f FORMAT] [-C] [-X] [-P] [-L] [-N] [-R] [-U]
Expand Down Expand Up @@ -141,8 +141,8 @@ Optional Arguments:
-L, --no-serious-leech-check
Don't checking serious leech, except anonymous peers
-N, --no-refused-upload-check
Don't checking refused upload, this checking is useful to
connect potential active peers
Don't checking refused upload, except anonymous peers, this
checking is useful to connect potential active peers
-R, --private-check
Enable checking for private torrents
-U, --log-unknown
Expand All @@ -167,7 +167,7 @@ Optional Arguments:

```markdown
$ ban-peers
Welcome using Ban-Peers 1.0.0
Welcome using Ban-Peers 1.0.1
No ipfilter has be inputted, try load from config file
Load ipfilter from config file fail, found nothing
Please input uTorrent settings folder path or ipfilter file path:
Expand All @@ -186,7 +186,7 @@ Choose your operation: (Q)uit, (S)top, (R)estart, (P)ause/Proceed

...
$ ban_peers -p 12345 -a username:password /var/lib/utserver --save-config
Welcome using Ban-Peers 1.0.0
Welcome using Ban-Peers 1.0.1
Start saving config file "<YOUR CONFIG DIR>/BanPeers/ban_peers.conf"
Save argument "ipfilter = /var/lib/utserver"
Save argument "port = 12345"
Expand All @@ -195,7 +195,7 @@ Save argument "authorization = username:password"

...
$ ban-peers -p 54321
Welcome using Ban-Peers 1.0.0
Welcome using Ban-Peers 1.0.1
No ipfilter has be inputted, try load from config file
Start loading config file "<YOUR CONFIG DIR>/BanPeers/ban_peers.conf"
Load argument "ipfilter = /var/lib/utserver"
Expand Down
11 changes: 6 additions & 5 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Android:

```
ban_peers -h
欢迎使用 Ban-Peers 1.0.0
欢迎使用 Ban-Peers 1.0.1
用法: ban_peers [-H IP|域名] [-p 端口] [-a 用户名:密码] [-e 小时] [-t 分钟]
[-f 格式] [-C] [-X] [-P] [-L] [-N] [-R] [-U] [-A] [-O]
Expand Down Expand Up @@ -125,7 +125,8 @@ ban_peers -h
-L, --no-serious-leech-check
不进行严重吸血检查,匿名对端除外
-N, --no-refused-upload-check
不进行拒绝上传检查,此检查有助于连接潜在的活跃对端
不进行拒绝上传检查,匿名对端除外,此检查有助于连接潜在的活
跃对端
-R, --private-check
启用对私有种子的检查
-U, --log-unknown
Expand All @@ -149,7 +150,7 @@ ban_peers -h

```markdown
C:\Users\username>ban_peers
欢迎使用 Ban-Peers 1.0.0
欢迎使用 Ban-Peers 1.0.1
没有输入 ipfilter,尝试从配置文件加载
从配置文件加载 ipfilter 失败,什么都没有找到
请输入 uTorrent 配置文件夹路径,或者 ipfilter 文件路径:
Expand All @@ -168,7 +169,7 @@ X:\uTorrent

...
C:\Users\username>ban_peers -p 12345 -a username:password X:\uTorrent --save-config
欢迎使用 Ban-Peers 1.0.0
欢迎使用 Ban-Peers 1.0.1
开始保存配置文件 "<你的配置目录>\BanPeers\ban_peers.conf"
保存参数 "ipfilter = X:\uTorrent"
保存参数 "port = 12345"
Expand All @@ -177,7 +178,7 @@ C:\Users\username>ban_peers -p 12345 -a username:password X:\uTorrent --save-con

...
C:\Users\username>ban_peers -p 54321
欢迎使用 Ban-Peers 1.0.0
欢迎使用 Ban-Peers 1.0.1
没有输入 ipfilter,尝试从配置文件加载
开始加载配置文件 "<你的配置目录>\BanPeers\ban_peers.conf"
加载参数 "ipfilter = X:\uTorrent"
Expand Down
28 changes: 12 additions & 16 deletions src/ban_peers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
uTorrent.
""")
__app_name__ = 'Ban-Peers'
__version__ = '1.0.0'
__version__ = '1.0.1'
__author__ = 'SeaHOH'
__email__ = '[email protected]'
__license__ = 'MIT'
Expand Down Expand Up @@ -657,7 +657,7 @@ def is_private(self, hash:str) -> bool:
props = self.get_props(hash)
self._torrents_private[hash] = private = \
props['dht'] == props['pex'] == -1 and (
props['trackers'].find('?') > 0 or
props['trackers'].find('?') > 0 or #
props['trackers'].count('://') < 3) # Maybe flag by mistake
return private

Expand Down Expand Up @@ -780,24 +780,21 @@ def log(msg):
size_millesimal = torrent.size // 1000
seeding = torrent.progress >= 1000 # uTorrent bug?
hash = torrent.hash
time_fp = 60
ratio_sl = 10
if seeding:
self._statistics_started.pop(hash, None)
else:
elif self.check_fake_progress or self.check_serious_leech:
started = self._statistics_started.setdefault(hash, ct)
if self.check_fake_progress or self.check_serious_leech:
files = list(self.get_files(hash))
size_todl = sum(file.size for file in files if file.priority)
size_todl_tenth = size_todl // 10
size_downloaded = sum(file.downloaded for file in files)
size_last_downloaded = torrent.downloaded - size_downloaded
time_fp = 60
ratio_sl = 10
# High level thresholds are used for older/weaker Torrents
if hash in self._high_level:
if torrent.availability < 10:
time_fp = 300
ratio_sl = 30
elif not seeding and ct - started > 300 and \
elif ct - started > 300 and \
torrent.eta * _10g > torrent.remaining * 86400:
# Less than 10 GiB/day
time_fp = 300
Expand Down Expand Up @@ -960,9 +957,6 @@ def log(msg):
except KeyError:
luploaded = suploaded = _suploaded = 0
t = None
if size_last_downloaded > _10m:
# May has been seeding before
_suploaded = peer.uploaded
if seeding:
_suploaded = peer.uploaded - luploaded
uploaded = 0
Expand All @@ -981,7 +975,8 @@ def log(msg):
0 < peer.downspeed * 100 < peer.upspeed) and
uploaded > min(max(size_todl_tenth, _10m), _100m) and
uploaded > peer.downloaded * ratio_sl < relevance):
if t is None:
if t is None or self.check_refused_upload and \
peer.relevance > 0 and peer.downloaded == 0:
t = ct
elif peer.relevance == 0 or \
ct - t > peer.downloaded / _1m * 10:
Expand All @@ -995,7 +990,7 @@ def log(msg):
t = None
self._statistics_uploaded[hash][ip_port] = \
luploaded, suploaded, _suploaded, t
if self.check_refused_upload and \
if (self.check_refused_upload or anonymous) and \
not seeding and peer.downloaded == 0:
t = self._statistics_refused[hash].get(ip_port)
if reasons:
Expand Down Expand Up @@ -1313,8 +1308,9 @@ def formatter_class(prog:str, *args, **kwargs) -> argparse.HelpFormatter:
parser.add_argument('-N', '--no-refused-upload-check',
action='store_true',
help=_(
'Don\'t checking refused upload, this checking is '
'useful to connect potential active peers'))
'Don\'t checking refused upload, except anonymous peers'
', this checking is useful to connect potential active '
'peers'))
parser.add_argument('-R', '--private-check',
action='store_true',
help=_(
Expand Down
Loading

0 comments on commit e92e2b6

Please sign in to comment.