diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..42b93c9 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# @global-owner1 and @global-owner2 will be requested for +# review when someone opens a pull request. +* @rdkcentral/networkmanager-maintainers diff --git a/INetworkManager.h b/INetworkManager.h index 254eb06..c1920bb 100644 --- a/INetworkManager.h +++ b/INetworkManager.h @@ -243,7 +243,7 @@ namespace WPEFramework virtual uint32_t StopConnectivityMonitoring(void) const = 0; /* @brief Get the Public IP used for external world communication */ - virtual uint32_t GetPublicIP (const string &ipversion /* @in */, string& ipaddress /* @out */) = 0; + virtual uint32_t GetPublicIP (string &ipversion /* @inout */, string& ipaddress /* @out */) = 0; /* @brief Request for ping and get the response in as event. The GUID used in the request will be returned in the event. */ virtual uint32_t Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t count /* @in */, const uint16_t timeout /* @in */, const string guid /* @in */, string& response /* @out */) = 0; diff --git a/NetworkManager.h b/NetworkManager.h index a2543be..353c34f 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -132,6 +132,14 @@ namespace WPEFramework void Deinitialize(PluginHost::IShell *service) override; string Information() const override; + //override Subscribe from IDispatcher + uint32_t Subscribe(const uint32_t channel, const string& event, const string& designator) override + { + NMLOG_DEBUG("Subscription received for %s event from channelID (%u) with designator as %s", event.c_str(), channel, designator.c_str()); + JSONRPC::Subscribe(channel, event, designator); + return Core::ERROR_NONE; + } + // Do not allow copy/move constructors NetworkManager(const NetworkManager &) = delete; NetworkManager &operator=(const NetworkManager &) = delete; diff --git a/NetworkManagerGnomeWIFI.cpp b/NetworkManagerGnomeWIFI.cpp index 4bb0f38..adcb434 100644 --- a/NetworkManagerGnomeWIFI.cpp +++ b/NetworkManagerGnomeWIFI.cpp @@ -965,7 +965,6 @@ namespace WPEFramework std::string ssidPattern = "ssid="; std::string passphrasePattern = "psk="; std::string security = "", ssid = "", passphrase = ""; - Exchange::INetworkManager::WiFiConnectTo wifiData = {}; std::string wpaCliResult = ""; gboolean wpsConnect = false; struct timespec startTime = {}, endTime = {}; @@ -973,7 +972,6 @@ namespace WPEFramework long wpsPBCDuration = 0; int count = 0; bool scanResult = false; - bool ssidFound = false; const char* bssid = nullptr; gboolean pbcFound = false; const GPtrArray *aps; @@ -1009,7 +1007,6 @@ namespace WPEFramework gsize size; std::string ssidStr; - NMLOG_DEBUG("Access point flag value : %u", flags); if ((flags & NM_802_11_AP_FLAGS_WPS_PBC) && (wpsApCount < MAX_WPS_AP_COUNT)) { clock_gettime(CLOCK_MONOTONIC, &endTime); @@ -1040,6 +1037,7 @@ namespace WPEFramework if(!pbcFound || wpsStop.load()) { + NMLOG_ERROR("PBC enabled SSID not found in the scan results"); g_main_context_pop_thread_default(m_wpsContext); g_main_context_release(m_wpsContext); if (m_wpsContext) { @@ -1075,6 +1073,7 @@ namespace WPEFramework wpaCliCommand = "wpa_cli -i " + std::string(nmUtils::wlanIface()) + " wps_pbc " + std::string(apList[wpsPbcAp].bssid); NMLOG_DEBUG("wpacli pbc command with bssid = %s", wpaCliCommand.c_str()); NMLOG_INFO("Connecting with the SSID = %s", apList[wpsPbcAp].ssid); + wpaCliResult.clear(); wpaCliResult = wifiManager::executeWpaCliCommand(wpaCliCommand); if (wpaCliResult == "ERROR") { @@ -1087,155 +1086,116 @@ namespace WPEFramework } return ; } - NMLOG_DEBUG("wps pbc connect output = %s", wpaCliResult.c_str()); - std::string wpaCliStatus = WPA_CLI_STATUS; + startTime = {}, endTime = {}; - wpaCliResult.clear(); + int waitTime = (MAX_WPS_WAIT_DURATION - wpsPBCDuration)/wpsApCount; clock_gettime(CLOCK_MONOTONIC, &startTime); - while(!wpsStop.load()) + while(!wpsConnect && !wpsStop.load()) { - wpaCliResult = wifiManager::executeWpaCliCommand(wpaCliStatus); - if (wpaCliResult == "ERROR") - { - NMLOG_ERROR("WPS not able to fetch the connection status"); - continue; - } - NMLOG_DEBUG("wpacli status = %s", wpaCliResult.c_str()); - wpsConnect = (wpaCliResult.find("wpa_state=COMPLETED") != std::string::npos); - clock_gettime(CLOCK_MONOTONIC, &endTime); - timeDiff = (endTime.tv_sec - startTime.tv_sec); - NMLOG_DEBUG("Time elapsed in getting state completed = %ld", timeDiff); - if(wpsConnect || timeDiff > 20) + std::ifstream configFile(WPA_SUPPLICANT_CONF); + if (!configFile.is_open()) { - NMLOG_WARNING("WPS Connect status = %d; took %ld seconds", wpsConnect, (wpsPBCDuration + timeDiff)); - break; + NMLOG_ERROR("WPS connected with an SSID but not able to fetch IP address"); + g_main_context_pop_thread_default(m_wpsContext); + g_main_context_release(m_wpsContext); + if (m_wpsContext) { + g_main_context_unref(m_wpsContext); + m_wpsContext = nullptr; + } + return; } - sleep(3); - } - } - if(!wpsConnect) - { - g_main_context_pop_thread_default(m_wpsContext); - g_main_context_release(m_wpsContext);/* TODO: Need to disconnect the wpa_cli connection, as the libnm is not aware of the connection created by wpa_cli */ - wpaCliCommand.clear(); - wpaCliResult.clear(); - wpaCliCommand = "wpa_cli -i " + std::string(nmUtils::wlanIface()) + " wps_cancel"; - wpaCliResult = wifiManager::executeWpaCliCommand(wpaCliCommand); - if (wpaCliResult == "ERROR") - NMLOG_ERROR("WPS cancel failed"); - if (m_wpsContext) { - g_main_context_unref(m_wpsContext); - m_wpsContext = nullptr; - } - return; - } - - count = 0; - while(count < 2 && !ssidFound) - { - std::ifstream configFile(WPA_SUPPLICANT_CONF); - if (!configFile.is_open()) - { - NMLOG_ERROR("WPS connected with an SSID but not able to fetch IP address"); - g_main_context_pop_thread_default(m_wpsContext); - g_main_context_release(m_wpsContext); - if (m_wpsContext) { - g_main_context_unref(m_wpsContext); - m_wpsContext = nullptr; - } - return; - } - - while (std::getline(configFile, line)) - { - NMLOG_DEBUG("Attempting to read the configuration to populate SSID specific information"); - size_t pos; - - // Fetch ssid value - pos = line.find(ssidPattern); - if (pos != std::string::npos) + while (std::getline(configFile, line)) { - pos += ssidPattern.length(); - size_t end = line.find('"', pos + 1); - if (end == std::string::npos) - { - end = line.length(); - } - ssid = line.substr(pos + 1, end - pos - 1); - ssidFound = true; - NMLOG_DEBUG("SSID found"); - continue; - } + NMLOG_DEBUG("Attempting to read the configuration to populate SSID specific information"); + size_t pos; - if (ssidFound) { - // Fetch security value - pos = line.find(securityPattern); + // Fetch ssid value + pos = line.find(ssidPattern); if (pos != std::string::npos) { - pos += securityPattern.length(); - size_t end = line.find(' ', pos); + pos += ssidPattern.length(); + size_t end = line.find('"', pos + 1); if (end == std::string::npos) { end = line.length(); } - security = line.substr(pos, end - pos); + ssid = line.substr(pos + 1, end - pos - 1); + wpsConnect = true; + NMLOG_DEBUG("SSID found"); continue; } - // Fetch passphare value - pos = line.find(passphrasePattern); - if (pos != std::string::npos) - { - pos += passphrasePattern.length(); - size_t end = line.find('"', pos + 1); - if (end == std::string::npos) + if (wpsConnect) { + // Fetch security value + pos = line.find(securityPattern); + if (pos != std::string::npos) { - end = line.length(); + pos += securityPattern.length(); + size_t end = line.find(' ', pos); + if (end == std::string::npos) + { + end = line.length(); + } + security = line.substr(pos, end - pos); + continue; } - passphrase = line.substr(pos + 1, end - pos - 1); + + // Fetch passphare value + pos = line.find(passphrasePattern); + if (pos != std::string::npos) + { + pos += passphrasePattern.length(); + size_t end = line.find('"', pos + 1); + if (end == std::string::npos) + { + end = line.length(); + } + passphrase = line.substr(pos + 1, end - pos - 1); + } + NMLOG_DEBUG("Fetched SSID = %s, security = %s", ssid.c_str(), security.c_str()); } - NMLOG_DEBUG("Fetched SSID = %s, security = %s", ssid.c_str(), security.c_str()); } + configFile.close(); + clock_gettime(CLOCK_MONOTONIC, &endTime); + timeDiff = (endTime.tv_sec - startTime.tv_sec); + NMLOG_DEBUG("Time elapsed in getting SSID = %ld", timeDiff); + if(ssid.empty() && timeDiff < waitTime) + { + NMLOG_INFO("connected successfully; attempting to retrive SSID info to persist"); + sleep(5); + } + else + break; } - configFile.close(); - if(ssid.empty()) - { - count++; - NMLOG_INFO("connected successfully; attempting to retrive SSID info to persist"); - sleep(5); - } + } + if(wpsConnect) + { + std::string nmCliCommand1 = "nmcli connection add type wifi ifname " + std::string(nmUtils::wlanIface()) + " con-name " + ssid + " ssid " + ssid + " wifi-sec.psk " + passphrase + " wifi-sec.key-mgmt wpa-psk && "; + std::string nmCliCommand2 = "nmcli connection up " + ssid; + std::string nmCliCommand = nmCliCommand1 + nmCliCommand2; + std::string nmCliResult = ""; + nmCliResult = wifiManager::executeWpaCliCommand(nmCliCommand); + if (nmCliResult != "ERROR") + NMLOG_INFO("NetworkManager updated with WPS status - connected successfully"); else { - wifiData.ssid = ssid; - wifiData.passphrase = passphrase; - if(security == "WPA-PSK") - wifiData.security = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_AES; - else if(security == "WPA2-PSK") - wifiData.security = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA2_PSK_AES; - m_loop = g_main_loop_new(m_wpsContext, FALSE); - if(this->wifiConnect(wifiData)) - NMLOG_INFO("NetworkManager updated with WPS status - connected successfully"); - else + NMLOG_ERROR("NetworkManager is not able to sync up with underneath wpa_supplicant/hal regarding the WPS connect"); /* TODO: Need to disconnect the wpa_cli connection, as the libnm is not aware of the connection created by wpa_cli */ + wpaCliCommand.clear(); + wpaCliResult.clear(); + wpaCliCommand = "wpa_cli -i " + std::string(nmUtils::wlanIface()) + " wps_cancel"; + wpaCliResult = wifiManager::executeWpaCliCommand(wpaCliCommand); + if (wpaCliResult == "ERROR") { - NMLOG_ERROR("NetworkManager is not able to sync up with underneath wpa_supplicant/hal regarding the WPS connect"); /* TODO: Need to disconnect the wpa_cli connection, as the libnm is not aware of the connection created by wpa_cli */ - wpaCliCommand.clear(); - wpaCliResult.clear(); - wpaCliCommand = "wpa_cli -i " + std::string(nmUtils::wlanIface()) + " wps_cancel"; - wpaCliResult = wifiManager::executeWpaCliCommand(wpaCliCommand); - if (wpaCliResult == "ERROR") - { - NMLOG_ERROR("WPS cancel failed"); - } + NMLOG_ERROR("WPS cancel failed"); } - m_loop = g_main_loop_new(m_nmContext, FALSE); } } g_main_context_pop_thread_default(m_wpsContext); g_main_context_release(m_wpsContext); if (m_wpsContext) { - g_main_context_unref(m_wpsContext); - m_wpsContext = nullptr; + g_main_context_unref(m_wpsContext); + m_wpsContext = nullptr; } return; } diff --git a/NetworkManagerGnomeWIFI.h b/NetworkManagerGnomeWIFI.h index 6b7dfe1..4a5bf2a 100644 --- a/NetworkManagerGnomeWIFI.h +++ b/NetworkManagerGnomeWIFI.h @@ -33,6 +33,8 @@ #define WPA_SUPPLICANT_CONF "/opt/secure/wifi/wpa_supplicant.conf" #define WPA_CLI_STATUS "wpa_cli status" #define MAX_WPS_AP_COUNT 3 +#define MAX_WPS_WAIT_DURATION 120 + typedef struct _wifi_wps_pbc_ap { char bssid[32]; diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index f08fe09..311967f 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -280,7 +280,7 @@ namespace WPEFramework } /* @brief Get the Public IP used for external world communication */ - uint32_t NetworkManagerImplementation::GetPublicIP (const string &ipversion /* @in */, string& ipaddress /* @out */) + uint32_t NetworkManagerImplementation::GetPublicIP (string &ipversion /* @inout */, string& ipaddress /* @out */) { LOG_ENTRY_FUNCTION(); stun::bind_result result; @@ -289,6 +289,11 @@ namespace WPEFramework stun::protocol proto (isIPv6 ? stun::protocol::af_inet6 : stun::protocol::af_inet); if(stunClient.bind(m_stunEndPoint, m_stunPort, m_defaultInterface, proto, m_stunBindTimeout, m_stunCacheTimeout, result)) { + if (isIPv6) + ipversion = "IPv6"; + else + ipversion = "IPv4"; + ipaddress = result.public_ip; return Core::ERROR_NONE; } @@ -598,6 +603,12 @@ namespace WPEFramework { _notificationLock.Lock(); NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str()); + + if(currentActiveinterface == "eth0") + m_ethConnected = true; + else if (currentActiveinterface == "wlan0") + m_wlanConnected = true; + for (const auto callback : _notificationCallbacks) { callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface); } @@ -611,6 +622,11 @@ namespace WPEFramework // Start the connectivity monitor with 'true' to indicate the interface is up. // The monitor will conntinoue even after no internet retry completed, Exit when fully connectd. connectivityMonitor.startConnectivityMonitor(); + // if ipaddress is aquired means there should be interface connected + if(interface == "eth0") + m_ethConnected = true; + else if (interface == "wlan0") + m_wlanConnected = true; } _notificationLock.Lock(); diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 64767f9..8897b7d 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -197,7 +197,7 @@ namespace WPEFramework uint32_t StopConnectivityMonitoring(void) const override; /* @brief Get the Public IP used for external world communication */ - uint32_t GetPublicIP (const string &ipversion /* @in */, string& ipaddress /* @out */) override; + uint32_t GetPublicIP (string &ipversion /* @inout */, string& ipaddress /* @out */) override; /* @brief Request for ping and get the response in as event. The GUID used in the request will be returned in the event. */ uint32_t Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const uint16_t timeOutInSeconds /* @in */, const string guid /* @in */, string& response /* @out */) override; diff --git a/NetworkManagerJsonRpc.cpp b/NetworkManagerJsonRpc.cpp index 1079443..6628628 100644 --- a/NetworkManagerJsonRpc.cpp +++ b/NetworkManagerJsonRpc.cpp @@ -567,7 +567,6 @@ namespace WPEFramework void NetworkManager::PublishToThunderAboutInternet() { - NMLOG_DEBUG("No public IP persisted yet; Update the data"); if (m_publicIPAddress.empty()) { JsonObject input, output; @@ -576,6 +575,7 @@ namespace WPEFramework if (!m_publicIPAddress.empty()) { + NMLOG_DEBUG("No public IP persisted yet; Update the data"); PluginHost::ISubSystem* subSystem = _service->SubSystems(); if (subSystem != nullptr) diff --git a/NetworkManagerStunClient.cpp b/NetworkManagerStunClient.cpp index 999f14e..1960f0f 100644 --- a/NetworkManagerStunClient.cpp +++ b/NetworkManagerStunClient.cpp @@ -51,7 +51,7 @@ namespace details { int m_fd; }; - #ifdef _STUN_DEBUG +#ifdef _STUN_DEBUG void dump_buffer(char const * prefix, buffer const & buff) { if (prefix) @@ -61,14 +61,7 @@ namespace details { printf("\n"); return; } - #endif - - #ifdef _STUN_DEBUG - #define STUN_TRACE(format, ...) printf("STUN:" format __VA_OPT__(,) __VA_ARGS__) - #else - #define STUN_TRACE(format, ...) - #endif - +#endif void throw_error(char const * format, ...) { @@ -126,7 +119,7 @@ namespace details { details::throw_error("failed to find ip for interface:%s", iface.c_str()); return iface_info; } - STUN_TRACE("local_addr:%s\n", sockaddr_to_string(iface_info).c_str()); + NMLOG_DEBUG("local_addr:%s", sockaddr_to_string(iface_info).c_str()); return iface_info; } @@ -290,7 +283,6 @@ client::client() , m_cache_timeout(30) , m_last_cache_time() , m_last_result() - , m_verbose(true) , m_fd(-1) { } @@ -350,7 +342,7 @@ bool client::bind( dirty = true; } - verbose("client::bind enter: server=%s port=%u iface=%s ipv6=%u timeout=%u cache_timeout=%u dirty=%u\n", + NMLOG_DEBUG("client::bind enter: server=%s port=%u iface=%s ipv6=%u timeout=%u cache_timeout=%u dirty=%u", hostname.c_str(), port, interface.c_str(), proto == stun::protocol::af_inet6, bind_timeout, cache_timeout, dirty); if(m_cache_timeout > 0 /*asking if caching is enabled*/ @@ -360,18 +352,18 @@ bool client::bind( auto time_in_cache = std::chrono::duration_cast( std::chrono::steady_clock::now() - m_last_cache_time); - verbose("client::bind cache time=%lld\n", time_in_cache.count()); + NMLOG_DEBUG("client::bind cache time=%ld", time_in_cache.count()); if(time_in_cache.count() < m_cache_timeout) { result = m_last_result; - verbose("client::bind returning cached result: %s\n", result.public_ip.c_str()); + NMLOG_DEBUG("client::bind returning cached result: %s", result.public_ip.c_str()); return true; } else { - verbose("client::client::bind cached result expired\n"); + NMLOG_DEBUG("client::client::bind cached result expired"); } } @@ -387,7 +379,7 @@ bool client::bind( std::chrono::milliseconds wait_time(interval_wait_time); for (int i = 0; i < num_attempts && total_time < m_bind_timeout; ++i) { - verbose("client::bind sending bind request\n"); + NMLOG_DEBUG("client::bind sending bind request"); std::unique_ptr binding_response = send_binding_request(wait_time); @@ -415,25 +407,25 @@ bool client::bind( m_last_cache_time = std::chrono::steady_clock::now(); - verbose("client::bind success: public_ip=%s\n", result.public_ip.c_str()); + NMLOG_DEBUG("client::bind success: public_ip=%s", result.public_ip.c_str()); ret_ok = true; } else { - verbose("client::bind failed: ip missing from binding response\n"); + NMLOG_DEBUG("client::bind failed: ip missing from binding response"); } } else { - verbose("client::bind failed: no response received from server\n"); + NMLOG_INFO("client::bind failed: no response received from server"); } } } #ifdef __cpp_exceptions catch (std::exception const & err) { - verbose("client::bind failed: %s\n", err.what()); + NMLOG_WARNING("client::bind failed: %s", err.what()); } #endif @@ -454,13 +446,13 @@ void client::create_udp_socket(int inet_family) if (inet_family != AF_INET && inet_family != AF_INET6) details::throw_error("invalid inet family:%d", inet_family); - verbose("creating udp/%s socket\n", details::family_to_string(inet_family)); + NMLOG_DEBUG("creating udp/%s socket", details::family_to_string(inet_family)); int soc = socket(inet_family, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (soc < 0) details::throw_error("error creating socket. %s", strerror(errno)); - #ifdef _SUN_USE_MSGHDR + #ifdef _STUN_USE_MSGHDR int optval = 1; setsockopt(soc, IPPROTO_IP, IP_PKTINFO, &optval, sizeof(int)); #endif @@ -468,7 +460,7 @@ void client::create_udp_socket(int inet_family) if (!m_interface.empty()) { sockaddr_storage local_addr = details::get_interface_address(m_interface, inet_family); - verbose("binding to local interface %s/%s\n", m_interface.c_str(), + NMLOG_DEBUG("binding to local interface %s/%s", m_interface.c_str(), sockaddr_to_string(local_addr).c_str()); int ret = ::bind(soc, reinterpret_cast(&local_addr), details::socket_length(local_addr)); @@ -479,18 +471,16 @@ void client::create_udp_socket(int inet_family) sockaddr_to_string(local_addr).c_str(), strerror(err)); } else { - if (m_verbose) { sockaddr_storage local_endpoint; socklen_t socklen = sizeof(sockaddr_storage); int ret = getsockname(soc, reinterpret_cast(&local_endpoint), &socklen); if (ret == 0) - verbose("local endpoint %s/%d\n", sockaddr_to_string(local_endpoint).c_str(), + NMLOG_DEBUG("local endpoint %s/%d", sockaddr_to_string(local_endpoint).c_str(), details::sockaddr_get_port(local_endpoint)); - } } } else - verbose("no local interface supplied to bind to\n"); + NMLOG_DEBUG("no local interface supplied to bind to"); if (m_fd != -1) close(m_fd); @@ -506,13 +496,13 @@ message * client::send_message(sockaddr_storage const & remote_addr, message con buffer bytes = req.encode(); - STUN_TRACE("remote_addr:%s\n", sockaddr_to_string(remote_addr).c_str()); + NMLOG_DEBUG("remote_addr:%s", sockaddr_to_string(remote_addr).c_str()); #ifdef _STUN_DEBUG details::dump_buffer("STUN >>> ", bytes); #endif - verbose("sending messsage\n"); + NMLOG_DEBUG("sending messsage"); ssize_t n = sendto(m_fd, &bytes[0], bytes.size(), 0, (sockaddr *) &remote_addr, details::socket_length(remote_addr)); if (n < 0) @@ -537,10 +527,10 @@ message * client::send_message(sockaddr_storage const & remote_addr, message con timeout.tv_sec = (timeout.tv_usec / kMicrosecondsPerSecond); timeout.tv_usec -= (timeout.tv_sec * kMicrosecondsPerSecond); } - verbose("waiting for response, timeout set to %lus - %luus\n", timeout.tv_sec, timeout.tv_usec); + NMLOG_DEBUG("waiting for response, timeout set to %lus - %luus", timeout.tv_sec, timeout.tv_usec); int ret = select(m_fd + 1, &rfds, nullptr, nullptr, &timeout); if (ret == 0) { - STUN_TRACE("select timeout out\n"); + NMLOG_DEBUG("select timeout out"); return nullptr; } @@ -608,18 +598,6 @@ message * client::send_message(sockaddr_storage const & remote_addr, message con return decoder::decode_message(bytes, nullptr); } -void client::verbose(char const * format, ...) -{ - if (!m_verbose) - return; - va_list ap; - va_start(ap, format); - printf("STUN:"); - vprintf(format, ap); - va_end(ap); - return; -} - network_access_type client::discover_network_access_type(server const & srv) { std::chrono::milliseconds wait_time(250); @@ -672,7 +650,7 @@ std::unique_ptr client::send_binding_request(std::chrono::milliseconds std::unique_ptr client::send_binding_request(sockaddr_storage const & addr, std::chrono::milliseconds wait_time) { - this->verbose("sending binding request with wait time:%lld ms\n", wait_time.count()); + NMLOG_DEBUG("sending binding request with wait time:%ld ms", wait_time.count()); this->create_udp_socket(addr.ss_family); std::unique_ptr binding_request(message_factory::create_binding_request()); std::unique_ptr binding_response(this->send_message(addr, *binding_request, wait_time)); diff --git a/NetworkManagerStunClient.h b/NetworkManagerStunClient.h index c2f6929..09f093a 100644 --- a/NetworkManagerStunClient.h +++ b/NetworkManagerStunClient.h @@ -8,6 +8,7 @@ #include #include #include +#include "NetworkManagerLogger.h" namespace stun { @@ -157,11 +158,7 @@ class client { network_access_type discover_network_access_type(server const & srv); - inline void set_verbose(bool b) { - m_verbose = b; - } private: - void verbose(char const * format, ...) __attribute__((format(printf, 2, 3))); void create_udp_socket(int inet_family); std::unique_ptr send_binding_request(std::chrono::milliseconds wait_time); @@ -180,7 +177,6 @@ class client { uint16_t m_cache_timeout; std::chrono::time_point m_last_cache_time; bind_result m_last_result; - bool m_verbose; int m_fd; };