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

Fix network discovery

parent 6e7763bd
No related branches found
No related tags found
No related merge requests found
...@@ -202,7 +202,7 @@ class Network(QObject): ...@@ -202,7 +202,7 @@ class Network(QObject):
blocks_occurences = Counter(blocks) blocks_occurences = Counter(blocks)
blocks_by_occurences = {} blocks_by_occurences = {}
for key, value in blocks_occurences.items(): for key, value in blocks_occurences.items():
the_block = [n.block for n in self.nodes if n.block['hash'] == key][0] the_block = [n.block for n in self.nodes if n.block and n.block['hash'] == key][0]
if value not in blocks_by_occurences: if value not in blocks_by_occurences:
blocks_by_occurences[value] = [the_block] blocks_by_occurences[value] = [the_block]
else: else:
...@@ -244,7 +244,7 @@ class Network(QObject): ...@@ -244,7 +244,7 @@ class Network(QObject):
synced_block_hash = blocks_by_occurences[most_present][0]['hash'] synced_block_hash = blocks_by_occurences[most_present][0]['hash']
for n in [n for n in self._nodes if n.state in (Node.ONLINE, Node.DESYNCED)]: for n in [n for n in self._nodes if n.state in (Node.ONLINE, Node.DESYNCED)]:
if n.block['hash'] == synced_block_hash: if n.block and n.block['hash'] == synced_block_hash:
n.state = Node.ONLINE n.state = Node.ONLINE
else: else:
n.state = Node.DESYNCED n.state = Node.DESYNCED
......
...@@ -99,7 +99,7 @@ class Node(QObject): ...@@ -99,7 +99,7 @@ class Node(QObject):
raise InvalidNodeCurrency(peer.currency, currency) raise InvalidNodeCurrency(peer.currency, currency)
node = cls(peer.currency, peer.endpoints, node = cls(peer.currency, peer.endpoints,
"", pubkey, bma.blockchain.Block.null_value, "", pubkey, None,
Node.ONLINE, time.time(), Node.ONLINE, time.time(),
{'root': "", 'leaves': []}, {'root': "", 'leaves': []},
"", "", 0) "", "", 0)
...@@ -349,6 +349,8 @@ class Node(QObject): ...@@ -349,6 +349,8 @@ class Node(QObject):
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
@asyncify
@asyncio.coroutine
def refresh_summary(self): def refresh_summary(self):
conn_handler = self.endpoint.conn_handler() conn_handler = self.endpoint.conn_handler()
...@@ -371,12 +373,15 @@ class Node(QObject): ...@@ -371,12 +373,15 @@ class Node(QObject):
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
@asyncify
@asyncio.coroutine
def refresh_uid(self): def refresh_uid(self):
conn_handler = self.endpoint.conn_handler() conn_handler = self.endpoint.conn_handler()
try: try:
data = yield from bma.wot.Lookup(conn_handler, self.pubkey).get() data = yield from bma.wot.Lookup(conn_handler, self.pubkey).get()
self.state = Node.ONLINE self.state = Node.ONLINE
timestamp = 0 timestamp = 0
uid = None
for result in data['results']: for result in data['results']:
if result["pubkey"] == self.pubkey: if result["pubkey"] == self.pubkey:
uids = result['uids'] uids = result['uids']
...@@ -384,8 +389,7 @@ class Node(QObject): ...@@ -384,8 +389,7 @@ class Node(QObject):
if uid["meta"]["timestamp"] > timestamp: if uid["meta"]["timestamp"] > timestamp:
timestamp = uid["meta"]["timestamp"] timestamp = uid["meta"]["timestamp"]
uid = uid["uid"] uid = uid["uid"]
if uid and self._uid != uid:
if self._uid != uid:
self._uid = uid self._uid = uid
self.changed.emit() self.changed.emit()
except ValueError as e: except ValueError as e:
...@@ -401,6 +405,8 @@ class Node(QObject): ...@@ -401,6 +405,8 @@ class Node(QObject):
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
@asyncify
@asyncio.coroutine
def refresh_peers(self): def refresh_peers(self):
conn_handler = self.endpoint.conn_handler() conn_handler = self.endpoint.conn_handler()
......
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