Skip to content
Snippets Groups Projects
Commit d97cbdee authored by inso's avatar inso
Browse files

Compatibility with new conn_handler method

parent 88f04278
No related branches found
No related tags found
No related merge requests found
......@@ -186,8 +186,8 @@ class BmaConnector:
endpoint = random.choice(endpoints)
self._logger.debug(
"Requesting {0} on endpoint {1}".format(str(request.__name__), str(endpoint)))
futures.append(request(
endpoint.conn_handler(session, proxy=self._user_parameters.proxy()),
futures.append(request(next(
endpoint.conn_handler(session, proxy=self._user_parameters.proxy())),
**req_args))
except StopIteration:
# When no more node is available, we go out of the while loop
......@@ -234,7 +234,7 @@ class BmaConnector:
try:
self._logger.debug("Requesting {0} on endpoint {1}".format(str(request.__name__), str(endpoint)))
async with aiohttp.ClientSession() as session:
json_data = await request(endpoint.conn_handler(session), **req_args)
json_data = await request(next(endpoint.conn_handler(session), **req_args))
return json_data
except errors.DuniterError as e:
if e.ucode == errors.HTTP_LIMITATION:
......@@ -283,8 +283,8 @@ class BmaConnector:
with aiohttp.ClientSession() as session:
for endpoint in endpoints:
self._logger.debug("Trying to connect to : " + str(endpoint))
reply = asyncio.ensure_future(request(endpoint.conn_handler(session,
proxy=self._user_parameters.proxy()),
reply = asyncio.ensure_future(request(next(endpoint.conn_handler(session,
proxy=self._user_parameters.proxy())),
**req_args))
replies.append(reply)
......
......@@ -95,7 +95,7 @@ class NodeConnector(QObject):
async def safe_request(self, endpoint, request, proxy, req_args={}):
try:
conn_handler = endpoint.conn_handler(self.session, proxy=proxy)
conn_handler = next(endpoint.conn_handler(self.session, proxy=proxy))
data = await request(conn_handler, **req_args)
return data
except (ClientError, gaierror, TimeoutError, ConnectionRefusedError, DisconnectedError, ValueError) as e:
......@@ -155,7 +155,7 @@ class NodeConnector(QObject):
for endpoint in [e for e in self.node.endpoints if isinstance(e, BMAEndpoint)]:
if not self._connected['block']:
try:
conn_handler = endpoint.conn_handler(self.session, proxy=self._user_parameters.proxy())
conn_handler = next(endpoint.conn_handler(self.session, proxy=self._user_parameters.proxy()))
ws_connection = bma.ws.block(conn_handler)
async with ws_connection as ws:
self._connected['block'] = True
......@@ -222,8 +222,8 @@ class NodeConnector(QObject):
self.node.state = Node.ONLINE
if not self.node.current_buid or self.node.current_buid.sha_hash != block_data['hash']:
for endpoint in [e for e in self.node.endpoints if isinstance(e, BMAEndpoint)]:
conn_handler = endpoint.conn_handler(self.session,
proxy=self._user_parameters.proxy())
conn_handler = next(endpoint.conn_handler(self.session,
proxy=self._user_parameters.proxy()))
self._logger.debug("Requesting {0}".format(conn_handler))
try:
previous_block = await self.safe_request(endpoint, bma.blockchain.block,
......@@ -285,8 +285,8 @@ class NodeConnector(QObject):
for endpoint in [e for e in self.node.endpoints if isinstance(e, BMAEndpoint)]:
if not self._connected['peer']:
try:
conn_handler = endpoint.conn_handler(self.session,
proxy=self._user_parameters.proxy())
conn_handler = next(endpoint.conn_handler(self.session,
proxy=self._user_parameters.proxy()))
ws_connection = bma.ws.peer(conn_handler)
async with ws_connection as ws:
self._connected['peer'] = True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment