reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TurnAllocation.hxx
Go to the documentation of this file.
1#ifndef TURNALLOCATION_HXX
2#define TURNALLOCATION_HXX
3
4#include <map>
5#include <asio.hpp>
6#ifdef USE_SSL
7#include <asio/ssl.hpp>
8#endif
9
10#include "StunTuple.hxx"
11#include "StunAuth.hxx"
12#include "TurnAllocationKey.hxx"
14#include "DataBuffer.hxx"
15#include "ChannelManager.hxx"
16
17#include <memory>
18
19namespace reTurn {
20
21class TurnPermission;
22class TurnManager;
23class TurnAllocationManager;
24class AsyncSocketBase;
25class UdpRelayServer;
26
29{
30public:
36 const StunAuth& clientAuth,
38 unsigned int lifetime);
42
45
46 bool startRelay();
47 void stopRelay();
48
49 const TurnAllocationKey& getKey() const noexcept { return mKey; }
50 void refresh(unsigned int lifetime); // update expiration time
51
52 // checks if the permission exists or not - also checks for expired
53 // permissions
54 bool existsPermission(const asio::ip::address& address);
55
56 // create Permission if not present, otherwise refresh permission timer
57 void refreshPermission(const asio::ip::address& address);
58
59 // this get's called when being notified that the socket that the allocation came from
60 // has been destroyed
61 void onSocketDestroyed() override;
62
63 // Used when framed data is received from client, to forward data to peer
64 void sendDataToPeer(unsigned short channelNumber, const std::shared_ptr<DataBuffer>& data, bool isFramed);
65 // Used when Send Indication is received from client, to forward data to peer
66 void sendDataToPeer(const StunTuple& peerAddress, const std::shared_ptr<DataBuffer>& data, bool isFramed);
67 // Used when Data is received from peer, to forward data to client
68 void sendDataToClient(const StunTuple& peerAddress, const std::shared_ptr<DataBuffer>& data);
69
70 // Called when a ChannelBind Request is received
71 bool addChannelBinding(const StunTuple& peerAddress, unsigned short channelNumber);
72
73 const StunTuple& getRequestedTuple() const noexcept { return mRequestedTuple; }
74 time_t getExpires() const noexcept { return mExpires; }
75 const StunAuth& getClientAuth() const noexcept { return mClientAuth; }
76
77private:
78 TurnAllocationKey mKey; // contains ClientLocalTuple and clientRemoteTuple
79 StunAuth mClientAuth;
80 StunTuple mRequestedTuple;
81
82 time_t mExpires;
83 //unsigned int mBandwidth; // future use
84
85 typedef std::map<asio::ip::address,TurnPermission*> TurnPermissionMap;
86 TurnPermissionMap mTurnPermissionMap;
87
88 TurnManager& mTurnManager;
89 TurnAllocationManager& mTurnAllocationManager;
90 asio::steady_timer mAllocationTimer;
91
92 AsyncSocketBase* mLocalTurnSocket;
93 std::shared_ptr<UdpRelayServer> mUdpRelayServer;
94
95 ChannelManager mChannelManager;
96
97 // Flags to control logging on Data channel/relay. Used so that errors only print at Warning level once
98 bool mBadChannelErrorLogged;
99 bool mNoPermissionToPeerLogged;
100 bool mNoPermissionFromPeerLogged;
101};
102
103}
104
105#endif
106
107
108/* ====================================================================
109
110 Copyright (c) 2007-2008, Plantronics, Inc.
111 All rights reserved.
112
113 Redistribution and use in source and binary forms, with or without
114 modification, are permitted provided that the following conditions are
115 met:
116
117 1. Redistributions of source code must retain the above copyright
118 notice, this list of conditions and the following disclaimer.
119
120 2. Redistributions in binary form must reproduce the above copyright
121 notice, this list of conditions and the following disclaimer in the
122 documentation and/or other materials provided with the distribution.
123
124 3. Neither the name of Plantronics nor the names of its contributors
125 may be used to endorse or promote products derived from this
126 software without specific prior written permission.
127
128 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
129 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
130 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
131 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
132 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
133 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
134 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
135 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
136 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
137 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
138 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139
140 ==================================================================== */
const StunAuth & getClientAuth() const noexcept
bool addChannelBinding(const StunTuple &peerAddress, unsigned short channelNumber)
const StunTuple & getRequestedTuple() const noexcept
void sendDataToPeer(unsigned short channelNumber, const std::shared_ptr< DataBuffer > &data, bool isFramed)
void onSocketDestroyed() override
TurnAllocation(TurnAllocation &&)=delete
void refresh(unsigned int lifetime)
const TurnAllocationKey & getKey() const noexcept
TurnAllocation & operator=(TurnAllocation &&)=delete
void sendDataToClient(const StunTuple &peerAddress, const std::shared_ptr< DataBuffer > &data)
TurnAllocation(const TurnAllocation &)=delete
bool existsPermission(const asio::ip::address &address)
time_t getExpires() const noexcept
void refreshPermission(const asio::ip::address &address)
TurnAllocation & operator=(const TurnAllocation &)=delete
void list()
Definition userAdmin.cxx:66