mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 10:28:10 +01:00
prepare: Deduplicate Monero tor config
This commit is contained in:
@@ -202,6 +202,20 @@ WALLET_ENCRYPTION_PWD = os.getenv('WALLET_ENCRYPTION_PWD', '')
|
||||
|
||||
use_tor_proxy: bool = False
|
||||
|
||||
monerod_proxy_config = [
|
||||
f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}',
|
||||
'proxy-allow-dns-leaks=0',
|
||||
'no-igd=1', # Disable UPnP port mapping
|
||||
'hide-my-port=1', # Don't share the p2p port
|
||||
'p2p-bind-ip=127.0.0.1', # Don't broadcast ip
|
||||
'in-peers=0', # Changes "error" in log to "incoming connections disabled"
|
||||
]
|
||||
|
||||
monero_wallet_rpc_proxy_config = [
|
||||
'daemon-ssl-allow-any-cert=1',
|
||||
]
|
||||
|
||||
|
||||
default_socket = socket.socket
|
||||
default_socket_timeout = socket.getdefaulttimeout()
|
||||
default_socket_getaddrinfo = socket.getaddrinfo
|
||||
@@ -814,8 +828,8 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic, extra_opts={}):
|
||||
fp.write('prune-blockchain=1\n')
|
||||
|
||||
if tor_control_password is not None:
|
||||
fp.write('proxy-allow-dns-leaks=0\n')
|
||||
fp.write('no-igd=1\n')
|
||||
for opt_line in monerod_proxy_config:
|
||||
fp.write(opt_line + '\n')
|
||||
|
||||
if XMR_RPC_USER != '':
|
||||
fp.write(f'rpc-login={XMR_RPC_USER}:{XMR_RPC_PWD}\n')
|
||||
@@ -846,7 +860,8 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic, extra_opts={}):
|
||||
|
||||
if tor_control_password is not None:
|
||||
if not core_settings['manage_daemon']:
|
||||
fp.write(f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}\n')
|
||||
for opt_line in monero_wallet_rpc_proxy_config:
|
||||
fp.write(opt_line + '\n')
|
||||
return
|
||||
|
||||
core_conf_path = os.path.join(data_dir, coin + '.conf')
|
||||
@@ -989,30 +1004,29 @@ def modify_tor_config(settings, coin, tor_control_password=None, enable=False, e
|
||||
shutil.copyfile(core_conf_path, core_conf_path + '.last')
|
||||
shutil.copyfile(wallet_conf_path, wallet_conf_path + '.last')
|
||||
|
||||
daemon_tor_settings = ('proxy=', 'proxy-allow-dns-leaks=', 'no-igd=')
|
||||
with open(core_conf_path, 'w') as fp:
|
||||
with open(core_conf_path + '.last') as fp_in:
|
||||
# Disable tor first
|
||||
for line in fp_in:
|
||||
skip_line = False
|
||||
for setting in daemon_tor_settings:
|
||||
skip_line: bool = False
|
||||
for opt_line in monerod_proxy_config:
|
||||
setting: str = opt_line[0: opt_line.find('=') + 1]
|
||||
if line.startswith(setting):
|
||||
skip_line = True
|
||||
break
|
||||
if not skip_line:
|
||||
fp.write(line)
|
||||
if enable:
|
||||
fp.write(f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}\n')
|
||||
fp.write('proxy-allow-dns-leaks=0\n')
|
||||
fp.write('no-igd=1\n')
|
||||
for opt_line in monerod_proxy_config:
|
||||
fp.write(opt_line + '\n')
|
||||
|
||||
wallet_tor_settings = ('proxy=', 'daemon-ssl-allow-any-cert=',)
|
||||
with open(wallet_conf_path, 'w') as fp:
|
||||
with open(wallet_conf_path + '.last') as fp_in:
|
||||
# Disable tor first
|
||||
for line in fp_in:
|
||||
skip_line = False
|
||||
for setting in wallet_tor_settings:
|
||||
for opt_line in monero_wallet_rpc_proxy_config + ['proxy=',]:
|
||||
setting: str = opt_line[0: opt_line.find('=') + 1]
|
||||
if line.startswith(setting):
|
||||
skip_line = True
|
||||
break
|
||||
@@ -1020,8 +1034,8 @@ def modify_tor_config(settings, coin, tor_control_password=None, enable=False, e
|
||||
fp.write(line)
|
||||
if enable:
|
||||
if not coin_settings['manage_daemon']:
|
||||
fp.write(f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}\n')
|
||||
fp.write('daemon-ssl-allow-any-cert=1\n')
|
||||
for opt_line in monero_wallet_rpc_proxy_config:
|
||||
fp.write(opt_line + '\n')
|
||||
|
||||
coin_settings['trusted_daemon'] = extra_opts.get('trust_remote_node', 'auto')
|
||||
return
|
||||
|
||||
@@ -176,11 +176,11 @@ def runClient(fp, data_dir, chain, start_only_coins):
|
||||
if v['manage_wallet_daemon'] is True:
|
||||
swap_client.log.info(f'Starting {display_name} wallet daemon')
|
||||
daemon_addr = '{}:{}'.format(v['rpchost'], v['rpcport'])
|
||||
trusted_daemon: bool = swap_client.getXMRTrustedDaemon(c, v['rpchost'])
|
||||
trusted_daemon: bool = swap_client.getXMRTrustedDaemon(coin_id, v['rpchost'])
|
||||
opts = ['--daemon-address', daemon_addr, ]
|
||||
|
||||
proxy_log_str = ''
|
||||
proxy_host, proxy_port = swap_client.getXMRWalletProxy(c, v['rpchost'])
|
||||
proxy_host, proxy_port = swap_client.getXMRWalletProxy(coin_id, v['rpchost'])
|
||||
if proxy_host:
|
||||
proxy_log_str = ' through proxy'
|
||||
opts += ['--proxy', f'{proxy_host}:{proxy_port}', ]
|
||||
|
||||
Reference in New Issue
Block a user