/[resiprocate]/main/reTurn/TurnAllocationManager.cxx
ViewVC logotype

Contents of /main/reTurn/TurnAllocationManager.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10138 - (show annotations) (download)
Sun Apr 28 19:58:33 2013 UTC (6 years, 6 months ago) by sgodin
File size: 4097 byte(s)
-track allocations per connection - reduces map sizes and lookups when TCP/TLS 
 client connections are used
1 #include <rutil/Lock.hxx>
2
3 #include "TurnAllocationManager.hxx"
4 #include "TurnAllocation.hxx"
5 #include <rutil/Logger.hxx>
6 #include "ReTurnSubsystem.hxx"
7
8 #define RESIPROCATE_SUBSYSTEM ReTurnSubsystem::RETURN
9
10 using namespace std;
11
12 namespace reTurn {
13
14 TurnAllocationManager::TurnAllocationManager()
15 {
16 }
17
18 TurnAllocationManager::~TurnAllocationManager()
19 {
20 TurnAllocationMap::iterator it = mTurnAllocationMap.begin();
21 for(;it != mTurnAllocationMap.end();it++)
22 {
23 delete it->second;
24 }
25
26 InfoLog(<< "Turn Allocation Manager destroyed.");
27 }
28
29 void
30 TurnAllocationManager::addTurnAllocation(TurnAllocation* turnAllocation)
31 {
32 assert(findTurnAllocation(turnAllocation->getKey()) == 0);
33 mTurnAllocationMap[turnAllocation->getKey()] = turnAllocation;
34 }
35
36 void
37 TurnAllocationManager::removeTurnAllocation(const TurnAllocationKey& turnAllocationKey)
38 {
39 TurnAllocationMap::iterator it = mTurnAllocationMap.find(turnAllocationKey);
40 if(it != mTurnAllocationMap.end())
41 {
42 delete it->second;
43 mTurnAllocationMap.erase(it);
44 }
45 }
46
47 TurnAllocation*
48 TurnAllocationManager::findTurnAllocation(const TurnAllocationKey& turnAllocationKey)
49 {
50 TurnAllocationMap::iterator it = mTurnAllocationMap.find(turnAllocationKey);
51 if(it != mTurnAllocationMap.end())
52 {
53 return it->second;
54 }
55 return 0;
56 }
57
58 TurnAllocation*
59 TurnAllocationManager::findTurnAllocation(const StunTuple& requestedTuple)
60 {
61 TurnAllocationMap::iterator it;
62 for(it = mTurnAllocationMap.begin(); it != mTurnAllocationMap.end(); it++)
63 {
64 if(it->second->getRequestedTuple() == requestedTuple)
65 {
66 return it->second;
67 }
68 }
69 return 0;
70 }
71
72 void
73 TurnAllocationManager::allocationExpired(const asio::error_code& e, const TurnAllocationKey& turnAllocationKey)
74 {
75 if (e != asio::error::operation_aborted) // Note: nothing currently stops timers
76 {
77 // Timer was not cancelled, take necessary action.
78 InfoLog(<< "Turn Allocation Expired! clientLocal=" << turnAllocationKey.getClientLocalTuple() << " clientRemote=" << turnAllocationKey.getClientRemoteTuple());
79
80 TurnAllocationMap::iterator it = mTurnAllocationMap.find(turnAllocationKey);
81 if(it != mTurnAllocationMap.end())
82 {
83 if(time(0) >= it->second->getExpires())
84 {
85 delete it->second;
86 mTurnAllocationMap.erase(it);
87 }
88 }
89 }
90 }
91
92 } // namespace
93
94
95 /* ====================================================================
96
97 Copyright (c) 2007-2008, Plantronics, Inc.
98 All rights reserved.
99
100 Redistribution and use in source and binary forms, with or without
101 modification, are permitted provided that the following conditions are
102 met:
103
104 1. Redistributions of source code must retain the above copyright
105 notice, this list of conditions and the following disclaimer.
106
107 2. Redistributions in binary form must reproduce the above copyright
108 notice, this list of conditions and the following disclaimer in the
109 documentation and/or other materials provided with the distribution.
110
111 3. Neither the name of Plantronics nor the names of its contributors
112 may be used to endorse or promote products derived from this
113 software without specific prior written permission.
114
115 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
116 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
117 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
118 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
119 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
120 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
121 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
122 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
123 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
124 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
125 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126
127 ==================================================================== */

Properties

Name Value
svn:eol-style native

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27