LCOV - code coverage report
Current view: top level - src/jamidht/swarm - swarm_channel_handler.cpp (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 79.4 % 34 27
Test Date: 2026-07-06 08:25:38 Functions: 87.5 % 8 7

            Line data    Source code
       1              : /*
       2              :  *  Copyright (C) 2004-2026 Savoir-faire Linux Inc.
       3              :  *
       4              :  *  This program is free software: you can redistribute it and/or modify
       5              :  *  it under the terms of the GNU General Public License as published by
       6              :  *  the Free Software Foundation, either version 3 of the License, or
       7              :  *  (at your option) any later version.
       8              :  *
       9              :  *  This program is distributed in the hope that it will be useful,
      10              :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12              :  *  GNU General Public License for more details.
      13              :  *
      14              :  *  You should have received a copy of the GNU General Public License
      15              :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16              :  */
      17              : 
      18              : #include "swarm_channel_handler.h"
      19              : #include "jamidht/jamiaccount.h"
      20              : 
      21              : namespace jami {
      22              : 
      23          694 : SwarmChannelHandler::SwarmChannelHandler(const std::shared_ptr<JamiAccount>& acc, dhtnet::ConnectionManager& cm)
      24              :     : ChannelHandlerInterface()
      25          694 :     , account_(acc)
      26          694 :     , connectionManager_(cm)
      27          694 : {}
      28              : 
      29         1388 : SwarmChannelHandler::~SwarmChannelHandler() {}
      30              : 
      31              : void
      32            0 : SwarmChannelHandler::connect(const DeviceId& deviceId,
      33              :                              const std::string& conversationId,
      34              :                              ConnectCb&& cb,
      35              :                              const std::string& /*connectionType*/,
      36              :                              bool /*forceNewConnection*/)
      37              : {
      38              : #ifdef LIBJAMI_TEST
      39            0 :     if (disableSwarmManager)
      40            0 :         return;
      41              : #endif
      42            0 :     connectionManager_.connectDevice(deviceId, fmt::format("swarm://{}", conversationId), cb);
      43            0 : }
      44              : 
      45              : bool
      46          550 : SwarmChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, const std::string& name)
      47              : {
      48              : #ifdef LIBJAMI_TEST
      49          550 :     if (disableSwarmManager)
      50            0 :         return false;
      51              : #endif
      52          550 :     auto acc = account_.lock();
      53          550 :     if (!cert || !cert->issuer || !acc)
      54            0 :         return false;
      55              : 
      56          550 :     auto sep = name.find_last_of('/');
      57          550 :     auto conversationId = name.substr(sep + 1);
      58          550 :     auto* convModule = acc->convModule(true);
      59          550 :     if (!convModule) {
      60            4 :         JAMI_ERROR("[Account {}] Received swarm channel request for '{}' but conversation module is unavailable",
      61              :                    acc->getAccountID(),
      62              :                    name);
      63            1 :         return false;
      64              :     }
      65          549 :     auto issuerUri = cert->issuer->getId().toString();
      66          549 :     auto deviceUri = cert->getLongId().toString();
      67              : 
      68          549 :     return convModule->isPeerAuthorized(conversationId, issuerUri, deviceUri, true);
      69          550 : }
      70              : 
      71              : void
      72         1026 : SwarmChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&,
      73              :                              const std::string& uri,
      74              :                              std::shared_ptr<dhtnet::ChannelSocket> socket)
      75              : {
      76         1026 :     auto sep = uri.find_last_of('/');
      77         1027 :     auto conversationId = uri.substr(sep + 1);
      78         1027 :     if (auto acc = account_.lock()) {
      79         1027 :         if (auto* convModule = acc->convModule(true)) {
      80         1026 :             convModule->addSwarmChannel(conversationId, socket);
      81              :         }
      82         1027 :     }
      83         1027 : }
      84              : } // namespace jami
        

Generated by: LCOV version 2.0-1