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

Working on bug fixing with no internet connection

parent 3cb5a502
No related branches found
No related tags found
No related merge requests found
...@@ -183,7 +183,7 @@ class Community(QObject): ...@@ -183,7 +183,7 @@ class Community(QObject):
""" """
# Get cached block by block number # Get cached block by block number
block_number = self.network.latest_block_number block_number = self.network.latest_block_number
block = yield from self.bma_access.future_request(self, bma.blockchain.Block, block = yield from self.bma_access.future_request(bma.blockchain.Block,
req_args={'number': block_number}) req_args={'number': block_number})
return block['monetaryMass'] return block['monetaryMass']
......
...@@ -155,7 +155,8 @@ class BmaAccess(QObject): ...@@ -155,7 +155,8 @@ class BmaAccess(QObject):
if need_reload: if need_reload:
nodes = self._network.synced_nodes nodes = self._network.synced_nodes
if len(nodes) > 0: if len(nodes) > 0:
for i in range(0, 6): tries = 0
while tries < 3:
node = random.choice(nodes) node = random.choice(nodes)
conn_handler = node.endpoint.conn_handler() conn_handler = node.endpoint.conn_handler()
req = request(conn_handler, **req_args) req = request(conn_handler, **req_args)
...@@ -166,9 +167,11 @@ class BmaAccess(QObject): ...@@ -166,9 +167,11 @@ class BmaAccess(QObject):
except ValueError as e: except ValueError as e:
if '404' in str(e) or '400' in str(e): if '404' in str(e) or '400' in str(e):
raise raise
continue tries += 1
except ClientError: except ClientError:
continue tries += 1
else:
raise NoPeerAvailable("", nodes)
return json_data return json_data
def simple_request(self, request, req_args={}, get_args={}): def simple_request(self, request, req_args={}, get_args={}):
...@@ -205,10 +208,13 @@ class BmaAccess(QObject): ...@@ -205,10 +208,13 @@ class BmaAccess(QObject):
""" """
nodes = self._network.online_nodes nodes = self._network.online_nodes
replies = [] replies = []
for node in nodes: if len(nodes) > 0:
logging.debug("Trying to connect to : " + node.pubkey) for node in nodes:
conn_handler = node.endpoint.conn_handler() logging.debug("Trying to connect to : " + node.pubkey)
req = request(conn_handler, **req_args) conn_handler = node.endpoint.conn_handler()
reply = yield from req.post(**post_args) req = request(conn_handler, **req_args)
replies.append(reply) reply = yield from req.post(**post_args)
replies.append(reply)
else:
raise NoPeerAvailable("", nodes)
return tuple(replies) return tuple(replies)
...@@ -12,6 +12,7 @@ from ucoinpy.api import bma as bma ...@@ -12,6 +12,7 @@ from ucoinpy.api import bma as bma
from ucoinpy.api.bma import ConnectionHandler from ucoinpy.api.bma import ConnectionHandler
import asyncio import asyncio
from aiohttp.errors import ClientError
import logging import logging
import time import time
import json import json
...@@ -251,6 +252,7 @@ class Node(QObject): ...@@ -251,6 +252,7 @@ class Node(QObject):
self.state, new_state)) self.state, new_state))
if self._state != new_state: if self._state != new_state:
self.last_change = time.time() self.last_change = time.time()
self.changed.emit()
self._state = new_state self._state = new_state
@property @property
...@@ -305,6 +307,9 @@ class Node(QObject): ...@@ -305,6 +307,9 @@ class Node(QObject):
self.set_block(None) self.set_block(None)
logging.debug("Error in block reply") logging.debug("Error in block reply")
self.changed.emit() self.changed.emit()
except ClientError:
logging.debug("Client error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
...@@ -335,6 +340,9 @@ class Node(QObject): ...@@ -335,6 +340,9 @@ class Node(QObject):
except ValueError as e: except ValueError as e:
logging.debug("Error in peering reply : {0}".format(str(e))) logging.debug("Error in peering reply : {0}".format(str(e)))
self.changed.emit() self.changed.emit()
except ClientError:
logging.debug("Client error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
...@@ -353,6 +361,9 @@ class Node(QObject): ...@@ -353,6 +361,9 @@ class Node(QObject):
except ValueError as e: except ValueError as e:
logging.debug("Error in summary : {0}".format(e)) logging.debug("Error in summary : {0}".format(e))
self.changed.emit() self.changed.emit()
except ClientError:
logging.debug("Client error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
...@@ -379,6 +390,9 @@ class Node(QObject): ...@@ -379,6 +390,9 @@ class Node(QObject):
else: else:
logging.debug("error in uid reply") logging.debug("error in uid reply")
self.changed.emit() self.changed.emit()
except ClientError:
logging.debug("Client error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
...@@ -409,6 +423,9 @@ class Node(QObject): ...@@ -409,6 +423,9 @@ class Node(QObject):
except ValueError as e: except ValueError as e:
logging.debug("Error in peers reply") logging.debug("Error in peers reply")
self.changed.emit() self.changed.emit()
except ClientError:
logging.debug("Client error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
......
...@@ -6,6 +6,7 @@ import json ...@@ -6,6 +6,7 @@ import json
import asyncio import asyncio
import logging import logging
from aiohttp.errors import ClientError from aiohttp.errors import ClientError
from ...tools.exceptions import NoPeerAvailable
class IdentitiesRegistry: class IdentitiesRegistry:
...@@ -69,8 +70,12 @@ class IdentitiesRegistry: ...@@ -69,8 +70,12 @@ class IdentitiesRegistry:
return identity return identity
except ValueError as e: except ValueError as e:
lookup_tries += 1 lookup_tries += 1
except asyncio.TimeoutError:
lookup_tries += 1
except ClientError: except ClientError:
lookup_tries += 1 lookup_tries += 1
except NoPeerAvailable:
return identity
return identity return identity
if pubkey in self._instances: if pubkey in self._instances:
...@@ -91,8 +96,12 @@ class IdentitiesRegistry: ...@@ -91,8 +96,12 @@ class IdentitiesRegistry:
return (yield from lookup()) return (yield from lookup())
else: else:
tries += 1 tries += 1
except asyncio.TimeoutError:
tries += 1
except ClientError: except ClientError:
tries += 1 tries += 1
except NoPeerAvailable:
return identity
return identity return identity
def from_handled_data(self, uid, pubkey, blockchain_state): def from_handled_data(self, uid, pubkey, blockchain_state):
......
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