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

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

parent 014cf030
......@@ -57,47 +57,29 @@ AudioRtpFactory::~AudioRtpFactory()
void AudioRtpFactory::initAudioRtpConfig ()
{
if (_rtpSession != NULL) {
_debug ("An audio rtp thread was already created but not" \
"destroyed. Forcing it before continuing.");
if (_rtpSession != NULL)
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)
_error ("AudioRtpFactory: Error no account found");
std::string accountId(Manager::instance().getAccountFromCall(ca_->getCallId()));
registerAccount(account, accountId);
}
void AudioRtpFactory::registerAccount(Account * /*account*/, const std::string & /* id */)
{
_srtpEnabled = false;
_keyExchangeProtocol = Symmetric;
_helloHashEnabled = false;
}
SIPAccount *account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount (accountId));
if (account) {
_srtpEnabled = account->getSrtpEnabled();
std::string key(account->getSrtpKeyExchange());
if (key == "sdes")
_keyExchangeProtocol = Sdes;
else if (key == "zrtp")
_keyExchangeProtocol = Zrtp;
else
_keyExchangeProtocol = Symmetric;
void AudioRtpFactory::registerAccount(SIPAccount *sipaccount, const std::string& accountId)
{
_srtpEnabled = sipaccount->getSrtpEnabled();
std::string tempkey(sipaccount->getSrtpKeyExchange());
if (tempkey == "sdes")
_keyExchangeProtocol = Sdes;
else if (tempkey == "zrtp")
_keyExchangeProtocol = Zrtp;
else
_helloHashEnabled = account->getZrtpHelloHash();
} else {
_srtpEnabled = false;
_keyExchangeProtocol = Symmetric;
_debug ("AudioRtpFactory: Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), _keyExchangeProtocol);
_helloHashEnabled = sipaccount->getZrtpHelloHash();
_helloHashEnabled = false;
}
}
void AudioRtpFactory::initAudioSymmetricRtpSession ()
......@@ -113,24 +95,20 @@ void AudioRtpFactory::initAudioSymmetricRtpSession ()
case Zrtp:
_rtpSession = new AudioZrtpSession (ca_, zidFilename);
if (_helloHashEnabled) {
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's
// not even available at that point.
ca_->getLocalSDP()->setZrtpHash (static_cast<AudioZrtpSession *> (_rtpSession)->getHelloHash());
_debug ("AudioRtpFactory: Zrtp hello hash fed to SDP");
}
break;
case Sdes:
_rtpSession = new AudioSrtpSession (ca_);
break;
default:
_debug ("AudioRtpFactory: Unsupported Rtp Session Exception Type!");
throw UnsupportedRtpSessionType();
throw UnsupportedRtpSessionType("Unsupported Rtp Session Exception Type!");
}
} else {
_rtpSession = new AudioSymmetricRtpSession (ca_);
......
......@@ -152,8 +152,6 @@ class AudioRtpFactory
void sendDtmfDigit (int digit);
private:
void registerAccount(Account *account, const std::string &id);
void registerAccount(SIPAccount *account, const std::string &id);
AudioRtpSession *_rtpSession;
ost::Mutex _audioRtpThreadMutex;
......
......@@ -165,10 +165,9 @@ IAXVoIPLink::terminateIAXCall()
void
IAXVoIPLink::getEvent()
{
iax_event* event = NULL;
{
ost::MutexLock m(mutexIAX_);
iax_event *event;
while ((event = iax_get_event (IAX_NONBLOCKING)) != NULL) {
// If we received an 'ACK', libiax2 tells apps to ignore them.
if (event->etype == IAX_EVENT_NULL)
......@@ -263,8 +262,6 @@ IAXVoIPLink::getIAXCall (const std::string& id)
void
IAXVoIPLink::sendRegister (Account *a)
{
_debug ("IAX: Sending registration");
IAXAccount *account = dynamic_cast<IAXAccount*>(a);
if (account->getHostname().empty())
......@@ -273,43 +270,28 @@ IAXVoIPLink::sendRegister (Account *a)
if (account->getUsername().empty())
throw VoipLinkException("Account username is empty");
// lock
ost::MutexLock m(mutexIAX_);
// Always use a brand new session
if (regSession_)
iax_destroy(regSession_);
regSession_ = iax_session_new();
if (!regSession_)
_debug ("IAX: Error when generating new session for register");
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.
if (regSession_) {
iax_register (regSession_, account->getHostname().data(), account->getUsername().data(), account->getPassword().data(), 120);
nextRefreshStamp_ = time (NULL) + 10;
account->setRegistrationState (Trying);
account->setRegistrationState(Trying);
}
}
void
IAXVoIPLink::sendUnregister (Account *a)
{
_debug ("IAXVoipLink: Send unregister");
{
ost::MutexLock m(mutexIAX_);
if (regSession_) {
iax_destroy (regSession_);
regSession_ = NULL;
}
}
mutexIAX_.leaveMutex();
ost::MutexLock m(mutexIAX_);
if (regSession_) {
iax_destroy (regSession_);
regSession_ = NULL;
}
nextRefreshStamp_ = 0;
......
......@@ -2755,10 +2755,6 @@ void ManagerImpl::loadAccountMap(Conf::YamlParser *parser)
// IP to IP settings (most likely using port 5060)
link->createDefaultSipUdpTransport();
// Call this method to create TLS listener
link->createDefaultSipTlsListener();
// Force IP2IP settings to be loaded to be loaded
// No registration in the sense of the REGISTER method is performed.
ip2ip->registerVoIPLink();
......
......@@ -535,7 +535,7 @@ void SIPAccount::registerVoIPLink()
return;
try {
link_->sendRegister (this);
link_->sendRegister(this);
}
catch (const VoipLinkException &e) {
_error("SIPAccount: %s", e.what());
......
This diff is collapsed.
......@@ -257,16 +257,7 @@ class SIPVoIPLink : public VoIPLink
pjsip_tpselector *initTransportSelector (pjsip_transport *, pj_pool_t *);
/**
* Helper function for creating a route set from information
* 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.
* This function unset the transport for a given account.
*/
void shutdownSipTransport (SIPAccount *account);
......@@ -285,11 +276,6 @@ class SIPVoIPLink : public VoIPLink
*/
void createDefaultSipUdpTransport();
/**
* Create the default TLS litener using IP2IP_PROFILE settings
*/
void createDefaultSipTlsListener();
private:
/**
* Start a SIP Call
......@@ -313,49 +299,35 @@ class SIPVoIPLink : public VoIPLink
*/
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
* transport type specified in account settings
* @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
* @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
* @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
* @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
......
Markdown is supported
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