From 89933c1df40aaa6d10b4482c5d2e51739c47e8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Wed, 26 Jul 2023 14:53:30 -0400 Subject: [PATCH] ice, tls: add logs Change-Id: Ie0e79bf41803e256c1d6d300acfd6caf30079311 --- include/ice_transport.h | 2 +- include/ice_transport_factory.h | 3 ++- src/ice_transport.cpp | 17 +++++++++-------- tests/connectionManager.cpp | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/ice_transport.h b/include/ice_transport.h index ca4b086..c5047b3 100644 --- a/include/ice_transport.h +++ b/include/ice_transport.h @@ -78,7 +78,7 @@ public: /** * Constructor */ - IceTransport(std::string_view name); + IceTransport(std::string_view name, const std::shared_ptr<Logger>& logger = {}); ~IceTransport(); const std::shared_ptr<Logger>& logger() const; diff --git a/include/ice_transport_factory.h b/include/ice_transport_factory.h index ecb04b0..03aef10 100644 --- a/include/ice_transport_factory.h +++ b/include/ice_transport_factory.h @@ -33,7 +33,7 @@ namespace dhtnet { class IceTransportFactory { public: - IceTransportFactory(); + IceTransportFactory(const std::shared_ptr<Logger>& logger = {}); ~IceTransportFactory(); std::shared_ptr<IceTransport> createTransport(std::string_view name); @@ -50,6 +50,7 @@ public: private: std::shared_ptr<pj_caching_pool> cp_; pj_ice_strans_cfg ice_cfg_; + std::shared_ptr<Logger> logger_ {}; }; }; // namespace jami diff --git a/src/ice_transport.cpp b/src/ice_transport.cpp index 602347d..58e722d 100644 --- a/src/ice_transport.cpp +++ b/src/ice_transport.cpp @@ -95,7 +95,7 @@ public: class IceTransport::Impl { public: - Impl(std::string_view name); + Impl(std::string_view name, const std::shared_ptr<Logger>& logger); ~Impl(); void initIceInstance(const IceTransportOptions& options); @@ -327,8 +327,8 @@ add_turn_server(pj_pool_t& pool, pj_ice_strans_cfg& cfg, const TurnServerInfo& i //============================================================================== -IceTransport::Impl::Impl(std::string_view name) - : sessionName_(name) +IceTransport::Impl::Impl(std::string_view name, const std::shared_ptr<Logger>& logger) + : logger_(logger), sessionName_(name) { if (logger_) logger_->debug("[ice:{}] Creating IceTransport session for \"{:s}\"", fmt::ptr(this), name); @@ -1161,8 +1161,8 @@ IceTransport::Impl::_waitForInitialization(std::chrono::milliseconds timeout) //============================================================================== -IceTransport::IceTransport(std::string_view name) - : pimpl_ {std::make_unique<Impl>(name)} +IceTransport::IceTransport(std::string_view name, const std::shared_ptr<dht::log::Logger>& logger) + : pimpl_ {std::make_unique<Impl>(name, logger)} {} IceTransport::~IceTransport() @@ -1795,13 +1795,14 @@ IceTransport::link() const //============================================================================== -IceTransportFactory::IceTransportFactory() +IceTransportFactory::IceTransportFactory(const std::shared_ptr<Logger>& logger) : cp_(new pj_caching_pool(), [](pj_caching_pool* p) { pj_caching_pool_destroy(p); delete p; }) , ice_cfg_() + , logger_(logger) { pj_caching_pool_init(cp_.get(), NULL, 0); @@ -1826,7 +1827,7 @@ std::shared_ptr<IceTransport> IceTransportFactory::createTransport(std::string_view name) { try { - return std::make_shared<IceTransport>(name); + return std::make_shared<IceTransport>(name, logger_); } catch (const std::exception& e) { //JAMI_ERR("%s", e.what()); return nullptr; @@ -1837,7 +1838,7 @@ std::unique_ptr<IceTransport> IceTransportFactory::createUTransport(std::string_view name) { try { - return std::make_unique<IceTransport>(name); + return std::make_unique<IceTransport>(name, logger_); } catch (const std::exception& e) { //JAMI_ERR("%s", e.what()); return nullptr; diff --git a/tests/connectionManager.cpp b/tests/connectionManager.cpp index ef843ef..a4e3759 100644 --- a/tests/connectionManager.cpp +++ b/tests/connectionManager.cpp @@ -197,7 +197,7 @@ ConnectionManagerTest::setUp() //print the error; } }); - factory = std::make_unique<IceTransportFactory>(); + factory = std::make_unique<IceTransportFactory>(logger); alice = setupHandler("alice"); bob = setupHandler("bob"); } -- GitLab