0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-08 14:34:53 -05:00

mapport: 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.
This commit is contained in:
Antoine Poinsot 2024-10-31 18:43:31 -04:00
parent 8fb45fcda0
commit 9e6cba2988

View file

@ -25,7 +25,6 @@
static CThreadInterrupt g_mapport_interrupt;
static std::thread g_mapport_thread;
static std::atomic_bool g_mapport_enabled{false};
using namespace std::chrono_literals;
static constexpr auto PORT_MAPPING_REANNOUNCE_PERIOD{20min};
@ -124,20 +123,9 @@ static bool ProcessPCP()
static void ThreadMapPort()
{
bool ok;
do {
ok = false;
if (g_mapport_enabled) {
ok = ProcessPCP();
if (ok) continue;
}
if (!g_mapport_enabled) {
return;
}
} while (ok || g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD));
ProcessPCP();
} while (g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD));
}
void StartThreadMapPort()
@ -150,8 +138,7 @@ void StartThreadMapPort()
void StartMapPort(bool enable)
{
g_mapport_enabled = enable;
if (g_mapport_enabled) {
if (enable) {
StartThreadMapPort();
} else {
InterruptMapPort();
@ -161,7 +148,6 @@ void StartMapPort(bool enable)
void InterruptMapPort()
{
g_mapport_enabled = false;
if (g_mapport_thread.joinable()) {
g_mapport_interrupt();
}