reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TransactionController.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
20#ifdef USE_SSL
22#endif
24#include "rutil/DnsUtil.hxx"
25#include "rutil/Logger.hxx"
28
29using namespace resip;
30
31#define RESIPROCATE_SUBSYSTEM Subsystem::TRANSACTION
32
33#if defined(WIN32) && !defined (__GNUC__)
34#pragma warning( disable : 4355 ) // using this in base member initializer list
35#endif
36
39
41 AsyncProcessHandler* handler,
42 bool useDnsVip) :
43 mStack(stack),
44 mDiscardStrayResponses(true),
45 mFixBadDialogIdentifiers(true),
46 mFixBadCSeqNumbers(true),
47 mStateMacFifo(handler),
48 mStateMacFifoOutBuffer(mStateMacFifo),
49 mCongestionManager(0),
50 mTuSelector(stack.mTuSelector),
51 mTransportSelector(mStateMacFifo,
52 stack.getSecurity(),
53 stack.getDnsStub(),
54 stack.getCompression(),
55 useDnsVip),
56 mTimers(mTimerFifo),
57 mShuttingDown(false),
58 mStatsManager(stack.mStatsManager),
59 mHostname(DnsUtil::getLocalHostName())
60{
61 mStateMacFifo.setDescription("TransactionController::mStateMacFifo");
62}
63
64#if defined(WIN32) && !defined(__GNUC__)
65#pragma warning( default : 4355 )
66#endif
67
69{
70 if(mClientTransactionMap.size())
71 {
72 WarningLog(<< "On shutdown, there are Client TransactionStates remaining!");
73 }
74
75 if(mServerTransactionMap.size())
76 {
77 WarningLog(<< "On shutdown, there are Server TransactionStates remaining!");
78 }
79}
80
81
82bool
87
88void
90{
91 mShuttingDown = true;
92 mTransportSelector.shutdown();
93}
94
95void
97{
98 if (mShuttingDown &&
99 //mTimers.empty() &&
100 !mStateMacFifoOutBuffer.messageAvailable() && // !dcm! -- see below
101 !mStack.mTUFifo.messageAvailable() &&
102 mTransportSelector.isFinished())
103// !dcm! -- why would one wait for the Tu's fifo to be empty before delivering a
104// shutdown message?
105 {
108 }
109 else
110 {
111 unsigned int nextTimer(mTimers.msTillNextTimer());
112 timeout=resipMin((int)nextTimer, timeout);
113 if(timeout==0)
114 {
115 // *sigh*
116 timeout=-1;
117 }
118
119 // Check if Statistics Manager needs to be polled - note: all statistic manager polls should happen from the
120 // TransactionController thread / process loop
121 if(mStack.mStatisticsManagerEnabled)
122 {
123 mStatsManager.process();
124 }
125
126 // If non-zero is passed for timeout, we understand that the caller is ok
127 // with us waiting up to that long on this call. A non-zero timeout is
128 // passed by TransactionControllerThread, for example. This gets us
129 // something approximating a blocking wait on both the state machine fifo
130 // and the timer queue.
131 TransactionMessage* message=mStateMacFifoOutBuffer.getNext(timeout);
132
133 // If we either had timers ready to go at the beginning of this call, or
134 // the getNext() call above timed out, our timer queue is likely ready to
135 // be serviced.
136 if(!message || nextTimer==0)
137 {
138 mTimers.process();
139 TimerMessage* timer;
140 while ((timer=mTimerFifo.getNext(-1)))
141 {
143 }
144 }
145
146 if(message)
147 {
148 // Only do 16 at a time; don't let the timer queue (or other
149 // processing) starve.
150 int runs=16;
151 while(message)
152 {
153 TransactionState::process(*this, message);
154 if(--runs==0)
155 {
156 break;
157 }
158 message = mStateMacFifoOutBuffer.getNext(-1);
159 }
160
161 mTransportSelector.poke();
162 }
163 }
164}
165
166unsigned int
168{
169 if ( mStateMacFifoOutBuffer.messageAvailable() )
170 {
171 return 0;
172 }
173 return mTimers.msTillNextTimer();
174}
175
176void
178{
179 if(msg->isRequest() &&
180 msg->method() != ACK &&
182 {
183 // Need to 503 this.
184 SipMessage* resp(Helper::makeResponse(*msg, 503));
185 resp->header(h_RetryAfter).value()=(uint32_t)mStateMacFifo.expectedWaitTimeMilliSec()/1000;
188 delete msg;
189 return;
190 }
191 mStateMacFifo.add(msg);
192}
193
194
195unsigned int
197{
198 return mTuSelector.size();
199}
200
201unsigned int
203{
204 return mTransportSelector.sumTransportFifoSizes();
205}
206
207unsigned int
209{
210 // Should we include the stuff in mStateMacFifoOutBuffer here too? This is
211 // likely to be called from other threads...
212 return mStateMacFifo.size();
213}
214
215unsigned int
217{
218 return mClientTransactionMap.size();
219}
220
221unsigned int
223{
224 return mServerTransactionMap.size();
225}
226
227unsigned int
229{
230 return mTimers.size();
231}
232
233void
235{
236 mStateMacFifo.add(new ZeroOutStatistics());
237}
238
239void
241{
242 mStateMacFifo.add(new PollStatistics());
243}
244
245void
247{
248 mTransportSelector.registerMarkListener(listener);
249}
250
252{
253 mTransportSelector.unregisterMarkListener(listener);
254}
255
256void
258{
259 mStateMacFifo.add(new AbandonServerTransaction(tid));
260}
261
262void
264{
265 mStateMacFifo.add(new CancelClientInviteTransaction(tid, reasons));
266}
267
268void
269TransactionController::addTransport(std::unique_ptr<Transport> transport)
270{
271 mStateMacFifo.add(new AddTransport(std::move(transport)));
272}
273
274void
276{
277 mStateMacFifo.add(new RemoveTransport(transportKey));
278}
279
280void
282{
283 mStateMacFifo.add(new TerminateFlow(flow));
284}
285
286void
288{
289 mStateMacFifo.add(new EnableFlowTimer(flow));
290}
291
292void
294{
295 mStateMacFifo.setInterruptor(handler);
296}
297
298void
303
304/* ====================================================================
305 * The Vovida Software License, Version 1.0
306 *
307 * Copyright (c) 2004 Vovida Networks, Inc. All rights reserved.
308 *
309 * Redistribution and use in source and binary forms, with or without
310 * modification, are permitted provided that the following conditions
311 * are met:
312 *
313 * 1. Redistributions of source code must retain the above copyright
314 * notice, this list of conditions and the following disclaimer.
315 *
316 * 2. Redistributions in binary form must reproduce the above copyright
317 * notice, this list of conditions and the following disclaimer in
318 * the documentation and/or other materials provided with the
319 * distribution.
320 *
321 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
322 * and "Vovida Open Communication Application Library (VOCAL)" must
323 * not be used to endorse or promote products derived from this
324 * software without prior written permission. For written
325 * permission, please contact vocal@vovida.org.
326 *
327 * 4. Products derived from this software may not be called "VOCAL", nor
328 * may "VOCAL" appear in their name, without prior written
329 * permission of Vovida Networks, Inc.
330 *
331 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
332 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
333 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
334 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
335 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
336 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
337 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
338 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
339 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
340 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
341 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
342 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
343 * DAMAGE.
344 *
345 * ====================================================================
346 *
347 * This software consists of voluntary contributions made by Vovida
348 * Networks, Inc. and many individuals on behalf of Vovida Networks,
349 * Inc. For more information on Vovida Networks, Inc., please see
350 * <http://www.vovida.org/>.
351 *
352 * vi: set shiftwidth=3 expandtab:
353 */
#define WarningLog(args_)
Definition Logger.hxx:134
@ NORMAL
Not rejecting any work.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Provides a collection of utility functions for manipulating DNS names and IP addresses and discoverin...
Definition DnsUtil.hxx:29
static void makeResponse(SipMessage &response, const SipMessage &request, int responseCode, const Data &reason=Data::Empty, const Data &hostname=Data::Empty, const Data &warning=Data::Empty)
Make a response to a provided request.
Definition Helper.cxx:412
TransactionUser * getTransactionUser()
Definition Message.hxx:49
void setTransactionUser(TransactionUser *t)
Definition Message.hxx:48
Represents a SIP message.
bool isRequest() const
Returns true if message is a request, false otherwise.
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
resip::MethodTypes method() const
returns the method type of the message
This is the primary point of interaction between the app-layer and the stack.
Definition SipStack.hxx:160
unsigned int msTillNextTimer()
provides the time in milliseconds before the next timer will fire
virtual uint64_t process()
gets the set of timers that have fired, and inserts TimerMsg into the state machine fifo and applicat...
void invokeAfterSocketCreationFunc(TransportType type)
void addTransport(std::unique_ptr< Transport > transport)
void cancelClientInviteTransaction(const Data &tid, const resip::Tokens *reasons)
unsigned int getTransactionFifoSize() const
TransactionController(SipStack &stack, AsyncProcessHandler *handler, bool useDnsVip)
CongestionManager::RejectionBehavior getRejectionBehavior() const
unsigned int getNumClientTransactions() const
void abandonServerTransaction(const Data &tid)
void enableFlowTimer(const resip::Tuple &flow)
unsigned int getNumServerTransactions() const
void removeTransport(unsigned int transportKey)
void registerMarkListener(MarkListener *listener)
void unregisterMarkListener(MarkListener *listener)
void terminateFlow(const resip::Tuple &flow)
void setInterruptor(AsyncProcessHandler *handler)
static void processTimer(TransactionController &controller, TimerMessage *timer)
static void process(TransactionController &controller, TransactionMessage *message)
void registerMarkListener(MarkListener *listener)
unsigned int sumTransportFifoSizes() const
void poke()
Causes transport process loops to be interrupted if there is stuff in their transmit fifos.
bool isFinished() const
Returns true if all Transports have their buffers cleared, false otherwise.
void shutdown()
Shuts down all transports.
void unregisterMarkListener(MarkListener *listener)
bool wouldAccept(TimeLimitFifo< Message >::DepthUsage usage) const
void add(Message *msg, TimeLimitFifo< Message >::DepthUsage usage)
unsigned int size() const
Represents a network address.
Definition Tuple.hxx:59
dcm! – add UnusedChecking(_enum) below;
const _Tp & resipMin(const _Tp &__a, const _Tp &__b)
Definition compat.hxx:182
unsigned int uint32_t
Definition Stun.hxx:34
TransportType
An enumeration of transport protocols.