reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
FlowManager.hxx
Go to the documentation of this file.
1#if !defined(FlowManager_hxx)
2#define FlowManager_hxx
3
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#endif
7
8#include "FlowContext.hxx"
9#include "MediaStream.hxx"
12
14#include <openssl/crypto.h>
15#include <openssl/ssl.h>
16
17#include <asio.hpp>
18#include <asio/ssl.hpp>
19
20#include <map>
21#include <memory>
22#include <utility>
23
24using namespace reTurn;
25
26namespace flowmanager
27{
28
29class IOServiceThread;
30class FlowDtlsTimerContext;
31
43{
44public:
45 FlowManager(); // throws FlowManagerException
46 virtual ~FlowManager();
47
48 // This API assumes that RTCP localBinding is always the same as RTP binding but add one to the port number
49 // We can add a new API in the future to accomodate, custom RTCP bindings as required
51 const StunTuple& localBinding,
52 bool rtcpEnabled = true,
54 const char* natTraversalServerHostname = 0,
55 unsigned short natTraversalServerPort = 0,
56 const char* stunUsername = 0,
57 const char* stunPassword = 0,
58 bool forceCOMedia = false,
59 std::shared_ptr<FlowContext> context = nullptr);
60
61 void initializeDtlsFactory(const char* certAor);
62#ifdef USE_SSL
63 // Creates the self-signed RSA certificate initializeDtlsFactory uses, for the AOR sip:<pAor>,
64 // signed with SHA-256. Returns non-zero on success.
65 static int createCert(const resip::Data& pAor, int expireDays, int keyLen, X509*& outCert, EVP_PKEY*& outKey);
66#endif
67 dtls::DtlsFactory* getDtlsFactory() { return mDtlsFactory; }
68
69#ifdef USE_SSL
74#endif
75
79 void setValidateTlsServerHostname(bool validate) { mValidateTlsServerHostname = validate; }
80
81 void setRTCPEventLoggingHandler(std::shared_ptr<RTCPEventLoggingHandler> handler) noexcept { mRtcpEventLoggingHandler = handler; }
82 RTCPEventLoggingHandler* getRTCPEventLoggingHandler() const noexcept { return 0 != mRtcpEventLoggingHandler.get() ? mRtcpEventLoggingHandler.get() : 0; }
83
84protected:
85
86private:
87 static void srtpEventHandler(srtp_event_data_t *data);
88
89 std::shared_ptr<RTCPEventLoggingHandler> mRtcpEventLoggingHandler;
90
91 // Member variables used to manager asio io service thread
92 asio::io_context mIOService;
93 IOServiceThread* mIOServiceThread;
94 asio::executor_work_guard<asio::io_context::executor_type>* mIOServiceWork;
95 asio::ssl::context mSslContext;
96
97 X509* mClientCert;
98 EVP_PKEY* mClientKey;
99 dtls::DtlsFactory* mDtlsFactory;
100 FlowDtlsTimerContext* mDtlsTimerContext; // owned by mDtlsFactory
101 bool mValidateTlsServerHostname = true;
102};
103
104}
105
106#endif
107
108
109/* ====================================================================
110
111 Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
112 Copyright (c) 2007-2008, Plantronics, Inc.
113 All rights reserved.
114
115 Redistribution and use in source and binary forms, with or without
116 modification, are permitted provided that the following conditions are
117 met:
118
119 1. Redistributions of source code must retain the above copyright
120 notice, this list of conditions and the following disclaimer.
121
122 2. Redistributions in binary form must reproduce the above copyright
123 notice, this list of conditions and the following disclaimer in the
124 documentation and/or other materials provided with the distribution.
125
126 3. Neither the name of Plantronics nor the names of its contributors
127 may be used to endorse or promote products derived from this
128 software without specific prior written permission.
129
130 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
131 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
132 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
133 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
134 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
135 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
136 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
137 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
138 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
139 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
140 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141
142 ==================================================================== */
struct evp_pkey_st EVP_PKEY
struct x509_st X509
This class represents the Flow Manager.
void setRTCPEventLoggingHandler(std::shared_ptr< RTCPEventLoggingHandler > handler) noexcept
bool addTlsRootCertificates(const resip::Data &rootCertificatesFile)
Adds the root (CA) certificates in a PEM file to those TURN servers' TLS certificates are verified wi...
static int createCert(const resip::Data &pAor, int expireDays, int keyLen, X509 *&outCert, EVP_PKEY *&outKey)
void setValidateTlsServerHostname(bool validate)
Whether flows using TURN over TLS check that the server's certificate is for the TURN server's host n...
void initializeDtlsFactory(const char *certAor)
MediaStream * createMediaStream(MediaStreamHandler &mediaStreamHandler, const StunTuple &localBinding, bool rtcpEnabled=true, MediaStream::NatTraversalMode natTraversalMode=MediaStream::NoNatTraversal, const char *natTraversalServerHostname=0, unsigned short natTraversalServerPort=0, const char *stunUsername=0, const char *stunPassword=0, bool forceCOMedia=false, std::shared_ptr< FlowContext > context=nullptr)
dtls::DtlsFactory * getDtlsFactory()
RTCPEventLoggingHandler * getRTCPEventLoggingHandler() const noexcept
This class represents a media stream, that consists of a series of componenets or flows.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
This class is used during media sessions that use Dtls-Srtp for a media transport.
Definition ErrorCode.hxx:4
void list()
Definition userAdmin.cxx:66