mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
parent
9b0773cf2b
commit
1cfac928f9
4 changed files with 27 additions and 13 deletions
|
@ -1159,7 +1159,9 @@ class Network(PrintError):
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _send_http_on_proxy(cls, method: str, url: str, params: str = None, body: bytes = None, json: dict = None, headers=None, on_finish=None):
|
async def _send_http_on_proxy(cls, method: str, url: str, params: str = None,
|
||||||
|
body: bytes = None, json: dict = None, headers=None,
|
||||||
|
on_finish=None, timeout=None):
|
||||||
async def default_on_finish(resp: ClientResponse):
|
async def default_on_finish(resp: ClientResponse):
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return await resp.text()
|
return await resp.text()
|
||||||
|
@ -1169,7 +1171,7 @@ class Network(PrintError):
|
||||||
on_finish = default_on_finish
|
on_finish = default_on_finish
|
||||||
network = cls.get_instance()
|
network = cls.get_instance()
|
||||||
proxy = network.proxy if network else None
|
proxy = network.proxy if network else None
|
||||||
async with make_aiohttp_session(proxy) as session:
|
async with make_aiohttp_session(proxy, timeout=timeout) as session:
|
||||||
if method == 'get':
|
if method == 'get':
|
||||||
async with session.get(url, params=params, headers=headers) as resp:
|
async with session.get(url, params=params, headers=headers) as resp:
|
||||||
return await on_finish(resp)
|
return await on_finish(resp)
|
||||||
|
@ -1193,7 +1195,8 @@ class Network(PrintError):
|
||||||
else:
|
else:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
coro = asyncio.run_coroutine_threadsafe(cls._send_http_on_proxy(method, url, **kwargs), loop)
|
coro = asyncio.run_coroutine_threadsafe(cls._send_http_on_proxy(method, url, **kwargs), loop)
|
||||||
return coro.result(5)
|
# note: _send_http_on_proxy has its own timeout, so no timeout here:
|
||||||
|
return coro.result()
|
||||||
|
|
||||||
# methods used in scripts
|
# methods used in scripts
|
||||||
async def get_peers(self):
|
async def get_peers(self):
|
||||||
|
|
|
@ -67,12 +67,12 @@ class HandlerTwoFactor(QObject, PrintError):
|
||||||
return
|
return
|
||||||
window = self.window.top_level_window()
|
window = self.window.top_level_window()
|
||||||
auth_code = self.plugin.auth_dialog(window)
|
auth_code = self.plugin.auth_dialog(window)
|
||||||
try:
|
WaitingDialog(parent=window,
|
||||||
wallet.on_otp(tx, auth_code)
|
message=_('Waiting for TrustedCoin server to sign transaction...'),
|
||||||
except:
|
task=lambda: wallet.on_otp(tx, auth_code),
|
||||||
on_failure(sys.exc_info())
|
on_success=lambda *args: on_success(tx),
|
||||||
return
|
on_error=on_failure)
|
||||||
on_success(tx)
|
|
||||||
|
|
||||||
class Plugin(TrustedCoinPlugin):
|
class Plugin(TrustedCoinPlugin):
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ class TrustedCoinCosignerClient(PrintError):
|
||||||
except:
|
except:
|
||||||
return await resp.text()
|
return await resp.text()
|
||||||
|
|
||||||
def send_request(self, method, relative_url, data=None):
|
def send_request(self, method, relative_url, data=None, *, timeout=None):
|
||||||
network = Network.get_instance()
|
network = Network.get_instance()
|
||||||
if not network:
|
if not network:
|
||||||
raise ErrorConnectingServer('You are offline.')
|
raise ErrorConnectingServer('You are offline.')
|
||||||
|
@ -148,9 +148,17 @@ class TrustedCoinCosignerClient(PrintError):
|
||||||
headers['user-agent'] = self.user_agent
|
headers['user-agent'] = self.user_agent
|
||||||
try:
|
try:
|
||||||
if method == 'get':
|
if method == 'get':
|
||||||
response = Network.send_http_on_proxy(method, url, params=data, headers=headers, on_finish=self.handle_response)
|
response = Network.send_http_on_proxy(method, url,
|
||||||
|
params=data,
|
||||||
|
headers=headers,
|
||||||
|
on_finish=self.handle_response,
|
||||||
|
timeout=timeout)
|
||||||
elif method == 'post':
|
elif method == 'post':
|
||||||
response = Network.send_http_on_proxy(method, url, json=data, headers=headers, on_finish=self.handle_response)
|
response = Network.send_http_on_proxy(method, url,
|
||||||
|
json=data,
|
||||||
|
headers=headers,
|
||||||
|
on_finish=self.handle_response,
|
||||||
|
timeout=timeout)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
except TrustedCoinException:
|
except TrustedCoinException:
|
||||||
|
@ -219,7 +227,8 @@ class TrustedCoinCosignerClient(PrintError):
|
||||||
'otp': otp,
|
'otp': otp,
|
||||||
'transaction': transaction
|
'transaction': transaction
|
||||||
}
|
}
|
||||||
return self.send_request('post', 'cosigner/%s/sign' % quote(id), payload)
|
return self.send_request('post', 'cosigner/%s/sign' % quote(id), payload,
|
||||||
|
timeout=60)
|
||||||
|
|
||||||
def transfer_credit(self, id, recipient, otp, signature_callback):
|
def transfer_credit(self, id, recipient, otp, signature_callback):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -953,6 +953,8 @@ def make_aiohttp_session(proxy: Optional[dict], headers=None, timeout=None):
|
||||||
headers = {'User-Agent': 'Electrum'}
|
headers = {'User-Agent': 'Electrum'}
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = aiohttp.ClientTimeout(total=10)
|
timeout = aiohttp.ClientTimeout(total=10)
|
||||||
|
elif isinstance(timeout, (int, float)):
|
||||||
|
timeout = aiohttp.ClientTimeout(total=timeout)
|
||||||
ssl_context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=ca_path)
|
ssl_context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=ca_path)
|
||||||
|
|
||||||
if proxy:
|
if proxy:
|
||||||
|
|
Loading…
Add table
Reference in a new issue