Use then
instead of then_some
when checking upnp_enabled
to avoid useless UPnP query
#6170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Addressed
I noticed that Lighthouse sends to UPnP's multicast address
239.255.255.250
even though I passed--disable-upnp
. After some investigation, I found out thatlibp2p_upnp
'sBehaviour::default
immediately starts the search for the gateway. As we usebool::then_some
to transformupnp_enabled
into anOption<Behaviour>
, we have to callBehaviour::default
eagerly to pass it, triggering the search even ifupnp_enabled
isfalse
.Proposed Changes
Use
bool::then
instead, passingBehaviour::default
as function reference so that it is called lazily (only whenupnp_enabled
istrue
).Additional Info
In my opinion, starting the search immediately when
Behaviour::default
is invoked is bad design (as usuallydefault
only returns "some data"), so an alternative fix is to try and improve the API upstream.