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

Fix errors due to bad connection quality

parent a936dec2
Branches
Tags
No related merge requests found
...@@ -11,7 +11,7 @@ from ucoinpy.api import bma as bma ...@@ -11,7 +11,7 @@ from ucoinpy.api import bma as bma
from ucoinpy.api.bma import ConnectionHandler from ucoinpy.api.bma import ConnectionHandler
import asyncio import asyncio
from aiohttp.errors import ClientError from aiohttp.errors import ClientError, DisconnectedError
import logging import logging
import time import time
import jsonschema import jsonschema
...@@ -21,7 +21,7 @@ from PyQt5.QtCore import QObject, pyqtSignal ...@@ -21,7 +21,7 @@ from PyQt5.QtCore import QObject, pyqtSignal
class Node(QObject): 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 : This node can have multiple states :
- ONLINE : The node is available for requests - ONLINE : The node is available for requests
- OFFLINE: The node is disconnected - OFFLINE: The node is disconnected
...@@ -317,6 +317,9 @@ class Node(QObject): ...@@ -317,6 +317,9 @@ class Node(QObject):
except ClientError: except ClientError:
logging.debug("Client error : {0}".format(self.pubkey)) logging.debug("Client error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
except DisconnectedError:
logging.debug("Disconnected error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
...@@ -338,6 +341,9 @@ class Node(QObject): ...@@ -338,6 +341,9 @@ class Node(QObject):
except ClientError: except ClientError:
logging.debug("Client error : {0}".format(self.pubkey)) logging.debug("Client error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
except DisconnectedError:
logging.debug("Disconnected error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
...@@ -375,6 +381,9 @@ class Node(QObject): ...@@ -375,6 +381,9 @@ class Node(QObject):
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
except DisconnectedError:
logging.debug("Disconnected error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except jsonschema.ValidationError: except jsonschema.ValidationError:
logging.debug("Validation error : {0}".format(self.pubkey)) logging.debug("Validation error : {0}".format(self.pubkey))
self.state = Node.CORRUPTED self.state = Node.CORRUPTED
...@@ -405,6 +414,9 @@ class Node(QObject): ...@@ -405,6 +414,9 @@ class Node(QObject):
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
except DisconnectedError:
logging.debug("Disconnected error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except jsonschema.ValidationError: except jsonschema.ValidationError:
logging.debug("Validation error : {0}".format(self.pubkey)) logging.debug("Validation error : {0}".format(self.pubkey))
self.state = Node.CORRUPTED self.state = Node.CORRUPTED
...@@ -443,6 +455,9 @@ class Node(QObject): ...@@ -443,6 +455,9 @@ class Node(QObject):
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
except DisconnectedError:
logging.debug("Disconnected error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except jsonschema.ValidationError: except jsonschema.ValidationError:
logging.debug("Validation error : {0}".format(self.pubkey)) logging.debug("Validation error : {0}".format(self.pubkey))
self.state = Node.CORRUPTED self.state = Node.CORRUPTED
...@@ -480,6 +495,9 @@ class Node(QObject): ...@@ -480,6 +495,9 @@ class Node(QObject):
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
except DisconnectedError:
logging.debug("Disconnected error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except jsonschema.ValidationError: except jsonschema.ValidationError:
logging.debug("Validation error : {0}".format(self.pubkey)) logging.debug("Validation error : {0}".format(self.pubkey))
self.state = Node.CORRUPTED self.state = Node.CORRUPTED
...@@ -494,6 +512,9 @@ class Node(QObject): ...@@ -494,6 +512,9 @@ class Node(QObject):
except asyncio.TimeoutError: except asyncio.TimeoutError:
logging.debug("Timeout error : {0}".format(self.pubkey)) logging.debug("Timeout error : {0}".format(self.pubkey))
self.state = Node.OFFLINE self.state = Node.OFFLINE
except DisconnectedError:
logging.debug("Disconnected error : {0}".format(self.pubkey))
self.state = Node.OFFLINE
except jsonschema.ValidationError: except jsonschema.ValidationError:
logging.debug("Validation error : {0}".format(self.pubkey)) logging.debug("Validation error : {0}".format(self.pubkey))
self.state = Node.CORRUPTED self.state = Node.CORRUPTED
......
...@@ -6,6 +6,7 @@ Created on 8 mars 2014 ...@@ -6,6 +6,7 @@ Created on 8 mars 2014
import logging import logging
import asyncio import asyncio
import aiohttp
from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QApplication from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QApplication
from PyQt5.QtGui import QCursor from PyQt5.QtGui import QCursor
...@@ -88,8 +89,8 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) ...@@ -88,8 +89,8 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2])))
server = self.config_dialog.lineedit_server.text() server = self.config_dialog.lineedit_server.text()
port = self.config_dialog.spinbox_port.value() port = self.config_dialog.spinbox_port.value()
logging.debug("Is valid ? ") logging.debug("Is valid ? ")
try:
self.node = yield from Node.from_address(None, server, port) self.node = yield from Node.from_address(None, server, port)
if self.node:
community = Community.create(self.node) community = Community.create(self.node)
self.config_dialog.button_connect.setEnabled(False) self.config_dialog.button_connect.setEnabled(False)
self.config_dialog.button_register.setEnabled(False) self.config_dialog.button_register.setEnabled(False)
...@@ -119,8 +120,10 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) ...@@ -119,8 +120,10 @@ Yours : {0}, the network : {1}""".format(registered[1], registered[2])))
Yours : {0}, the network : {1}""".format(registered[1], registered[2]))) Yours : {0}, the network : {1}""".format(registered[1], registered[2])))
else: else:
self.config_dialog.label_error.setText(self.tr("Your account already exists on the network")) self.config_dialog.label_error.setText(self.tr("Your account already exists on the network"))
else: except aiohttp.errors.DisconnectedError as e:
self.config_dialog.label_error.setText(self.tr("Could not connect.")) self.config_dialog.label_error.setText(str(e))
except aiohttp.errors.ClientError as e:
self.config_dialog.label_error.setText(str(e))
@pyqtSlot() @pyqtSlot()
def check_register(self): def check_register(self):
......
...@@ -41,7 +41,8 @@ def async_exception_handler(loop, context): ...@@ -41,7 +41,8 @@ def async_exception_handler(loop, context):
log_lines.append('{}: {!r}'.format(key, context[key])) log_lines.append('{}: {!r}'.format(key, context[key]))
logging.error('\n'.join(log_lines), exc_info=exc_info) 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) os._exit(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment