From 31c5b624cff05ab28389f0bcade3f3438fb66478 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Sat, 25 Apr 2015 15:42:34 +0200 Subject: [PATCH] Correction du bug de raffrichissement de la liste des noeuds --- res/icons/connected.svg | 16 +++++------ res/icons/disconnected.svg | 18 ++++++------- res/icons/weak_connect.svg | 18 ++++++------- src/cutecoin/core/net/network.py | 38 ++++++++++++--------------- src/cutecoin/core/net/node.py | 3 ++- src/cutecoin/core/watching/monitor.py | 5 ++++ src/cutecoin/gui/currency_tab.py | 6 ++--- src/cutecoin/gui/network_tab.py | 3 ++- 8 files changed, 55 insertions(+), 52 deletions(-) diff --git a/res/icons/connected.svg b/res/icons/connected.svg index 8e4a1717..c6a97c9c 100644 --- a/res/icons/connected.svg +++ b/res/icons/connected.svg @@ -40,7 +40,7 @@ fx="52.325901" fy="1005.1627" r="42.926411" - gradientTransform="matrix(1.539681,0,0,1.5451884,-48.391841,-562.49866)" + gradientTransform="matrix(1.539681,0,0,1.5451884,-68.190831,-562.49866)" gradientUnits="userSpaceOnUse" /> </defs> <sodipodi:namedview @@ -51,7 +51,7 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="2.8284271" - inkscape:cx="80.436882" + inkscape:cx="18.741815" inkscape:cy="33.829638" inkscape:document-units="px" inkscape:current-layer="layer1" @@ -59,9 +59,9 @@ units="px" inkscape:snap-bbox="false" inkscape:window-width="1366" - inkscape:window-height="725" - inkscape:window-x="-7" - inkscape:window-y="17" + inkscape:window-height="709" + inkscape:window-x="-4" + inkscape:window-y="0" inkscape:window-maximized="1" /> <metadata id="metadata3341"> @@ -71,7 +71,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -81,7 +81,7 @@ id="layer1" transform="translate(0,-952.36216)"> <ellipse - style="opacity:1;fill:#17d017;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + style="opacity:1;fill:#17d017;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="path3346" cx="51.785713" cy="1005.5765" @@ -90,7 +90,7 @@ <ellipse style="opacity:0.65;fill:url(#radialGradient4162);fill-opacity:1;stroke:none;stroke-width:1.25129819;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="path4148" - cx="32.173359" + cx="12.374369" cy="990.66699" rx="64.928177" ry="65.10495" /> diff --git a/res/icons/disconnected.svg b/res/icons/disconnected.svg index 4224156f..6647ff69 100644 --- a/res/icons/disconnected.svg +++ b/res/icons/disconnected.svg @@ -40,7 +40,7 @@ fx="52.325901" fy="1005.1627" r="42.926411" - gradientTransform="matrix(1.539681,0,0,1.5451884,-48.038287,-560.37733)" + gradientTransform="matrix(1.539681,0,0,1.5451884,-50.51316,-559.67022)" gradientUnits="userSpaceOnUse" /> </defs> <sodipodi:namedview @@ -51,7 +51,7 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="2.8284271" - inkscape:cx="80.436882" + inkscape:cx="18.741815" inkscape:cy="33.829638" inkscape:document-units="px" inkscape:current-layer="layer1" @@ -59,9 +59,9 @@ units="px" inkscape:snap-bbox="false" inkscape:window-width="1366" - inkscape:window-height="725" - inkscape:window-x="-7" - inkscape:window-y="17" + inkscape:window-height="709" + inkscape:window-x="-4" + inkscape:window-y="0" inkscape:window-maximized="1" /> <metadata id="metadata3341"> @@ -71,7 +71,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -81,7 +81,7 @@ id="layer1" transform="translate(0,-952.36216)"> <ellipse - style="opacity:1;fill:#c60002;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + style="opacity:1;fill:#c60002;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="path3346" cx="51.785713" cy="1005.5765" @@ -90,8 +90,8 @@ <ellipse style="opacity:0.65;fill:url(#radialGradient4162);fill-opacity:1;stroke:none;stroke-width:1.25129819;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="path4148" - cx="32.526913" - cy="992.78827" + cx="30.05204" + cy="993.49536" rx="64.928177" ry="65.10495" /> </g> diff --git a/res/icons/weak_connect.svg b/res/icons/weak_connect.svg index 26e2d94c..a00e5213 100644 --- a/res/icons/weak_connect.svg +++ b/res/icons/weak_connect.svg @@ -40,7 +40,7 @@ fx="52.325901" fy="1005.1627" r="42.926411" - gradientTransform="matrix(1.539681,0,0,1.5451884,-51.220268,-564.97353)" + gradientTransform="matrix(1.539681,0,0,1.5451884,-51.927374,-565.68063)" gradientUnits="userSpaceOnUse" /> </defs> <sodipodi:namedview @@ -51,7 +51,7 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="2.8284271" - inkscape:cx="80.436882" + inkscape:cx="18.741815" inkscape:cy="33.829638" inkscape:document-units="px" inkscape:current-layer="layer1" @@ -59,9 +59,9 @@ units="px" inkscape:snap-bbox="false" inkscape:window-width="1366" - inkscape:window-height="725" - inkscape:window-x="-7" - inkscape:window-y="17" + inkscape:window-height="709" + inkscape:window-x="-4" + inkscape:window-y="0" inkscape:window-maximized="1" /> <metadata id="metadata3341"> @@ -71,7 +71,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -81,7 +81,7 @@ id="layer1" transform="translate(0,-952.36216)"> <ellipse - style="opacity:1;fill:#fff41c;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + style="opacity:1;fill:#fff41c;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="path3346" cx="51.785713" cy="1005.5765" @@ -90,8 +90,8 @@ <ellipse style="opacity:0.65;fill:url(#radialGradient4162);fill-opacity:1;stroke:none;stroke-width:1.25129819;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="path4148" - cx="29.344933" - cy="988.19208" + cx="28.637825" + cy="987.48499" rx="64.928177" ry="65.10495" /> </g> diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py index 3154aa8b..4a85193f 100644 --- a/src/cutecoin/core/net/network.py +++ b/src/cutecoin/core/net/network.py @@ -201,36 +201,32 @@ class Network(Watcher): ''' self._must_crawl = True while self.continue_crawling(): + emit_change = False nodes = self.crawling(interval=10) new_inlines = [n.endpoint.inline() for n in nodes] last_inlines = [n.endpoint.inline() for n in self.nodes] - hash_new_nodes = hash(tuple(frozenset(sorted(new_inlines)))) - hash_last_nodes = hash(tuple(frozenset(sorted(last_inlines)))) - emit_change = False - self._mutex.lock() - try: - if hash_new_nodes != hash_last_nodes: - self.nodes = nodes + hash_new_nodes = str(tuple(frozenset(sorted(new_inlines)))) + hash_last_nodes = str(tuple(frozenset(sorted(last_inlines)))) + if hash_new_nodes != hash_last_nodes: + logging.debug("Nodes changed...") + self.nodes = nodes + emit_change = True + + for node in self.nodes: + if node.last_change + 3600 < time.time() and \ + node.state in (Node.OFFLINE, Node.CORRUPTED): + try: + node.changed.disconnect() + except TypeError: + logging.debug("Error : {0} not connected".format(node.pubkey)) + self.nodes.remove(node) emit_change = True - for node in self.nodes: - if node.last_change + 3600 < time.time() and \ - node.state in (Node.OFFLINE, Node.CORRUPTED): - try: - node.changed.disconnect() - except TypeError: - logging.debug("Error : {0} not connected".format(node.pubkey)) - self.nodes.remove(node) - emit_change = True - except: - raise - finally: - self._mutex.unlock() if emit_change: self.nodes_changed.emit() - + QCoreApplication.processEvents() self.stopped_perpetual_crawling.emit() diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 3f6cb0b6..04486092 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -275,6 +275,7 @@ class Node(QObject): except: logging.error('Error calling libc.__res_init') except RequestException as e: + logging.debug(str(e)) if self.state != Node.OFFLINE: self.state = Node.OFFLINE logging.debug("Change : new state offine") @@ -347,7 +348,7 @@ class Node(QObject): logging.debug(traversed_pubkeys) logging.debug("Traversing : next to read : {0} : {1}".format(node.pubkey, (node.pubkey not in traversed_pubkeys))) - node.peering_traversal(found_nodes, + node.peering_traversal(knew_pubkeys, found_nodes, traversed_pubkeys, interval, continue_crawling) time.sleep(interval) except RequestException as e: diff --git a/src/cutecoin/core/watching/monitor.py b/src/cutecoin/core/watching/monitor.py index 51ea8037..b2181a2a 100644 --- a/src/cutecoin/core/watching/monitor.py +++ b/src/cutecoin/core/watching/monitor.py @@ -77,3 +77,8 @@ class Monitor(object): self.threads_pool.remove(watcher.thread()) watcher.deleteLater() watcher.thread().deleteLater() + + self.threads_pool = [] + self._blockchain_watchers = {} + self._network_watchers = {} + self._persons_watchers = {} diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index b0017eb6..f1ab6025 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -156,13 +156,13 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): logging.debug("Refresh status") if self.community.network_quality() > 0.66: icon = '<img src=":/icons/connected" width="12" height="12"/>' - text = "Connected : Block {0}".format(self.community.network.latest_block) + text = " Block {0}".format(self.community.network.latest_block) elif self.community.network_quality() > 0.33: icon = '<img src=":/icons/weak_connect" width="12" height="12"/>' - text = "Connected (weak link) : Block {0}".format(self.community.network.latest_block) + text = " Block {0}".format(self.community.network.latest_block) else: icon = '<img src=":/icons/disconnected" width="12" height="12"/>' - text = "Disconnected : Block {0}".format(self.community.network.latest_block) + text = " Block {0}".format(self.community.network.latest_block) self.status_label.setText("{0}{1}".format(icon, text)) def refresh_wallets(self): diff --git a/src/cutecoin/gui/network_tab.py b/src/cutecoin/gui/network_tab.py index 71c70044..2bfbda91 100644 --- a/src/cutecoin/gui/network_tab.py +++ b/src/cutecoin/gui/network_tab.py @@ -6,7 +6,7 @@ Created on 20 févr. 2015 import logging from PyQt5.QtWidgets import QWidget -from PyQt5.QtCore import Qt, QThread +from PyQt5.QtCore import Qt, QThread, pyqtSlot from ..models.network import NetworkTableModel, NetworkFilterProxyModel from ..gen_resources.network_tab_uic import Ui_NetworkTabWidget @@ -30,6 +30,7 @@ class NetworkTabWidget(QWidget, Ui_NetworkTabWidget): community.network.nodes_changed.connect(self.refresh_nodes) + @pyqtSlot() def refresh_nodes(self): logging.debug("Refresh nodes") self.table_network.model().sourceModel().modelReset.emit() -- GitLab