WIP: Add support for tor using PySocks and optionally stem #2

Draft
lee.miller wants to merge 22 commits from lee.miller/MiNode:tor into v0.3
2 changed files with 18 additions and 6 deletions
Showing only changes of commit c385b43a09 - Show all commits

View File

@ -544,11 +544,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:

View File

@ -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():
@ -266,6 +269,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()