From 375b652336e34ca7d804146cb6a1003a310fca7a Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 21 Nov 2024 20:20:01 -0500 Subject: [PATCH] Cherry/localhostports (#393) * c++17 * Feat/advertise local hostports (#392) * respond to authenticate with local host ports * wip --- Makefile.am | 2 ++ src/client.cpp | 6 ++++-- src/controller.cpp | 3 +++ src/controller.hpp | 1 + src/sip-transports.cpp | 19 +++++++++++++++++++ src/sip-transports.hpp | 2 ++ 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index c1180dbc4e..bc1469008e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +AM_CXXFLAGS = -std=c++17 + MYVERSION=$(shell git describe --always 2>/dev/null || echo 1.0.0) AM_LDFLAGS= -L/usr/local/lib -L${srcdir}/deps/prometheus-cpp/build/lib diff --git a/src/client.cpp b/src/client.cpp index 9bc7917d9f..5495ec94fd 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -163,10 +163,12 @@ namespace drachtio { return false ; } else { - vector hps ; + vector hps, local_hps ; theOneAndOnlyController->getMyHostports( hps ) ; + theOneAndOnlyController->getMyLocalHostports( local_hps ) ; string hostports = boost::algorithm::join(hps, ",") ; - string response = hostports + "|" + DRACHTIO_VERSION; + string localHostports = boost::algorithm::join(local_hps, ",") ; + string response = hostports + "|" + DRACHTIO_VERSION + "|" + localHostports ; createResponseMsg( tokens[0], msgResponse, true, response.c_str()) ; DR_LOG(log_debug) << "Client::processAuthentication - secret validated successfully: " << secret ; return true ; diff --git a/src/controller.cpp b/src/controller.cpp index be06aae192..1e9fe36871 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1791,6 +1791,9 @@ namespace drachtio { void DrachtioController::getMyHostports( vector& vec ) { return SipTransport::getAllHostports( vec ) ; } + void DrachtioController::getMyLocalHostports( vector& vec ) { + return SipTransport::getAllLocalHostports( vec ) ; + } bool DrachtioController::getMySipAddress( const char* proto, string& host, string& port, bool ipv6 ) { string desc, p ; const tport_t* tp = getTportForProtocol(host, proto) ; diff --git a/src/controller.hpp b/src/controller.hpp index 75cd0ed600..6eb79f76a0 100644 --- a/src/controller.hpp +++ b/src/controller.hpp @@ -149,6 +149,7 @@ namespace drachtio { su_home_t* getHome(void) { return m_home; } void getMyHostports( vector& vec ) ; + void getMyLocalHostports( vector& vec ) ; bool getMySipAddress( const char* proto, string& host, string& port, bool ipv6 = false ) ; diff --git a/src/sip-transports.cpp b/src/sip-transports.cpp index a92d7ade81..45ab5363b2 100644 --- a/src/sip-transports.cpp +++ b/src/sip-transports.cpp @@ -173,6 +173,17 @@ namespace drachtio { s += getPort() ; } + void SipTransport::getLocalHostport(string& s) { + if( hasTport() ) { + s += getProtocol() ; + s += "/" ; + s += getHost() ; + s += ":" ; + s += getPort() ; + } + } + + void SipTransport::getBindableContactUri(string& contact) { contact = m_contactScheme ; contact.append(":"); @@ -538,6 +549,14 @@ namespace drachtio { vec.push_back(desc) ; } } + void SipTransport::getAllLocalHostports( vector& vec ) { + for (mapTport2SipTransport::const_iterator it = m_mapTport2SipTransport.begin(); m_mapTport2SipTransport.end() != it; ++it ) { + std::shared_ptr p = it->second ; + string desc ; + p->getLocalHostport(desc); + vec.push_back(desc) ; + } + } bool SipTransport::isLocalAddress(const char* szHost, tport_t* tp) { if( tp ) { diff --git a/src/sip-transports.hpp b/src/sip-transports.hpp index 1b71d9f85c..51252e0353 100644 --- a/src/sip-transports.hpp +++ b/src/sip-transports.hpp @@ -78,6 +78,7 @@ namespace drachtio { void getDescription(string& s, bool shortVersion = true) ; void getHostport(string& s) ; + void getLocalHostport(string& s) ; uint32_t getOctetMatchCount(const string& address); @@ -86,6 +87,7 @@ namespace drachtio { static std::shared_ptr findAppropriateTransport(const char* remoteHost, const char* proto = "udp") ; static void logTransports() ; static void getAllHostports( vector& vec ) ; + static void getAllLocalHostports( vector& vec ) ; static void getAllExternalIps( vector& vec ) ; static void getAllExternalContacts( vector< pair >& vec ) ; static bool isLocalAddress(const char* szHost, tport_t* tp = NULL) ;