Skip to content
Snippets Groups Projects
Commit 84bf4184 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

connectionmanager: pass turn_cache to config

This allow upper layers to manage the configuration of the cache.

Change-Id: I2c79fb1946f22b23a0de955728811618ab84272c
parent 883c7657
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ice_options.h" #include "ice_options.h"
#include "multiplexed_socket.h" #include "multiplexed_socket.h"
#include "turn_cache.h"
#include <opendht/dhtrunner.h> #include <opendht/dhtrunner.h>
#include <opendht/infohash.h> #include <opendht/infohash.h>
...@@ -237,9 +238,7 @@ struct ConnectionManager::Config ...@@ -237,9 +238,7 @@ struct ConnectionManager::Config
std::string turnServerPwd; std::string turnServerPwd;
std::string turnServerRealm; std::string turnServerRealm;
mutable std::mutex cachedTurnMutex {}; std::shared_ptr<TurnCache> turnCache;
dht::SockAddr cacheTurnV4 {};
dht::SockAddr cacheTurnV6 {};
std::string cachePath {}; std::string cachePath {};
......
...@@ -1408,12 +1408,18 @@ ConnectionManager::Impl::getIceOptions() const noexcept ...@@ -1408,12 +1408,18 @@ ConnectionManager::Impl::getIceOptions() const noexcept
if (config_->stunEnabled) if (config_->stunEnabled)
opts.stunServers.emplace_back(StunServerInfo().setUri(config_->stunServer)); opts.stunServers.emplace_back(StunServerInfo().setUri(config_->stunServer));
if (config_->turnEnabled) { if (config_->turnEnabled) {
auto cached = false; if (config_->turnCache) {
std::lock_guard<std::mutex> lk(config_->cachedTurnMutex); auto turnAddr = config_->turnCache->getResolvedTurn();
cached = config_->cacheTurnV4 || config_->cacheTurnV6; if (turnAddr != std::nullopt) {
if (config_->cacheTurnV4) {
opts.turnServers.emplace_back(TurnServerInfo() opts.turnServers.emplace_back(TurnServerInfo()
.setUri(config_->cacheTurnV4.toString()) .setUri(turnAddr->toString())
.setUsername(config_->turnServerUserName)
.setPassword(config_->turnServerPwd)
.setRealm(config_->turnServerRealm));
}
} else {
opts.turnServers.emplace_back(TurnServerInfo()
.setUri(config_->turnServer)
.setUsername(config_->turnServerUserName) .setUsername(config_->turnServerUserName)
.setPassword(config_->turnServerPwd) .setPassword(config_->turnServerPwd)
.setRealm(config_->turnServerRealm)); .setRealm(config_->turnServerRealm));
...@@ -1427,14 +1433,6 @@ ConnectionManager::Impl::getIceOptions() const noexcept ...@@ -1427,14 +1433,6 @@ ConnectionManager::Impl::getIceOptions() const noexcept
// .setPassword(turnServerPwd_) // .setPassword(turnServerPwd_)
// .setRealm(turnServerRealm_)); // .setRealm(turnServerRealm_));
//} //}
// Nothing cached, so do the resolution
if (!cached) {
opts.turnServers.emplace_back(TurnServerInfo()
.setUri(config_->turnServer)
.setUsername(config_->turnServerUserName)
.setPassword(config_->turnServerPwd)
.setRealm(config_->turnServerRealm));
}
} }
return opts; return opts;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment