reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
UdpTransport.hxx
Go to the documentation of this file.
1#if !defined(RESIP_UDPTRANSPORT_HXX)
2#define RESIP_UDPTRANSPORT_HXX
3
4#include <memory>
9
10#include <array>
11
12namespace osc { class Stack; }
13
14namespace resip
15{
16class UdpTransport;
17
23public:
25
30 virtual void operator()(UdpTransport* transport, const Tuple& source, std::unique_ptr<Data> unknownDatagram) = 0;
31};
32
43{
44public:
62 int portNum,
63 IpVersion version,
64 StunSetting stun,
65 const Data& interfaceObj,
66 AfterSocketCreationFuncPtr socketFunc = nullptr,
68 unsigned transportFlags = 0);
69 virtual ~UdpTransport();
70
71 virtual bool isReliable() const { return false; }
72 virtual bool isDatagram() const { return true; }
73
74 virtual void process(FdSet& fdset);
75 virtual void process();
76 virtual bool hasDataToSend() const;
77 virtual void buildFdSet( FdSet& fdset);
78 virtual void setPollGrp(FdPollGrp *grp);
79 virtual void setRcvBufLen(int buflen);
80
81 // FdPollItemIf
82 // virtual Socket getPollSocket() const;
83 virtual void processPollEvent(FdPollEventMask mask);
84
85 static constexpr int MaxMessageSize = 65535;
86
87 // STUN client functionality
95
117 bool stunSendTest(const Tuple& dest);
118
123 StunResult stunResult(Tuple& mappedAddress);
124
127
128protected:
129
130 void processRxAll();
131 int processRxRecv(Tuple& sender);
132 void processRxParse(int len, const Tuple& sender);
133 void processRxParseSip(char* buffer, int len, const Tuple& sender);
134 void processTxAll();
135 void processTxOne(SendData *data);
136 void updateEvents();
137
138 osc::Stack *mSigcompStack;
139
140 // statistics
142 unsigned mTxTryCnt;
143 unsigned mTxMsgCnt;
144 unsigned mTxFailCnt;
145 unsigned mRxTryCnt;
146 unsigned mRxMsgCnt;
149 std::array<char, MaxMessageSize> mRxBuffer{};
150private:
151#ifdef USE_SIGCOMP
152 std::array<char, MaxMessageSize> mRxUncompressedBuffer{};
153#endif
154 MsgHeaderScanner mMsgHeaderScanner;
155 mutable resip::Mutex myMutex;
156 Tuple mStunMappedAddress;
157
158 StunResult mStunResult;
159 StunSetting mStunSetting;
160
161 // STUN client state for the outstanding Binding Request (guarded by myMutex).
162 // Used to authenticate responses by source address and transaction id.
163 bool mStunTxIdValid; // true while a request is outstanding
164 std::array<unsigned char, 16> mStunTxId; // transaction id (incl. magic cookie) of the request
165 Tuple mStunServerTuple; // address the request was sent to
166
167 ExternalUnknownDatagramHandler* mExternalUnknownDatagramHandler;
168 bool mInWritable;
169};
170
171}
172
173#endif
174
175/* ====================================================================
176 * The Vovida Software License, Version 1.0
177 *
178 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
179 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
180 *
181 * Redistribution and use in source and binary forms, with or without
182 * modification, are permitted provided that the following conditions
183 * are met:
184 *
185 * 1. Redistributions of source code must retain the above copyright
186 * notice, this list of conditions and the following disclaimer.
187 *
188 * 2. Redistributions in binary form must reproduce the above copyright
189 * notice, this list of conditions and the following disclaimer in
190 * the documentation and/or other materials provided with the
191 * distribution.
192 *
193 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
194 * and "Vovida Open Communication Application Library (VOCAL)" must
195 * not be used to endorse or promote products derived from this
196 * software without prior written permission. For written
197 * permission, please contact vocal@vovida.org.
198 *
199 * 4. Products derived from this software may not be called "VOCAL", nor
200 * may "VOCAL" appear in their name, without prior written
201 * permission of Vovida Networks, Inc.
202 *
203 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
204 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
205 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
206 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
207 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
208 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
209 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
210 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
211 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
212 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
213 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
214 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
215 * DAMAGE.
216 *
217 * ====================================================================
218 *
219 * This software consists of voluntary contributions made by Vovida
220 * Networks, Inc. and many individuals on behalf of Vovida Networks,
221 * Inc. For more information on Vovida Networks, Inc., please see
222 * <http://www.vovida.org/>.
223 *
224 * vi: set shiftwidth=3 expandtab:
225 */
static Compression Disabled
Represents a compression configuration object with compression disabled.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Interface functor for external unrecognized datagram handling.
virtual void operator()(UdpTransport *transport, const Tuple &source, std::unique_ptr< Data > unknownDatagram)=0
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 network address.
Definition Tuple.hxx:59
A Transport based on UDP.
virtual bool isDatagram() const
void setExternalUnknownDatagramHandler(ExternalUnknownDatagramHandler *handler)
Installs a handler for the unknown datagrams arriving on the udp transport.
virtual bool isReliable() const
virtual void setRcvBufLen(int buflen)
void processRxParse(int len, const Tuple &sender)
Parse the contents of {mRxBuffer} and do something with it.
bool stunSendTest(const Tuple &dest)
Send a STUN Binding Request to dest for public-address discovery.
osc::Stack * mSigcompStack
int processRxRecv(Tuple &sender)
void processTxAll()
Added support for TXNOW and TXALL.
virtual void setPollGrp(FdPollGrp *grp)
static constexpr int MaxMessageSize
virtual void buildFdSet(FdSet &fdset)
Adds the Transport's socket FD to the appropriate read or write sets as applicable.
std::array< char, MaxMessageSize > mRxBuffer
RESIP_HeapCount(UdpTransport)
void processRxParseSip(char *buffer, int len, const Tuple &sender)
void processTxOne(SendData *data)
void processRxAll()
Add options RXALL (to try receive all readable data).
virtual void processPollEvent(FdPollEventMask mask)
Called by PollGrp when activity is possible.
StunResult stunResult(Tuple &mappedAddress)
Return the result of the most recent stunSendTest(); on StunResultSuccess, mappedAddress is filled wi...
virtual bool hasDataToSend() const
If we return true, the TransactionController will set the timeout to zero so that process() is called...
virtual void process()
Called after a message is added.
dcm! – add UnusedChecking(_enum) below;
void(* AfterSocketCreationFuncPtr)(Socket s, int transportType, const char *file, int line)
Definition Socket.hxx:107
unsigned short FdPollEventMask
Definition FdPoll.hxx:28
std::mutex Mutex
A semaphore that can be locked by only one thread at a time.
Definition Mutex.hxx:37
IpVersion
An enumeration of IP versions.