Parse socks_proxy arg with urllib.parse and support more parameters
This commit is contained in:
parent
04cd99ed2b
commit
dd7d08482d
|
@ -534,11 +534,13 @@ class SocksConnection(Connection):
|
|||
|
||||
import socks
|
||||
|
||||
proxy_type = socks.PROXY_TYPES[shared.socks_proxy.scheme.upper()]
|
||||
|
||||
try:
|
||||
self.s = socks.create_connection(
|
||||
(self.host, self.port), 30, None, socks.PROXY_TYPE_SOCKS5,
|
||||
shared.socks_proxy[0], shared.socks_proxy[1], True,
|
||||
None, None, None)
|
||||
(self.host, self.port), 30, None, proxy_type,
|
||||
shared.socks_proxy.hostname, shared.socks_proxy.port, True,
|
||||
shared.socks_proxy.username, shared.socks_proxy.password, None)
|
||||
self.status = 'connected'
|
||||
logging.debug('Established SOCKS connection to %s', peer_str)
|
||||
except socket.timeout:
|
||||
|
|
|
@ -5,8 +5,10 @@ import base64
|
|||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import socket
|
||||
from urllib import parse
|
||||
|
||||
try:
|
||||
import socks
|
||||
|
@ -118,10 +120,11 @@ def parse_arguments(): # pylint: disable=too-many-branches,too-many-statements
|
|||
if args.tor:
|
||||
shared.tor = True
|
||||
if not args.socks_proxy:
|
||||
shared.socks_proxy = ('127.0.0.1', 9050)
|
||||
args.socks_proxy = '127.0.0.1:9050'
|
||||
if args.socks_proxy:
|
||||
addr = args.socks_proxy.split(':')
|
||||
shared.socks_proxy = (addr[0], int(addr[1]))
|
||||
if not re.match(r'^.*://', args.socks_proxy):
|
||||
args.socks_proxy = '//' + args.socks_proxy
|
||||
shared.socks_proxy = parse.urlparse(args.socks_proxy, scheme='socks5')
|
||||
|
||||
|
||||
def bootstrap_from_dns():
|
||||
|
@ -262,6 +265,13 @@ def main():
|
|||
'Error while creating data directory in: %s',
|
||||
shared.data_directory, exc_info=True)
|
||||
|
||||
if shared.socks_proxy:
|
||||
try:
|
||||
socks.PROXY_TYPES[shared.socks_proxy.scheme.upper()]
|
||||
except KeyError:
|
||||
logging.error('Unsupported proxy schema!')
|
||||
return
|
||||
|
||||
if shared.ip_enabled and not shared.trusted_peer:
|
||||
bootstrap_from_dns()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user