mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
Add timeouts to all requests.
This commit is contained in:
@@ -1821,6 +1821,11 @@ class BasicSwap(BaseApp):
|
|||||||
xmr_swap.dest_af = msg_buf.dest_af
|
xmr_swap.dest_af = msg_buf.dest_af
|
||||||
xmr_swap.start_chain_a_height = ci_from.getChainHeight()
|
xmr_swap.start_chain_a_height = ci_from.getChainHeight()
|
||||||
xmr_swap.b_restore_height = ci_to.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)
|
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)
|
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(),
|
b_restore_height=ci_to.getChainHeight(),
|
||||||
start_chain_a_height=ci_from.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:
|
else:
|
||||||
bid.created_at = msg['sent']
|
bid.created_at = msg['sent']
|
||||||
bid.expire_at = msg['sent'] + bid_data.time_valid
|
bid.expire_at = msg['sent'] + bid_data.time_valid
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ class XMRInterface(CoinInterface):
|
|||||||
logging.info('generate_from_keys %s', dumpj(rv))
|
logging.info('generate_from_keys %s', dumpj(rv))
|
||||||
rv = self.rpc_wallet_cb('open_wallet', {'filename': address_b58})
|
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
|
# Debug
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import json
|
|||||||
import requests
|
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)
|
# auth is a tuple: (username, password)
|
||||||
try:
|
try:
|
||||||
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
|
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 = {
|
headers = {
|
||||||
'content-type': 'application/json'
|
'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)
|
r = json.loads(p.text)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise ValueError('RPC Server Error: {}'.format(str(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']
|
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:
|
try:
|
||||||
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
|
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, path)
|
||||||
request_body = {
|
request_body = {
|
||||||
@@ -40,7 +40,7 @@ def callrpc_xmr_na(rpc_port, method, params=[], rpc_host='127.0.0.1', path='json
|
|||||||
headers = {
|
headers = {
|
||||||
'content-type': 'application/json'
|
'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)
|
r = json.loads(p.text)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise ValueError('RPC Server Error: {}'.format(str(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']
|
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:
|
try:
|
||||||
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, method)
|
url = 'http://{}:{}/{}'.format(rpc_host, rpc_port, method)
|
||||||
headers = {
|
headers = {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
}
|
}
|
||||||
if params is None:
|
if params is None:
|
||||||
p = requests.post(url, headers=headers)
|
p = requests.post(url, headers=headers, timeout=timeout)
|
||||||
else:
|
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)
|
r = json.loads(p.text)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise ValueError('RPC Server Error: {}'.format(str(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
|
port = port
|
||||||
host = host
|
host = host
|
||||||
|
|
||||||
def rpc_func(method, params=None, wallet=None):
|
def rpc_func(method, params=None, wallet=None, timeout=120):
|
||||||
nonlocal port
|
nonlocal port
|
||||||
nonlocal host
|
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
|
return rpc_func
|
||||||
|
|
||||||
|
|
||||||
@@ -83,10 +83,10 @@ def make_xmr_rpc2_func(port, host='127.0.0.1'):
|
|||||||
port = port
|
port = port
|
||||||
host = host
|
host = host
|
||||||
|
|
||||||
def rpc_func(method, params=None, wallet=None):
|
def rpc_func(method, params=None, wallet=None, timeout=120):
|
||||||
nonlocal port
|
nonlocal port
|
||||||
nonlocal host
|
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
|
return rpc_func
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ def make_xmr_wallet_rpc_func(port, auth, host='127.0.0.1'):
|
|||||||
auth = auth
|
auth = auth
|
||||||
host = host
|
host = host
|
||||||
|
|
||||||
def rpc_func(method, params=None, wallet=None):
|
def rpc_func(method, params=None, wallet=None, timeout=120):
|
||||||
nonlocal port, auth, host
|
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
|
return rpc_func
|
||||||
|
|||||||
Reference in New Issue
Block a user