4
#if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400) \
5
&& (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600) \
6
&& !defined(ASIO_ENABLE_CANCELIO)
7
#error You must define ASIO_ENABLE_CANCELIO in your build settings.
12
#include <rutil/Data.hxx>
13
#include <rutil/Mutex.hxx>
15
#include "../StunTuple.hxx"
16
#include "../StunMessage.hxx"
17
#include "../ChannelManager.hxx"
24
static unsigned int UnspecifiedLifetime;
25
static unsigned int UnspecifiedBandwidth;
26
static unsigned short UnspecifiedToken;
27
static asio::ip::address UnspecifiedIpAddress;
29
explicit TurnSocket(const asio::ip::address& address = UnspecifiedIpAddress,
30
unsigned short port = 0);
31
virtual ~TurnSocket();
33
virtual unsigned int getSocketDescriptor() = 0;
34
virtual asio::error_code connect(const std::string& address, unsigned short port) = 0; // !slg! modify port parameter later to be able to do SRV lookups
36
// Note: Shared Secret requests have been deprecated by RFC5389, and not
37
// widely implemented in RFC3489 - so not really needed at all
38
asio::error_code requestSharedSecret(char* username, unsigned int usernameSize,
39
char* password, unsigned int passwordSize);
41
// Set the username and password for all future requests
42
void setUsernameAndPassword(const char* username, const char* password, bool shortTermAuth=false);
44
// Stun Binding Method - use getReflexiveTuple() to get binding info
45
asio::error_code bindRequest();
47
// Turn Allocation Methods
48
asio::error_code createAllocation(unsigned int lifetime = UnspecifiedLifetime,
49
unsigned int bandwidth = UnspecifiedBandwidth,
50
unsigned char requestedProps = StunMessage::PropsNone,
51
UInt64 reservationToken = UnspecifiedToken,
52
StunTuple::TransportType requestedTransportType = StunTuple::None);
53
asio::error_code refreshAllocation();
54
asio::error_code destroyAllocation();
56
// Accessors for properties associated with an allocation
57
StunTuple& getRelayTuple();
58
StunTuple& getReflexiveTuple();
59
unsigned int getLifetime();
60
unsigned int getBandwidth();
62
// Methods to control active destination
63
asio::error_code setActiveDestination(const asio::ip::address& address, unsigned short port);
64
asio::error_code clearActiveDestination();
67
asio::error_code send(const char* buffer, unsigned int size);
68
asio::error_code sendTo(const asio::ip::address& address, unsigned short port, const char* buffer, unsigned int size);
71
asio::error_code receive(char* buffer, unsigned int& size, unsigned int timeout, asio::ip::address* sourceAddress=0, unsigned short* sourcePort=0);
72
asio::error_code receiveFrom(const asio::ip::address& address, unsigned short port, char* buffer, unsigned int& size, unsigned int timeout);
75
virtual asio::error_code rawWrite(const char* buffer, unsigned int size) = 0;
76
virtual asio::error_code rawWrite(const std::vector<asio::const_buffer>& buffers) = 0;
77
virtual asio::error_code rawRead(unsigned int timeout, unsigned int* bytesRead, asio::ip::address* sourceAddress=0, unsigned short* sourcePort=0) = 0;
78
virtual void cancelSocket() = 0;
81
StunTuple mLocalBinding;
82
StunTuple mConnectedTuple;
84
// Authentication Info
85
resip::Data mUsername;
86
resip::Data mPassword;
91
// Turn Allocation Properties used in request
92
unsigned int mRequestedLifetime;
93
unsigned int mRequestedBandwidth;
94
unsigned char mRequestedProps;
95
UInt64 mReservationToken;
96
StunTuple::TransportType mRequestedTransportType;
98
// Turn Allocation Properties from response
100
time_t mAllocationRefreshTime;
101
StunTuple mRelayTuple;
102
StunTuple mReflexiveTuple;
103
unsigned int mLifetime;
104
unsigned int mBandwidth;
106
ChannelManager mChannelManager;
107
typedef std::map<unsigned short, time_t> ChannelBindingRefreshTimeMap;
108
ChannelBindingRefreshTimeMap mChannelBindingRefreshTimes;
109
RemotePeer* mActiveDestination;
111
asio::io_service mIOService;
113
// handlers and timers required to do a timed out read
114
asio::deadline_timer mReadTimer;
116
asio::error_code mReadErrorCode;
117
void startReadTimer(unsigned int timeout);
118
void handleRawRead(const asio::error_code& errorCode, size_t bytesRead);
119
void handleRawReadTimeout(const asio::error_code& errorCode);
121
// Read/Write Buffers
122
char mReadBuffer[8192];
123
char mWriteBuffer[8192];
128
asio::error_code channelBind(RemotePeer& remotePeer);
129
asio::error_code checkIfAllocationRefreshRequired();
130
asio::error_code checkIfChannelBindingRefreshRequired();
131
StunMessage* sendRequestAndGetResponse(StunMessage& request, asio::error_code& errorCode, bool addAuthInfo=true);
132
asio::error_code sendTo(RemotePeer& remotePeer, const char* buffer, unsigned int size);
133
asio::error_code handleStunMessage(StunMessage& stunMessage, char* buffer, unsigned int& size, asio::ip::address* sourceAddress=0, unsigned short* sourcePort=0);
134
asio::error_code handleRawData(char* data, unsigned int dataSize, unsigned int expectedSize, char* buffer, unsigned int& bufferSize);
142
/* ====================================================================
144
Copyright (c) 2007-2008, Plantronics, Inc.
147
Redistribution and use in source and binary forms, with or without
148
modification, are permitted provided that the following conditions are
151
1. Redistributions of source code must retain the above copyright
152
notice, this list of conditions and the following disclaimer.
154
2. Redistributions in binary form must reproduce the above copyright
155
notice, this list of conditions and the following disclaimer in the
156
documentation and/or other materials provided with the distribution.
158
3. Neither the name of Plantronics nor the names of its contributors
159
may be used to endorse or promote products derived from this
160
software without specific prior written permission.
162
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
163
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
164
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
165
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
166
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
167
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
168
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
169
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
170
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
171
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
172
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
174
==================================================================== */