From 385acfc3a5b9e871fefb4184c9054ea0069d4437 Mon Sep 17 00:00:00 2001 From: ovari123 Date: Sat, 21 Dec 2024 23:59:02 -0400 Subject: [PATCH] cleanup Change-Id: Id59bce284de0a8a683c62d5eb4388fe228f4d950 --- src/upnp/protocol/natpmp/nat_pmp.cpp | 20 +++++++-------- src/upnp/upnp_context.cpp | 38 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/upnp/protocol/natpmp/nat_pmp.cpp b/src/upnp/protocol/natpmp/nat_pmp.cpp index 9aeb71b..790b680 100644 --- a/src/upnp/protocol/natpmp/nat_pmp.cpp +++ b/src/upnp/protocol/natpmp/nat_pmp.cpp @@ -60,7 +60,7 @@ NatPmp::initNatPmp() // Local address must be valid. if (not getHostAddress() or getHostAddress().isLoopback()) { - if (logger_) logger_->warn("NAT-PMP: Does not have a valid local address!"); + if (logger_) logger_->warn("NAT-PMP: No valid local address!"); return; } @@ -94,7 +94,7 @@ NatPmp::initNatPmp() } if (err < 0) { - if (logger_) logger_->error("NAT-PMP: Unable to initialize libnatpmp -> {}", getNatPmpErrorStr(err)); + if (logger_) logger_->error("NAT-PMP: Unable to initialize libnatpmp → {}", getNatPmpErrorStr(err)); return; } @@ -105,8 +105,8 @@ NatPmp::initNatPmp() // Set the local (gateway) address. igd_->setLocalIp(igdAddr); - // NAT-PMP protocol does not have UID, but we will set generic - // one debugging purposes. + // NAT-PMP protocol does not have UID, setting genetic one + // for debugging purposes. igd_->setUID("NAT-PMP Gateway"); // Search and set the public address. @@ -226,7 +226,7 @@ bool NatPmp::isReady() const { if (observer_ == nullptr) { - if (logger_) logger_->error("NAT-PMP: the observer is not set!"); + if (logger_) logger_->error("NAT-PMP: The observer is not set!"); return false; } @@ -408,7 +408,7 @@ NatPmp::sendMappingRequest(Mapping& mapping, uint32_t& lifetime) if (response.type == NATPMP_RESPTYPE_PUBLICADDRESS) { responseValid = false; if (logger_) - logger_->error("NAT-PMP: unexpected response to request for mapping {} from IGD {} [type: PUBLICADDRESS]", + logger_->error("NAT-PMP: Unexpected response to request for mapping {} from IGD {} [type: PUBLICADDRESS]", mapping.toString(), igd_->toString()); } else { @@ -425,7 +425,7 @@ NatPmp::sendMappingRequest(Mapping& mapping, uint32_t& lifetime) response.pnu.newportmapping.privateport != expectedPrivatePort) { responseValid = false; if (logger_) - logger_->error("NAT-PMP: unexpected response to request for mapping {} from IGD {}" + logger_->error("NAT-PMP: Unexpected response to request for mapping {} from IGD {}" " [type={}, resultcode={}, privateport={}, mappedpublicport={}, lifetime={}]", mapping.toString(), igd_->toString(), @@ -451,8 +451,8 @@ NatPmp::sendMappingRequest(Mapping& mapping, uint32_t& lifetime) // We requested the creation/renewal of a mapping and didn't get an error, so at this point // newExternalPort and newLifetime should both be nonzero. if (newExternalPort == 0 || newLifetime == 0) { - if (logger_) logger_->error("NAT-PMP: response from IGD {} to request for mapping {}" - " indicates that the mapping was deleted [external port: {}, lifetime: {}]", + if (logger_) logger_->error("NAT-PMP: Response from IGD {} to request for mapping {} " + "indicates that the mapping was deleted [external port: {}, lifetime: {}]", igd_->toString(), mapping.toString(), newExternalPort, @@ -553,7 +553,7 @@ NatPmp::getIgdPublicAddress() int err = sendpublicaddressrequest(&natpmpHdl_); if (err < 0) { - if (logger_) logger_->error("NAT-PMP: send public address request on IGD {} failed with error: {}", + if (logger_) logger_->error("NAT-PMP: Send public address request on IGD {} failed with error: {}", igd_->toString(), getNatPmpErrorStr(err)); diff --git a/src/upnp/upnp_context.cpp b/src/upnp/upnp_context.cpp index 61f7232..f8d44b3 100644 --- a/src/upnp/upnp_context.cpp +++ b/src/upnp/upnp_context.cpp @@ -68,7 +68,7 @@ UPnPContext::createIoContext(const std::shared_ptr& ctx, const if (ctx) { return ctx; } else { - if (logger) logger->debug("UPnPContext: starting dedicated io_context thread"); + if (logger) logger->debug("UPnPContext: Starting dedicated io_context thread"); auto ioCtx = std::make_shared(); ioContextRunner_ = std::make_unique([ioCtx, l=logger]() { try { @@ -120,7 +120,7 @@ UPnPContext::shutdown() if (cv.wait_for(lk, std::chrono::seconds(30), [this] { return shutdownComplete_; })) { if (logger_) logger_->debug("Shutdown completed"); } else { - if (logger_) logger_->error("Shutdown timed out"); + if (logger_) logger_->error("Shutdown timed-out"); shutdownTimedOut_ = true; } // NOTE: It's important to unlock mappingMutex_ here, otherwise we get a @@ -129,11 +129,11 @@ UPnPContext::shutdown() lk.unlock(); if (ioContextRunner_) { - if (logger_) logger_->debug("UPnPContext: stopping io_context thread {}", fmt::ptr(this)); + if (logger_) logger_->debug("UPnPContext: Stopping io_context thread {}", fmt::ptr(this)); ctx->stop(); ioContextRunner_->join(); ioContextRunner_.reset(); - if (logger_) logger_->debug("UPnPContext: stopping io_context thread - finished {}", fmt::ptr(this)); + if (logger_) logger_->debug("UPnPContext: Stopping io_context thread - finished {}", fmt::ptr(this)); } } @@ -250,7 +250,7 @@ UPnPContext::_connectivityChanged(const asio::error_code& ec) auto hostAddr = ip_utils::getLocalAddr(AF_INET); - if (logger_) logger_->debug("Connectivity change check: host address {}", hostAddr.toString()); + if (logger_) logger_->debug("Connectivity change check: Host address {}", hostAddr.toString()); auto restartUpnp = false; @@ -417,7 +417,7 @@ UPnPContext::registerController(void* controller) { std::lock_guard lock(mappingMutex_); if (shutdownComplete_) { - if (logger_) logger_->warn("UPnPContext already shut down"); + if (logger_) logger_->warn("UPnPContext already shutdown"); return; } auto ret = controllerList_.emplace(controller); @@ -488,7 +488,7 @@ UPnPContext::getAvailablePortNumber(PortType type) } // Very unlikely to get here. - if (logger_) logger_->error("Unable to find an available port after {} attempts", MAX_REQUEST_RETRIES); + if (logger_) logger_->error("Unable to find an available port after {} attempt(s)", MAX_REQUEST_RETRIES); return 0; } @@ -534,7 +534,7 @@ UPnPContext::provisionNewMappings(PortType type, int portCount) registerMapping(map); } else { // Very unlikely to get here! - if (logger_) logger_->error("Unable to provision port: no available port number"); + if (logger_) logger_->error("Unable to provision port: No available port number"); return; } } @@ -543,7 +543,7 @@ UPnPContext::provisionNewMappings(PortType type, int portCount) void UPnPContext::deleteUnneededMappings(PortType type, int portCount) { - if (logger_) logger_->debug("Remove {:d} unneeded mapping of type [{}]", portCount, Mapping::getTypeStr(type)); + if (logger_) logger_->debug("Remove {:d} unneeded mapping(s) of type [{}]", portCount, Mapping::getTypeStr(type)); std::lock_guard lock(mappingMutex_); auto& mappingList = getMappingList(type); @@ -563,7 +563,7 @@ UPnPContext::deleteUnneededMappings(PortType type, int portCount) it = mappingList.erase(it); portCount--; } else if (map->getState() != MappingState::OPEN) { - // If this methods is called, it means there are more open + // If this method is called, it means there are more open // mappings than required. So, all mappings in a state other // than "OPEN" state (typically in in-progress state) will // be deleted as well. @@ -609,7 +609,7 @@ UPnPContext::updateCurrentIgd() currentIgd_->getUID(), currentIgd_->toString()); } else { - if (logger_) logger_->warn("Unable to update current IGD: no valid IGD was found"); + if (logger_) logger_->warn("Unable to update current IGD: No valid IGD was found"); } } @@ -680,7 +680,7 @@ UPnPContext::renewMappings() const auto& igd = getCurrentIgd(); if (!igd) { - if (logger_) logger_->debug("Unable to renew mappings: no valid IGD available"); + if (logger_) logger_->debug("Unable to renew mappings: No valid IGD available"); return; } @@ -712,7 +712,7 @@ UPnPContext::renewMappings() } if (!toRenew.empty()) { - if (logger_) logger_->debug("Sending renewal requests for {} mappings", toRenew.size()); + if (logger_) logger_->debug("Sending renewal requests for {} mapping(s)", toRenew.size()); } for (const auto& map : toRenew) { const auto& protocol = protocolList_.at(map->getIgd()->getProtocol()); @@ -720,7 +720,7 @@ UPnPContext::renewMappings() } if (toRenewLaterCount > 0) { nextRenewalTime += MAPPING_RENEWAL_THROTTLING_DELAY; - if (logger_) logger_->debug("{} mappings didn't need to be renewed (next renewal scheduled for {:%Y-%m-%d %H:%M:%S})", + if (logger_) logger_->debug("{} mapping(s) didn't need to be renewed (next renewal scheduled for {:%Y-%m-%d %H:%M:%S})", toRenewLaterCount, fmt::localtime(sys_clock::to_time_t(nextRenewalTime))); mappingRenewalTimer_.expires_at(nextRenewalTime); @@ -943,7 +943,7 @@ UPnPContext::processPendingRequests() const auto& mappingList = getMappingList(type); for (const auto& [_, map] : mappingList) { if (map->getState() == MappingState::PENDING) { - if (logger_) logger_->debug("Will attempt to send a request for pending mapping {}", + if (logger_) logger_->debug("Attempting to send a request for pending mapping {}", map->toString()); requestsList.emplace_back(map); } @@ -994,8 +994,8 @@ UPnPContext::onIgdUpdated(const std::shared_ptr& igd, UpnpIgdEvent event) { std::lock_guard lock(publicAddressMutex_); if (knownPublicAddress_ and igd->getPublicIp() != knownPublicAddress_) { - if (logger_) logger_->warn("[{}] IGD external address [{}] does not match known public address [{}]." - " The mapped addresses might not be reachable", + if (logger_) logger_->warn("[{}] IGD external address [{}] does not match known public address [{}]. " + "The mapped addresses might not be reachable", protocolName, igd->getPublicIp().toString(), knownPublicAddress_.toString()); @@ -1068,7 +1068,7 @@ UPnPContext::onMappingRenewed(const std::shared_ptr& igd, const Mapping& ma return; } if (!mapPtr->isValid() || mapPtr->getState() != MappingState::OPEN) { - if (logger_) logger_->warn("Renewed mapping {} from IGD {} [{}] is in unexpected state", + if (logger_) logger_->warn("Renewed mapping {} from IGD {} [{}] is in an unexpected state", mapPtr->toString(), igd->toString(), mapPtr->getProtocolName()); @@ -1165,7 +1165,7 @@ UPnPContext::registerMapping(Mapping& map, bool available) if (map.getExternalPort() == 0) { auto port = getAvailablePortNumber(map.getType()); if (port == 0) { - if (logger_) logger_->error("Unable to register mapping: no available port number"); + if (logger_) logger_->error("Unable to register mapping: No available port number"); return mapPtr; } map.setExternalPort(port);