Line data Source code
1 : /* 2 : * Copyright (C) 2004-2025 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/auth_channel_handler.h" 18 : #include "archive_account_manager.h" 19 : 20 : #include <opendht/thread_pool.h> 21 : 22 : namespace jami { 23 : 24 669 : AuthChannelHandler::AuthChannelHandler(const std::shared_ptr<JamiAccount>& acc, dhtnet::ConnectionManager& cm) 25 : : ChannelHandlerInterface() 26 669 : , account_(acc) 27 669 : , connectionManager_(cm) 28 669 : {} 29 : 30 1338 : AuthChannelHandler::~AuthChannelHandler() {} 31 : 32 : // deprecated 33 : void 34 0 : AuthChannelHandler::connect(const DeviceId& deviceId, 35 : const std::string& name, 36 : ConnectCb&& cb, 37 : const std::string& connectionType, 38 : bool forceNewConnection) 39 : { 40 0 : JAMI_DEBUG("[AuthChannel {}] connecting to name = {}", deviceId.toString(), name); 41 0 : connectionManager_.connectDevice(deviceId, name, std::move(cb)); 42 0 : } 43 : 44 : void 45 5 : AuthChannelHandler::connect(const dht::InfoHash& infoHash, const std::string& channelPath, ConnectCallbackLegacy&& cb) 46 : { 47 20 : JAMI_DEBUG("[AuthChannel {}] connecting to channelPath = {}", infoHash.toString(), channelPath); 48 5 : connectionManager_.connectDevice(infoHash, channelPath, std::move(cb)); 49 5 : } 50 : 51 : bool 52 0 : AuthChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, const std::string& name) 53 : { 54 0 : JAMI_DEBUG("[AuthChannel] New auth channel requested for `{}`.", cert->getId().toString()); 55 0 : auto acc = account_.lock(); 56 0 : if (!cert || !cert->issuer || !acc) 57 0 : return false; 58 : 59 0 : JAMI_DEBUG("[AuthChannel] New auth channel requested with name = `{}`.", name); 60 : 61 0 : if (auto acc = account_.lock()) 62 0 : return true; 63 : 64 0 : return false; 65 0 : } 66 : 67 : void 68 4 : AuthChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& cert, 69 : const std::string& deviceId, 70 : std::shared_ptr<dhtnet::ChannelSocket> channel) 71 : { 72 16 : JAMI_DEBUG("[AuthChannel] Auth channel with {}/{} ready.", cert->getId().toString(), deviceId); 73 4 : } 74 : 75 : } // namespace jami