Introduce pluggable proxy configurators

This commit is contained in:
Dmitri Bogomolov 2019-07-23 18:57:19 +03:00
parent 2bd75b87bd
commit ec11632297
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 26 additions and 0 deletions

View File

@ -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'
# ]

View File

@ -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