From 48e8f0534c9e9a83b5b9d55b8eb060f80e9ce978 Mon Sep 17 00:00:00 2001 From: anand k Date: Wed, 26 Jun 2024 07:34:08 +0530 Subject: [PATCH] Moved protocol to network module --- src/api.py | 2 +- src/class_objectProcessor.py | 2 +- src/class_singleWorker.py | 2 +- src/network/bmobject.py | 2 +- src/network/bmproto.py | 2 +- src/network/connectionchooser.py | 2 +- src/{ => network}/protocol.py | 30 ++++++++++++++++++++---------- src/tests/core.py | 2 +- src/tests/test_api_thread.py | 2 +- src/tests/test_packets.py | 3 ++- src/tests/test_protocol.py | 3 ++- 11 files changed, 32 insertions(+), 20 deletions(-) rename src/{ => network}/protocol.py (96%) diff --git a/src/api.py b/src/api.py index a444556951..7e628d90de 100644 --- a/src/api.py +++ b/src/api.py @@ -73,13 +73,13 @@ import helper_inbox import helper_sent -import protocol import proofofwork import queues import shared import shutdown import state +import network.protocol as protocol from addresses import ( addBMIfNotPresent, decodeAddress, diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index 469ccbfab8..4555e9415d 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -19,10 +19,10 @@ import helper_sent import highlevelcrypto import l10n -import protocol import queues import shared import state +import network.protocol as protocol from addresses import ( decodeAddress, decodeVarint, encodeAddress, encodeVarint, varintDecodeError diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index f2821f6570..f2c949e8bc 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -20,11 +20,11 @@ import highlevelcrypto import l10n import proofofwork -import protocol import queues import shared import state import tr +import network.protocol as protocol from addresses import decodeAddress, decodeVarint, encodeVarint from bmconfigparser import config from helper_sql import sqlExecute, sqlQuery diff --git a/src/network/bmobject.py b/src/network/bmobject.py index 83311b9b53..8b0f02be6f 100644 --- a/src/network/bmobject.py +++ b/src/network/bmobject.py @@ -4,8 +4,8 @@ import logging import time -import protocol import state +import protocol import connectionpool from network import dandelion_ins from highlevelcrypto import calculateInventoryHash diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 797dab5e84..068181b554 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -13,9 +13,9 @@ # magic imports! import addresses import knownnodes -import protocol import state import connectionpool +import protocol from bmconfigparser import config from queues import invQueue, objectProcessorQueue, portCheckerQueue from randomtrackingdict import RandomTrackingDict diff --git a/src/network/connectionchooser.py b/src/network/connectionchooser.py index d7062d2479..1696c7ae51 100644 --- a/src/network/connectionchooser.py +++ b/src/network/connectionchooser.py @@ -6,8 +6,8 @@ import random import knownnodes -import protocol import state +import protocol from bmconfigparser import config from queues import queue, portCheckerQueue diff --git a/src/protocol.py b/src/network/protocol.py similarity index 96% rename from src/protocol.py rename to src/network/protocol.py index 96c980bbe9..601c98cbc3 100644 --- a/src/protocol.py +++ b/src/network/protocol.py @@ -13,16 +13,26 @@ from binascii import hexlify from struct import Struct, pack, unpack -import defaults -import highlevelcrypto -import state -from addresses import ( - encodeVarint, decodeVarint, decodeAddress, varintDecodeError) -from bmconfigparser import config -from debug import logger -from helper_sql import sqlExecute -from network.node import Peer -from version import softwareVersion +try: + import defaults + import highlevelcrypto + import state + from addresses import ( + encodeVarint, decodeVarint, decodeAddress, varintDecodeError) + from bmconfigparser import config + from debug import logger + from helper_sql import sqlExecute + from version import softwareVersion +except ImportError: + from pybitmessage import defaults, highlevelcrypto, state + from pybitmessage.addresses import ( + encodeVarint, decodeVarint, decodeAddress, varintDecodeError) + from pybitmessage.bmconfigparser import config + from pybitmessage.debug import logger + from pybitmessage.helper_sql import sqlExecute + from pybitmessage.version import softwareVersion + +from .node import Peer # Network constants magic = 0xE9BEB4D9 diff --git a/src/tests/core.py b/src/tests/core.py index fd9b0d08ba..d610c04910 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -16,10 +16,10 @@ import time import unittest -import protocol import state import helper_sent import helper_addressbook +import network.protocol as protocol from bmconfigparser import config from helper_msgcoding import MsgEncode, MsgDecode diff --git a/src/tests/test_api_thread.py b/src/tests/test_api_thread.py index 6e453b1923..e28f20b8ac 100644 --- a/src/tests/test_api_thread.py +++ b/src/tests/test_api_thread.py @@ -7,7 +7,7 @@ from six.moves import queue, xmlrpc_client -from pybitmessage import protocol +from pybitmessage.network import protocol from pybitmessage.highlevelcrypto import calculateInventoryHash from .partial import TestPartialRun diff --git a/src/tests/test_packets.py b/src/tests/test_packets.py index 9dfb1d23a8..e6471017e9 100644 --- a/src/tests/test_packets.py +++ b/src/tests/test_packets.py @@ -3,7 +3,8 @@ from binascii import unhexlify from struct import pack -from pybitmessage import addresses, protocol +from pybitmessage import addresses +from pybitmessage.network import protocol from .samples import ( sample_addr_data, sample_object_data, sample_object_expires) diff --git a/src/tests/test_protocol.py b/src/tests/test_protocol.py index e3137b25a3..e923b8994c 100644 --- a/src/tests/test_protocol.py +++ b/src/tests/test_protocol.py @@ -5,7 +5,8 @@ import sys import unittest -from pybitmessage import protocol, state +from pybitmessage import state +from pybitmessage.network import protocol from pybitmessage.helper_startup import fixSocket