From c7923ebcc7eed7fbf7303612294396ac08c85cb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 3 Jul 2023 09:54:48 -0400
Subject: [PATCH] jamiaccount: setAccountDetails should update connection
 manager's config

Change-Id: Ic1f6906a566aeaff55dd574a316e79dbc37d8e33
---
 src/connectivity/connectionmanager.cpp |  2 --
 src/connectivity/connectionmanager.h   | 12 ------------
 src/jamidht/jamiaccount.cpp            | 13 +++++++++++++
 src/sip/sipaccountbase.cpp             |  2 --
 4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/src/connectivity/connectionmanager.cpp b/src/connectivity/connectionmanager.cpp
index 85afa5c084..d7c0968016 100644
--- a/src/connectivity/connectionmanager.cpp
+++ b/src/connectivity/connectionmanager.cpp
@@ -1363,8 +1363,6 @@ ConnectionManager::Impl::getIceOptions() const noexcept
     IceTransportOptions opts;
     opts.upnpEnable = getUPnPActive();
 
-    if (config_->stunEnabled_)
-        opts.stunServers.emplace_back(StunServerInfo().setUri(config_->stunServer_));
     if (config_->turnEnabled_) {
         auto cached = false;
         std::lock_guard<std::mutex> lk(config_->cachedTurnMutex_);
diff --git a/src/connectivity/connectionmanager.h b/src/connectivity/connectionmanager.h
index d2fc5d037d..0112017865 100644
--- a/src/connectivity/connectionmanager.h
+++ b/src/connectivity/connectionmanager.h
@@ -250,18 +250,6 @@ public:
      * ie: if it is able to make port mappings
      */
     bool getUPnPActive() const;
-
-    /**
-     * Determine if STUN public address resolution is required to register this account. In this
-     * case a STUN server hostname must be specified.
-     */
-    bool stunEnabled_ {false};
-
-    /**
-     * The STUN server hostname (optional), used to provide the public IP address in case the
-     * softphone stay behind a NAT.
-     */
-    std::string stunServer_ {};
     /**
      * The TURN server hostname (optional), used to provide the public IP address in case the
      * softphone stay behind a NAT.
diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 350c8f84e8..84b31c0420 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -895,6 +895,17 @@ JamiAccount::loadConfig()
     registeredName_ = config().registeredName;
     if (accountManager_)
         accountManager_->setAccountDeviceName(config().deviceName);
+    if (connectionManager_) {
+        if (auto c = connectionManager_->getConfig()) {
+            // Update connectionManager's config
+            c->upnpEnabled_ = config().upnpEnabled;
+            c->turnEnabled_ = config().turnEnabled;
+            c->turnServer_ = config().turnServer;
+            c->turnServerUserName_ = config().turnServerUserName;
+            c->turnServerPwd_ = config().turnServerPwd;
+            c->turnServerRealm_ = config().turnServerRealm;
+        }
+    }
     try {
         auto str = fileutils::loadCacheTextFile(cachePath_ + DIR_SEPARATOR_STR "dhtproxy",
                                                 std::chrono::hours(24 * 7));
@@ -4193,6 +4204,8 @@ JamiAccount::initConnectionManager()
                                                           config().turnEnabled);
         connectionManagerConfig->cachePath = cachePath_;
         connectionManager_ = std::make_unique<ConnectionManager>(connectionManagerConfig);
+        channelHandlers_[Uri::Scheme::SWARM]
+            = std::make_unique<SwarmChannelHandler>(shared(), *connectionManager_.get());
         channelHandlers_[Uri::Scheme::GIT]
             = std::make_unique<ConversationChannelHandler>(shared(), *connectionManager_.get());
         channelHandlers_[Uri::Scheme::SYNC]
diff --git a/src/sip/sipaccountbase.cpp b/src/sip/sipaccountbase.cpp
index 9fa372d4fb..f7fe7ad938 100644
--- a/src/sip/sipaccountbase.cpp
+++ b/src/sip/sipaccountbase.cpp
@@ -252,8 +252,6 @@ SIPAccountBase::getIceOptions() const noexcept
     IceTransportOptions opts;
     opts.upnpEnable = getUPnPActive();
 
-    // if (config().stunEnabled)
-    //     opts.stunServers.emplace_back(StunServerInfo().setUri(stunServer_));
     if (config().turnEnabled && turnCache_) {
         auto turnAddr = turnCache_->getResolvedTurn();
         if (turnAddr != std::nullopt) {
-- 
GitLab