moved dandelion_enabled from state to dandelion instance as enabled attribute #2246
No reviewers
Labels
No Label
bug
build
dependencies
developers
documentation
duplicate
enhancement
formatting
invalid
legal
mobile
obsolete
packaging
performance
protocol
question
refactoring
regression
security
test
translation
usability
wontfix
No Milestone
No project
No Assignees
1 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Bitmessage/PyBitmessage-2024-12-12#2246
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "test3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
how about making this into a static method that returns
True
/False
? Then the instance and the config are decoupled, you pass the result ofis_dandelion_enabled
do the constructor.@ -351,14 +350,14 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
raise BMProtoExcessiveDataError()
what we can do here is to move this check into the
Dandelion.hasHash
method. Then bmproto doesn't need to check.@ -40,10 +40,10 @@ class InvThread(StoppableThread):
@staticmethod
def handleLocallyGenerated(stream, hashId):
here,
addHash
could returnTrue
/False
depending on whether dandelion is on/off, and we could use this for further checks.here,
objectChildStem
could return value depending on whether dandelion is enabled or not@ -75,10 +75,10 @@ class InvThread(StoppableThread):
except KeyError:
continue
try:
Hmm, I forgot, the value is actually an int between 0 and 100. We need to rethink.
@ -105,7 +105,6 @@ class InvThread(StoppableThread):
for _ in range(len(chunk)):
this check could also be moved down (i.e.
reRandomiseStems
could check check the time.but the problem is we need a variable where we can store the return value. currently after checking we are storing in class attr.
@ -351,14 +350,14 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
raise BMProtoExcessiveDataError()
we can move into Dandelion.hasHash. but
hasHash
here used in some checks in iteration. i think that could not work same as here, like return direct True.Hmm, now I see the problem. We then probably could create a
Placeholder
instance insidedandelion.py
and create a proper instance here inbitmessagemain.py
. Then we can pass the value to the constructor.@ -351,14 +350,14 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
raise BMProtoExcessiveDataError()
The easiest solution is just to use the same approach in
if
as infor
. It would result in dummy loops but my guess is that it's not a big performance hit. It could be optimised for performance later if needed.invthread.py", line 55, in run
handleExpiredDandelion(dandelion.instance.expire())
@ -179,19 +191,18 @@ class Dandelion: # pylint: disable=old-style-class
def reRandomiseStems(self):
"""Re-shuffle stem mapping (parent <-> child pairs)"""
assert self.pool is not None
We could use lazy initialisation on
pool
too and keep it as an attribute, then we don't need to pass it later.@ -336,8 +336,8 @@ def assembleAddrMessage(peerList):
return retval
We can have
dandelion_enabled
default toTrue
. Then we can put it at the end of arguments as well.@ -319,16 +319,17 @@ class TestCore(unittest.TestCase):
def test_version(self):
we don't really need an instance of dandelion here. We just need a variable and we pass the same variable to
assembleVersionMessage
andassertEqual
It should maybe say "pass instance", I don't think "lazy init" is a good comment. We're not lazy initialising is_enabled or pool, we're lazy initialising dandelion.
Why in
bmobject
it doesfrom . import dandelion_ins
and here it doesfrom network import dandelion_ins
? Why is it inconsistent?@ -47,10 +46,23 @@ class Dandelion: # pylint: disable=old-style-class
average = FLUFF_TRIGGER_MEAN_DELAY
return start + expovariate(1.0 / average) + FLUFF_TRIGGER_FIXED_DELAY
Maybe "pass pool instance"
Do we need a separate
init_is_enabled
andis_dandelion_enabled
?@ -93,3 +104,4 @@
def maybeAddStem(self, connection, invQueue):
"""
If we had too few outbound connections, add the current one to the
current stem list. Dandelion as designed by the authors should
this isn't necessary, you can retrieve enabled directly as an object attribute
@ -182,4 +198,4 @@
with self.lock:
try:
# random two connections
self.stem = sample(
duplicate
we can just use
dandelion_ins.enabled
As per this (https://github.com/Bitmessage/PyBitmessage/pull/2246#discussion_r1618334811) , here
objectChildStem
is returning value whether dandelion is enabled or not and that is used here. I've modified it now as mentioned here.@ -182,4 +198,4 @@
with self.lock:
try:
# random two connections
self.stem = sample(
Fixed
@ -93,3 +104,4 @@
def maybeAddStem(self, connection, invQueue):
"""
If we had too few outbound connections, add the current one to the
current stem list. Dandelion as designed by the authors should
https://github.com/Bitmessage/PyBitmessage/pull/2246#discussion_r1618334811 , I've modified it now as mentioned here.
@ -47,10 +46,23 @@ class Dandelion: # pylint: disable=old-style-class
average = FLUFF_TRIGGER_MEAN_DELAY
return start + expovariate(1.0 / average) + FLUFF_TRIGGER_FIXED_DELAY
merged it into
is_dandelion_enabled
by changing it to classmethod from staticmethod. and removedinit_is_enabled
.changed comment.
@ -47,10 +46,23 @@ class Dandelion: # pylint: disable=old-style-class
average = FLUFF_TRIGGER_MEAN_DELAY
return start + expovariate(1.0 / average) + FLUFF_TRIGGER_FIXED_DELAY
Done
Chenged it to
from network import dandelion_ins
everywhere.@ -179,19 +191,18 @@ class Dandelion: # pylint: disable=old-style-class
def reRandomiseStems(self):
"""Re-shuffle stem mapping (parent <-> child pairs)"""
assert self.pool is not None
Done
@ -319,16 +319,17 @@ class TestCore(unittest.TestCase):
def test_version(self):
Done
Resolved now. moved Dandelion instance into
network/__init__.py
@ -75,10 +75,10 @@ class InvThread(StoppableThread):
except KeyError:
continue
try:
when dandelion is on what would be the probable return value. that help us resolve the fixing comparison between
int
andbool
As per https://github.com/Bitmessage/PyBitmessage/pull/2246#discussion_r1618334222. i have returned dandelion enabled value here as we. do i need to use
dandelion_ins.enabled
here as well?I would also pass
invQueue
using dependency injection. Then we can simplify import.@ -47,10 +46,23 @@ class Dandelion: # pylint: disable=old-style-class
average = FLUFF_TRIGGER_MEAN_DELAY
return start + expovariate(1.0 / average) + FLUFF_TRIGGER_FIXED_DELAY
I would call this
init_dandelion_enabled
We probably don't need to check for
dandelion_enabled
here.I think using
dandelion_ins.enabled
makes more sense.@ -47,10 +46,23 @@ class Dandelion: # pylint: disable=old-style-class
average = FLUFF_TRIGGER_MEAN_DELAY
return start + expovariate(1.0 / average) + FLUFF_TRIGGER_FIXED_DELAY
Value is coming from config at startup. so i think it is required.
Done
@ -47,10 +46,23 @@ class Dandelion: # pylint: disable=old-style-class
average = FLUFF_TRIGGER_MEAN_DELAY
return start + expovariate(1.0 / average) + FLUFF_TRIGGER_FIXED_DELAY
done
@ -47,10 +46,23 @@ class Dandelion: # pylint: disable=old-style-class
average = FLUFF_TRIGGER_MEAN_DELAY
return start + expovariate(1.0 / average) + FLUFF_TRIGGER_FIXED_DELAY
I mean we're checking twice, should work ok if we just check once.
At Constructor level, dependency injection is not working, having same issue. Dandelion class have two fns having invQueue dependency.
from pybitmessage.queues import invQueue
is working but for portable it fails.i think try except option would be better here until project fully migrated to py3
Used dependency injection at function level.