From 95af3a859bdfb647f0f1a70291705c6af1131e10 Mon Sep 17 00:00:00 2001 From: anand k Date: Mon, 22 Apr 2024 08:59:00 +0530 Subject: [PATCH] Renamed dandelion flag to dandelion_enabled --- src/bitmessagemain.py | 6 +++--- src/network/bmproto.py | 2 +- src/network/dandelion.py | 2 +- src/network/invthread.py | 4 ++-- src/protocol.py | 4 ++-- src/state.py | 2 +- src/tests/core.py | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 18e62773..f51ee063 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -156,12 +156,12 @@ class Main(object): set_thread_name("PyBitmessage") - state.dandelion = config.safeGetInt('network', 'dandelion') + state.dandelion_enabled = config.safeGetInt('network', 'dandelion') # dandelion requires outbound connections, without them, # stem objects will get stuck forever - if state.dandelion and not config.safeGetBoolean( + if state.dandelion_enabled and not config.safeGetBoolean( 'bitmessagesettings', 'sendoutgoingconnections'): - state.dandelion = 0 + state.dandelion_enabled = 0 if state.testmode or config.safeGetBoolean( 'bitmessagesettings', 'extralowdifficulty'): diff --git a/src/network/bmproto.py b/src/network/bmproto.py index f4dd8845..a0674077 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -350,7 +350,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): raise BMProtoExcessiveDataError() # ignore dinv if dandelion turned off - if dandelion and not state.dandelion: + if dandelion and not state.dandelion_enabled: return True for i in map(str, items): diff --git a/src/network/dandelion.py b/src/network/dandelion.py index 8a7aff29..35e70c95 100644 --- a/src/network/dandelion.py +++ b/src/network/dandelion.py @@ -49,7 +49,7 @@ class Dandelion: # pylint: disable=old-style-class def addHash(self, hashId, source=None, stream=1): """Add inventory vector to dandelion stem""" - if not state.dandelion: + if not state.dandelion_enabled: return with self.lock: self.hashMap[hashId] = Stem( diff --git a/src/network/invthread.py b/src/network/invthread.py index e1dc1b65..346baa93 100644 --- a/src/network/invthread.py +++ b/src/network/invthread.py @@ -41,7 +41,7 @@ class InvThread(StoppableThread): """Locally generated inventory items require special handling""" state.Dandelion.addHash(hashId, stream=stream) for connection in BMConnectionPool().connections(): - if state.dandelion and connection != \ + if state.dandelion_enabled and connection != \ state.Dandelion.objectChildStem(hashId): continue connection.objectsNewToThem[hashId] = time() @@ -77,7 +77,7 @@ class InvThread(StoppableThread): if connection == state.Dandelion.objectChildStem(inv[1]): # Fluff trigger by RNG # auto-ignore if config set to 0, i.e. dandelion is off - if random.randint(1, 100) >= state.dandelion: # nosec B311 + if random.randint(1, 100) >= state.dandelion_enabled: # nosec B311 fluffs.append(inv[1]) # send a dinv only if the stem node supports dandelion elif connection.services & protocol.NODE_DANDELION > 0: diff --git a/src/protocol.py b/src/protocol.py index d6ea884d..d1a5f865 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -351,7 +351,7 @@ def assembleVersionMessage( '>q', NODE_NETWORK | (NODE_SSL if haveSSL(server) else 0) - | (NODE_DANDELION if state.dandelion else 0) + | (NODE_DANDELION if state.dandelion_enabled else 0) ) payload += pack('>q', int(time.time())) @@ -375,7 +375,7 @@ def assembleVersionMessage( '>q', NODE_NETWORK | (NODE_SSL if haveSSL(server) else 0) - | (NODE_DANDELION if state.dandelion else 0) + | (NODE_DANDELION if state.dandelion_enabled else 0) ) # = 127.0.0.1. This will be ignored by the remote host. # The actual remote connected IP will be used. diff --git a/src/state.py b/src/state.py index 21584560..e3f49215 100644 --- a/src/state.py +++ b/src/state.py @@ -44,7 +44,7 @@ ownAddresses = {} discoveredPeers = {} -dandelion = 0 +dandelion_enabled = 0 kivy = False diff --git a/src/tests/core.py b/src/tests/core.py index 868efe2b..21966dcc 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -324,7 +324,7 @@ class TestCore(unittest.TestCase): decoded = self._decode_msg(msg, "IQQiiQlsLv") peer, _, ua, streams = self._decode_msg(msg, "IQQiiQlsLv")[4:] self.assertEqual( - peer, Node(11 if state.dandelion else 3, '127.0.0.1', 8444)) + peer, Node(11 if state.dandelion_enabled else 3, '127.0.0.1', 8444)) self.assertEqual(ua, '/PyBitmessage:' + softwareVersion + '/') self.assertEqual(streams, [1]) # with multiple streams