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 a4445569..7e628d90 100644 --- a/src/api.py +++ b/src/api.py @@ -73,13 +73,13 @@ from six.moves import configparser, http_client, xmlrpc_server 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 469ccbfa..4555e941 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -19,10 +19,10 @@ import helper_msgcoding 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 f2821f65..f2c949e8 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -20,11 +20,11 @@ import helper_sql 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 83311b9b..8b0f02be 100644 --- a/src/network/bmobject.py +++ b/src/network/bmobject.py @@ -4,8 +4,8 @@ BMObject and it's exceptions. 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 797dab5e..068181b5 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -13,9 +13,9 @@ import time # 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 d7062d24..1696c7ae 100644 --- a/src/network/connectionchooser.py +++ b/src/network/connectionchooser.py @@ -6,8 +6,8 @@ import logging 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 96c980bb..601c98cb 100644 --- a/src/protocol.py +++ b/src/network/protocol.py @@ -13,16 +13,26 @@ import time 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 fd9b0d08..d610c049 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -16,10 +16,10 @@ import threading 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 6e453b19..e28f20b8 100644 --- a/src/tests/test_api_thread.py +++ b/src/tests/test_api_thread.py @@ -7,7 +7,7 @@ from struct import pack 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 9dfb1d23..e6471017 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 e3137b25..e923b899 100644 --- a/src/tests/test_protocol.py +++ b/src/tests/test_protocol.py @@ -5,7 +5,8 @@ Tests for common protocol functions import sys import unittest -from pybitmessage import protocol, state +from pybitmessage import state +from pybitmessage.network import protocol from pybitmessage.helper_startup import fixSocket