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