From ec11632297d0969ee9fab7da3c1cb96f1d85d618 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 23 Jul 2019 18:57:19 +0300 Subject: [PATCH] Introduce pluggable proxy configurators --- setup.py | 4 ++++ src/bitmessagemain.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/setup.py b/setup.py index e3f97bac..3a9c7a3c 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ EXTRAS_REQUIRE = { 'prctl': ['python_prctl'], # Named threads 'qrcode': ['qrcode'], 'sound;platform_system=="Windows"': ['winsound'], + 'tor': ['stem'], 'docs': [ 'sphinx', # fab build_docs 'graphviz', # fab build_docs @@ -147,6 +148,9 @@ if __name__ == "__main__": 'libmessaging =' 'pybitmessage.plugins.indicator_libmessaging [gir]' ], + 'bitmessage.proxyconfig': [ + 'stem = pybitmessage.plugins.proxyconfig_stem [tor]' + ], # 'console_scripts': [ # 'pybitmessage = pybitmessage.bitmessagemain:main' # ] diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 5639edae..90e15c52 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -184,6 +184,27 @@ def signal_handler(signum, frame): class Main: + @staticmethod + def start_proxyconfig(config): + """Check socksproxytype and start any proxy configuration plugin""" + proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype') + if proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'): + # pylint: disable=relative-import + from plugins.plugin import get_plugin + try: + proxyconfig_start = time.time() + get_plugin('proxyconfig', name=proxy_type)(config) + except TypeError: + logger.error( + 'Failed to run proxy config plugin %s', + proxy_type, exc_info=True) + shutdown.doCleanShutdown() + sys.exit(2) + else: + logger.info( + 'Started proxy config plugin %s in %s sec', + proxy_type, time.time() - proxyconfig_start) + def start(self): _fixSocket() @@ -343,6 +364,7 @@ class Main: # start network components if networking is enabled if state.enableNetwork: + self.start_proxyconfig(config) BMConnectionPool() asyncoreThread = BMNetworkThread() asyncoreThread.daemon = True