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 569 : AuthChannelHandler::AuthChannelHandler(const std::shared_ptr<JamiAccount>& acc, 25 569 : dhtnet::ConnectionManager& cm) 26 : : ChannelHandlerInterface() 27 569 : , account_(acc) 28 569 : , connectionManager_(cm) 29 569 : {} 30 : 31 1138 : AuthChannelHandler::~AuthChannelHandler() {} 32 : 33 : // deprecated 34 : void 35 0 : AuthChannelHandler::connect(const DeviceId& deviceId, 36 : const std::string& name, 37 : ConnectCb&& cb, 38 : const std::string& connectionType, 39 : bool forceNewConnection) 40 : { 41 0 : JAMI_DEBUG("[AuthChannel {}] connecting to name = {}", deviceId.toString(), name); 42 0 : connectionManager_.connectDevice(deviceId, name, std::move(cb)); 43 0 : } 44 : 45 : void 46 5 : AuthChannelHandler::connect(const dht::InfoHash& infoHash, 47 : const std::string& channelPath, 48 : ConnectCallbackLegacy&& cb) 49 : { 50 15 : JAMI_DEBUG("[AuthChannel {}] connecting to channelPath = {}", infoHash.toString(), channelPath); 51 5 : connectionManager_.connectDevice(infoHash, channelPath, std::move(cb)); 52 5 : } 53 : 54 : bool 55 0 : AuthChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, 56 : const std::string& name) 57 : { 58 0 : JAMI_DEBUG("[AuthChannel] New auth channel requested for `{}`.", cert->getId().toString()); 59 0 : auto acc = account_.lock(); 60 0 : if (!cert || !cert->issuer || !acc) 61 0 : return false; 62 : 63 0 : JAMI_DEBUG("[AuthChannel] New auth channel requested with name = `{}`.", name); 64 : 65 0 : if (auto acc = account_.lock()) 66 0 : return true; 67 : 68 0 : return false; 69 0 : } 70 : 71 : void 72 4 : AuthChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& cert, 73 : const std::string& deviceId, 74 : std::shared_ptr<dhtnet::ChannelSocket> channel) 75 : { 76 12 : JAMI_DEBUG("[AuthChannel] Auth channel with {}/{} ready.", cert->getId().toString(), deviceId); 77 4 : } 78 : 79 : } // namespace jami