LCOV - code coverage report
Current view: top level - src/jamidht/swarm - swarm_channel_handler.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 28 34 82.4 %
Date: 2024-05-13 08:43:34 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2024 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, write to the Free Software
      16             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "swarm_channel_handler.h"
      20             : 
      21             : namespace jami {
      22             : 
      23         465 : SwarmChannelHandler::SwarmChannelHandler(const std::shared_ptr<JamiAccount>& acc,
      24         465 :                                          dhtnet::ConnectionManager& cm)
      25             :     : ChannelHandlerInterface()
      26         465 :     , account_(acc)
      27         465 :     , connectionManager_(cm)
      28         465 : {}
      29             : 
      30         930 : SwarmChannelHandler::~SwarmChannelHandler() {}
      31             : 
      32             : void
      33           0 : SwarmChannelHandler::connect(const DeviceId& deviceId,
      34             :                              const std::string& conversationId,
      35             :                              ConnectCb&& cb)
      36             : {
      37             : #ifdef LIBJAMI_TESTABLE
      38           0 :     if (disableSwarmManager)
      39           0 :         return;
      40             : #endif
      41           0 :     connectionManager_.connectDevice(deviceId, fmt::format("swarm://{}", conversationId), cb);
      42             : }
      43             : 
      44             : bool
      45         424 : SwarmChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert,
      46             :                                const std::string& name)
      47             : {
      48             : #ifdef LIBJAMI_TESTABLE
      49         424 :     if (disableSwarmManager)
      50           1 :         return false;
      51             : #endif
      52         423 :     auto acc = account_.lock();
      53         423 :     if (!cert || !cert->issuer || !acc)
      54           0 :         return false;
      55             : 
      56         423 :     auto sep = name.find_last_of('/');
      57         423 :     auto conversationId = name.substr(sep + 1);
      58         423 :     if (auto acc = account_.lock())
      59         423 :         if (auto convModule = acc->convModule(true)) {
      60         423 :             auto res = !convModule->isBanned(conversationId, cert->issuer->getId().toString());
      61         423 :             res &= !convModule->isBanned(conversationId, cert->getLongId().toString());
      62         423 :             return res;
      63         423 :         }
      64           0 :     return false;
      65         423 : }
      66             : 
      67             : void
      68         832 : SwarmChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&,
      69             :                              const std::string& uri,
      70             :                              std::shared_ptr<dhtnet::ChannelSocket> socket)
      71             : {
      72         832 :     auto sep = uri.find_last_of('/');
      73         832 :     auto conversationId = uri.substr(sep + 1);
      74         832 :     if (auto acc = account_.lock()) {
      75         832 :         if (auto convModule = acc->convModule(true)) {
      76         832 :             convModule->addSwarmChannel(conversationId, socket);
      77             :         }
      78         832 :     }
      79         832 : }
      80             : } // namespace jami

Generated by: LCOV version 1.14