diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp index 48b3c3abfd8e448a582bd15ccf9f51939a072a63..3cf0fd3583a6b0eb62094842eb00d74e2f322589 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp @@ -54,10 +54,8 @@ AudioRtpFactory::~AudioRtpFactory() stop(); } -void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) +void AudioRtpFactory::initAudioRtpConfig(SIPCall *ca) { - ost::MutexLock m (_audioRtpThreadMutex); - assert (ca); if (_rtpSession != NULL) { @@ -68,36 +66,35 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) AccountID accountId = Manager::instance().getAccountFromCall (ca->getCallId()); - bool srtpEnabled = false; - int keyExchangeProtocol = 1; - bool helloHashEnabled = true; - // Check if it is an IP-to-IP call - if (accountId == AccountNULL) { - srtpEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, SRTP_ENABLE); - keyExchangeProtocol = Manager::instance().getConfigInt (IP2IP_PROFILE, SRTP_KEY_EXCHANGE); - _debug ("Ip-to-ip profile selected with key exchange protocol number %d", keyExchangeProtocol); - helloHashEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, ZRTP_HELLO_HASH); + _srtpEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, SRTP_ENABLE); + _keyExchangeProtocol = Manager::instance().getConfigInt (IP2IP_PROFILE, SRTP_KEY_EXCHANGE); + _debug ("Ip-to-ip profile selected with key exchange protocol number %d", _keyExchangeProtocol); + _helloHashEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, ZRTP_HELLO_HASH); } else { - srtpEnabled = Manager::instance().getConfigBool (accountId, SRTP_ENABLE); - keyExchangeProtocol = Manager::instance().getConfigInt (accountId, SRTP_KEY_EXCHANGE); - _debug ("Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), keyExchangeProtocol); - helloHashEnabled = Manager::instance().getConfigBool (accountId, ZRTP_HELLO_HASH); + _srtpEnabled = Manager::instance().getConfigBool (accountId, SRTP_ENABLE); + _keyExchangeProtocol = Manager::instance().getConfigInt (accountId, SRTP_KEY_EXCHANGE); + _debug ("Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), _keyExchangeProtocol); + _helloHashEnabled = Manager::instance().getConfigBool (accountId, ZRTP_HELLO_HASH); } +} - _debug ("Srtp enable: %d ", srtpEnabled); +void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) +{ + ost::MutexLock m (_audioRtpThreadMutex); - if (srtpEnabled) { + _debug ("Srtp enable: %d ", _srtpEnabled); + if (_srtpEnabled) { std::string zidFilename (Manager::instance().getConfigString (SIGNALISATION, ZRTP_ZIDFILE)); - switch (keyExchangeProtocol) { + switch (_keyExchangeProtocol) { case Zrtp: _rtpSession = new AudioZrtpSession (&Manager::instance(), ca, zidFilename); _rtpSessionType = Zrtp; - if (helloHashEnabled) { + if (_helloHashEnabled) { // TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's // not even available at that point. ca->getLocalSDP()->set_zrtp_hash (static_cast<AudioZrtpSession *> (_rtpSession)->getHelloHash()); diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h index d965e53f4751c43e1f0e516290b446df87e13f61..cfa14165f1cf0f85960eb775b4b09fd476df7062 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h @@ -61,6 +61,8 @@ namespace sfl { AudioRtpFactory(SIPCall * ca); ~AudioRtpFactory(); + void initAudioRtpConfig(SIPCall *ca); + /** * Lazy instantiation method. Create a new RTP session of a given * type according to the content of the configuration file. @@ -108,7 +110,22 @@ namespace sfl { /** * @param Set internal audio rtp session type (Symmetric, Zrtp, Sdes) */ - inline RtpMethod setAudioRtpType(RtpMethod type) { _rtpSessionType = type; } + inline void setAudioRtpType(RtpMethod type) { _rtpSessionType = type; } + + /** + * Manually set the srtpEnable option (usefull for RTP fallback) + */ + void setSrtpEnabled(bool enable){ _srtpEnabled = enable; } + + /** + * Manually set the keyExchangeProtocol parameter (usefull for RTP fallback) + */ + void setKeyExchangeProtocol(int proto){ _keyExchangeProtocol = proto; } + + /** + * Manually set the setHelloHashEnabled parameter (usefull for RTP fallback) + */ + void setHelloHashEnabled(bool enable){ _helloHashEnabled = enable; } /** * Get the current AudioZrtpSession. Throws an AudioRtpFactoryException @@ -127,6 +144,18 @@ namespace sfl { void * _rtpSession; RtpMethod _rtpSessionType; ost::Mutex _audioRtpThreadMutex; + + // Field used when initializinga udio rtp session + // May be set manually or from config using initAudioRtpConfig + bool _srtpEnabled; + + // Field used when initializinga udio rtp session + // May be set manually or from config using initAudioRtpConfig + int _keyExchangeProtocol; + + // Field used when initializinga udio rtp session + // May be set manually or from config using initAudioRtpConfig + bool _helloHashEnabled; }; } #endif // __AUDIO_RTP_FACTORY_H__ diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 2fac4d186e1f5239f299fdfdfb6bd73fb31ff5e5..ed81c182f92f36fac8117d3a55cfc43ff2e09bf3 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -757,6 +757,7 @@ SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) try { _debug ("Creating new rtp session in newOutgoingCall"); + call->getAudioRtp()->initAudioRtpConfig (call); call->getAudioRtp()->initAudioRtpSession (call); } catch (...) { _debug ("Failed to create rtp thread from newOutGoingCall"); @@ -1060,6 +1061,7 @@ SIPVoIPLink::offhold (const CallID& id) } try { + call->getAudioRtp()->initAudioRtpConfig (call); call->getAudioRtp()->initAudioRtpSession (call); } catch (...) { _debug ("! SIP Failure: Unable to create RTP Session (%s:%d)", __FILE__, __LINE__); @@ -1569,6 +1571,7 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) // Audio Rtp Session must be initialized before creating initial offer in SDP session // since SDES require crypto attribute. try { + call->getAudioRtp()->initAudioRtpConfig (call); call->getAudioRtp()->initAudioRtpSession (call); } catch (...) { _debug ("! SIP Failure: Unable to create RTP Session in SIPVoIPLink::new_ip_to_ip_call (%s:%d)", __FILE__, __LINE__); @@ -3265,9 +3268,10 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) // We did not found any crypto context for this media // @TODO if SRTPONLY, CallFail - // if RTPFALLBACK, change RTP session + // if RTPFALLBACK, change RTP session + _debug("Did not found any crypto or negociation failed but Sdes enabled"); call->getAudioRtp()->stop(); - call->getAudioRtp()->setAudioRtpType(sfl::Symmetric); + call->getAudioRtp()->setSrtpEnabled(false); call->getAudioRtp()->initAudioRtpSession(call); } @@ -3661,6 +3665,7 @@ mod_on_rx_request (pjsip_rx_data *rdata) call->getLocalSDP()->set_ip_address (addrSdp); try { + call->getAudioRtp()->initAudioRtpConfig (call); call->getAudioRtp()->initAudioRtpSession (call); } catch (...) { _debug ("Failed to create rtp thread from answer");