From e768deac5b4c640e6d8ecc75564bf5ce5ca8af75 Mon Sep 17 00:00:00 2001 From: inso <insomniak.fr@gmaiL.com> Date: Mon, 12 Mar 2018 16:35:11 +0100 Subject: [PATCH] Squashed commit of the following: commit fdb977d1353c6eeaa6b0e1fe9ead2aebdb03d14b Author: inso <insomniak.fr@gmaiL.com> Date: Mon Mar 12 16:01:59 2018 +0100 Add connector if we go below the limit commit 36c80d9f8343a9a33f6f17f92797d7b0daa47487 Author: inso <insomniak.fr@gmaiL.com> Date: Mon Mar 12 15:57:42 2018 +0100 Stabilisation of WS2P requests commit f782e818834f4af7b80af36b84be58ab486675b3 Author: inso <insomniak.fr@gmaiL.com> Date: Mon Mar 12 14:09:55 2018 +0100 Use WS2P to detect consensus --- src/sakia/data/connectors/bma.py | 11 ++++++++++- src/sakia/services/network.py | 4 ++-- tests/conftest.py | 2 +- tests/functional/test_connection_cfg_dialog.py | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/sakia/data/connectors/bma.py b/src/sakia/data/connectors/bma.py index 1d91c919..0a3378b7 100644 --- a/src/sakia/data/connectors/bma.py +++ b/src/sakia/data/connectors/bma.py @@ -165,7 +165,15 @@ class BmaConnector: async def _verified_request(self, node, request): try: - return await request + res = await request + self._nodes_processor.handle_success(node) + return res + except errors.DuniterError as e: + if e.ucode == errors.HTTP_LIMITATION: + self._logger.debug("Exception in responses : " + str(e)) + self._nodes_processor.handle_failure(node) + else: + return e except BaseException as e: self._logger.debug(str(e)) self._nodes_processor.handle_failure(node) @@ -233,6 +241,7 @@ class BmaConnector: else: return _best_answer(answers, answers_data, nb_verification) + nodes = self._nodes_processor.nodes(currency) raise NoPeerAvailable("", len(synced_nodes)) async def simple_get(self, currency, request, req_args): diff --git a/src/sakia/services/network.py b/src/sakia/services/network.py index 826d590c..d52b28b2 100644 --- a/src/sakia/services/network.py +++ b/src/sakia/services/network.py @@ -87,7 +87,7 @@ class NetworkService(QObject): sample.append(n) continue - for node in random.sample(sample, 6): + for node in random.sample(sample, min(len(sample), 6)): connectors.append(NodeConnector(node, app.parameters)) network = cls(app, currency, node_processor, connectors, blockchain_service, identities_service) return network @@ -176,7 +176,7 @@ class NetworkService(QObject): sample.append(n) continue - for node in random.sample(sample, 1): + for node in random.sample(sample, min(len(sample), 1)): self.add_connector(NodeConnector(node, self.app.parameters)) diff --git a/tests/conftest.py b/tests/conftest.py index c3df0702..adf11990 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -102,7 +102,7 @@ def fake_server(application, event_loop): uid="", current_buid=BlockUID.empty(), current_ts=0, - state=Node.ONLINE, + state=0, software="duniter", version="0.40.2")) application.instanciate_services() diff --git a/tests/functional/test_connection_cfg_dialog.py b/tests/functional/test_connection_cfg_dialog.py index 10599d38..54ebcf82 100644 --- a/tests/functional/test_connection_cfg_dialog.py +++ b/tests/functional/test_connection_cfg_dialog.py @@ -65,7 +65,7 @@ async def test_register_empty_blockchain(application, fake_server, bob, tmpdir): assert len(ConnectionsProcessor.instanciate(application).connections()) == 1 accept_dialog("Registration") - application.loop.call_later(10, close_dialog) + application.loop.call_later(30, close_dialog) asyncio.ensure_future(exec_test()) await connection_config_dialog.async_exec() await fake_server.close() -- GitLab