Execute shutdown on port mapping thread

This commit is contained in:
Piotr Wójcik 2024-08-03 13:54:56 +02:00
commit 5f3337b53d
2 changed files with 11 additions and 0 deletions

View file

@ -66,6 +66,11 @@ void nano::port_mapping::stop ()
{ {
thread.join (); thread.join ();
} }
}
void nano::port_mapping::shutdown ()
{
node.logger.debug (nano::log::type::upnp, "UPnP shutdown...");
nano::lock_guard<nano::mutex> guard_l (mutex); nano::lock_guard<nano::mutex> guard_l (mutex);
for (auto & protocol : protocols | boost::adaptors::filtered ([] (auto const & p) { return p.enabled; })) for (auto & protocol : protocols | boost::adaptors::filtered ([] (auto const & p) { return p.enabled; }))
@ -308,6 +313,10 @@ void nano::port_mapping::run ()
condition.wait_for (lock, node.network_params.portmapping.health_check_period, [this] { return stopped.load (); }); condition.wait_for (lock, node.network_params.portmapping.health_check_period, [this] { return stopped.load (); });
} }
lock.unlock ();
shutdown ();
} }
/* /*

View file

@ -56,12 +56,14 @@ public:
private: private:
void run (); void run ();
void shutdown ();
/** Add port mappings for the node port (not RPC). Refresh when the lease ends. */ /** Add port mappings for the node port (not RPC). Refresh when the lease ends. */
void refresh_mapping (); void refresh_mapping ();
/** Check occasionally to refresh in case router loses mapping */ /** Check occasionally to refresh in case router loses mapping */
void check_mapping (); void check_mapping ();
/** Returns false if mapping still exists */ /** Returns false if mapping still exists */
bool check_lost_or_old_mapping (); bool check_lost_or_old_mapping ();
std::string get_config_port (std::string const &); std::string get_config_port (std::string const &);
private: // Dependencies private: // Dependencies