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"?>
<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>
<import addon="xbmc.python" version="2.14.0"/>
<import addon="script.module.libtorrent" />

View File

@ -1,3 +1,7 @@
[B]Version 1.0.0[/B]
+ Исправлен механизм добавления трекеров
+ Добавлена поддержка прокси SOCKS длч подключения к трекерам
[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,
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,

View File

@ -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 != '':