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

Cancel wot_tab draw task when changing data

parent ac26fb38
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,8 @@ class Graph(object):
"""
self.app = app
self.community = community
self.signature_validity = 0
self.ARC_STATUS_STRONG_time = 0
# graph empty if None parameter
self._graph = graph or (dict() and (graph is None))
......@@ -157,75 +159,76 @@ class Graph(object):
:param identity identity_account: Account identity instance
:return:
"""
yield from self.refresh_signature_validity()
# add certifiers of uid
for certifier in tuple(certifier_list):
# add only valid certification...
if (time.time() - certifier['cert_time']) > self.signature_validity:
continue
# new node
if certifier['identity'].pubkey not in self._graph.keys():
node_status = 0
is_member = yield from certifier['identity'].is_member(self.community)
if certifier['identity'].pubkey == identity_account.pubkey:
node_status += NODE_STATUS_HIGHLIGHTED
if is_member is False:
node_status += NODE_STATUS_OUT
self._graph[certifier['identity'].pubkey] = {
'id': certifier['identity'].pubkey,
'arcs': list(),
'text': certifier['identity'].uid,
'tooltip': certifier['identity'].pubkey,
'status': node_status,
'connected': [identity.pubkey]
}
# keep only the latest certification
if self._graph[certifier['identity'].pubkey]['arcs']:
if certifier['cert_time'] < self._graph[certifier['identity'].pubkey]['arcs'][0]['cert_time']:
if self.community:
yield from self.refresh_signature_validity()
# add certifiers of uid
for certifier in tuple(certifier_list):
# add only valid certification...
if (time.time() - certifier['cert_time']) > self.signature_validity:
continue
# display validity status
if (time.time() - certifier['cert_time']) > self.ARC_STATUS_STRONG_time:
arc_status = ARC_STATUS_WEAK
else:
arc_status = ARC_STATUS_STRONG
# new node
if certifier['identity'].pubkey not in self._graph.keys():
node_status = 0
is_member = yield from certifier['identity'].is_member(self.community)
if certifier['identity'].pubkey == identity_account.pubkey:
node_status += NODE_STATUS_HIGHLIGHTED
if is_member is False:
node_status += NODE_STATUS_OUT
self._graph[certifier['identity'].pubkey] = {
'id': certifier['identity'].pubkey,
'arcs': list(),
'text': certifier['identity'].uid,
'tooltip': certifier['identity'].pubkey,
'status': node_status,
'connected': [identity.pubkey]
}
arc = {
'id': identity.pubkey,
'status': arc_status,
'tooltip': QLocale.toString(
QLocale(),
QDateTime.fromTime_t(certifier['cert_time'] + self.signature_validity).date(),
QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
),
'cert_time': certifier['cert_time']
}
# keep only the latest certification
if self._graph[certifier['identity'].pubkey]['arcs']:
if certifier['cert_time'] < self._graph[certifier['identity'].pubkey]['arcs'][0]['cert_time']:
continue
# display validity status
if (time.time() - certifier['cert_time']) > self.ARC_STATUS_STRONG_time:
arc_status = ARC_STATUS_WEAK
else:
arc_status = ARC_STATUS_STRONG
if certifier['block_number']:
current_validations = self.community.network.latest_block_number - certifier['block_number']
else:
current_validations = 0
members_pubkeys = yield from self.community.members_pubkeys()
max_validation = self.community.network.fork_window(members_pubkeys) + 1
arc = {
'id': identity.pubkey,
'status': arc_status,
'tooltip': QLocale.toString(
QLocale(),
QDateTime.fromTime_t(certifier['cert_time'] + self.signature_validity).date(),
QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
),
'cert_time': certifier['cert_time']
}
# Current validation can be negative if self.community.network.latest_block_number
# is not refreshed yet
if max_validation > current_validations > 0:
if self.app.preferences['expert_mode']:
arc['validation_text'] = "{0}/{1}".format(current_validations,
max_validation)
if certifier['block_number']:
current_validations = self.community.network.latest_block_number - certifier['block_number']
else:
validation = current_validations / max_validation * 100
arc['validation_text'] = "{0} %".format(QLocale().toString(float(validation), 'f', 0))
else:
arc['validation_text'] = None
current_validations = 0
members_pubkeys = yield from self.community.members_pubkeys()
max_validation = self.community.network.fork_window(members_pubkeys) + 1
# Current validation can be negative if self.community.network.latest_block_number
# is not refreshed yet
if max_validation > current_validations > 0:
if self.app.preferences['expert_mode']:
arc['validation_text'] = "{0}/{1}".format(current_validations,
max_validation)
else:
validation = current_validations / max_validation * 100
arc['validation_text'] = "{0} %".format(QLocale().toString(float(validation), 'f', 0))
else:
arc['validation_text'] = None
# add arc to certifier
self._graph[certifier['identity'].pubkey]['arcs'].append(arc)
# if certifier node not in identity nodes
if certifier['identity'].pubkey not in tuple(self._graph[identity.pubkey]['connected']):
# add certifier node to identity node
self._graph[identity.pubkey]['connected'].append(certifier['identity'].pubkey)
# add arc to certifier
self._graph[certifier['identity'].pubkey]['arcs'].append(arc)
# if certifier node not in identity nodes
if certifier['identity'].pubkey not in tuple(self._graph[identity.pubkey]['connected']):
# add certifier node to identity node
self._graph[identity.pubkey]['connected'].append(certifier['identity'].pubkey)
@asyncio.coroutine
def add_certified_list(self, certified_list, identity, identity_account):
......
......@@ -153,8 +153,9 @@ class BmaAccess(QObject):
strdata = bytes(reply.readAll()).decode('utf-8')
json_data = json.loads(strdata)
self._update_cache(request, req_args, get_args, json_data)
future_data.set_result(json_data)
else:
if not future_data.cancelled():
future_data.set_result(json_data)
elif not future_data.cancelled():
future_data.set_result(request.null_value)
future_data = asyncio.Future()
......
......@@ -59,7 +59,8 @@ class IdentitiesRegistry:
identity.local_state = LocalState.PARTIAL
identity.blockchain_state = BlockchainState.VALIDATED
logging.debug("Lookup : found {0}".format(identity))
future_identity.set_result(True)
if not future_identity.cancelled():
future_identity.set_result(True)
else:
reply = community.bma_access.simple_request(qtbma.wot.Lookup,
req_args={'search': pubkey})
......@@ -67,7 +68,7 @@ class IdentitiesRegistry:
elif tries < 3:
reply = community.bma_access.simple_request(qtbma.wot.CertifiersOf, req_args={'search': pubkey})
reply.finished.connect(lambda: handle_certifiersof_reply(reply, tries=tries+1))
else:
elif not future_identity.cancelled():
future_identity.set_result(True)
def handle_lookup_reply(reply, tries=0):
......@@ -89,26 +90,28 @@ class IdentitiesRegistry:
identity.blockchain_state = BlockchainState.BUFFERED
identity.local_state = LocalState.PARTIAL
logging.debug("Lookup : found {0}".format(identity))
future_identity.set_result(True)
if not future_identity.cancelled():
future_identity.set_result(identity)
return
future_identity.set_result(True)
if not future_identity.cancelled():
future_identity.set_result(identity)
elif tries < 3:
reply = community.bma_access.simple_request(qtbma.wot.Lookup, req_args={'search': pubkey})
reply.finished.connect(lambda: handle_lookup_reply(reply, tries=tries+1))
else:
future_identity.set_result(True)
elif not future_identity.cancelled():
future_identity.set_result(identity)
future_identity = asyncio.Future()
if pubkey in self._instances:
identity = self._instances[pubkey]
future_identity.set_result(True)
if not future_identity.cancelled():
future_identity.set_result(identity)
else:
identity = Identity.empty(pubkey)
self._instances[pubkey] = identity
reply = community.bma_access.simple_request(qtbma.wot.CertifiersOf, req_args={'search': pubkey})
reply.finished.connect(lambda: handle_certifiersof_reply(reply))
yield from future_identity
return identity
return future_identity
def from_handled_data(self, uid, pubkey, blockchain_state):
"""
......
......@@ -48,6 +48,7 @@ class WotTabWidget(QWidget, Ui_WotTabWidget):
self.community = None
self.password_asker = None
self.app = app
self.draw_task = None
# nodes list for menu from search
self.nodes = list()
......@@ -60,6 +61,9 @@ class WotTabWidget(QWidget, Ui_WotTabWidget):
self.password_asker = password_asker
def change_community(self, community):
if self.draw_task and not self.draw_task.done:
self.draw_task.cancel()
if self.community:
self.community.network.new_block_mined.disconnect(self.refresh)
if community:
......@@ -157,9 +161,17 @@ class WotTabWidget(QWidget, Ui_WotTabWidget):
)
)
@asyncify
@asyncio.coroutine
def draw_graph(self, identity):
if self.draw_task and not self.draw_task.done():
self.draw_task.cancel()
try:
self.draw_task = asyncio.async(self.cor_draw_graph(identity))
except asyncio.CancelledError:
logging.debug("Cancelled drawing task")
@asyncio.coroutine
def cor_draw_graph(self, identity):
"""
Draw community graph centered on the identity
......
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