From e4daf6cd7ae1f2d5b87c8c1b0fbc121a93748a28 Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> Date: Mon, 18 Jul 2016 17:22:05 -0400 Subject: [PATCH] ringaccount: perform ICE init after returning call This way we don't have to wait for the ICE init before the manager can get a callId to return to the client. The ICE init can take a long time in certain cases (eg: bad TURN password, slow UPnP) which causes the UI to freeze while waiting for the daemon to return outgoingCall() with the callId. Note this changes the behaviour of the daemon slightly. Before if the ICE init failed then no callId would be returned. Now the callId is always returned and the call will later emit a state change of Fail if the ICE init fails. Tuleap: #620 Change-Id: I712d1d52be9e9b809b794bb7694ad31bdd2e3bb1 --- src/ringdht/ringaccount.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index 7c91778c7b..0d38b9115a 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -182,29 +182,36 @@ RingAccount::newOutgoingCall(const std::string& toUrl) auto& manager = Manager::instance(); auto call = manager.callFactory.newCall<SIPCall, RingAccount>(*this, manager.getNewCallID(), Call::CallType::OUTGOING); + call->setIPToIP(true); call->setSecure(isTlsEnabled()); - // Create an ICE transport for SIP channel - auto ice = createIceTransport(("sip:" + call->getCallId()).c_str(), - ICE_COMPONENTS, true, getIceOptions()); - if (not ice) { - call->removeCall(); - return nullptr; - } - - auto shared_this = std::static_pointer_cast<RingAccount>(shared_from_this()); - auto iceInitTimeout = std::chrono::steady_clock::now() + std::chrono::seconds {ICE_INIT_TIMEOUT}; - // TODO: for now, we automatically trust all explicitly called peers setCertificateStatus(toUri, tls::TrustStore::PermissionStatus::ALLOWED); + auto shared_this = std::static_pointer_cast<RingAccount>(shared_from_this()); std::weak_ptr<SIPCall> weak_call = call; - manager.addTask([shared_this, weak_call, ice, iceInitTimeout, toUri] { + manager.addTask([shared_this, weak_call, toUri] { auto call = weak_call.lock(); - if (not call) + if (not call) { + call->onFailure(); + return false; + } + + // Create an ICE transport for SIP channel + std::shared_ptr<IceTransport> ice {}; + + try { + ice = shared_this->createIceTransport(("sip:" + call->getCallId()).c_str(), + ICE_COMPONENTS, true, shared_this->getIceOptions()); + } catch (std::runtime_error& e) { + RING_ERR("%s", e.what()); + call->onFailure(); return false; + } + + auto iceInitTimeout = std::chrono::steady_clock::now() + std::chrono::seconds {ICE_INIT_TIMEOUT}; /* First step: wait for an initialized ICE transport for SIP channel */ if (ice->isFailed() or std::chrono::steady_clock::now() >= iceInitTimeout) { -- GitLab