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