SOCKS-прокси для подключения к трекерам. Исправлена функция add_tracker

master
Роман Бородин 2020-04-28 22:25:14 +03:00
parent 037e32ae9b
commit f39749807f
4 changed files with 29 additions and 8 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.pyrrent2http" name="pyrrent2http" version="0.9.9" provider-name="inpos"> <addon id="script.module.pyrrent2http" name="pyrrent2http" version="1.0.0" provider-name="inpos">
<requires> <requires>
<import addon="xbmc.python" version="2.14.0"/> <import addon="xbmc.python" version="2.14.0"/>
<import addon="script.module.libtorrent" /> <import addon="script.module.libtorrent" />

View File

@ -1,3 +1,7 @@
[B]Version 1.0.0[/B]
+ Исправлен механизм добавления трекеров
+ Добавлена поддержка прокси SOCKS длч подключения к трекерам
[B]Version 0.9.0[/B] [B]Version 0.9.0[/B]
+ Изменён принцип работы с торрентом + Изменён принцип работы с торрентом

View File

@ -33,7 +33,7 @@ class Engine:
user_agent=None, startup_timeout=5, state_file='', enable_utp=True, enable_tcp=True, 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, 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, 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 Creates engine instance. It doesn't do anything except initializing object members. For starting engine use
start() method. start() method.
@ -126,6 +126,7 @@ class Engine:
self.logger = logger self.logger = logger
self.uri = uri self.uri = uri
self.started = False self.started = False
self.proxy = proxy
@staticmethod @staticmethod
def _validate_save_path(path): def _validate_save_path(path):
@ -166,6 +167,7 @@ class Engine:
kwargs = { kwargs = {
'torrentConnectBoost': self.torrent_connect_boost, 'torrentConnectBoost': self.torrent_connect_boost,
'trackers': ",".join(self.trackers), 'trackers': ",".join(self.trackers),
'proxy': self.proxy,
'resumeFile': self.resume_file, 'resumeFile': self.resume_file,
'minReconnectTime': self.min_reconnect_time, 'minReconnectTime': self.min_reconnect_time,
'enableUPNP': self.enable_upnp, 'enableUPNP': self.enable_upnp,

View File

@ -3,13 +3,13 @@ import os
import chardet import chardet
try: try:
from python_libtorrent import get_libtorrent from python_libtorrent import get_libtorrent # @UnresolvedImport
lt=get_libtorrent() lt=get_libtorrent()
print('Imported libtorrent v%s from python_libtorrent' %(lt.version, )) print('Imported libtorrent v%s from python_libtorrent' %(lt.version, ))
except Exception, e: except Exception, e:
print('Error importing python_libtorrent.Exception: %s' %(str(e),)) print('Error importing python_libtorrent.Exception: %s' %(str(e),))
try: try:
import libtorrent as lt import libtorrent as lt # @UnresolvedImport
except Exception as e: except Exception as e:
strerror = e.args strerror = e.args
print(strerror) print(strerror)
@ -42,8 +42,8 @@ if not hasattr(os, 'getppid'):
import ctypes import ctypes
TH32CS_SNAPPROCESS = 0x02L TH32CS_SNAPPROCESS = 0x02L
CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot # @UndefinedVariable
GetCurrentProcessId = ctypes.windll.kernel32.GetCurrentProcessId GetCurrentProcessId = ctypes.windll.kernel32.GetCurrentProcessId # @UndefinedVariable
MAX_PATH = 260 MAX_PATH = 260
@ -510,7 +510,7 @@ class Pyrrent2http(object):
maxUploadRate = -1, connectionsLimit = 200, encryption = 1, maxUploadRate = -1, connectionsLimit = 200, encryption = 1,
minReconnectTime = 60, maxFailCount = 3, noSparseFile = False, minReconnectTime = 60, maxFailCount = 3, noSparseFile = False,
randomPort = False, enableScrape = False, enableDHT = True, 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.torrentHandle = None
self.forceShutdown = False self.forceShutdown = False
self.session = None self.session = None
@ -555,6 +555,7 @@ class Pyrrent2http(object):
self.config.enableNATPMP = enableNATPMP self.config.enableNATPMP = enableNATPMP
self.config.enableUTP = enableUTP self.config.enableUTP = enableUTP
self.config.enableTCP = enableTCP self.config.enableTCP = enableTCP
self.config.proxy = proxy
if self.config.uri == '': if self.config.uri == '':
raise Exception("uri is empty string") raise Exception("uri is empty string")
if self.config.uri.startswith('magnet:'): if self.config.uri.startswith('magnet:'):
@ -608,7 +609,7 @@ class Pyrrent2http(object):
for n in range(len(trackers)): for n in range(len(trackers)):
tracker = trackers[n].strip() tracker = trackers[n].strip()
logging.info('Adding tracker: %s' % (tracker,) ) logging.info('Adding tracker: %s' % (tracker,) )
self.torrentHandle.add_tracker(tracker, startTier + n) self.torrentHandle.add_tracker({'url': tracker})
if self.config.enableScrape: if self.config.enableScrape:
logging.info('Sending scrape request to tracker') logging.info('Sending scrape request to tracker')
self.torrentHandle.scrape_tracker() self.torrentHandle.scrape_tracker()
@ -677,6 +678,20 @@ class Pyrrent2http(object):
settings["rate_limit_ip_overhead"] = True settings["rate_limit_ip_overhead"] = True
settings["min_announce_interval"] = 60 settings["min_announce_interval"] = 60
settings["tracker_backoff"] = 0 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) self.session.set_settings(settings)
if self.config.stateFile != '': if self.config.stateFile != '':