diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index aa7fb53320774d537d95142bf2416375059e6bec..4dd5c8dad86b5c9a5a992b7102cb2297b4e4b6f5 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -146,23 +146,10 @@ template <class... Args> std::shared_ptr<IceTransport> RingAccount::createIceTransport(const Args&... args) { - // We need a public address in case of NAT'ed network - // Trying to use one discovered by DHT service - if (getPublishedAddress().empty()) { - const auto& addresses = dht_.getPublicAddress(AF_INET); - if (addresses.size()) - setPublishedAddress(IpAddr{addresses[0].first}); - } - auto ice = Manager::instance().getIceTransportFactory().createTransport(args...); if (!ice) throw std::runtime_error("ICE transport creation failed"); - if (const auto& publicIP = getPublishedIpAddress()) { - for (unsigned compId = 1; compId <= ice->getComponentCount(); ++compId) - ice->registerPublicIP(compId, publicIP); - } - return ice; } @@ -321,6 +308,8 @@ RingAccount::startOutgoingCall(std::shared_ptr<SIPCall>& call, const std::string if (not ice->isInitialized()) return true; + sthis->registerDhtAddress(*ice); + // Next step: sent the ICE data to peer through DHT const dht::Value::Id callvid = udist(sthis->rand_); const dht::Value::Id vid = udist(sthis->rand_); @@ -1839,6 +1828,8 @@ RingAccount::replyToIncomingIceMsg(std::shared_ptr<SIPCall> call, const dht::IceCandidates& peer_ice_msg, std::shared_ptr<dht::crypto::Certificate> peer_cert) { + registerDhtAddress(*ice); + const auto vid = udist(rand_); dht::Value val { dht::IceCandidates(peer_ice_msg.id, ice->getLocalAttributesAndCandidates()) }; val.id = vid; @@ -2419,4 +2410,27 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string, }); } +void +RingAccount::registerDhtAddress(IceTransport& ice) +{ + auto ip = getPublishedAddress(); + + // We need a public address in case of NAT'ed network + // Trying to use one discovered by DHT service + if (ip.empty()) { + const auto& addresses = dht_.getPublicAddress(AF_INET); + if (addresses.size()) { + ip = IpAddr {addresses[0].first}; + setPublishedAddress(ip); + } + } + + if (!ip.empty()) { + RING_DBG("[dht] Using pub IP: %s", ip.c_str()); + for (unsigned compId = 1; compId <= ice.getComponentCount(); ++compId) + ice.registerPublicIP(compId, ip); + } else + RING_WARN("[dht] No public IP found!"); +} + } // namespace ring diff --git a/src/ringdht/ringaccount.h b/src/ringdht/ringaccount.h index 13e3ac5b3c71188efbcd6c405effe5c1c2414a9a..82dc120c6626ce131e76e2b7cd2c38a73b45d685 100644 --- a/src/ringdht/ringaccount.h +++ b/src/ringdht/ringaccount.h @@ -533,6 +533,8 @@ class RingAccount : public SIPAccountBase { template <class... Args> std::shared_ptr<IceTransport> createIceTransport(const Args&... args); + + void registerDhtAddress(IceTransport&); }; } // namespace ring