Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/advertise local hostports #392

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading