reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TransportSelector.hxx
Go to the documentation of this file.
1#if !defined(RESIP_TRANSPORTSELECTOR_HXX)
2#define RESIP_TRANSPORTSELECTOR_HXX
3
4#ifndef WIN32
5#include <sys/select.h>
6#endif
7
8#include <map>
9#include <vector>
10#include <list>
11
12#include "rutil/Data.hxx"
13#include "rutil/Fifo.hxx"
18
19
21class TestTransportSelector;
22
23namespace osc
24{
25 class Stack;
26}
27
28namespace resip
29{
30
31class DnsHandler;
32class Message;
33class TransactionMessage;
34class SipMessage;
35class TransactionController;
36class Security;
37class Compression;
38class FdPollGrp;
39
60{
61 public:
62 TransportSelector(Fifo<TransactionMessage>& fifo, Security* security, DnsStub& dnsStub, Compression &compression, bool useDnsVip);
63 virtual ~TransportSelector();
64
70 bool hasDataToSend() const;
71
73 void shutdown();
74
76 bool isFinished() const;
77
80 void setPollGrp(FdPollGrp *pollGrp);
81
83 // thread than the TransactionController; this will allow the thread to be
84 // interrupted when poke() is called.
86
90 void process(FdSet& fdset);
91 void process();
93 void buildFdSet(FdSet& fdset);
94
97 void poke();
98
100 void addTransport(std::unique_ptr<Transport> transport, bool isStackRunning);
101 void removeTransport(unsigned int transportKey);
102
105 void dnsResolve(DnsResult* result, SipMessage* msg);
106
112 typedef enum
113 {
115 Sent
117 TransmitState transmit( SipMessage* msg, Tuple& target, SendData* sendData=0 );
118
120 void retransmit(const SendData& msg);
121
122 void closeConnection(const Tuple& peer);
123
124 unsigned int sumTransportFifoSizes() const;
125
126 unsigned int getTimeTillNextProcessMS();
127 Fifo<TransactionMessage>& stateMacFifo() { return mStateMacFifo; }
128
129 void registerMarkListener(MarkListener* listener);
130 void unregisterMarkListener(MarkListener* listener);
131 void setEnumSuffixes(const std::vector<Data>& suffixes);
132
133 static Tuple getFirstInterface(bool is_v4, TransportType type);
134 void terminateFlow(const resip::Tuple& flow);
135 void enableFlowTimer(const resip::Tuple& flow);
136
137 bool setUdpOnlyOnNumeric(bool value)
138 {
139 return mDns.setUdpOnlyOnNumeric(value);
140 }
141
143 {
144 return mDns.getUdpOnlyOnNumeric();
145 }
146
148 {
149 for(TransportKeyMap::iterator i=mTransports.begin();
150 i!=mTransports.end();++i)
151 {
152 i->second->setCongestionManager(manager);
153 }
154 }
155
157
162 {
163 public:
164 TlsTransportKey() = delete;
165 TlsTransportKey(const resip::Data& domainName, const resip::Tuple& tuple);
170 ~TlsTransportKey() = default;
171
172 // Comparison operator which follow strict rules.
173 bool operator<(const TlsTransportKey& rhs) const;
174
176 };
177
178 protected: // for unit tests (testTransportSelector)
179 Transport* findTransportBySource(Tuple& src, const SipMessage* msg) const;
180 Transport* findTransportByDest(const Tuple& dest);
181
182 private:
183 void checkTransportAddRemoveQueue();
184 Connection* findConnection(const Tuple& dest) const;
185 Transport* findLoopbackTransportBySource(bool ignorePort, Tuple& src) const;
186 Transport* findTransportByVia(SipMessage* msg, const Tuple& dest, Tuple& src) const;
187 Transport* findTlsTransport(const Data& domain, const Tuple& search) const;
188 Tuple determineSourceInterface(SipMessage* msg, const Tuple& dest) const;
189 void rebuildAnyPortTransportMaps(void);
190
191 DnsInterface mDns;
192 Fifo<TransactionMessage>& mStateMacFifo;
193 Security* mSecurity;// for computing identity header
194
195 // specific port and interface
196 typedef std::map<Tuple, Transport*> ExactTupleMap;
197 ExactTupleMap mExactTransports;
198
199 // specific port, ANY interface
200 typedef std::map<Tuple, Transport*, Tuple::AnyInterfaceCompare> AnyInterfaceTupleMap;
201 AnyInterfaceTupleMap mAnyInterfaceTransports;
202
203 // ANY port, specific interface
204 typedef std::map<Tuple, Transport*, Tuple::AnyPortCompare> AnyPortTupleMap;
205 AnyPortTupleMap mAnyPortTransports;
206
207 // ANY port, ANY interface
208 typedef std::map<Tuple, Transport*, Tuple::AnyPortAnyInterfaceCompare> AnyPortAnyInterfaceTupleMap;
209 AnyPortAnyInterfaceTupleMap mAnyPortAnyInterfaceTransports;
210
211 typedef std::map<unsigned int, Transport*> TransportKeyMap;
212 TransportKeyMap mTransports; // owns all Transports
213
214 typedef std::map<TlsTransportKey, Transport*> TlsTransportMap ;
215 TlsTransportMap mTlsTransports;
216
217 typedef std::list<Transport*> TransportList;
218 TransportList mSharedProcessTransports; // Warning - only access this from the TransportSelector process loop / thread
219 TransportList mHasOwnProcessTransports;
220
221 typedef std::multimap<Tuple, Transport*, Tuple::AnyPortAnyInterfaceCompare> TypeToTransportMap;
222 TypeToTransportMap mTypeToTransportMap;
223
224 // fake socket(s) one for each netns, for connect() and route table lookups
225 mutable HashMap<Data, Socket> mSockets;
226 mutable HashMap<Data, Socket> mSocket6s;
227
228 // An AF_UNSPEC addr_in for rapid unconnect
229 GenericIPAddress mUnspecified;
230 GenericIPAddress mUnspecified6;
231
233 Compression &mCompression;
234 osc::Stack *mSigcompStack;
235
236 // epoll support, for sharedprocess transports
237 FdPollGrp* mPollGrp;
238
239 int mAvgBufferSize;
240 Fifo<Transport> mTransportsToAddRemove;
241 std::unique_ptr<SelectInterruptor> mSelectInterruptor;
242 FdPollItemHandle mInterruptorHandle;
243
245 friend class SipStack; // for debug only
246};
247
250
251}
252
253#endif
254
255/* ====================================================================
256 * The Vovida Software License, Version 1.0
257 *
258 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
259 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
260 *
261 * Redistribution and use in source and binary forms, with or without
262 * modification, are permitted provided that the following conditions
263 * are met:
264 *
265 * 1. Redistributions of source code must retain the above copyright
266 * notice, this list of conditions and the following disclaimer.
267 *
268 * 2. Redistributions in binary form must reproduce the above copyright
269 * notice, this list of conditions and the following disclaimer in
270 * the documentation and/or other materials provided with the
271 * distribution.
272 *
273 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
274 * and "Vovida Open Communication Application Library (VOCAL)" must
275 * not be used to endorse or promote products derived from this
276 * software without prior written permission. For written
277 * permission, please contact vocal@vovida.org.
278 *
279 * 4. Products derived from this software may not be called "VOCAL", nor
280 * may "VOCAL" appear in their name, without prior written
281 * permission of Vovida Networks, Inc.
282 *
283 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
284 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
285 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
286 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
287 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
288 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
289 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
290 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
291 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
292 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
293 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
294 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
295 * DAMAGE.
296 *
297 * ====================================================================
298 *
299 * This software consists of voluntary contributions made by Vovida
300 * Networks, Inc. and many individuals on behalf of Vovida Networks,
301 * Inc. For more information on Vovida Networks, Inc., please see
302 * <http://www.vovida.org/>.
303 *
304 */
305
306// vim: softtabstop=3:shiftwidth=3:expandtab
Abstract base class that provides a basic congestion management interface.
Connection implements, via sockets, ConnectionBase for managed connections.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
bool setUdpOnlyOnNumeric(bool value)
bool getUdpOnlyOnNumeric() const
Object-oriented wrapper for your platform's file-descriptor set.
Definition Socket.hxx:162
A templated, threadsafe message-queue class.
Definition Fifo.hxx:16
Represents a SIP message.
This is the primary point of interaction between the app-layer and the stack.
Definition SipStack.hxx:160
TlsTransportKey(const TlsTransportKey &)=default
TlsTransportKey & operator=(TlsTransportKey &&)=default
TlsTransportKey(TlsTransportKey &&)=default
bool operator<(const TlsTransportKey &rhs) const
TlsTransportKey & operator=(const TlsTransportKey &)=default
void registerMarkListener(MarkListener *listener)
unsigned int sumTransportFifoSizes() const
static Tuple getFirstInterface(bool is_v4, TransportType type)
Transport * findTransportBySource(Tuple &src, const SipMessage *msg) const
void closeConnection(const Tuple &peer)
bool setUdpOnlyOnNumeric(bool value)
void poke()
Causes transport process loops to be interrupted if there is stuff in their transmit fifos.
void createSelectInterruptor()
Called when the TransportSelector will be running in a different.
void buildFdSet(FdSet &fdset)
Builds an FdSet comprised of all FDs from all suitable Transports.
Transport * findTransportByDest(const Tuple &dest)
void setEnumSuffixes(const std::vector< Data > &suffixes)
bool isFinished() const
Returns true if all Transports have their buffers cleared, false otherwise.
void removeTransport(unsigned int transportKey)
void addTransport(std::unique_ptr< Transport > transport, bool isStackRunning)
Add/Remove a transport.
DnsResult * createDnsResult(DnsHandler *handler)
DNS Resolution.
void setPollGrp(FdPollGrp *pollGrp)
Configure a PollGrp to use (instead of buildFdSet/process) Must be called before adding any transport...
TransmitState
transmit results in msg->resolve() being called to either kick off dns resolution or to pick the next...
void enableFlowTimer(const resip::Tuple &flow)
void shutdown()
Shuts down all transports.
void unregisterMarkListener(MarkListener *listener)
void terminateFlow(const resip::Tuple &flow)
Fifo< TransactionMessage > & stateMacFifo()
void setCongestionManager(CongestionManager *manager)
TransmitState transmit(SipMessage *msg, Tuple &target, SendData *sendData=0)
void invokeAfterSocketCreationFunc(TransportType type)
void dnsResolve(DnsResult *result, SipMessage *msg)
void retransmit(const SendData &msg)
Resend to the same transport as last time.
The base class for Transport classes.
Definition Transport.hxx:83
Represents a network address.
Definition Tuple.hxx:59
dcm! – add UnusedChecking(_enum) below;
struct FdPollItemFake * FdPollItemHandle
This is opaque type used to identify a particular Item.
Definition FdPoll.hxx:42
TransportType
An enumeration of transport protocols.
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
#define EncodeStream
Represents an IP-address and port (V4 or V6).
void list()
Definition userAdmin.cxx:66