diff --git a/src/jamidht/p2p.cpp b/src/jamidht/p2p.cpp index 4bfb52357078afb1d31ba9f5b402b065e1cfaf39..4d06cff4dd22a5c9c62f97c14f421f4f70dc8cc0 100644 --- a/src/jamidht/p2p.cpp +++ b/src/jamidht/p2p.cpp @@ -570,17 +570,23 @@ DhtPeerConnector::Impl::turnConnect() if (turnAuthv6_ && !turnAuthv6_->isReady()) turnAuthv6_.reset(); - if (!turnAuthv4_ || !turnAuthv4_->isReady()) { - turn_param_v4.authorized_family = PJ_AF_INET; - turnAuthv4_ = std::make_unique<TurnTransport>(turn_param_v4); - } + try { + if (!turnAuthv4_ || !turnAuthv4_->isReady()) { + turn_param_v4.authorized_family = PJ_AF_INET; + turnAuthv4_ = std::make_unique<TurnTransport>(turn_param_v4); + } - if (!turnAuthv6_ || !turnAuthv6_->isReady()) { - auto turn_param_v6 = turn_param_v4; - turn_param_v6.authorized_family = PJ_AF_INET6; - turnAuthv6_ = std::make_unique<TurnTransport>(turn_param_v6); + if (!turnAuthv6_ || !turnAuthv6_->isReady()) { + auto turn_param_v6 = turn_param_v4; + turn_param_v6.authorized_family = PJ_AF_INET6; + turnAuthv6_ = std::make_unique<TurnTransport>(turn_param_v6); + } + } catch (...) { + JAMI_WARN("Turn allocation failed. Do not use the TURN"); + return false; } + // Wait until TURN server READY state (or timeout) Timeout<Clock> timeout {NET_CONNECTION_TIMEOUT}; timeout.start(); diff --git a/src/turn_transport.cpp b/src/turn_transport.cpp index c0727749e5937cf75413791eae3b0aced2e52370..66433514bdc276d2c28b3195ea1b84b2d2a9c082 100644 --- a/src/turn_transport.cpp +++ b/src/turn_transport.cpp @@ -197,7 +197,6 @@ TurnTransportPimpl::ioJob() //============================================================================== TurnTransport::TurnTransport(const TurnTransportParams& params) - : pimpl_ {new TurnTransportPimpl} { sip_utils::register_thread(); @@ -208,6 +207,7 @@ TurnTransport::TurnTransport(const TurnTransportParams& params) if (server.isUnspecified()) throw std::invalid_argument("invalid turn server address"); + pimpl_ = std::unique_ptr<TurnTransportPimpl>(new TurnTransportPimpl); pimpl_->settings = params; // PJSIP memory pool