LCOV - code coverage report
Current view: top level - src/jamidht - conversation_channel_handler.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 18 27 66.7 %
Date: 2024-11-13 09:04:27 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-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, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : #include "jamidht/conversation_channel_handler.h"
      18             : 
      19             : namespace jami {
      20             : 
      21         680 : ConversationChannelHandler::ConversationChannelHandler(const std::shared_ptr<JamiAccount>& acc,
      22         680 :                                                        dhtnet::ConnectionManager& cm)
      23             :     : ChannelHandlerInterface()
      24         680 :     , account_(acc)
      25         680 :     , connectionManager_(cm)
      26         680 : {}
      27             : 
      28        1360 : ConversationChannelHandler::~ConversationChannelHandler() {}
      29             : 
      30             : void
      31           0 : ConversationChannelHandler::connect(const DeviceId& deviceId,
      32             :                                     const std::string& channelName,
      33             :                                     ConnectCb&& cb)
      34             : {
      35           0 :     connectionManager_.connectDevice(deviceId,
      36           0 :                                      "git://" + deviceId.toString() + "/" + channelName,
      37           0 :                                      std::move(cb));
      38           0 : }
      39             : 
      40             : bool
      41         906 : ConversationChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert,
      42             :                                       const std::string& name)
      43             : {
      44         906 :     auto acc = account_.lock();
      45         906 :     if (!cert || !cert->issuer || !acc)
      46           0 :         return false;
      47             :     // Pre-check before acceptance. Sometimes, another device can start a conversation
      48             :     // which is still not synced. So, here we decline channel's request in this case
      49             :     // to avoid the other device to want to sync with us if we are not ready.
      50         906 :     auto sep = name.find_last_of('/');
      51         906 :     auto conversationId = name.substr(sep + 1);
      52             : 
      53         906 :     if (auto acc = account_.lock())
      54         906 :         if (auto convModule = acc->convModule(true)) {
      55         906 :             auto res = !convModule->isBanned(conversationId, cert->issuer->getId().toString());
      56         906 :             res &= !convModule->isBanned(conversationId, cert->getLongId().toString());
      57         906 :             return res;
      58         906 :         }
      59           0 :     return false;
      60         906 : }
      61             : 
      62             : void
      63           0 : ConversationChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&,
      64             :                                     const std::string&,
      65             :                                     std::shared_ptr<dhtnet::ChannelSocket>)
      66           0 : {}
      67             : 
      68             : } // namespace jami

Generated by: LCOV version 1.14