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