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-05-01 08:46:49 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2021-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, write to the Free Software
      18             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      19             :  */
      20             : 
      21             : #include "jamidht/conversation_channel_handler.h"
      22             : 
      23             : namespace jami {
      24             : 
      25         461 : ConversationChannelHandler::ConversationChannelHandler(const std::shared_ptr<JamiAccount>& acc,
      26         461 :                                                        dhtnet::ConnectionManager& cm)
      27             :     : ChannelHandlerInterface()
      28         461 :     , account_(acc)
      29         461 :     , connectionManager_(cm)
      30         461 : {}
      31             : 
      32         922 : ConversationChannelHandler::~ConversationChannelHandler() {}
      33             : 
      34             : void
      35           0 : ConversationChannelHandler::connect(const DeviceId& deviceId,
      36             :                                     const std::string& channelName,
      37             :                                     ConnectCb&& cb)
      38             : {
      39           0 :     connectionManager_.connectDevice(deviceId,
      40           0 :                                      "git://" + deviceId.toString() + "/" + channelName,
      41           0 :                                      std::move(cb));
      42           0 : }
      43             : 
      44             : bool
      45         787 : ConversationChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert,
      46             :                                       const std::string& name)
      47             : {
      48         787 :     auto acc = account_.lock();
      49         787 :     if (!cert || !cert->issuer || !acc)
      50           0 :         return false;
      51             :     // Pre-check before acceptance. Sometimes, another device can start a conversation
      52             :     // which is still not synced. So, here we decline channel's request in this case
      53             :     // to avoid the other device to want to sync with us if we are not ready.
      54         787 :     auto sep = name.find_last_of('/');
      55         787 :     auto conversationId = name.substr(sep + 1);
      56             : 
      57         787 :     if (auto acc = account_.lock())
      58         787 :         if (auto convModule = acc->convModule(true)) {
      59         787 :             auto res = !convModule->isBanned(conversationId, cert->issuer->getId().toString());
      60         787 :             res &= !convModule->isBanned(conversationId, cert->getLongId().toString());
      61         787 :             return res;
      62         787 :         }
      63           0 :     return false;
      64         787 : }
      65             : 
      66             : void
      67           0 : ConversationChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>&,
      68             :                                     const std::string&,
      69             :                                     std::shared_ptr<dhtnet::ChannelSocket>)
      70           0 : {}
      71             : 
      72             : } // namespace jami

Generated by: LCOV version 1.14