3
* Copyright 2004--2005, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#ifndef TALK_P2P_BASE_STUNPORT_H_
29
#define TALK_P2P_BASE_STUNPORT_H_
33
#include "talk/base/asyncpacketsocket.h"
34
#include "talk/p2p/base/udpport.h"
35
#include "talk/p2p/base/stunrequest.h"
44
extern const char STUN_PORT_TYPE[];
46
// Communicates using the address on the outside of a NAT.
47
class StunPort : public Port {
49
static StunPort* Create(talk_base::Thread* thread,
50
talk_base::PacketSocketFactory* factory,
51
talk_base::Network* network,
52
const talk_base::IPAddress& ip,
53
int min_port, int max_port,
54
const talk_base::SocketAddress& server_addr) {
55
StunPort* port = new StunPort(thread, factory, network,
56
ip, min_port, max_port, server_addr);
65
talk_base::SocketAddress GetLocalAddress() const {
66
return socket_->GetLocalAddress();
69
const talk_base::SocketAddress& server_addr() const { return server_addr_; }
70
void set_server_addr(const talk_base::SocketAddress& addr) {
74
const talk_base::SocketAddress& server_addr2() const { return server_addr2_; }
75
void set_server_addr2(const talk_base::SocketAddress& addr) {
79
virtual void PrepareAddress();
81
// This will contact the secondary server and signal another candidate
82
// address for this port (which may be the same as the first address).
83
void PrepareSecondaryAddress();
85
virtual Connection* CreateConnection(const Candidate& address,
86
CandidateOrigin origin);
87
virtual int SetOption(talk_base::Socket::Option opt, int value);
88
virtual int GetError();
91
StunPort(talk_base::Thread* thread, talk_base::PacketSocketFactory* factory,
92
talk_base::Network* network, const talk_base::IPAddress& ip,
93
int min_port, int max_port,
94
const talk_base::SocketAddress& server_addr);
97
virtual int SendTo(const void* data, size_t size,
98
const talk_base::SocketAddress& addr, bool payload);
100
void OnReadPacket(talk_base::AsyncPacketSocket* socket,
101
const char* data, size_t size,
102
const talk_base::SocketAddress& remote_addr);
105
// DNS resolution of the STUN server.
106
void ResolveStunAddress();
107
void OnResolveResult(talk_base::SignalThread* thread);
108
// Sends STUN requests to the server.
109
void OnSendPacket(const void* data, size_t size, StunRequest* req);
111
talk_base::SocketAddress server_addr_;
112
talk_base::SocketAddress server_addr2_;
113
StunRequestManager requests_;
114
talk_base::AsyncPacketSocket* socket_;
116
talk_base::AsyncResolver* resolver_;
118
friend class StunPortBindingRequest;
121
} // namespace cricket
123
#endif // TALK_P2P_BASE_STUNPORT_H_