reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Transport.hxx
Go to the documentation of this file.
1#if !defined(RESIP_TRANSPORT_HXX)
2#define RESIP_TRANSPORT_HXX
3
5#include "rutil/Data.hxx"
10#include "resip/stack/Tuple.hxx"
14
15#include <list>
16#include <memory>
17#include <utility>
18
19#include <atomic>
20
21namespace resip
22{
23
24class TransactionMessage;
25class SipMessage;
26class Connection;
27class Compression;
28class FdPollGrp;
29
65#define RESIP_TRANSPORT_FLAG_NOBIND (1<<0)
66#define RESIP_TRANSPORT_FLAG_RXALL (1<<1)
67#define RESIP_TRANSPORT_FLAG_TXALL (1<<2)
68#define RESIP_TRANSPORT_FLAG_TXNOW (1<<4)
69#define RESIP_TRANSPORT_FLAG_OWNTHREAD (1<<5)
70#define RESIP_TRANSPORT_FLAG_SYMMETRIC_CONNECTIONS (1<<6)
71
83{
84 public:
85
87 {
88 public:
92 virtual ~SipMessageLoggingHandler() = default;
93
96
97 virtual void outboundMessage(const Tuple &source, const Tuple &destination, const SipMessage &msg) = 0;
98 // Note: retransmissions store already encoded messages, so callback doesn't send SipMessage it sends
99 // the encoded version of the SipMessage instead. If you need a SipMessage you will need to
100 // re-parse back into a SipMessage in the callback handler.
101 virtual void outboundRetransmit(const Tuple &source, const Tuple &destination, const SendData &data) {}
102 virtual void inboundMessage(const Tuple& source, const Tuple& destination, const SipMessage &msg) = 0;
103 };
104
105 using SipMessageLoggingHandlerList = std::vector<std::shared_ptr<SipMessageLoggingHandler> >;
106
107 void setSipMessageLoggingHandler(std::shared_ptr<SipMessageLoggingHandler> handler);
108 void addSipMessageLoggingHandler(std::shared_ptr<SipMessageLoggingHandler> handler);
110 void unsetSipMessageLoggingHandler() noexcept;
112
119 class Exception final : public BaseException
120 {
121 public:
122 Exception(const Data& msg, const Data& file, int line);
123 const char* name() const noexcept override { return "TransportException"; }
124 };
125
137 const GenericIPAddress& address,
138 const Data& tlsDomain = Data::Empty, // !dcm! where is this used?
139 AfterSocketCreationFuncPtr socketFunc = nullptr,
141 );
142
165 int portNum,
166 IpVersion version,
167 const Data& interfaceObj,
168 const Data& tlsDomain = Data::Empty,
169 AfterSocketCreationFuncPtr socketFunc = nullptr,
170 Compression &compression = Compression::Disabled,
171 unsigned transportFlags = 0,
172 const Data& netNs = Data::Empty);
173
174 virtual ~Transport();
175
176 virtual void onReload();
177
183 virtual bool isFinished() const=0;
184
185 std::unique_ptr<SendData> makeSendData( const Tuple& tuple, const Data& data, const Data& tid, const Data &sigcompId = Data::Empty);
186
195 virtual void send(std::unique_ptr<SendData> data)=0;
196
204 virtual void poke(){};
205
221 virtual void process(FdSet& fdset) = 0;
222
227 virtual void buildFdSet( FdSet& fdset) =0;
228
229 virtual unsigned int getTimeTillNextProcessMS(){return UINT_MAX;}
230
235 virtual void process() = 0;
236
237 virtual void setPollGrp(FdPollGrp *grp) = 0;
238
243 void flowTerminated(const Tuple& flow,
244 TransportFailure::FailureReason failureReason,
245 int failureSubCode,
246 const Data& failureString,
247 const std::list<Data> additionalFailureStrings);
248 void keepAlivePong(const Tuple& flow);
249
253 void fail(const Data& tid,
255 int subCode = 0);
256
260 void setTcpConnectState(const Data& tid, TcpConnectState::State state);
261
268 static void error(int e);
269 static Data errorToString(int e);
270
271 // These methods are used by the TransportSelector
272 const Data& interfaceName() const { return mInterface; }
273
274 int port() const { return mTuple.getPort(); }
275
277 bool isV4() const { return mTuple.isV4(); } // !dcm! -- deprecate ASAP
278
279 IpVersion ipVersion() const { return mTuple.ipVersion(); }
280
286 const Data& tlsDomain() const { return mTlsDomain; }
287 const sockaddr& boundInterface() const { return mTuple.getSockaddr(); }
288 const Tuple& getTuple() const { return mTuple; }
289
291 const TransportType transport() const { return mTuple.getType(); }
292 virtual bool isReliable() const =0;
293 virtual bool isDatagram() const =0;
294
296 const Data& netNs() const { return(mTuple.getNetNs()); }
297
302 virtual bool hasSpecificContact() const { return false; }
303
312 bool basicCheck(const SipMessage& msg);
313
314 void makeFailedResponse(const SipMessage& msg,
315 int responseCode = 400,
316 const char * warning = nullptr);
317 std::unique_ptr<SendData> make503(SipMessage& msg,
318 uint16_t retryAfter);
319
320 std::unique_ptr<SendData> make100(SipMessage& msg);
321 void setRemoteSigcompId(SipMessage&msg, Data& id);
322 // mark the received= and rport parameters if necessary
323 static void stampReceived(SipMessage* request);
324
335 virtual bool shareStackProcessAndSelect() const=0;
336
346 virtual void startOwnProcessing()=0;
347
349 virtual bool hasDataToSend() const = 0;
350
361 virtual void shutdown()
362 {
363 // !jf! should use the fifo to pass this in
364 mShuttingDown = true;
365 }
366 virtual bool isShuttingDown() { return mShuttingDown; }
367
368 // also used by the TransportSelector.
369 // requires that the two transports be
370 bool operator==(const Transport& rhs) const;
371
372 //# queued messages on this transport
373 virtual unsigned int getFifoSize() const=0;
374
375 void callSocketFunc(Socket sock) const;
376 virtual void invokeAfterSocketCreationFunc() const = 0; //used to invoke the after socket creation func immediately for all existing sockets - can be used to modify QOS settings at runtime
377
391 bool setDscp(int dscp);
392
405 int effectiveDscp() const;
406
412 int effectiveDscp(int wanted) const;
413
421 void applySocketOptions(Socket sock) const;
422
433
434 protected:
435
440 void drainDscpRefresh();
441
442 private:
443
452 void reportDscp(int wanted) const;
453
454 public:
455
457 {
458 mCongestionManager=manager;
459 }
460
469
471 {
472 mStateMachineFifo.flush();
473 }
474
476 {
477 return (uint32_t)mStateMachineFifo.getFifo().expectedWaitTimeMilliSec()/1000;
478 }
479
480 // called by Connection to deliver a received message
481 virtual void pushRxMsgUp(SipMessage* msg);
482
483 // set the receive buffer length (SO_RCVBUF)
484 virtual void setRcvBufLen(int buflen) { }; // make pure?
485
486 inline unsigned int getKey() const {return mTuple.mTransportKey;}
487 inline void setKey(unsigned int pKey) { mTuple.mTransportKey = pKey;} // should only be called once after creation
488
489 protected:
490
495 virtual Socket getListenerSocket() const { return INVALID_SOCKET; }
496
499
503
504 void setTlsDomain(const Data& domain) { mTlsDomain = domain; }
505 private:
506 static const Data transportNames[MAX_TRANSPORT];
507 friend EncodeStream& operator<<(EncodeStream& strm, const Transport& rhs);
508
509 Data mTlsDomain;
510 SipMessageLoggingHandlerList mSipMessageLoggingHandlers;
511
512 protected:
516
517 // The signalling DSCP class, and the state its refresh needs.
518 std::atomic<int> mDscp { -1 };
522 std::atomic<bool> mDscpRefreshPending { false };
525 std::atomic<bool> mDscpReportPending { false };
528 mutable std::atomic<bool> mWasMarkRequested { false };
529};
530
531EncodeStream& operator<<(EncodeStream& strm, const Transport& rhs);
532
533}
534
535#endif
536
537/* ====================================================================
538 * The Vovida Software License, Version 1.0
539 *
540 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
541 *
542 * Redistribution and use in source and binary forms, with or without
543 * modification, are permitted provided that the following conditions
544 * are met:
545 *
546 * 1. Redistributions of source code must retain the above copyright
547 * notice, this list of conditions and the following disclaimer.
548 *
549 * 2. Redistributions in binary form must reproduce the above copyright
550 * notice, this list of conditions and the following disclaimer in
551 * the documentation and/or other materials provided with the
552 * distribution.
553 *
554 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
555 * and "Vovida Open Communication Application Library (VOCAL)" must
556 * not be used to endorse or promote products derived from this
557 * software without prior written permission. For written
558 * permission, please contact vocal@vovida.org.
559 *
560 * 4. Products derived from this software may not be called "VOCAL", nor
561 * may "VOCAL" appear in their name, without prior written
562 * permission of Vovida Networks, Inc.
563 *
564 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
565 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
566 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
567 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
568 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
569 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
570 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
571 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
572 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
573 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
574 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
575 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
576 * DAMAGE.
577 *
578 * ====================================================================
579 *
580 * This software consists of voluntary contributions made by Vovida
581 * Networks, Inc. and many individuals on behalf of Vovida Networks,
582 * Inc. For more information on Vovida Networks, Inc., please see
583 * <http://www.vovida.org/>.
584 *
585 * vi: set shiftwidth=3 expandtab:
586 */
#define INVALID_SOCKET
Definition Socket.hxx:95
The abstract base-class for all exceptions thrown by resip code.
static Compression Disabled
Represents a compression configuration object with compression disabled.
Abstract base class that provides a basic congestion management interface.
virtual RejectionBehavior getRejectionBehavior(const FifoStatsInterface *fifo) const =0
Return the current rejection behavior for this fifo.
@ NORMAL
Not rejecting any work.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static const Data Empty
Constant that represents a zero-length data.
Definition Data.hxx:882
An interface class for elements that use an FdSet to watch for IO.
Object-oriented wrapper for your platform's file-descriptor set.
Definition Socket.hxx:162
A templated, threadsafe message-queue class.
Definition Fifo.hxx:16
Class for buffering messages placed in a Fifo, to be used by a single producer.
Represents a SIP message.
General exception class for Transport.
const char * name() const noexcept override
SipMessageLoggingHandler & operator=(const SipMessageLoggingHandler &)=delete
virtual void outboundMessage(const Tuple &source, const Tuple &destination, const SipMessage &msg)=0
SipMessageLoggingHandler(SipMessageLoggingHandler &&)=delete
SipMessageLoggingHandler & operator=(SipMessageLoggingHandler &&)=delete
virtual void inboundMessage(const Tuple &source, const Tuple &destination, const SipMessage &msg)=0
virtual void outboundRetransmit(const Tuple &source, const Tuple &destination, const SendData &data)
SipMessageLoggingHandler(const SipMessageLoggingHandler &)=delete
The base class for Transport classes.
Definition Transport.hxx:83
virtual bool hasDataToSend() const =0
only applies to transports that shareStackProcessAndSelect
void drainDscpRefresh()
Serves a pending refresh and a pending report.
const Tuple & getTuple() const
virtual bool hasSpecificContact() const
std::unique_ptr< SendData > make503(SipMessage &msg, uint16_t retryAfter)
void setSipMessageLoggingHandlers(const SipMessageLoggingHandlerList &handlers)
Definition Transport.cxx:51
void makeFailedResponse(const SipMessage &msg, int responseCode=400, const char *warning=nullptr)
void unsetSipMessageLoggingHandler() noexcept
Definition Transport.cxx:57
virtual unsigned int getTimeTillNextProcessMS()
Returns the maximum timeout this object is willing to tolerate on the select call that is to be made,...
IpVersion ipVersion() const
std::atomic< bool > mWasMarkRequested
Whether this transport has asked a socket to carry a class that a clear would have to undo.
AfterSocketCreationFuncPtr mSocketFunc
int effectiveDscp() const
The class to write to a socket right now, or -1 to leave it alone.
const TransportType transport() const
virtual void poke()
Called when a writer is done adding messages to the TxFifo; this is used to interrupt the select call...
unsigned mTransportFlags
void flushStateMacFifo()
bool isV4() const
virtual void shutdown()
This starts shutting-down procedures for this Transport.
CongestionManager * mCongestionManager
virtual void pushRxMsgUp(SipMessage *msg)
unsigned int getKey() const
std::unique_ptr< SendData > make100(SipMessage &msg)
std::atomic< bool > mDscpReportPending
Set by every setDscp() call, cleared by the owning thread's report, so a reload that changed nothing ...
static void stampReceived(SipMessage *request)
int port() const
void setTlsDomain(const Data &domain)
static Data errorToString(int e)
SipMessageLoggingHandlerList getSipMessageLoggingHandlers() const noexcept
Definition Transport.cxx:63
virtual bool isFinished() const =0
virtual void setCongestionManager(CongestionManager *manager)
const Data & interfaceName() const
const Data & netNs() const
uint32_t getExpectedWaitForIncoming() const
void fail(const Data &tid, TransportFailure::FailureReason reason=TransportFailure::Failure, int subCode=0)
Posts a TransportFailure to the TransactionMessage Fifo.
Compression & mCompression
virtual unsigned int getFifoSize() const =0
std::atomic< int > mDscp
the class to write, -1 for "do not mark"
bool operator==(const Transport &rhs) const
void setKey(unsigned int pKey)
virtual void process(FdSet &fdset)=0
If there is work to do, this is the method that does it.
virtual ~Transport()
void callSocketFunc(Socket sock) const
bool basicCheck(const SipMessage &msg)
Perform basic sanity checks on message.
const sockaddr & boundInterface() const
virtual void invokeAfterSocketCreationFunc() const =0
void setSipMessageLoggingHandler(std::shared_ptr< SipMessageLoggingHandler > handler)
Definition Transport.cxx:31
virtual void setPollGrp(FdPollGrp *grp)=0
const Data & tlsDomain() const
friend EncodeStream & operator<<(EncodeStream &strm, const Transport &rhs)
bool setDscp(int dscp)
Sets the DSCP class this transport puts on its sockets, and returns whether it was accepted.
virtual bool isReliable() const =0
void applyDscpToOwnSockets()
Re-runs the per-socket set-up on every socket this transport holds – the listener,...
virtual void process()=0
Version of process to be invoked periodically when using callback-based IO (via FdPollGrp).
std::atomic< bool > mDscpRefreshPending
Set by setDscp() when the value changes, cleared by the owning thread's refresh.
void setRemoteSigcompId(SipMessage &msg, Data &id)
virtual void setRcvBufLen(int buflen)
void applySocketOptions(Socket sock) const
The one place a socket of this transport is configured.
virtual bool shareStackProcessAndSelect() const =0
Returns true if this Transport should be included in the FdSet processing loop, false if the Transpor...
CongestionManager::RejectionBehavior getRejectionBehaviorForIncoming() const
static void error(int e)
Generates a generic log for the platform specific socket error number.
virtual void onReload()
ProducerFifoBuffer< TransactionMessage > mStateMachineFifo
void keepAlivePong(const Tuple &flow)
virtual void startOwnProcessing()=0
transports that returned false to shareStackProcessAndSelect() shouldn't put messages into the fifo u...
std::vector< std::shared_ptr< SipMessageLoggingHandler > > SipMessageLoggingHandlerList
virtual bool isShuttingDown()
std::unique_ptr< SendData > makeSendData(const Tuple &tuple, const Data &data, const Data &tid, const Data &sigcompId=Data::Empty)
virtual void buildFdSet(FdSet &fdset)=0
Adds the Transport's socket FD to the appropriate read or write sets as applicable.
void flowTerminated(const Tuple &flow, TransportFailure::FailureReason failureReason, int failureSubCode, const Data &failureString, const std::list< Data > additionalFailureStrings)
Posts a ConnectionTerminated message to TransactionMessage Fifo.
void addSipMessageLoggingHandler(std::shared_ptr< SipMessageLoggingHandler > handler)
Definition Transport.cxx:42
virtual void send(std::unique_ptr< SendData > data)=0
virtual Socket getListenerSocket() const
The transport's own listening or bound socket, or INVALID_SOCKET for a transport that holds none.
virtual bool isDatagram() const =0
void setTcpConnectState(const Data &tid, TcpConnectState::State state)
Posts a TcpConnectState to the TransactionMessage Fifo.
Represents a network address.
Definition Tuple.hxx:59
IpVersion ipVersion() const
Returns V4 or V6 as appropriate.
Definition Tuple.cxx:537
const Data & getNetNs() const
Get the netns for this Tuple.
Definition Tuple.hxx:271
bool isV4() const
Definition Tuple.cxx:531
int getPort() const
Definition Tuple.cxx:466
TransportType getType() const
Definition Tuple.hxx:122
const sockaddr & getSockaddr() const
Retrieve a const binary representation of the socket address for this tuple.
Definition Tuple.hxx:109
TransportKey mTransportKey
Definition Tuple.hxx:190
dcm! – add UnusedChecking(_enum) below;
void(* AfterSocketCreationFuncPtr)(Socket s, int transportType, const char *file, int line)
Definition Socket.hxx:107
unsigned short uint16_t
Definition Stun.hxx:30
int Socket
Definition Socket.hxx:94
unsigned int uint32_t
Definition Stun.hxx:34
TransportType
An enumeration of transport protocols.
IpVersion
An enumeration of IP versions.
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
#define EncodeStream
Represents an IP-address and port (V4 or V6).