From e4dc9bd575fcf64144410d439100d2d7b8fc133a Mon Sep 17 00:00:00 2001 From: Jan Segre Date: Thu, 15 Jun 2023 00:22:59 +0200 Subject: [PATCH] refactor(sync): move sync-v1 files to a separate module --- hathor/p2p/manager.py | 8 ++++---- hathor/p2p/sync_v1/__init__.py | 0 hathor/p2p/{node_sync.py => sync_v1/agent.py} | 2 +- hathor/p2p/{ => sync_v1}/downloader.py | 2 +- .../p2p/{sync_v1_factory.py => sync_v1/factory_v1_0.py} | 6 +++--- .../p2p/{sync_v1_1_factory.py => sync_v1/factory_v1_1.py} | 4 ++-- tests/p2p/test_sync.py | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 hathor/p2p/sync_v1/__init__.py rename hathor/p2p/{node_sync.py => sync_v1/agent.py} (99%) rename hathor/p2p/{ => sync_v1}/downloader.py (99%) rename hathor/p2p/{sync_v1_factory.py => sync_v1/factory_v1_0.py} (90%) rename hathor/p2p/{sync_v1_1_factory.py => sync_v1/factory_v1_1.py} (93%) diff --git a/hathor/p2p/manager.py b/hathor/p2p/manager.py index 5a60d63d1..8db007ba5 100644 --- a/hathor/p2p/manager.py +++ b/hathor/p2p/manager.py @@ -98,8 +98,8 @@ def __init__(self, enable_sync_v1: bool, enable_sync_v2: bool, enable_sync_v1_1: bool) -> None: - from hathor.p2p.sync_v1_1_factory import SyncV11Factory - from hathor.p2p.sync_v1_factory import SyncV1Factory + from hathor.p2p.sync_v1.factory_v1_0 import SyncV10Factory + from hathor.p2p.sync_v1.factory_v1_1 import SyncV11Factory if not (enable_sync_v1 or enable_sync_v1_1 or enable_sync_v2): raise TypeError(f'{type(self).__name__}() at least one sync version is required') @@ -181,11 +181,11 @@ def __init__(self, # sync-manager factories self._sync_factories = {} if enable_sync_v1: - self._sync_factories[SyncVersion.V1] = SyncV1Factory(self) + self._sync_factories[SyncVersion.V1] = SyncV10Factory(self) if enable_sync_v1_1: self._sync_factories[SyncVersion.V1_1] = SyncV11Factory(self) if enable_sync_v2: - self._sync_factories[SyncVersion.V2] = SyncV1Factory(self) + self._sync_factories[SyncVersion.V2] = SyncV10Factory(self) def set_manager(self, manager: 'HathorManager') -> None: """Set the manager. This method must be called before start().""" diff --git a/hathor/p2p/sync_v1/__init__.py b/hathor/p2p/sync_v1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/hathor/p2p/node_sync.py b/hathor/p2p/sync_v1/agent.py similarity index 99% rename from hathor/p2p/node_sync.py rename to hathor/p2p/sync_v1/agent.py index 0ae5d51c3..ff551a91d 100644 --- a/hathor/p2p/node_sync.py +++ b/hathor/p2p/sync_v1/agent.py @@ -25,9 +25,9 @@ from zope.interface import implementer from hathor.conf import HathorSettings -from hathor.p2p.downloader import Downloader from hathor.p2p.messages import GetNextPayload, GetTipsPayload, NextPayload, ProtocolMessages, TipsPayload from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_v1.downloader import Downloader from hathor.transaction import BaseTransaction from hathor.transaction.base_transaction import tx_or_block_from_bytes from hathor.transaction.storage.exceptions import TransactionDoesNotExist diff --git a/hathor/p2p/downloader.py b/hathor/p2p/sync_v1/downloader.py similarity index 99% rename from hathor/p2p/downloader.py rename to hathor/p2p/sync_v1/downloader.py index cbff9a3ff..ee068baca 100644 --- a/hathor/p2p/downloader.py +++ b/hathor/p2p/sync_v1/downloader.py @@ -27,7 +27,7 @@ if TYPE_CHECKING: from hathor.manager import HathorManager - from hathor.p2p.node_sync import NodeSyncTimestamp + from hathor.p2p.sync_v1.agent import NodeSyncTimestamp from hathor.transaction import BaseTransaction logger = get_logger() diff --git a/hathor/p2p/sync_v1_factory.py b/hathor/p2p/sync_v1/factory_v1_0.py similarity index 90% rename from hathor/p2p/sync_v1_factory.py rename to hathor/p2p/sync_v1/factory_v1_0.py index 0811beab0..5b618a7a1 100644 --- a/hathor/p2p/sync_v1_factory.py +++ b/hathor/p2p/sync_v1/factory_v1_0.py @@ -14,18 +14,18 @@ from typing import TYPE_CHECKING, Optional -from hathor.p2p.downloader import Downloader from hathor.p2p.manager import ConnectionsManager -from hathor.p2p.node_sync import NodeSyncTimestamp from hathor.p2p.sync_factory import SyncManagerFactory from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_v1.agent import NodeSyncTimestamp +from hathor.p2p.sync_v1.downloader import Downloader from hathor.util import Reactor if TYPE_CHECKING: from hathor.p2p.protocol import HathorProtocol -class SyncV1Factory(SyncManagerFactory): +class SyncV10Factory(SyncManagerFactory): def __init__(self, connections: ConnectionsManager): self.connections = connections self._downloader: Optional[Downloader] = None diff --git a/hathor/p2p/sync_v1_1_factory.py b/hathor/p2p/sync_v1/factory_v1_1.py similarity index 93% rename from hathor/p2p/sync_v1_1_factory.py rename to hathor/p2p/sync_v1/factory_v1_1.py index 42d79bacf..43c7e11a8 100644 --- a/hathor/p2p/sync_v1_1_factory.py +++ b/hathor/p2p/sync_v1/factory_v1_1.py @@ -14,11 +14,11 @@ from typing import TYPE_CHECKING, Optional -from hathor.p2p.downloader import Downloader from hathor.p2p.manager import ConnectionsManager -from hathor.p2p.node_sync import NodeSyncTimestamp from hathor.p2p.sync_factory import SyncManagerFactory from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_v1.agent import NodeSyncTimestamp +from hathor.p2p.sync_v1.downloader import Downloader from hathor.util import Reactor if TYPE_CHECKING: diff --git a/tests/p2p/test_sync.py b/tests/p2p/test_sync.py index 8950c4601..0efbd7b82 100644 --- a/tests/p2p/test_sync.py +++ b/tests/p2p/test_sync.py @@ -253,7 +253,7 @@ class SyncV1HathorSyncMethodsTestCase(unittest.SyncV1Params, BaseHathorSyncMetho __test__ = True def test_downloader(self): - from hathor.p2p.node_sync import NodeSyncTimestamp + from hathor.p2p.sync_v1.agent import NodeSyncTimestamp blocks = self._add_new_blocks(3)