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 : #pragma once 18 : 19 : #include <dhtnet/multiplexed_socket.h> 20 : // #include <opendht/crypto.h> 21 : 22 : namespace jami { 23 : 24 : using DeviceId = dht::PkId; 25 : using ConnectCb = std::function<void(std::shared_ptr<dhtnet::ChannelSocket>, const DeviceId&)>; 26 : using ConnectCallbackLegacy 27 : = std::function<void(std::shared_ptr<dhtnet::ChannelSocket>, const dht::InfoHash&)>; 28 : 29 : // using ConnectCb = dhtnet::ConnectCallback; 30 : // using ConnectCallbackLegacy = dhtnet::ConnectCallbackLegacy; 31 : 32 : /** 33 : * A Channel handler is used to make the link between JamiAccount and ConnectionManager 34 : * Its role is to manage channels for a protocol (git/sip/etc) 35 : */ 36 : class ChannelHandlerInterface 37 : { 38 : public: 39 3414 : virtual ~ChannelHandlerInterface() {}; 40 : 41 : /** 42 : * Ask for a new channel 43 : * @param deviceId The device to connect 44 : * @param name The name of the channel 45 : * @param cb The callback to call when connected (can be immediate if already connected) 46 : * @param connectionType The connection type used by iOS notifications (not used) 47 : * @param forceNewConnection If we want a new SIP connection (not used) 48 : */ 49 : virtual void connect(const DeviceId& deviceId, 50 : const std::string& name, 51 : ConnectCb&& cb, 52 : const std::string& connectionType = "", 53 : bool forceNewConnection = false) 54 : = 0; 55 : 56 0 : virtual void connect(const dht::InfoHash& /*infoHash*/, 57 : const std::string& /*name*/, 58 0 : ConnectCallbackLegacy&& /*cb*/) {} 59 : 60 : /** 61 : * Determine if we accept or not the request. Called when ConnectionManager receives a request 62 : * @param peer Peer who asked 63 : * @param name The name of the channel 64 : * @return if we accept or not 65 : */ 66 : virtual bool onRequest(const std::shared_ptr<dht::crypto::Certificate>& peer, 67 : const std::string& name) 68 : = 0; 69 : 70 : /** 71 : * Called when ConnectionManager has a new channel ready 72 : * @param peer Connected peer 73 : * @param name The name of the channel 74 : * @param channel Channel to handle 75 : */ 76 : virtual void onReady(const std::shared_ptr<dht::crypto::Certificate>& peer, 77 : const std::string& name, 78 : std::shared_ptr<dhtnet::ChannelSocket> channel) 79 : = 0; 80 : }; 81 : 82 : } // namespace jami