Set monero-wallet-rpc proxy with parameter instead of config.

2024-05-20_merge
tecnovert 11 months ago
parent 14298d022a
commit ec29c9889c
  1. 38
      basicswap/basicswap.py
  2. 8
      bin/basicswap_prepare.py
  3. 13
      bin/basicswap_run.py

@ -512,6 +512,32 @@ class BasicSwap(BaseApp):
self.coin_clients[coin]['rpcuser'] = chain_client_settings.get('rpcuser', '') self.coin_clients[coin]['rpcuser'] = chain_client_settings.get('rpcuser', '')
self.coin_clients[coin]['rpcpassword'] = chain_client_settings.get('rpcpassword', '') self.coin_clients[coin]['rpcpassword'] = chain_client_settings.get('rpcpassword', '')
def getXMRTrustedDaemon(self, coin, node_host: str) -> bool:
chain_client_settings = self.getChainClientSettings(coin)
trusted_daemon_setting = chain_client_settings.get('trusted_daemon', 'auto')
if isinstance(trusted_daemon_setting, bool):
return trusted_daemon_setting
if trusted_daemon_setting == 'auto':
return is_private_ip_address(node_host)
ci = self.ci(coin)
self.log.warning(f'Unknown \'trusted_daemon\' setting for {ci.coin_name()}: {trusted_daemon_setting}.')
return False
def getXMRWalletProxy(self, coin, node_host: str) -> (Optional[str], Optional[int]):
chain_client_settings = self.getChainClientSettings(coin)
proxy_host = None
proxy_port = None
if self.use_tor_proxy:
have_cc_tor_opt = 'use_tor' in chain_client_settings
if have_cc_tor_opt and chain_client_settings['use_tor'] is False:
self.log.warning('use_tor is true for system but false for XMR.')
elif have_cc_tor_opt is False and is_private_ip_address(node_host):
self.log.warning(f'Not using proxy for XMR node at private ip address {node_host}.')
else:
proxy_host = self.tor_proxy_host
proxy_port = self.tor_proxy_port
return proxy_host, proxy_port
def selectXMRRemoteDaemon(self, coin): def selectXMRRemoteDaemon(self, coin):
self.log.info('Selecting remote XMR daemon.') self.log.info('Selecting remote XMR daemon.')
chain_client_settings = self.getChainClientSettings(coin) chain_client_settings = self.getChainClientSettings(coin)
@ -524,17 +550,7 @@ class BasicSwap(BaseApp):
def get_rpc_func(rpcport, daemon_login, rpchost): def get_rpc_func(rpcport, daemon_login, rpchost):
proxy_host = None proxy_host, proxy_port = self.getXMRWalletProxy(chain_client_settings, rpchost)
proxy_port = None
if self.use_tor_proxy:
have_cc_tor_opt = 'use_tor' in chain_client_settings
if have_cc_tor_opt and chain_client_settings['use_tor'] is False:
self.log.warning('use_tor is true for system but false for XMR.')
elif have_cc_tor_opt is False and is_private_ip_address(rpchost):
self.log.warning(f'Not using proxy for XMR node at private ip address {rpchost}.')
else:
proxy_host = self.tor_proxy_host
proxy_port = self.tor_proxy_port
if proxy_host: if proxy_host:
self.log.info(f'Connecting through proxy at {proxy_host}.') self.log.info(f'Connecting through proxy at {proxy_host}.')

@ -34,7 +34,6 @@ from basicswap.basicswap import BasicSwap
from basicswap.chainparams import Coins from basicswap.chainparams import Coins
from basicswap.ui.util import getCoinName from basicswap.ui.util import getCoinName
from basicswap.util import toBool from basicswap.util import toBool
from basicswap.util.network import is_private_ip_address
from basicswap.util.rfc2440 import rfc2440_hash_password from basicswap.util.rfc2440 import rfc2440_hash_password
from basicswap.contrib.rpcauth import generate_salt, password_to_hmac from basicswap.contrib.rpcauth import generate_salt, password_to_hmac
from bin.basicswap_run import startDaemon, startXmrWalletDaemon from bin.basicswap_run import startDaemon, startXmrWalletDaemon
@ -804,7 +803,6 @@ def prepareDataDir(coin, settings, chain, particl_mnemonic, extra_opts={}):
fp.write('prune-blockchain=1\n') fp.write('prune-blockchain=1\n')
if tor_control_password is not None: if tor_control_password is not None:
fp.write(f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}\n')
fp.write('proxy-allow-dns-leaks=0\n') fp.write('proxy-allow-dns-leaks=0\n')
fp.write('no-igd=1\n') fp.write('no-igd=1\n')
@ -1014,7 +1012,7 @@ def modify_tor_config(settings, coin, tor_control_password=None, enable=False, e
fp.write(f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}\n') fp.write(f'proxy={TOR_PROXY_HOST}:{TOR_PROXY_PORT}\n')
fp.write('daemon-ssl-allow-any-cert=1\n') fp.write('daemon-ssl-allow-any-cert=1\n')
coin_settings['trusted_daemon'] = extra_opts.get('trust_remote_node', is_private_ip_address(coin_settings['rpchost'])) coin_settings['trusted_daemon'] = extra_opts.get('trust_remote_node', 'auto')
return return
config_path = os.path.join(data_dir, coin + '.conf') config_path = os.path.join(data_dir, coin + '.conf')
@ -1084,7 +1082,7 @@ def printHelp():
print('--htmlhost= Interface to host html server on, default:127.0.0.1.') print('--htmlhost= Interface to host html server on, default:127.0.0.1.')
print('--wshost= Interface to host websocket server on, disable by setting to "none", default:127.0.0.1.') print('--wshost= Interface to host websocket server on, disable by setting to "none", default:127.0.0.1.')
print('--xmrrestoreheight=n Block height to restore Monero wallet from, default:{}.'.format(DEFAULT_XMR_RESTORE_HEIGHT)) print('--xmrrestoreheight=n Block height to restore Monero wallet from, default:{}.'.format(DEFAULT_XMR_RESTORE_HEIGHT))
print('--trustremotenode Set trusted-daemon for XMR, default is true for private ip addresses else false') print('--trustremotenode Set trusted-daemon for XMR, defaults to auto: true when daemon rpchost value is a private ip address else false')
print('--noextractover Prevent extracting cores if files exist. Speeds up tests') print('--noextractover Prevent extracting cores if files exist. Speeds up tests')
print('--usetorproxy Use TOR proxy during setup. Note that some download links may be inaccessible over TOR.') print('--usetorproxy Use TOR proxy during setup. Note that some download links may be inaccessible over TOR.')
print('--notorproxy Force usetorproxy off, usetorproxy is automatically set when tor is enabled') print('--notorproxy Force usetorproxy off, usetorproxy is automatically set when tor is enabled')
@ -1573,7 +1571,7 @@ def main():
'zmqport': BASE_XMR_ZMQ_PORT + port_offset, 'zmqport': BASE_XMR_ZMQ_PORT + port_offset,
'walletrpcport': BASE_XMR_WALLET_PORT + port_offset, 'walletrpcport': BASE_XMR_WALLET_PORT + port_offset,
'rpchost': XMR_RPC_HOST, 'rpchost': XMR_RPC_HOST,
'trusted_daemon': extra_opts.get('trust_remote_node', is_private_ip_address(XMR_RPC_HOST)), 'trusted_daemon': extra_opts.get('trust_remote_node', 'auto'),
'walletrpchost': XMR_WALLET_RPC_HOST, 'walletrpchost': XMR_WALLET_RPC_HOST,
'walletrpcuser': XMR_WALLET_RPC_USER, 'walletrpcuser': XMR_WALLET_RPC_USER,
'walletrpcpassword': XMR_WALLET_RPC_PWD, 'walletrpcpassword': XMR_WALLET_RPC_PWD,

@ -176,10 +176,17 @@ def runClient(fp, data_dir, chain, start_only_coins):
if v['manage_wallet_daemon'] is True: if v['manage_wallet_daemon'] is True:
swap_client.log.info(f'Starting {display_name} wallet daemon') swap_client.log.info(f'Starting {display_name} wallet daemon')
daemon_addr = '{}:{}'.format(v['rpchost'], v['rpcport']) daemon_addr = '{}:{}'.format(v['rpchost'], v['rpcport'])
trusted_daemon: bool = swap_client.getXMRTrustedDaemon(c, v['rpchost'])
trusted_daemon: bool = v.get('trusted_daemon', False)
swap_client.log.info('daemon-address: {} ({})'.format(daemon_addr, 'trusted' if trusted_daemon else 'untrusted'))
opts = ['--daemon-address', daemon_addr, ] opts = ['--daemon-address', daemon_addr, ]
proxy_log_str = ''
proxy_host, proxy_port = swap_client.getXMRWalletProxy(c, v['rpchost'])
if proxy_host:
proxy_log_str = ' through proxy'
opts += ['--proxy', f'{proxy_host}:{proxy_port}', ]
swap_client.log.info('daemon-address: {} ({}){}'.format(daemon_addr, 'trusted' if trusted_daemon else 'untrusted', proxy_log_str))
daemon_rpcuser = v.get('rpcuser', '') daemon_rpcuser = v.get('rpcuser', '')
daemon_rpcpass = v.get('rpcpassword', '') daemon_rpcpass = v.get('rpcpassword', '')
if daemon_rpcuser != '': if daemon_rpcuser != '':

Loading…
Cancel
Save