Line data Source code
1 : /* 2 : * Copyright (C) 2004-2026 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 "noncopyable.h" 20 : #include "jamidht/abstract_sip_transport.h" 21 : 22 : #include <dhtnet/multiplexed_socket.h> 23 : 24 : #include <atomic> 25 : #include <condition_variable> 26 : #include <chrono> 27 : #include <list> 28 : #include <memory> 29 : #include <thread> 30 : #include <type_traits> 31 : #include <utility> 32 : 33 : namespace jami { 34 : 35 : using onShutdownCb = std::function<void(void)>; 36 : 37 : namespace tls { 38 : 39 : /** 40 : * ChanneledSIPTransport 41 : * 42 : * Implements a pjsip_transport on top of a ChannelSocket 43 : */ 44 : class ChanneledSIPTransport : public AbstractSIPTransport 45 : { 46 : public: 47 : ChanneledSIPTransport(pjsip_endpoint* endpt, 48 : const std::shared_ptr<dhtnet::ChannelSocket>& socket, 49 : onShutdownCb&& cb); 50 : ~ChanneledSIPTransport(); 51 : 52 : /** 53 : * Connect callbacks for channeled socket, must be done when the channel is ready to be used 54 : */ 55 : void start(); 56 : 57 352 : pjsip_transport* getTransportBase() override { return &trData_.base; } 58 : 59 182 : dhtnet::IpAddr getLocalAddress() const override { return local_; } 60 : 61 : private: 62 : NON_COPYABLE(ChanneledSIPTransport); 63 : 64 : // The SIP transport uses a ChannelSocket to send and receive datas 65 : std::shared_ptr<dhtnet::ChannelSocket> socket_ {}; 66 : onShutdownCb shutdownCb_ {}; 67 : dhtnet::IpAddr local_ {}; 68 : dhtnet::IpAddr remote_ {}; 69 : 70 : // PJSIP transport backend 71 : TransportData trData_ {}; // uplink to "this" (used by PJSIP called C-callbacks) 72 : 73 : sip_utils::PoolPtr pool_; 74 : sip_utils::PoolPtr rxPool_; 75 : pjsip_rx_data rdata_ {}; 76 : 77 : pj_status_t send(pjsip_tx_data*, const pj_sockaddr_t*, int, void*, pjsip_transport_callback); 78 : 79 : // Handle disconnected event 80 : std::atomic_bool disconnected_ {false}; 81 : }; 82 : 83 : } // namespace tls 84 : } // namespace jami