diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 359d6bf22e6275f979c041a883f291951de8aec9..e57e96cc4aad17fffc804fde731f0334a67b1574 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -11,7 +11,7 @@ from ucoinpy.api import bma as bma from ucoinpy.api.bma import ConnectionHandler import asyncio -from aiohttp.errors import ClientError +from aiohttp.errors import ClientError, DisconnectedError import logging import time import jsonschema @@ -21,7 +21,7 @@ from PyQt5.QtCore import QObject, pyqtSignal class Node(QObject): """ - A node is a peer seend from the client point of view. + A node is a peer send from the client point of view. This node can have multiple states : - ONLINE : The node is available for requests - OFFLINE: The node is disconnected @@ -317,6 +317,9 @@ class Node(QObject): except ClientError: logging.debug("Client error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + except DisconnectedError: + logging.debug("Disconnected error : {0}".format(self.pubkey)) + self.state = Node.OFFLINE except asyncio.TimeoutError: logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE @@ -338,6 +341,9 @@ class Node(QObject): except ClientError: logging.debug("Client error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + except DisconnectedError: + logging.debug("Disconnected error : {0}".format(self.pubkey)) + self.state = Node.OFFLINE except asyncio.TimeoutError: logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE @@ -375,6 +381,9 @@ class Node(QObject): except asyncio.TimeoutError: logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + except DisconnectedError: + logging.debug("Disconnected error : {0}".format(self.pubkey)) + self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) self.state = Node.CORRUPTED @@ -405,6 +414,9 @@ class Node(QObject): except asyncio.TimeoutError: logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + except DisconnectedError: + logging.debug("Disconnected error : {0}".format(self.pubkey)) + self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) self.state = Node.CORRUPTED @@ -443,6 +455,9 @@ class Node(QObject): except asyncio.TimeoutError: logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + except DisconnectedError: + logging.debug("Disconnected error : {0}".format(self.pubkey)) + self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) self.state = Node.CORRUPTED @@ -480,6 +495,9 @@ class Node(QObject): except asyncio.TimeoutError: logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + except DisconnectedError: + logging.debug("Disconnected error : {0}".format(self.pubkey)) + self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) self.state = Node.CORRUPTED @@ -494,6 +512,9 @@ class Node(QObject): except asyncio.TimeoutError: logging.debug("Timeout error : {0}".format(self.pubkey)) self.state = Node.OFFLINE + except DisconnectedError: + logging.debug("Disconnected error : {0}".format(self.pubkey)) + self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) self.state = Node.CORRUPTED diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index 6e925d0cf8d45c878f9c61daa6bc8aa988637e71..0fac26596c32b4a9b20d362e703b0d8f1af29cf1 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -6,6 +6,7 @@ Created on 8 mars 2014 import logging import asyncio +import aiohttp from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QApplication from PyQt5.QtGui import QCursor @@ -88,8 +89,8 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) server = self.config_dialog.lineedit_server.text() port = self.config_dialog.spinbox_port.value() logging.debug("Is valid ? ") - self.node = yield from Node.from_address(None, server, port) - if self.node: + try: + self.node = yield from Node.from_address(None, server, port) community = Community.create(self.node) self.config_dialog.button_connect.setEnabled(False) self.config_dialog.button_register.setEnabled(False) @@ -119,8 +120,10 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) else: self.config_dialog.label_error.setText(self.tr("Your account already exists on the network")) - else: - self.config_dialog.label_error.setText(self.tr("Could not connect.")) + except aiohttp.errors.DisconnectedError as e: + self.config_dialog.label_error.setText(str(e)) + except aiohttp.errors.ClientError as e: + self.config_dialog.label_error.setText(str(e)) @pyqtSlot() def check_register(self): diff --git a/src/cutecoin/main.py b/src/cutecoin/main.py index 5145e7bd740ca26e37eca3a9d9391143edf68849..962f95cb43c0ac0dff2ab263e9760c6f1612ebff 100755 --- a/src/cutecoin/main.py +++ b/src/cutecoin/main.py @@ -41,7 +41,8 @@ def async_exception_handler(loop, context): log_lines.append('{}: {!r}'.format(key, context[key])) logging.error('\n'.join(log_lines), exc_info=exc_info) - if "Unclosed" not in message: + if "Unclosed" not in message and \ + "gaierror(-2" not in message: os._exit(1)