reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
resip::UdpTransport Class Reference

A Transport based on UDP. More...

#include <UdpTransport.hxx>

Inheritance diagram for resip::UdpTransport:
[legend]

Public Types

enum  StunResult { StunResultUnknown , StunResultSuccess , StunResultNoResponse , StunResultResponseParseFailed }
 
- Public Types inherited from resip::Transport
using SipMessageLoggingHandlerList = std::vector< std::shared_ptr< SipMessageLoggingHandler > >
 

Public Member Functions

 RESIP_HeapCount (UdpTransport)
 
 UdpTransport (Fifo< TransactionMessage > &fifo, int portNum, IpVersion version, StunSetting stun, const Data &interfaceObj, AfterSocketCreationFuncPtr socketFunc=nullptr, Compression &compression=Compression::Disabled, unsigned transportFlags=0)
 
virtual ~UdpTransport ()
 
virtual bool isReliable () const
 
virtual bool isDatagram () const
 
virtual void process (FdSet &fdset)
 If there is work to do, this is the method that does it.
 
virtual void process ()
 Called after a message is added.
 
virtual bool hasDataToSend () const
 If we return true, the TransactionController will set the timeout to zero so that process() is called immediately.
 
virtual void buildFdSet (FdSet &fdset)
 Adds the Transport's socket FD to the appropriate read or write sets as applicable.
 
virtual void setPollGrp (FdPollGrp *grp)
 
virtual void setRcvBufLen (int buflen)
 
virtual void processPollEvent (FdPollEventMask mask)
 Called by PollGrp when activity is possible.
 
bool stunSendTest (const Tuple &dest)
 Send a STUN Binding Request to dest for public-address discovery.
 
StunResult stunResult (Tuple &mappedAddress)
 Return the result of the most recent stunSendTest(); on StunResultSuccess, mappedAddress is filled with the discovered public address.
 
void setExternalUnknownDatagramHandler (ExternalUnknownDatagramHandler *handler)
 Installs a handler for the unknown datagrams arriving on the udp transport.
 
- Public Member Functions inherited from resip::InternalTransport
 InternalTransport (Fifo< TransactionMessage > &rxFifo, int portNum, IpVersion version, const Data &interfaceObj, AfterSocketCreationFuncPtr socketFunc=0, Compression &compression=Compression::Disabled, unsigned transportFlags=0, const Data &netNs=Data::Empty)
 
virtual ~InternalTransport ()
 
virtual bool isFinished () const
 
virtual bool shareStackProcessAndSelect () const
 Returns true if this Transport should be included in the FdSet processing loop, false if the Transport will provide its own cycles.
 
virtual void startOwnProcessing ()
 transports that returned false to shareStackProcessAndSelect() shouldn't put messages into the fifo until this is called
 
void bind ()
 
virtual unsigned int getFifoSize () const
 
virtual void send (std::unique_ptr< SendData > data)
 
virtual void poke ()
 Called when a writer is done adding messages to the TxFifo; this is used to interrupt the select call if the Transport is running in its own thread.
 
virtual void setCongestionManager (CongestionManager *manager)
 
virtual void invokeAfterSocketCreationFunc () const
 
- Public Member Functions inherited from resip::Transport
void setSipMessageLoggingHandler (std::shared_ptr< SipMessageLoggingHandler > handler)
 
void addSipMessageLoggingHandler (std::shared_ptr< SipMessageLoggingHandler > handler)
 
void setSipMessageLoggingHandlers (const SipMessageLoggingHandlerList &handlers)
 
void unsetSipMessageLoggingHandler () noexcept
 
SipMessageLoggingHandlerList getSipMessageLoggingHandlers () const noexcept
 
 Transport (Fifo< TransactionMessage > &rxFifo, const GenericIPAddress &address, const Data &tlsDomain=Data::Empty, AfterSocketCreationFuncPtr socketFunc=nullptr, Compression &compression=Compression::Disabled)
 
 Transport (Fifo< TransactionMessage > &rxFifo, int portNum, IpVersion version, const Data &interfaceObj, const Data &tlsDomain=Data::Empty, AfterSocketCreationFuncPtr socketFunc=nullptr, Compression &compression=Compression::Disabled, unsigned transportFlags=0, const Data &netNs=Data::Empty)
 
virtual ~Transport ()
 
virtual void onReload ()
 
std::unique_ptr< SendData > makeSendData (const Tuple &tuple, const Data &data, const Data &tid, const Data &sigcompId=Data::Empty)
 
virtual unsigned int getTimeTillNextProcessMS ()
 Returns the maximum timeout this object is willing to tolerate on the select call that is to be made, to prevent starvation of work that is not IO-based.
 
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 keepAlivePong (const Tuple &flow)
 
void fail (const Data &tid, TransportFailure::FailureReason reason=TransportFailure::Failure, int subCode=0)
 Posts a TransportFailure to the TransactionMessage Fifo.
 
void setTcpConnectState (const Data &tid, TcpConnectState::State state)
 Posts a TcpConnectState to the TransactionMessage Fifo.
 
const Data & interfaceName () const
 
int port () const
 
bool isV4 () const
 
IpVersion ipVersion () const
 
const Data & tlsDomain () const
 
const sockaddr & boundInterface () const
 
const Tuple & getTuple () const
 
const TransportType transport () const
 
const Data & netNs () const
 
virtual bool hasSpecificContact () const
 
bool basicCheck (const SipMessage &msg)
 Perform basic sanity checks on message.
 
void makeFailedResponse (const SipMessage &msg, int responseCode=400, const char *warning=nullptr)
 
std::unique_ptr< SendData > make503 (SipMessage &msg, uint16_t retryAfter)
 
std::unique_ptr< SendData > make100 (SipMessage &msg)
 
void setRemoteSigcompId (SipMessage &msg, Data &id)
 
virtual void shutdown ()
 This starts shutting-down procedures for this Transport.
 
virtual bool isShuttingDown ()
 
bool operator== (const Transport &rhs) const
 
void callSocketFunc (Socket sock) const
 
bool setDscp (int dscp)
 Sets the DSCP class this transport puts on its sockets, and returns whether it was accepted.
 
int effectiveDscp () const
 The class to write to a socket right now, or -1 to leave it alone.
 
int effectiveDscp (int wanted) const
 effectiveDscp() for a value the caller has already read.
 
void applySocketOptions (Socket sock) const
 The one place a socket of this transport is configured.
 
void applyDscpToOwnSockets ()
 Re-runs the per-socket set-up on every socket this transport holds – the listener, and each established connection.
 
CongestionManager::RejectionBehavior getRejectionBehaviorForIncoming () const
 
void flushStateMacFifo ()
 
uint32_t getExpectedWaitForIncoming () const
 
virtual void pushRxMsgUp (SipMessage *msg)
 
unsigned int getKey () const
 
void setKey (unsigned int pKey)
 
- Public Member Functions inherited from resip::FdSetIOObserver
 FdSetIOObserver ()
 
virtual ~FdSetIOObserver ()
 
- Public Member Functions inherited from resip::FdPollItemIf
 FdPollItemIf ()
 
virtual ~FdPollItemIf ()
 

Static Public Attributes

static constexpr int MaxMessageSize = 65535
 

Protected Member Functions

void processRxAll ()
 Add options RXALL (to try receive all readable data).
 
int processRxRecv (Tuple &sender)
 
void processRxParse (int len, const Tuple &sender)
 Parse the contents of {mRxBuffer} and do something with it.
 
void processRxParseSip (char *buffer, int len, const Tuple &sender)
 
void processTxAll ()
 Added support for TXNOW and TXALL.
 
void processTxOne (SendData *data)
 
void updateEvents ()
 
- Protected Member Functions inherited from resip::InternalTransport
virtual Socket getListenerSocket () const
 The transport's own listening or bound socket, or INVALID_SOCKET for a transport that holds none.
 
- Protected Member Functions inherited from resip::Transport
void drainDscpRefresh ()
 Serves a pending refresh and a pending report.
 
void setTlsDomain (const Data &domain)
 

Protected Attributes

osc::Stack * mSigcompStack
 
unsigned mPollEventCnt
 
unsigned mTxTryCnt
 
unsigned mTxMsgCnt
 
unsigned mTxFailCnt
 
unsigned mRxTryCnt
 
unsigned mRxMsgCnt
 
unsigned mRxKeepaliveCnt
 
unsigned mRxTransactionCnt
 
std::array< char, MaxMessageSize > mRxBuffer {}
 
- Protected Attributes inherited from resip::InternalTransport
Socket mFd
 
SelectInterruptor mSelectInterruptor
 
FdPollItemHandle mInterruptorHandle
 
Fifo< SendData > mTxFifo
 
ConsumerFifoBuffer< SendData > mTxFifoOutBuffer
 
FdPollGrp * mPollGrp
 
FdPollItemHandle mPollItemHandle
 
- Protected Attributes inherited from resip::Transport
Data mInterface
 
Tuple mTuple
 
CongestionManager * mCongestionManager
 
ProducerFifoBuffer< TransactionMessage > mStateMachineFifo
 
bool mShuttingDown
 
AfterSocketCreationFuncPtr mSocketFunc
 
Compression & mCompression
 
unsigned mTransportFlags
 
std::atomic< int > mDscp { -1 }
 the class to write, -1 for "do not mark"
 
std::atomic< bool > mDscpRefreshPending { false }
 Set by setDscp() when the value changes, cleared by the owning thread's refresh.
 
std::atomic< bool > mDscpReportPending { false }
 Set by every setDscp() call, cleared by the owning thread's report, so a reload that changed nothing still says what the listener carries.
 
std::atomic< bool > mWasMarkRequested { false }
 Whether this transport has asked a socket to carry a class that a clear would have to undo.
 

Additional Inherited Members

- Static Public Member Functions inherited from resip::InternalTransport
static Socket socket (TransportType type, IpVersion ipVer)
 
- Static Public Member Functions inherited from resip::Transport
static void error (int e)
 Generates a generic log for the platform specific socket error number.
 
static Data errorToString (int e)
 
static void stampReceived (SipMessage *request)
 

Detailed Description

A Transport based on UDP.

Definition at line 42 of file UdpTransport.hxx.

Member Enumeration Documentation

◆ StunResult

Enumerator
StunResultUnknown 
StunResultSuccess 
StunResultNoResponse 
StunResultResponseParseFailed 

Definition at line 88 of file UdpTransport.hxx.

Constructor & Destructor Documentation

◆ UdpTransport()

UdpTransport::UdpTransport ( Fifo< TransactionMessage > &  fifo,
int  portNum,
IpVersion  version,
StunSetting  stun,
const Data &  interfaceObj,
AfterSocketCreationFuncPtr  socketFunc = nullptr,
Compression &  compression = Compression::Disabled,
unsigned  transportFlags = 0 
)
Parameters
fifothe TransactionMessage Fifo that will receive any ConnectionTerminated or TransportFailure messages.
interfaceObja "presentation format" representation of the IP address of this transport
See also
Tuple::inet_ntop() for information about "presentation format"
Parameters
portNumis the port to receive and/or send on
socketFuncFunctor (defined in rutil/Socket.hxx) that is called when a socket is created; allows app to log fd creation, tweak sockopts, and so forth.

Definition at line 31 of file UdpTransport.cxx.

◆ ~UdpTransport()

UdpTransport::~UdpTransport ( )
virtual

Definition at line 76 of file UdpTransport.cxx.

Member Function Documentation

◆ buildFdSet()

void UdpTransport::buildFdSet ( FdSet &  fdset)
virtual

Adds the Transport's socket FD to the appropriate read or write sets as applicable.

Implements resip::Transport.

Reimplemented in resip::DtlsTransport.

Definition at line 192 of file UdpTransport.cxx.

◆ hasDataToSend()

bool UdpTransport::hasDataToSend ( ) const
virtual

If we return true, the TransactionController will set the timeout to zero so that process() is called immediately.

We don't want this; instead, we depend upon the writable-socket callback (fdset or poll).

Reimplemented from resip::InternalTransport.

Definition at line 186 of file UdpTransport.cxx.

◆ isDatagram()

virtual bool resip::UdpTransport::isDatagram ( ) const
inlinevirtual

Implements resip::Transport.

Reimplemented in resip::DtlsTransport.

Definition at line 72 of file UdpTransport.hxx.

◆ isReliable()

virtual bool resip::UdpTransport::isReliable ( ) const
inlinevirtual

Implements resip::Transport.

Reimplemented in resip::DtlsTransport.

Definition at line 71 of file UdpTransport.hxx.

◆ process() [1/2]

void UdpTransport::process ( )
virtual

Called after a message is added.

Could try writing it now.

Implements resip::Transport.

Definition at line 122 of file UdpTransport.cxx.

◆ process() [2/2]

void UdpTransport::process ( FdSet &  fdset)
virtual

If there is work to do, this is the method that does it.

If the socket is readable, it is read. If the socket is writable and there are outgoing messages to be sent, they are sent.

Incoming messages are parsed and dispatched to the relevant entity. SIP messages will be posted to the TransactionMessage Fifo.

See also
sendData()
Parameters
fdsetis the FdSet after select() has been called.
See also
FdSet::select()

Implements resip::Transport.

Reimplemented in resip::DtlsTransport.

Definition at line 203 of file UdpTransport.cxx.

◆ processPollEvent()

void UdpTransport::processPollEvent ( FdPollEventMask  mask)
virtual

Called by PollGrp when activity is possible.

Implements resip::FdPollItemIf.

Definition at line 161 of file UdpTransport.cxx.

◆ processRxAll()

void UdpTransport::processRxAll ( )
protected

Add options RXALL (to try receive all readable data).

With RXALL, every read cycle will have end with an EAGAIN read. Testing in very limited cases shows marginal (5%) performance improvements. Probably "real" traffic (that is bursty) would more impact.

Definition at line 321 of file UdpTransport.cxx.

◆ processRxParse()

void UdpTransport::processRxParse ( int  len,
const Tuple &  sender 
)
protected

Parse the contents of {mRxBuffer} and do something with it.

Definition at line 386 of file UdpTransport.cxx.

◆ processRxParseSip()

void UdpTransport::processRxParseSip ( char *  buffer,
int  len,
const Tuple &  sender 
)
protected

Definition at line 539 of file UdpTransport.cxx.

◆ processRxRecv()

int UdpTransport::processRxRecv ( Tuple &  sender)
protected

Definition at line 350 of file UdpTransport.cxx.

◆ processTxAll()

void UdpTransport::processTxAll ( )
protected

Added support for TXNOW and TXALL.

Generally only makes sense to specify one of these. Limited testing shows limited performance gain from either of these: the socket-event overhead appears tiny.

Definition at line 228 of file UdpTransport.cxx.

◆ processTxOne()

void UdpTransport::processTxOne ( SendData *  data)
protected

Definition at line 244 of file UdpTransport.cxx.

◆ RESIP_HeapCount()

resip::UdpTransport::RESIP_HeapCount ( UdpTransport  )

◆ setExternalUnknownDatagramHandler()

void UdpTransport::setExternalUnknownDatagramHandler ( ExternalUnknownDatagramHandler *  handler)

Installs a handler for the unknown datagrams arriving on the udp transport.

Definition at line 771 of file UdpTransport.cxx.

◆ setPollGrp()

void UdpTransport::setPollGrp ( FdPollGrp *  grp)
virtual

Reimplemented from resip::InternalTransport.

Definition at line 97 of file UdpTransport.cxx.

◆ setRcvBufLen()

void UdpTransport::setRcvBufLen ( int  buflen)
virtual

Reimplemented from resip::Transport.

Definition at line 777 of file UdpTransport.cxx.

◆ stunResult()

UdpTransport::StunResult UdpTransport::stunResult ( Tuple &  mappedAddress)

Return the result of the most recent stunSendTest(); on StunResultSuccess, mappedAddress is filled with the discovered public address.

See also
stunSendTest for the single-outstanding-request restriction.

Definition at line 759 of file UdpTransport.cxx.

◆ stunSendTest()

bool UdpTransport::stunSendTest ( const Tuple &  dest)

Send a STUN Binding Request to dest for public-address discovery.

The request is unauthenticated, as is typical for public STUN servers. The response is only accepted if it originates from dest and echoes the request's transaction id, so spoofed or off-path responses are rejected (RFC 5389/8489).

Note
Short-term credential (MESSAGE-INTEGRITY) support is intentionally not provided here: this is a SIP signaling transport, and STUN on it is used only for unauthenticated public-address discovery. Short-term authenticated Binding Requests belong to ICE connectivity checks on the media/RTP path (see the reTurn client), not the SIP transport.
Only one STUN test may be outstanding per transport at a time. Each call replaces any in-flight request: the stored transaction id and server address are overwritten, so a response to a prior request will no longer be accepted, and stunResult() always reflects the most recent call. This is sufficient for the UserAgent public-address-discovery use case; it is not a general concurrent STUN client.

Definition at line 717 of file UdpTransport.cxx.

◆ updateEvents()

void UdpTransport::updateEvents ( )
protected

Definition at line 143 of file UdpTransport.cxx.

Member Data Documentation

◆ MaxMessageSize

constexpr int resip::UdpTransport::MaxMessageSize = 65535
staticconstexpr

Definition at line 85 of file UdpTransport.hxx.

◆ mPollEventCnt

unsigned resip::UdpTransport::mPollEventCnt
protected

Definition at line 141 of file UdpTransport.hxx.

◆ mRxBuffer

std::array<char, MaxMessageSize> resip::UdpTransport::mRxBuffer {}
protected

Definition at line 149 of file UdpTransport.hxx.

◆ mRxKeepaliveCnt

unsigned resip::UdpTransport::mRxKeepaliveCnt
protected

Definition at line 147 of file UdpTransport.hxx.

◆ mRxMsgCnt

unsigned resip::UdpTransport::mRxMsgCnt
protected

Definition at line 146 of file UdpTransport.hxx.

◆ mRxTransactionCnt

unsigned resip::UdpTransport::mRxTransactionCnt
protected

Definition at line 148 of file UdpTransport.hxx.

◆ mRxTryCnt

unsigned resip::UdpTransport::mRxTryCnt
protected

Definition at line 145 of file UdpTransport.hxx.

◆ mSigcompStack

osc::Stack* resip::UdpTransport::mSigcompStack
protected

Definition at line 138 of file UdpTransport.hxx.

◆ mTxFailCnt

unsigned resip::UdpTransport::mTxFailCnt
protected

Definition at line 144 of file UdpTransport.hxx.

◆ mTxMsgCnt

unsigned resip::UdpTransport::mTxMsgCnt
protected

Definition at line 143 of file UdpTransport.hxx.

◆ mTxTryCnt

unsigned resip::UdpTransport::mTxTryCnt
protected

Definition at line 142 of file UdpTransport.hxx.


The documentation for this class was generated from the following files: