Followup to #31130, this does a couple cleanups to src/mapport.* to clarify the logic now that there is a single protocol option for port mapping.
Cleanups to port mapping module post UPnP drop #31157
pull darosior wants to merge 7 commits into bitcoin:master from darosior:2410_cleanups_post_upnp_drop changing 4 files +10 −61-
darosior commented at 7:21 PM on October 25, 2024: member
-
DrahtBot commented at 7:21 PM on October 25, 2024: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
Code Coverage & Benchmarks
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31157.
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline for information on the review process.
Type Reviewers ACK laanwj, TheCharlatan If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
No conflicts as of last run.
- darosior renamed this:
Cleanups to port mapping module post UPnP dropt
Cleanups to port mapping module post UPnP drop
on Oct 25, 2024 - laanwj requested review from laanwj on Oct 27, 2024
- fanquake added this to the milestone 29.0 on Oct 28, 2024
-
c4e82b854c
mapport: make 'enabled' and 'current' bool
Since there is only a single protocol now, clarify the code by changing the protocol enum for a bool for both variables.
- darosior force-pushed on Oct 28, 2024
- darosior marked this as ready for review on Oct 28, 2024
-
2a6536ceda
mapport: rename 'use_pcp' to 'enable'
There is only a single protocol now, caller should just be concerned about whether to enable port mapping or not.
-
mapport: drop unnecessary function 9bd936fa34
-
in src/qt/optionsmodel.cpp:529 in f6855a369c outdated
525 | @@ -526,7 +526,7 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: 526 | case MapPortNatpmp: // core option - can be changed on-the-fly 527 | if (changed()) { 528 | update(value.toBool()); 529 | - node().mapPort(value.toBool()); 530 | + if (value.toBool()) node().mapPort();
laanwj commented at 10:39 AM on October 29, 2024:By adding this if here, this no longer accounts for the situation where port mapping is turned from on to off. i think i slightly prefer the old API for
mapPort.
darosior commented at 2:33 PM on October 29, 2024:Ah, yeah, right, that was stupid. I'll stick to just renaming
use_pcptoenabled.
darosior commented at 4:55 PM on October 29, 2024:Done.
darosior force-pushed on Oct 29, 2024in src/mapport.cpp:154 in 9bd936fa34 outdated
152 | @@ -153,44 +153,23 @@ void StartThreadMapPort() 153 | 154 | static void DispatchMapPort()
laanwj commented at 10:18 AM on October 30, 2024:DispatchMapPort is local and only called in one place; might as well roll it into
StartMapPort?
darosior commented at 10:48 PM on October 31, 2024:Done.
mapport: merge DispatchMapPort into StartMapPort 1b223cb19bmapport: remove unnecessary 'g_mapport_current' variable 8fb45fcda0in src/mapport.cpp:156 in 9bd936fa34 outdated
152 | @@ -153,44 +153,23 @@ void StartThreadMapPort() 153 | 154 | static void DispatchMapPort() 155 | { 156 | - if (g_mapport_current_proto == MapPortProtoFlag::NONE && g_mapport_enabled_protos == MapPortProtoFlag::NONE) { 157 | - return; 158 | - } 159 | - 160 | - if (g_mapport_current_proto == MapPortProtoFlag::NONE && g_mapport_enabled_protos != MapPortProtoFlag::NONE) { 161 | + if (!g_mapport_current && g_mapport_enabled) {
laanwj commented at 10:23 AM on October 30, 2024:Maybe i'm missing something but the intent of
g_mapport_currentis hazy to me. It's turned on inThreadMapPortwhileProcessPCPis running, then turned off temporarily whenProcessPCPreturns false.- If we want to know if the mapport thread is running,
g_mapport_thread.joinable()seems to suffice. - If we want to know if mapport thread is supposed to be running, or stop it, there's
g_mapport_enabled.
darosior commented at 9:46 PM on October 31, 2024:Yes, as far as i can tell it's an artifact of switching between protocols. I should remove it. In fact i think
g_mapport_enabledcan be removed as well as we can just useg_mapport_interruptto stop it.
darosior commented at 10:49 PM on October 31, 2024:Done for both
currentandenabled.
laanwj commented at 11:17 AM on November 1, 2024:Nice! Good catch.
9e6cba2988mapport: remove unnecessary 'g_mapport_enabled'
It was only necessary for switching between mapping protocols. It's also used to return in ThreadMapPort but we can just use the interrupt for this purpose.
70398ae05bmapport: make ProcessPCP void
Its return value is now unused. (It was also effectively unused before the previous commit, just in a roundabout way).
in src/mapport.cpp:126 in 28b21b8eef outdated
137 | - if (g_mapport_enabled_protos == MapPortProtoFlag::NONE) { 138 | - return; 139 | - } 140 | - 141 | - } while (ok || g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD)); 142 | + while ((!g_mapport_interrupt && ProcessPCP()) || g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD)) {}
laanwj commented at 11:17 AM on November 1, 2024:The thread is not supposed to exit if
ProcessPCP()fails. It should be more persistent: it should just wait a while and try again, maybe for the user to join a different network, swap their router, upgrade firmware, etc.
darosior commented at 1:17 PM on November 1, 2024:Yes, this will not exit if
ProcessPCPfails. (Unless it's interrupted of course.)
darosior commented at 1:39 PM on November 1, 2024:Maybe i should make this loop clearer? Like:
diff --git a/src/mapport.cpp b/src/mapport.cpp index b303017144..8df78f435d 100644 --- a/src/mapport.cpp +++ b/src/mapport.cpp @@ -123,7 +123,9 @@ static bool ProcessPCP() static void ThreadMapPort() { - while ((!g_mapport_interrupt && ProcessPCP()) || g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD)) {} + do { + ProcessPCP(); + } while (g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD)); } void StartThreadMapPort()Which also makes clearer that
ProcessPCP()should actually bevoid.
laanwj commented at 3:35 PM on November 1, 2024:Yes, that seems better. Making ProcessPCP a void is also fine with me.
darosior commented at 7:37 PM on November 4, 2024:Done.
darosior force-pushed on Nov 4, 2024darosior commented at 3:33 AM on January 14, 2025: memberI was playing with a couple routers and figured i'd test this. Could successfully map ports against an OPNSense box and a Spectrum "WIFI 6E router".
laanwj added the label P2P on Jan 14, 2025laanwj approvedlaanwj commented at 9:12 AM on January 15, 2025: memberCode review ACK 70398ae05bc36a2788e87f67ae06962f43fe35a6
glozow requested review from TheCharlatan on Feb 13, 2025glozow requested review from achow101 on Feb 13, 2025in src/mapport.cpp:119 in 70398ae05b
116 | @@ -119,28 +117,13 @@ static bool ProcessPCP() 117 | 118 | // We don't delete the mappings when the thread is interrupted because this would add additional complexity, so 119 | // we rather just choose a fairly short expiry time.
TheCharlatan commented at 7:18 PM on February 13, 2025:This comment seems to be lacking context now.
darosior commented at 8:02 PM on February 13, 2025:Why? If we are interrupted the
while()clause above will continue here and we won't tell the router to remove the mappings and just return instead.
TheCharlatan commented at 9:16 AM on February 14, 2025:Ah, I was irritated by the reference to the expiry, but it is only a couple of lines above, so I guess that is fine as is.
TheCharlatan approvedTheCharlatan commented at 9:38 AM on February 14, 2025: contributorACK 70398ae05bc36a2788e87f67ae06962f43fe35a6
Just a nit: Maybe cleanup the dangling includes?
fanquake merged this on Feb 14, 2025fanquake closed this on Feb 14, 2025darosior deleted the branch on Feb 18, 2025ContributorsLabelsMilestone
29.0
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 09:13 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me