Skip to content

Commit

Permalink
Cherry/localhostports (#393)
Browse files Browse the repository at this point in the history
* c++17

* Feat/advertise local hostports (#392)

* respond to authenticate with local host ports

* wip
  • Loading branch information
davehorton authored Nov 22, 2024
1 parent 92bfc9c commit 375b652
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ namespace drachtio {
return false ;
}
else {
vector<string> hps ;
vector<string> 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 ;
Expand Down
3 changes: 3 additions & 0 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,9 @@ namespace drachtio {
void DrachtioController::getMyHostports( vector<string>& vec ) {
return SipTransport::getAllHostports( vec ) ;
}
void DrachtioController::getMyLocalHostports( vector<string>& 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) ;
Expand Down
1 change: 1 addition & 0 deletions src/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace drachtio {
su_home_t* getHome(void) { return m_home; }

void getMyHostports( vector<string>& vec ) ;
void getMyLocalHostports( vector<string>& vec ) ;

bool getMySipAddress( const char* proto, string& host, string& port, bool ipv6 = false ) ;

Expand Down
19 changes: 19 additions & 0 deletions src/sip-transports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(":");
Expand Down Expand Up @@ -538,6 +549,14 @@ namespace drachtio {
vec.push_back(desc) ;
}
}
void SipTransport::getAllLocalHostports( vector<string>& vec ) {
for (mapTport2SipTransport::const_iterator it = m_mapTport2SipTransport.begin(); m_mapTport2SipTransport.end() != it; ++it ) {
std::shared_ptr<SipTransport> p = it->second ;
string desc ;
p->getLocalHostport(desc);
vec.push_back(desc) ;
}
}

bool SipTransport::isLocalAddress(const char* szHost, tport_t* tp) {
if( tp ) {
Expand Down
2 changes: 2 additions & 0 deletions src/sip-transports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -86,6 +87,7 @@ namespace drachtio {
static std::shared_ptr<SipTransport> findAppropriateTransport(const char* remoteHost, const char* proto = "udp") ;
static void logTransports() ;
static void getAllHostports( vector<string>& vec ) ;
static void getAllLocalHostports( vector<string>& vec ) ;
static void getAllExternalIps( vector<string>& vec ) ;
static void getAllExternalContacts( vector< pair<string, string> >& vec ) ;
static bool isLocalAddress(const char* szHost, tport_t* tp = NULL) ;
Expand Down

0 comments on commit 375b652

Please sign in to comment.