Commit d3d74da0 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6905 : simplify udp/stun/tls pjsip transport creation

parent 014cf030
...@@ -57,47 +57,29 @@ AudioRtpFactory::~AudioRtpFactory() ...@@ -57,47 +57,29 @@ AudioRtpFactory::~AudioRtpFactory()
void AudioRtpFactory::initAudioRtpConfig () void AudioRtpFactory::initAudioRtpConfig ()
{ {
if (_rtpSession != NULL) { if (_rtpSession != NULL)
_debug ("An audio rtp thread was already created but not" \
"destroyed. Forcing it before continuing.");
stop(); stop();
}
std::string accountId(Manager::instance().getAccountFromCall (ca_->getCallId()));
_debug ("AudioRtpFactory: Init rtp session for account %s", accountId.c_str());
// Manager::instance().getAccountLink (accountId);
Account *account = Manager::instance().getAccount (accountId);
if (!account) std::string accountId(Manager::instance().getAccountFromCall(ca_->getCallId()));
_error ("AudioRtpFactory: Error no account found");
registerAccount(account, accountId); SIPAccount *account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount (accountId));
} if (account) {
_srtpEnabled = account->getSrtpEnabled();
void AudioRtpFactory::registerAccount(Account * /*account*/, const std::string & /* id */) std::string key(account->getSrtpKeyExchange());
{
_srtpEnabled = false;
_keyExchangeProtocol = Symmetric;
_helloHashEnabled = false;
}
if (key == "sdes")
_keyExchangeProtocol = Sdes;
else if (key == "zrtp")
_keyExchangeProtocol = Zrtp;
else
_keyExchangeProtocol = Symmetric;
void AudioRtpFactory::registerAccount(SIPAccount *sipaccount, const std::string& accountId) _helloHashEnabled = account->getZrtpHelloHash();
{ } else {
_srtpEnabled = sipaccount->getSrtpEnabled(); _srtpEnabled = false;
std::string tempkey(sipaccount->getSrtpKeyExchange());
if (tempkey == "sdes")
_keyExchangeProtocol = Sdes;
else if (tempkey == "zrtp")
_keyExchangeProtocol = Zrtp;
else
_keyExchangeProtocol = Symmetric; _keyExchangeProtocol = Symmetric;
_helloHashEnabled = false;
_debug ("AudioRtpFactory: Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), _keyExchangeProtocol); }
_helloHashEnabled = sipaccount->getZrtpHelloHash();
} }
void AudioRtpFactory::initAudioSymmetricRtpSession () void AudioRtpFactory::initAudioSymmetricRtpSession ()
...@@ -113,24 +95,20 @@ void AudioRtpFactory::initAudioSymmetricRtpSession () ...@@ -113,24 +95,20 @@ void AudioRtpFactory::initAudioSymmetricRtpSession ()
case Zrtp: case Zrtp:
_rtpSession = new AudioZrtpSession (ca_, zidFilename); _rtpSession = new AudioZrtpSession (ca_, zidFilename);
if (_helloHashEnabled) { if (_helloHashEnabled) {
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's // TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's
// not even available at that point. // not even available at that point.
ca_->getLocalSDP()->setZrtpHash (static_cast<AudioZrtpSession *> (_rtpSession)->getHelloHash()); ca_->getLocalSDP()->setZrtpHash (static_cast<AudioZrtpSession *> (_rtpSession)->getHelloHash());
_debug ("AudioRtpFactory: Zrtp hello hash fed to SDP"); _debug ("AudioRtpFactory: Zrtp hello hash fed to SDP");
} }
break; break;
case Sdes: case Sdes:
_rtpSession = new AudioSrtpSession (ca_); _rtpSession = new AudioSrtpSession (ca_);
break; break;
default: default:
_debug ("AudioRtpFactory: Unsupported Rtp Session Exception Type!"); throw UnsupportedRtpSessionType("Unsupported Rtp Session Exception Type!");
throw UnsupportedRtpSessionType();
} }
} else { } else {
_rtpSession = new AudioSymmetricRtpSession (ca_); _rtpSession = new AudioSymmetricRtpSession (ca_);
......
...@@ -152,8 +152,6 @@ class AudioRtpFactory ...@@ -152,8 +152,6 @@ class AudioRtpFactory
void sendDtmfDigit (int digit); void sendDtmfDigit (int digit);
private: private:
void registerAccount(Account *account, const std::string &id);
void registerAccount(SIPAccount *account, const std::string &id);
AudioRtpSession *_rtpSession; AudioRtpSession *_rtpSession;
ost::Mutex _audioRtpThreadMutex; ost::Mutex _audioRtpThreadMutex;
......
...@@ -165,10 +165,9 @@ IAXVoIPLink::terminateIAXCall() ...@@ -165,10 +165,9 @@ IAXVoIPLink::terminateIAXCall()
void void
IAXVoIPLink::getEvent() IAXVoIPLink::getEvent()
{ {
iax_event* event = NULL;
{ {
ost::MutexLock m(mutexIAX_); ost::MutexLock m(mutexIAX_);
iax_event *event;
while ((event = iax_get_event (IAX_NONBLOCKING)) != NULL) { while ((event = iax_get_event (IAX_NONBLOCKING)) != NULL) {
// If we received an 'ACK', libiax2 tells apps to ignore them. // If we received an 'ACK', libiax2 tells apps to ignore them.
if (event->etype == IAX_EVENT_NULL) if (event->etype == IAX_EVENT_NULL)
...@@ -263,8 +262,6 @@ IAXVoIPLink::getIAXCall (const std::string& id) ...@@ -263,8 +262,6 @@ IAXVoIPLink::getIAXCall (const std::string& id)
void void
IAXVoIPLink::sendRegister (Account *a) IAXVoIPLink::sendRegister (Account *a)
{ {
_debug ("IAX: Sending registration");
IAXAccount *account = dynamic_cast<IAXAccount*>(a); IAXAccount *account = dynamic_cast<IAXAccount*>(a);
if (account->getHostname().empty()) if (account->getHostname().empty())
...@@ -273,43 +270,28 @@ IAXVoIPLink::sendRegister (Account *a) ...@@ -273,43 +270,28 @@ IAXVoIPLink::sendRegister (Account *a)
if (account->getUsername().empty()) if (account->getUsername().empty())
throw VoipLinkException("Account username is empty"); throw VoipLinkException("Account username is empty");
// lock
ost::MutexLock m(mutexIAX_); ost::MutexLock m(mutexIAX_);
// Always use a brand new session
if (regSession_) if (regSession_)
iax_destroy(regSession_); iax_destroy(regSession_);
regSession_ = iax_session_new(); regSession_ = iax_session_new();
if (!regSession_) if (regSession_) {
_debug ("IAX: Error when generating new session for register"); iax_register (regSession_, account->getHostname().data(), account->getUsername().data(), account->getPassword().data(), 120);
else {
_debug ("IAX: Sending registration to %s with user %s", account->getHostname().c_str() , account->getUsername().c_str());
int val = iax_register (regSession_, account->getHostname().data(), account->getUsername().data(), account->getPassword().data(), 120);
_debug ("IAX: Return value: %d", val);
// set the time-out to 15 seconds, after that, resend a registration request.
// until we unregister.
nextRefreshStamp_ = time (NULL) + 10; nextRefreshStamp_ = time (NULL) + 10;
account->setRegistrationState(Trying);
account->setRegistrationState (Trying);
} }
} }
void void
IAXVoIPLink::sendUnregister (Account *a) IAXVoIPLink::sendUnregister (Account *a)
{ {
_debug ("IAXVoipLink: Send unregister"); ost::MutexLock m(mutexIAX_);
if (regSession_) {
{ iax_destroy (regSession_);
ost::MutexLock m(mutexIAX_); regSession_ = NULL;
if (regSession_) { }
iax_destroy (regSession_);
regSession_ = NULL;
}
}
mutexIAX_.leaveMutex();
nextRefreshStamp_ = 0; nextRefreshStamp_ = 0;
......
...@@ -2755,10 +2755,6 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser *parser) ...@@ -2755,10 +2755,6 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser *parser)
// IP to IP settings (most likely using port 5060) // IP to IP settings (most likely using port 5060)
link->createDefaultSipUdpTransport(); link->createDefaultSipUdpTransport();
// Call this method to create TLS listener
link->createDefaultSipTlsListener();
// Force IP2IP settings to be loaded to be loaded // Force IP2IP settings to be loaded to be loaded
// No registration in the sense of the REGISTER method is performed. // No registration in the sense of the REGISTER method is performed.
ip2ip->registerVoIPLink(); ip2ip->registerVoIPLink();
......
...@@ -535,7 +535,7 @@ void SIPAccount::registerVoIPLink() ...@@ -535,7 +535,7 @@ void SIPAccount::registerVoIPLink()
return; return;
try { try {
link_->sendRegister (this); link_->sendRegister(this);
} }
catch (const VoipLinkException &e) { catch (const VoipLinkException &e) {
_error("SIPAccount: %s", e.what()); _error("SIPAccount: %s", e.what());
......
This diff is collapsed.
...@@ -257,16 +257,7 @@ class SIPVoIPLink : public VoIPLink ...@@ -257,16 +257,7 @@ class SIPVoIPLink : public VoIPLink
pjsip_tpselector *initTransportSelector (pjsip_transport *, pj_pool_t *); pjsip_tpselector *initTransportSelector (pjsip_transport *, pj_pool_t *);
/** /**
* Helper function for creating a route set from information * This function unset the transport for a given account.
* stored in configuration file.
*/
pjsip_route_hdr *createRouteSet(Account *account, pj_pool_t *pool);
/**
* This function unset the transport for a given account. It tests wether the
* associated transport is used by other accounts. If not, it shutdown the transport
* putting its reference counter to zero. PJSIP assumes transport destruction since
* this action can be delayed by ongoing SIP transactions.
*/ */
void shutdownSipTransport (SIPAccount *account); void shutdownSipTransport (SIPAccount *account);
...@@ -285,11 +276,6 @@ class SIPVoIPLink : public VoIPLink ...@@ -285,11 +276,6 @@ class SIPVoIPLink : public VoIPLink
*/ */
void createDefaultSipUdpTransport(); void createDefaultSipUdpTransport();
/**
* Create the default TLS litener using IP2IP_PROFILE settings
*/
void createDefaultSipTlsListener();
private: private:
/** /**
* Start a SIP Call * Start a SIP Call
...@@ -313,49 +299,35 @@ class SIPVoIPLink : public VoIPLink ...@@ -313,49 +299,35 @@ class SIPVoIPLink : public VoIPLink
*/ */
pj_status_t stunServerResolve (SIPAccount *); pj_status_t stunServerResolve (SIPAccount *);
/**
* Function used to create a new sip transport or get an existing one from the map.
* The SIP transport is "acquired" according to account's current settings.
* This function should be called before registering an account
* @param account An account for which transport is to be set
*
*/
void acquireTransport (SIPAccount *account);
/** /**
* Create the default TLS litener according to account settings. * Create the default TLS listener.
*/ */
void createTlsListener (SIPAccount*); void createTlsListener (SIPAccount*, pjsip_tpfactory **listener);
/** /**
* General Sip transport creation method according to the * General Sip transport creation method according to the
* transport type specified in account settings * transport type specified in account settings
* @param account The account for which a transport must be created. * @param account The account for which a transport must be created.
*/ */
bool createSipTransport (SIPAccount *account); void createSipTransport (SIPAccount *account);
/** /**
* Create SIP UDP transport from account's setting * Create SIP UDP transport from account's setting
* @param account The account for which a transport must be created. * @param account The account for which a transport must be created.
* @param local True if the account is IP2IP
* @return the transport
*/ */
pjsip_transport * createUdpTransport (SIPAccount *account, bool local); void createUdpTransport (SIPAccount *account);
/** /**
* Create a TLS transport from the default TLS listener from * Create a TLS transport from the default TLS listener from
* @param account The account for which a transport must be created. * @param account The account for which a transport must be created.
* @return pj_status_t PJ_SUCCESS on success
*/ */
pj_status_t createTlsTransport (SIPAccount *, std::string remoteAddr); void createTlsTransport (SIPAccount *, std::string remoteAddr);
/** /**
* Create a UDP transport using stun server to resove public address * Create a UDP transport using stun server to resove public address
* @param account The account for which a transport must be created. * @param account The account for which a transport must be created.
* @return pj_status_t PJ_SUCCESS on success
*/ */
pj_status_t createAlternateUdpTransport (SIPAccount *account); void createStunTransport (SIPAccount *account);
/** /**
* Get the correct address to use (ie advertised) from * Get the correct address to use (ie advertised) from
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment