Add timeouts to all requests.

This commit is contained in:
tecnovert 2020-12-31 17:30:14 +02:00
parent 2049fcef3d
commit 0ad3856460
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
3 changed files with 22 additions and 14 deletions

View file

@ -1821,6 +1821,11 @@ class BasicSwap(BaseApp):
xmr_swap.dest_af = msg_buf.dest_af
xmr_swap.start_chain_a_height = ci_from.getChainHeight()
xmr_swap.b_restore_height = ci_to.getChainHeight()
if xmr_swap.b_restore_height < ci_to._restore_height:
xmr_swap.b_restore_height = ci_to._restore_height
self.log.warning('XMR swap restore height clamped to {}'.format(ci_to._restore_height))
kbvf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, 1, for_ed25519=True)
kbsf = self.getPathKey(coin_from, coin_to, bid_created_at, xmr_swap.contract_count, 2, for_ed25519=True)
@ -3751,6 +3756,9 @@ class BasicSwap(BaseApp):
b_restore_height=ci_to.getChainHeight(),
start_chain_a_height=ci_from.getChainHeight(),
)
if xmr_swap.b_restore_height < ci_to._restore_height:
xmr_swap.b_restore_height = ci_to._restore_height
self.log.warning('XMR swap restore height clamped to {}'.format(ci_to._restore_height))
else:
bid.created_at = msg['sent']
bid.expire_at = msg['sent'] + bid_data.time_valid

View file

@ -244,7 +244,7 @@ class XMRInterface(CoinInterface):
logging.info('generate_from_keys %s', dumpj(rv))
rv = self.rpc_wallet_cb('open_wallet', {'filename': address_b58})
rv = self.rpc_wallet_cb('refresh')
rv = self.rpc_wallet_cb('refresh', timeout=600)
'''
# Debug

View file

@ -4,7 +4,7 @@ import json
import requests
def callrpc_xmr(rpc_port, auth, method, params=[], rpc_host='127.0.0.1', path='json_rpc'):
def callrpc_xmr(rpc_port, auth, method, params=[], rpc_host='127.0.0.1', path='json_rpc', timeout=120):
# auth is a tuple: (username, password)
try:
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
@ -17,7 +17,7 @@ def callrpc_xmr(rpc_port, auth, method, params=[], rpc_host='127.0.0.1', path='j
headers = {
'content-type': 'application/json'
}
p = requests.post(url, data=json.dumps(request_body), auth=requests.auth.HTTPDigestAuth(auth[0], auth[1]), headers=headers)
p = requests.post(url, data=json.dumps(request_body), auth=requests.auth.HTTPDigestAuth(auth[0], auth[1]), headers=headers, timeout=timeout)
r = json.loads(p.text)
except Exception as ex:
raise ValueError('RPC Server Error: {}'.format(str(ex)))
@ -28,7 +28,7 @@ def callrpc_xmr(rpc_port, auth, method, params=[], rpc_host='127.0.0.1', path='j
return r['result']
def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json_rpc'):
def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json_rpc', timeout=120):
try:
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
request_body = {
@ -40,7 +40,7 @@ def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json
headers = {
'content-type': 'application/json'
}
p = requests.post(url, data=json.dumps(request_body), headers=headers)
p = requests.post(url, data=json.dumps(request_body), headers=headers, timeout=timeout)
r = json.loads(p.text)
except Exception as ex:
raise ValueError('RPC Server Error: {}'.format(str(ex)))
@ -51,16 +51,16 @@ def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json
return r['result']
def callrpc_xmr2(rpc_port, method, params=None, rpc_host='127.0.0.1'):
def callrpc_xmr2(rpc_port, method, params=None, rpc_host='127.0.0.1', timeout=120):
try:
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, method)
headers = {
'content-type': 'application/json'
}
if params is None:
p = requests.post(url, headers=headers)
p = requests.post(url, headers=headers, timeout=timeout)
else:
p = requests.post(url, data=json.dumps(params), headers=headers)
p = requests.post(url, data=json.dumps(params), headers=headers, timeout=timeout)
r = json.loads(p.text)
except Exception as ex:
raise ValueError('RPC Server Error: {}'.format(str(ex)))
@ -72,10 +72,10 @@ def make_xmr_rpc_func(port, host='127.0.0.1'):
port = port
host = host
def rpc_func(method, params=None, wallet=None):
def rpc_func(method, params=None, wallet=None, timeout=120):
nonlocal port
nonlocal host
return callrpc_xmr_na(port, method, params, rpc_host=host)
return callrpc_xmr_na(port, method, params, rpc_host=host, timeout=timeout)
return rpc_func
@ -83,10 +83,10 @@ def make_xmr_rpc2_func(port, host='127.0.0.1'):
port = port
host = host
def rpc_func(method, params=None, wallet=None):
def rpc_func(method, params=None, wallet=None, timeout=120):
nonlocal port
nonlocal host
return callrpc_xmr2(port, method, params, rpc_host=host)
return callrpc_xmr2(port, method, params, rpc_host=host, timeout=timeout)
return rpc_func
@ -95,7 +95,7 @@ def make_xmr_wallet_rpc_func(port, auth, host='127.0.0.1'):
auth = auth
host = host
def rpc_func(method, params=None, wallet=None):
def rpc_func(method, params=None, wallet=None, timeout=120):
nonlocal port, auth, host
return callrpc_xmr(port, auth, method, params, rpc_host=host)
return callrpc_xmr(port, auth, method, params, rpc_host=host, timeout=timeout)
return rpc_func