From f39749807f4ab5381689de33ff7e55beb3c5108f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=A0=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD?= Date: Tue, 28 Apr 2020 22:25:14 +0300 Subject: [PATCH] =?UTF-8?q?SOCKS-=D0=BF=D1=80=D0=BE=D0=BA=D1=81=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=20=D1=82=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=D0=BC.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20add=5Ftracker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon.xml | 2 +- changelog.txt | 4 ++++ lib/pyrrent2http/engine.py | 4 +++- lib/pyrrent2http/pyrrent2http.py | 27 +++++++++++++++++++++------ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/addon.xml b/addon.xml index dc4a86f..68b934a 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + diff --git a/changelog.txt b/changelog.txt index 27fd57f..6e5dcd4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +[B]Version 1.0.0[/B] ++ Исправлен механизм добавления трекеров ++ Добавлена поддержка прокси SOCKS длч подключения к трекерам + [B]Version 0.9.0[/B] + Изменён принцип работы с торрентом diff --git a/lib/pyrrent2http/engine.py b/lib/pyrrent2http/engine.py index 7d4b573..f3e8692 100644 --- a/lib/pyrrent2http/engine.py +++ b/lib/pyrrent2http/engine.py @@ -33,7 +33,7 @@ class Engine: user_agent=None, startup_timeout=5, state_file='', enable_utp=True, enable_tcp=True, debug_alerts=False, logger=None, torrent_connect_boost=50, connection_speed=50, peer_connect_timeout=15, request_timeout=20, min_reconnect_time=60, max_failcount=3, - dht_routers=None, trackers=None): + dht_routers=None, trackers=None, proxy=None): """ Creates engine instance. It doesn't do anything except initializing object members. For starting engine use start() method. @@ -126,6 +126,7 @@ class Engine: self.logger = logger self.uri = uri self.started = False + self.proxy = proxy @staticmethod def _validate_save_path(path): @@ -166,6 +167,7 @@ class Engine: kwargs = { 'torrentConnectBoost': self.torrent_connect_boost, 'trackers': ",".join(self.trackers), + 'proxy': self.proxy, 'resumeFile': self.resume_file, 'minReconnectTime': self.min_reconnect_time, 'enableUPNP': self.enable_upnp, diff --git a/lib/pyrrent2http/pyrrent2http.py b/lib/pyrrent2http/pyrrent2http.py index 0070d36..1ab53da 100755 --- a/lib/pyrrent2http/pyrrent2http.py +++ b/lib/pyrrent2http/pyrrent2http.py @@ -3,13 +3,13 @@ import os import chardet try: - from python_libtorrent import get_libtorrent + from python_libtorrent import get_libtorrent # @UnresolvedImport lt=get_libtorrent() print('Imported libtorrent v%s from python_libtorrent' %(lt.version, )) except Exception, e: print('Error importing python_libtorrent.Exception: %s' %(str(e),)) try: - import libtorrent as lt + import libtorrent as lt # @UnresolvedImport except Exception as e: strerror = e.args print(strerror) @@ -42,8 +42,8 @@ if not hasattr(os, 'getppid'): import ctypes TH32CS_SNAPPROCESS = 0x02L - CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot - GetCurrentProcessId = ctypes.windll.kernel32.GetCurrentProcessId + CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot # @UndefinedVariable + GetCurrentProcessId = ctypes.windll.kernel32.GetCurrentProcessId # @UndefinedVariable MAX_PATH = 260 @@ -510,7 +510,7 @@ class Pyrrent2http(object): maxUploadRate = -1, connectionsLimit = 200, encryption = 1, minReconnectTime = 60, maxFailCount = 3, noSparseFile = False, randomPort = False, enableScrape = False, enableDHT = True, - enableLSD = True, enableUPNP = True, enableNATPMP = True, enableUTP = True, enableTCP = True): + enableLSD = True, enableUPNP = True, enableNATPMP = True, enableUTP = True, enableTCP = True, proxy=None): self.torrentHandle = None self.forceShutdown = False self.session = None @@ -555,6 +555,7 @@ class Pyrrent2http(object): self.config.enableNATPMP = enableNATPMP self.config.enableUTP = enableUTP self.config.enableTCP = enableTCP + self.config.proxy = proxy if self.config.uri == '': raise Exception("uri is empty string") if self.config.uri.startswith('magnet:'): @@ -608,7 +609,7 @@ class Pyrrent2http(object): for n in range(len(trackers)): tracker = trackers[n].strip() logging.info('Adding tracker: %s' % (tracker,) ) - self.torrentHandle.add_tracker(tracker, startTier + n) + self.torrentHandle.add_tracker({'url': tracker}) if self.config.enableScrape: logging.info('Sending scrape request to tracker') self.torrentHandle.scrape_tracker() @@ -677,6 +678,20 @@ class Pyrrent2http(object): settings["rate_limit_ip_overhead"] = True settings["min_announce_interval"] = 60 settings["tracker_backoff"] = 0 + ### Непонятно, как заставить использовать прокси только для подключения к трекеру? + if self.config.proxy is not None: + ps = lt.proxy_settings() + #peer_ps = lt.proxy_settings() + #peer_ps.type = lt.proxy_type.none + ps.hostname = self.config.proxy['host'] + ps.port = self.config.proxy['port'] + ps.type = lt.proxy_type.socks5 + #self.session.set_peer_proxy(peer_ps) + self.session.set_proxy(ps) + settings['force_proxy'] = False + settings['proxy_peer_connections'] = False + settings['anonymous_mode'] = False + settings['proxy_tracker_connections'] = True self.session.set_settings(settings) if self.config.stateFile != '':