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