From 58df28d697613f4b2b2b951180e76ddadec32600 Mon Sep 17 00:00:00 2001 From: ovari123 Date: Wed, 27 Nov 2024 00:10:56 -0400 Subject: [PATCH] cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ssh → SSH stun server → STUN server try → attempt turn server → TURN server UPNP → UPnP Change-Id: Ia31a3baae908850a7e99d50128447f2eb9113df1 --- include/turn_cache.h | 6 ++-- src/ice_transport.cpp | 46 +++++++++++++++---------------- src/turn/turn_transport.cpp | 2 +- src/upnp/protocol/pupnp/pupnp.cpp | 8 +++--- src/upnp/protocol/pupnp/pupnp.h | 6 ++-- src/upnp/upnp_context.cpp | 8 +++--- tools/dhtnet_crtmgr/main.cpp | 8 +++--- tools/dnc/dnc.yaml | 2 +- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/turn_cache.h b/include/turn_cache.h index a971e7f3..1fb7e32e 100644 --- a/include/turn_cache.h +++ b/include/turn_cache.h @@ -74,18 +74,18 @@ class TurnCache : public std::enable_shared_from_this */ std::atomic_bool isRefreshing_ {false}; /** - * This will cache the turn server resolution each time we launch + * This will cache the TURN server resolution each time we launch * Jami, or for each connectivityChange() */ void testTurn(IpAddr server); std::unique_ptr testTurnV4_; std::unique_ptr testTurnV6_; - // Used to detect if a turn server is down. + // Used to detect if a TURN server is down. void refreshTurnDelay(bool scheduleNext); std::chrono::seconds turnRefreshDelay_ {std::chrono::seconds(10)}; - // Store resoved turn addresses + // Store resoved TURN addresses mutable std::mutex cachedTurnMutex_ {}; std::unique_ptr cacheTurnV4_ {}; std::unique_ptr cacheTurnV6_ {}; diff --git a/src/ice_transport.cpp b/src/ice_transport.cpp index 7b9aad9f..dcf4b349 100644 --- a/src/ice_transport.cpp +++ b/src/ice_transport.cpp @@ -143,7 +143,7 @@ class IceTransport::Impl void addServerReflexiveCandidates(const std::vector>& addrList); // Generate server reflexive candidates using the published (DHT/Account) address std::vector> setupGenericReflexiveCandidates(); - // Generate server reflexive candidates using UPNP mappings. + // Generate server reflexive candidates using UPnP mappings. std::vector> setupUpnpReflexiveCandidates(); void setDefaultRemoteAddress(unsigned comp_id, const IpAddr& addr); IpAddr getDefaultRemoteAddress(unsigned comp_id) const; @@ -259,7 +259,7 @@ class IceTransport::Impl //============================================================================== /** - * Add stun/turn configuration or default host as candidates + * Add STUN/TURN configuration or default host as candidates */ static void @@ -288,7 +288,7 @@ add_stun_server(pj_pool_t& pool, pj_ice_strans_cfg& cfg, const StunServerInfo& i stun.cfg.max_pkt_size = STUN_MAX_PACKET_SIZE; stun.conn_type = cfg.stun.conn_type; if (logger) - logger->debug("Added stun server '{}', port {}", pj_strbuf(&stun.server), stun.port); + logger->debug("Added STUN server '{}', port {}", pj_strbuf(&stun.server), stun.port); } static void @@ -330,7 +330,7 @@ add_turn_server(pj_pool_t& pool, pj_ice_strans_cfg& cfg, const TurnServerInfo& i info.password.size()); } if (logger) - logger->debug("Added turn server '{}', port {}", pj_strbuf(&turn.server), turn.port); + logger->debug("Added TURN server '{}', port {}", pj_strbuf(&turn.server), turn.port); } //============================================================================== @@ -455,18 +455,18 @@ IceTransport::Impl::initIceInstance(const IceTransportOptions& options) if (not pool_) throw std::runtime_error("pj_pool_create() failed"); - // Note: For server reflexive candidates, UPNP mappings will + // Note: For server reflexive candidates, UPnP mappings will // be used if available. Then, the public address learnt during // the account registration process will be added only if it - // differs from the UPNP public address. - // Also note that UPNP candidates should be added first in order + // differs from the UPnP public address. + // Also note that UPnP candidates should be added first in order // to have a higher priority when performing the connectivity // checks. // STUN configs layout: // - index 0 : host IPv4 // - index 1 : host IPv6 - // - index 2 : upnp/generic srflx IPv4. - // - index 3 : generic srflx (if upnp exists and different) + // - index 2 : UPnP/generic srflx IPv4 + // - index 3 : generic srflx (if UPnP exists and different) config_.stun_tp_cnt = 0; @@ -482,7 +482,7 @@ IceTransport::Impl::initIceInstance(const IceTransportOptions& options) if (not upnpSrflxCand.empty()) { addServerReflexiveCandidates(upnpSrflxCand); // if (logger_) - // logger_->debug("[ice:{}] Added UPNP srflx candidates:", fmt::ptr(this)); + // logger_->debug("[ice:{}] Added UPnP srflx candidates:", fmt::ptr(this)); } } @@ -490,7 +490,7 @@ IceTransport::Impl::initIceInstance(const IceTransportOptions& options) if (not genericSrflxCand.empty()) { // Generic srflx candidates will be added only if different - // from upnp candidates. + // from UPnP candidates. if (upnpSrflxCand.empty() or (upnpSrflxCand[0].second.toString() != genericSrflxCand[0].second.toString())) { addServerReflexiveCandidates(genericSrflxCand); @@ -953,7 +953,7 @@ IceTransport::Impl::requestUpnpMappings() pendingState_ = state; } - // Request upnp mapping for each component. + // Request UPnP mapping for each component. for (unsigned id = 1; id <= compCount_; id++) { // Set port number to 0 to get any available port. Mapping requestedMap(portType); @@ -973,7 +973,7 @@ IceTransport::Impl::requestUpnpMappings() } else if (mapPtr->getState() == MappingState::FAILED) { state->failed = true; if (l) - l->error("UPNP mapping failed: {:s}", + l->error("UPnP mapping failed: {:s}", mapPtr->toString(true)); } state->cv.notify_all(); @@ -996,7 +996,7 @@ IceTransport::Impl::requestUpnpMappings() // Check the number of mappings if (state->failed || state->mappings.size() != compCount_) { if (logger_) - logger_->error("[ice:{}] UPNP mapping failed: expected {:d} mappings, got {:d}", + logger_->error("[ice:{}] UPnP mapping failed: expected {:d} mappings, got {:d}", fmt::ptr(this), compCount_, state->mappings.size()); @@ -1007,7 +1007,7 @@ IceTransport::Impl::requestUpnpMappings() } else { for (auto& map : state->mappings) { if(logger_) - logger_->debug("[ice:{}] UPNP mapping {:s} successfully allocated\n", + logger_->debug("[ice:{}] UPnP mapping {:s} successfully allocated\n", fmt::ptr(this), map.second->toString(true)); upnpMappings_.emplace(map.first, *map.second); @@ -1039,7 +1039,7 @@ IceTransport::Impl::addServerReflexiveCandidates( return; } - // Add config for server reflexive candidates (UPNP or from DHT). + // Add config for server reflexive candidates (UPnP or from DHT). if (not addStunConfig(pj_AF_INET())) return; @@ -1115,7 +1115,7 @@ IceTransport::Impl::setupGenericReflexiveCandidates() std::vector> IceTransport::Impl::setupUpnpReflexiveCandidates() { - // Add UPNP server reflexive candidates if available. + // Add UPnP server reflexive candidates if available. if (not hasUpnp()) return {}; @@ -1374,7 +1374,7 @@ IceTransport::startIce(const SDP& sdp) if (not isInitialized()) { if (pimpl_->logger_) - pimpl_->logger_->error(FMT_STRING("[ice:{}] not initialized transport"), fmt::ptr(pimpl_)); + pimpl_->logger_->error(FMT_STRING("[ice:{}] Uninitialized transport"), fmt::ptr(pimpl_)); pimpl_->is_stopped_ = true; return false; } @@ -1389,7 +1389,7 @@ IceTransport::startIce(const SDP& sdp) } if (pimpl_->logger_) - pimpl_->logger_->debug("[ice:{}] negotiation starting ({:u} remote candidates)", + pimpl_->logger_->debug("[ice:{}] Negotiation starting ({:u} remote candidates)", fmt::ptr(pimpl_), sdp.candidates.size()); pj_str_t ufrag, pwd; @@ -1626,7 +1626,7 @@ IceTransport::parseIceAttributeLine(unsigned streamIdx, cand.type = PJ_ICE_CAND_TYPE_RELAYED; else { if (pimpl_->logger_) - pimpl_->logger_->warn("[ice:{}] invalid remote candidate type '{:s}'", fmt::ptr(pimpl_), type); + pimpl_->logger_->warn("[ice:{}] Invalid remote candidate type '{:s}'", fmt::ptr(pimpl_), type); return false; } @@ -1639,7 +1639,7 @@ IceTransport::parseIceAttributeLine(unsigned streamIdx, cand.transport = PJ_CAND_TCP_SO; else { if (pimpl_->logger_) - pimpl_->logger_->warn("[ice:{}] invalid transport type type '{:s}'", fmt::ptr(pimpl_), tcp_type); + pimpl_->logger_->warn("[ice:{}] Invalid transport type type '{:s}'", fmt::ptr(pimpl_), tcp_type); return false; } } else { @@ -1667,7 +1667,7 @@ IceTransport::parseIceAttributeLine(unsigned streamIdx, status = pj_sockaddr_set_str_addr(af, &cand.addr, &tmpaddr); if (status != PJ_SUCCESS) { if (pimpl_->logger_) - pimpl_->logger_->warn("[ice:{}] invalid IP address '{:s}'", fmt::ptr(pimpl_), ipaddr); + pimpl_->logger_->warn("[ice:{}] Invalid IP address '{:s}'", fmt::ptr(pimpl_), ipaddr); return false; } @@ -1777,7 +1777,7 @@ IceTransport::send(unsigned compId, const unsigned char* buf, size_t len) errno = EAGAIN; } else { if (pimpl_->logger_) - pimpl_->logger_->error("[ice:{}] ice send failed: {:s}", fmt::ptr(pimpl_), sip_utils::sip_strerror(status)); + pimpl_->logger_->error("[ice:{}] ICE send failed: {:s}", fmt::ptr(pimpl_), sip_utils::sip_strerror(status)); errno = EIO; } return -1; diff --git a/src/turn/turn_transport.cpp b/src/turn/turn_transport.cpp index 0e36f464..d2f6e9a3 100644 --- a/src/turn/turn_transport.cpp +++ b/src/turn/turn_transport.cpp @@ -182,7 +182,7 @@ TurnTransport::TurnTransport(const TurnTransportParams& params, std::functionsettings = params; // PJSIP memory pool pj_caching_pool_init(&pimpl_->poolCache, &pj_pool_factory_default_policy, 0); diff --git a/src/upnp/protocol/pupnp/pupnp.cpp b/src/upnp/protocol/pupnp/pupnp.cpp index a4b077c7..87eb69c1 100644 --- a/src/upnp/protocol/pupnp/pupnp.cpp +++ b/src/upnp/protocol/pupnp/pupnp.cpp @@ -93,7 +93,7 @@ errorOnResponse(IXML_Document* doc, const std::shared_ptr& log return false; } -// UPNP class implementation +// UPnP class implementation PUPnP::PUPnP(const std::shared_ptr& ctx, const std::shared_ptr& logger) : UPnPProtocol(logger), ioContext(ctx), searchForIgdTimer_(*ctx) @@ -170,7 +170,7 @@ PUPnP::registerClient() { assert(not clientRegistered_); - // Register Upnp control point. + // Register UPnP control point. int upnp_err = UpnpRegisterClient(ctrlPtCallback, this, &ctrlptHandle_); if (upnp_err != UPNP_E_SUCCESS) { if (logger_) logger_->error("PUPnP: Unable to register client: {}", UpnpGetErrorMessage(upnp_err)); @@ -347,7 +347,7 @@ PUPnP::searchForIgd() searchForDevices(); observer_->onIgdDiscoveryStarted(); } else { - if (logger_) logger_->warn("PUPnP: PUPNP not fully setup. Skipping the IGD search"); + if (logger_) logger_->warn("PUPnP: PUPnP not fully setup. Skipping the IGD search"); } } @@ -1611,7 +1611,7 @@ PUPnP::actionAddPortMapping(const Mapping& mapping) auto errorCode = getFirstDocItem(response.get(), "errorCode"); if (not errorCode.empty()) { success = false; - // Try to get the error description. + // Attempt to get the error description. std::string errorDescription; if (response) { errorDescription = getFirstDocItem(response.get(), "errorDescription"); diff --git a/src/upnp/protocol/pupnp/pupnp.h b/src/upnp/protocol/pupnp/pupnp.h index ae02d45a..f83de6c0 100644 --- a/src/upnp/protocol/pupnp/pupnp.h +++ b/src/upnp/protocol/pupnp/pupnp.h @@ -131,10 +131,10 @@ class PUPnP : public UPnPProtocol // Unregister the client void unregisterClient(); - // Start search for UPNP devices + // Start search for UPnP devices void searchForDevices(); - // Start search for UPNP device in a different thread + // Start search for UPnP device in a different thread void searchForDeviceAsync(const std::string& deviceType); // Return true if it has at least one valid IGD. @@ -249,7 +249,7 @@ class PUPnP : public UPnPProtocol IpAddr hostAddress_ {}; // Calls from other threads that does not need synchronous access are - // rescheduled on the UPNP private queue. This will avoid the need to + // rescheduled on the UPnP private queue. This will avoid the need to // protect most of the data members of this class. // For some internal members (namely the validIgdList and the hostAddress) // that need to be synchronously accessed, are protected by this mutex. diff --git a/src/upnp/upnp_context.cpp b/src/upnp/upnp_context.cpp index 38a5a856..61f72320 100644 --- a/src/upnp/upnp_context.cpp +++ b/src/upnp/upnp_context.cpp @@ -115,7 +115,7 @@ UPnPContext::shutdown() ctx->post([&, this] { shutdown(cv); }); - if (logger_) logger_->debug("Waiting for shutdown ..."); + if (logger_) logger_->debug("Waiting for shutdown…"); if (cv.wait_for(lk, std::chrono::seconds(30), [this] { return shutdownComplete_; })) { if (logger_) logger_->debug("Shutdown completed"); @@ -163,7 +163,7 @@ UPnPContext::startUpnp() { assert(not controllerList_.empty()); - if (logger_) logger_->debug("Starting UPNP context"); + if (logger_) logger_->debug("Starting UPnP context"); // Request a new IGD search. for (auto const& [_, protocol] : protocolList_) { @@ -329,7 +329,7 @@ UPnPContext::reserveMapping(Mapping& requestedMap) if (logger_) logger_->debug("Desired port is not set, will provide the first available port for [{}]", requestedMap.getTypeStr()); } else { - if (logger_) logger_->debug("Try to find mapping for port {:d} [{}]", desiredPort, requestedMap.getTypeStr()); + if (logger_) logger_->debug("Attempt to find mapping for port {:d} [{}]", desiredPort, requestedMap.getTypeStr()); } Mapping::sharedPtr_t mapRes; @@ -594,7 +594,7 @@ UPnPContext::updateCurrentIgd() if (not igd->isValid()) continue; - // Prefer NAT-PMP over PUPNP. + // Prefer NAT-PMP over PUPnP. if (currentIgd_ and igd->getProtocol() != NatProtocolType::NAT_PMP) continue; diff --git a/tools/dhtnet_crtmgr/main.cpp b/tools/dhtnet_crtmgr/main.cpp index bd79b7e0..807f40ee 100644 --- a/tools/dhtnet_crtmgr/main.cpp +++ b/tools/dhtnet_crtmgr/main.cpp @@ -122,7 +122,7 @@ int create_yaml_config(std::filesystem::path file, std::filesystem::path certifi yaml_file << "\n# When verbose is set to true, the server logs all incoming connections\n"; yaml_file << "verbose: false\n"; - yaml_file << "\n# If true, will send request to use UPNP if available\n"; + yaml_file << "\n# If true, will send request to use UPnP if available\n"; yaml_file << "enable_upnp: true\n"; yaml_file << "\n# On server, identities are saved in /etc/dhtnet/id/\n"; @@ -168,7 +168,7 @@ int configure_ssh_config(std::filesystem::path yaml_config) } std::filesystem::path ssh_dir = home_dir / ".ssh"; if (!std::filesystem::exists(ssh_dir)) { - fmt::print(stderr, "Error: {} folder doesn't exist. Install and configure ssh client first.\n", ssh_dir); + fmt::print(stderr, "Error: {} folder doesn't exist. Install and configure SSH client first.\n", ssh_dir); return 1; } std::filesystem::path ssh_config = ssh_dir / "config"; @@ -177,7 +177,7 @@ int configure_ssh_config(std::filesystem::path yaml_config) std::string line; while (std::getline(ssh_file, line)) { if (line.find("Host dnc") != std::string::npos) { - Log("Info: dnc configuration already exists in ssh config. File is left untouched\n"); + Log("Info: dnc configuration already exists in SSH config. File is left untouched\n"); return 0; } } @@ -189,7 +189,7 @@ int configure_ssh_config(std::filesystem::path yaml_config) ssh_file.close(); Log("SSH configuration added to {}\n", ssh_config); } else { - fmt::print(stderr, "Error: Unable to open ssh config file.\n"); + fmt::print(stderr, "Error: Unable to open SSH config file.\n"); return 1; } return 0; diff --git a/tools/dnc/dnc.yaml b/tools/dnc/dnc.yaml index b445a106..a49d0c36 100644 --- a/tools/dnc/dnc.yaml +++ b/tools/dnc/dnc.yaml @@ -16,7 +16,7 @@ turn_realm: "sfl" # When verbose is set to true, the server logs all incoming connections verbose: false -# If true, will send request to use UPNP if available +# If true, will send request to use UPnP if available enable_upnp: true # On server, identities are saved in /etc/dhtnet/id/