diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index c3c45bce0cdca352cb534f720818d5e76935c335..51d533e29ed448972e544e2565bd6b4aa91f7912 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -181,6 +181,7 @@ class Application(QObject): with open(network_path, 'r') as json_data: data = json.load(json_data) if 'version' in data and data['version'] == __version__: + logging.debug("Merging network : {0}".format(data)) community.load_merge_network(data['network']) else: os.remove(network_path) diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index e3e3a4f8e13dbfeef22e6a1445ab5f8844be41d7..5645a2295d793d53eb3b739083a8d1b90678d368 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -380,7 +380,7 @@ class Community(QObject): if cached: return self._cache.request(request, req_args, get_args) else: - nodes = self._network.online_nodes + nodes = self._network.synced_nodes for node in nodes: try: req = request(node.endpoint.conn_handler(), **req_args) @@ -469,6 +469,11 @@ class Community(QObject): :return: The community as a dict in json format. ''' + + nodes_data = [] + for node in self._network.online_nodes: + nodes_data.append(node.jsonify()) + data = {'currency': self.currency, - 'peers': self._network.jsonify()} + 'peers': nodes_data} return data \ No newline at end of file diff --git a/src/cutecoin/core/net/network.py b/src/cutecoin/core/net/network.py index 61f960d3498840878c30fb85138374437349fc19..4f66e98412eb9dd58aa5228d9764c7d092ee59b0 100644 --- a/src/cutecoin/core/net/network.py +++ b/src/cutecoin/core/net/network.py @@ -84,7 +84,6 @@ class Network(QObject): for data in json_data: node = Node.from_json(currency, data) nodes.append(node) - logging.debug("Loading : {:}".format(data['pubkey'])) block_max = max([n.block for n in nodes]) for node in nodes: node.check_sync(block_max) @@ -114,12 +113,19 @@ class Network(QObject): return True @property - def online_nodes(self): + def synced_nodes(self): ''' Get nodes which are in the ONLINE state. ''' return [n for n in self._nodes if n.state == Node.ONLINE] + @property + def online_nodes(self): + ''' + Get nodes which are in the ONLINE state. + ''' + return [n for n in self._nodes if n.state in (Node.ONLINE, Node.DESYNCED)] + @property def all_nodes(self): ''' @@ -178,14 +184,18 @@ class Network(QObject): for node in [n for n in nodes if n.state == Node.ONLINE]: node.check_sync(block_max) - for node in self._nodes: + for node in 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)) pass - self._nodes.remove(node) + nodes.remove(node) + for node in nodes: + logging.debug("Syncing : {0} : last changed {1} : unsynced : {2}".format(node.pubkey[:5], + node.last_change, time.time() - node.last_change)) logging.debug("Nodes found : {0}".format(nodes)) return nodes diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 622bc2cf2871bd823b179cfa08386c1397579ad5..c99b67c70604ec942f0bf59acc201309a88fa807 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -96,7 +96,8 @@ class Node(QObject): uid = "" pubkey = "" last_change = time.time() - + state = Node.ONLINE + logging.debug(data) for endpoint_data in data['endpoints']: endpoints.append(Endpoint.from_inline(endpoint_data)) @@ -112,8 +113,13 @@ class Node(QObject): if 'last_change' in data: last_change = data['last_change'] + if 'state' in data: + state = data['state'] + else: + logging.debug("Error : no state in node") + node = cls(currency, endpoints, uid, pubkey, 0, - Node.ONLINE, last_change) + state, last_change) node.refresh_state() return node @@ -121,6 +127,7 @@ class Node(QObject): data = {'pubkey': self._pubkey, 'uid': self._uid, 'currency': self._currency, + 'state': self._state, 'last_change': self._last_change} endpoints = [] for e in self._endpoints: @@ -160,12 +167,21 @@ class Node(QObject): def last_change(self): return self._last_change + @last_change.setter + def last_change(self, val): + logging.debug("{:} | Changed state : {:}".format(self.pubkey[:5], + val)) + self._last_change = val + def _change_state(self, new_state): + logging.debug("{:} | Last state : {:} / new state : {:}".format(self.pubkey[:5], + self.state, new_state)) if self.state != new_state: - self._last_change = time.time() + self.last_change = time.time() self._state = new_state def check_sync(self, block): + logging.debug("Check sync") if self._block < block: self._change_state(Node.DESYNCED) else: @@ -190,6 +206,7 @@ class Node(QObject): return uid def refresh_state(self): + logging.debug("Refresh state") emit_change = False try: informations = bma.network.Peering(self.endpoint.conn_handler()).get() @@ -270,7 +287,7 @@ class Node(QObject): (node.pubkey not in traversed_pubkeys))) if node.pubkey not in traversed_pubkeys and continue_crawling(): node.peering_traversal(found_nodes, - traversed_pubkeys, interval, continue_crawling()) + traversed_pubkeys, interval, continue_crawling) time.sleep(interval) except RequestException as e: self._change_state(Node.OFFLINE) diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 3589bc2af35f68961337b1baf3c969e464262435..be0cd92464b0501b2891280a2def94ab5fd6e300 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -28,7 +28,6 @@ class Cache(): def load_from_json(self, data): self._transfers = [] - logging.debug(data) data_sent = data['transfers'] for s in data_sent: diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index d12cd9d0f98b001a75ddfbfbe62710bfe2fb808d..85ab4f7d19fd55be3d6fcb1d769e2673168fafa9 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -32,14 +32,11 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): Constructor ''' super().__init__() - logging.debug("Info") self.setupUi(self) self.community = community self.account = account self.password_asker = password_asker - logging.debug("Table") members_model = MembersTableModel(community) - logging.debug("Filter") proxy_members = MembersFilterProxyModel() proxy_members.setSourceModel(members_model) self.table_community_members.setModel(proxy_members) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 56b130b866485cb64877cc6161d4ce50e7a1a357..6715f08737c49630a8caf93c27d423ac6ec58183 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -36,26 +36,22 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.community = community self.password_asker = password_asker self.status_label = status_label - logging.debug("Com") self.tab_community = CommunityTabWidget(self.app.current_account, self.community, self.password_asker) - logging.debug("Wal") + self.tab_wallets = WalletsTabWidget(self.app, self.app.current_account, self.community, self.password_asker) - logging.debug("Net") self.tab_network = NetworkTabWidget(self.community) - logging.debug("Connect") self.community.new_block_mined.connect(self.refresh_block) persons_watcher = self.app.monitor.persons_watcher(self.community) persons_watcher.person_changed.connect(self.tab_community.refresh_person) bc_watcher = self.app.monitor.blockchain_watcher(self.community) bc_watcher.error.connect(self.display_error) - logging.debug("Connected") person = Person.lookup(self.app.current_account.pubkey, self.community) try: diff --git a/src/cutecoin/models/peering.py b/src/cutecoin/models/peering.py index c3cc96f5d1162720fd14a2a29ecf12cd92f401a4..f46efa622b9870cb860e7ebda7f2361dee16f8e1 100644 --- a/src/cutecoin/models/peering.py +++ b/src/cutecoin/models/peering.py @@ -96,7 +96,7 @@ class PeeringTreeModel(QAbstractItemModel): Constructor ''' super().__init__(None) - self.nodes = community.nodes + self.nodes = community.online_nodes self.root_item = RootItem(community.currency) self.refresh_tree()