Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: webrtc/base/natserver.h

Issue 1215713003: Ensuring that UDP TURN servers are always used as STUN servers. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing compiler warning from size_t->int cast Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/nat_unittest.cc ('k') | webrtc/base/natserver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_NATSERVER_H_ 11 #ifndef WEBRTC_BASE_NATSERVER_H_
12 #define WEBRTC_BASE_NATSERVER_H_ 12 #define WEBRTC_BASE_NATSERVER_H_
13 13
14 #include <map> 14 #include <map>
15 #include <set> 15 #include <set>
16 16
17 #include "webrtc/base/asyncudpsocket.h" 17 #include "webrtc/base/asyncudpsocket.h"
18 #include "webrtc/base/socketaddresspair.h" 18 #include "webrtc/base/socketaddresspair.h"
19 #include "webrtc/base/thread.h" 19 #include "webrtc/base/thread.h"
20 #include "webrtc/base/socketfactory.h" 20 #include "webrtc/base/socketfactory.h"
21 #include "webrtc/base/nattypes.h" 21 #include "webrtc/base/nattypes.h"
22 #include "webrtc/base/proxyserver.h"
22 23
23 namespace rtc { 24 namespace rtc {
24 25
25 // Change how routes (socketaddress pairs) are compared based on the type of 26 // Change how routes (socketaddress pairs) are compared based on the type of
26 // NAT. The NAT server maintains a hashtable of the routes that it knows 27 // NAT. The NAT server maintains a hashtable of the routes that it knows
27 // about. So these affect which routes are treated the same. 28 // about. So these affect which routes are treated the same.
28 struct RouteCmp { 29 struct RouteCmp {
29 explicit RouteCmp(NAT* nat); 30 explicit RouteCmp(NAT* nat);
30 size_t operator()(const SocketAddressPair& r) const; 31 size_t operator()(const SocketAddressPair& r) const;
31 bool operator()( 32 bool operator()(
32 const SocketAddressPair& r1, const SocketAddressPair& r2) const; 33 const SocketAddressPair& r1, const SocketAddressPair& r2) const;
33 34
34 bool symmetric; 35 bool symmetric;
35 }; 36 };
36 37
37 // Changes how addresses are compared based on the filtering rules of the NAT. 38 // Changes how addresses are compared based on the filtering rules of the NAT.
38 struct AddrCmp { 39 struct AddrCmp {
39 explicit AddrCmp(NAT* nat); 40 explicit AddrCmp(NAT* nat);
40 size_t operator()(const SocketAddress& r) const; 41 size_t operator()(const SocketAddress& r) const;
41 bool operator()(const SocketAddress& r1, const SocketAddress& r2) const; 42 bool operator()(const SocketAddress& r1, const SocketAddress& r2) const;
42 43
43 bool use_ip; 44 bool use_ip;
44 bool use_port; 45 bool use_port;
45 }; 46 };
46 47
47 // Implements the NAT device. It listens for packets on the internal network, 48 // Implements the NAT device. It listens for packets on the internal network,
48 // translates them, and sends them out over the external network. 49 // translates them, and sends them out over the external network.
50 //
51 // TCP connections initiated from the internal side of the NAT server are
52 // also supported, by making a connection to the NAT server's TCP address and
53 // then sending the remote address in quasi-STUN format. The connection status
54 // will be indicated back to the client as a 1 byte status code, where '0'
55 // indicates success.
49 56
50 const int NAT_SERVER_PORT = 4237; 57 const int NAT_SERVER_UDP_PORT = 4237;
58 const int NAT_SERVER_TCP_PORT = 4238;
51 59
52 class NATServer : public sigslot::has_slots<> { 60 class NATServer : public sigslot::has_slots<> {
53 public: 61 public:
54 NATServer( 62 NATServer(
55 NATType type, SocketFactory* internal, const SocketAddress& internal_addr, 63 NATType type, SocketFactory* internal,
64 const SocketAddress& internal_udp_addr,
65 const SocketAddress& internal_tcp_addr,
56 SocketFactory* external, const SocketAddress& external_ip); 66 SocketFactory* external, const SocketAddress& external_ip);
57 ~NATServer() override; 67 ~NATServer() override;
58 68
59 SocketAddress internal_address() const { 69 SocketAddress internal_udp_address() const {
60 return server_socket_->GetLocalAddress(); 70 return udp_server_socket_->GetLocalAddress();
71 }
72
73 SocketAddress internal_tcp_address() const {
74 return tcp_proxy_server_->GetServerAddress();
61 } 75 }
62 76
63 // Packets received on one of the networks. 77 // Packets received on one of the networks.
64 void OnInternalPacket(AsyncPacketSocket* socket, const char* buf, 78 void OnInternalUDPPacket(AsyncPacketSocket* socket, const char* buf,
65 size_t size, const SocketAddress& addr, 79 size_t size, const SocketAddress& addr,
66 const PacketTime& packet_time); 80 const PacketTime& packet_time);
67 void OnExternalPacket(AsyncPacketSocket* socket, const char* buf, 81 void OnExternalUDPPacket(AsyncPacketSocket* socket, const char* buf,
68 size_t size, const SocketAddress& remote_addr, 82 size_t size, const SocketAddress& remote_addr,
69 const PacketTime& packet_time); 83 const PacketTime& packet_time);
70 84
71 private: 85 private:
72 typedef std::set<SocketAddress, AddrCmp> AddressSet; 86 typedef std::set<SocketAddress, AddrCmp> AddressSet;
73 87
74 /* Records a translation and the associated external socket. */ 88 /* Records a translation and the associated external socket. */
75 struct TransEntry { 89 struct TransEntry {
76 TransEntry(const SocketAddressPair& r, AsyncUDPSocket* s, NAT* nat); 90 TransEntry(const SocketAddressPair& r, AsyncUDPSocket* s, NAT* nat);
77 ~TransEntry(); 91 ~TransEntry();
78 92
79 void WhitelistInsert(const SocketAddress& addr); 93 void WhitelistInsert(const SocketAddress& addr);
(...skipping 11 matching lines...) Expand all
91 /* Creates a new entry that translates the given route. */ 105 /* Creates a new entry that translates the given route. */
92 void Translate(const SocketAddressPair& route); 106 void Translate(const SocketAddressPair& route);
93 107
94 /* Determines whether the NAT would filter out a packet from this address. */ 108 /* Determines whether the NAT would filter out a packet from this address. */
95 bool ShouldFilterOut(TransEntry* entry, const SocketAddress& ext_addr); 109 bool ShouldFilterOut(TransEntry* entry, const SocketAddress& ext_addr);
96 110
97 NAT* nat_; 111 NAT* nat_;
98 SocketFactory* internal_; 112 SocketFactory* internal_;
99 SocketFactory* external_; 113 SocketFactory* external_;
100 SocketAddress external_ip_; 114 SocketAddress external_ip_;
101 AsyncUDPSocket* server_socket_; 115 AsyncUDPSocket* udp_server_socket_;
102 AsyncSocket* tcp_server_socket_; 116 ProxyServer* tcp_proxy_server_;
103 InternalMap* int_map_; 117 InternalMap* int_map_;
104 ExternalMap* ext_map_; 118 ExternalMap* ext_map_;
105 DISALLOW_COPY_AND_ASSIGN(NATServer); 119 DISALLOW_COPY_AND_ASSIGN(NATServer);
106 }; 120 };
107 121
108 } // namespace rtc 122 } // namespace rtc
109 123
110 #endif // WEBRTC_BASE_NATSERVER_H_ 124 #endif // WEBRTC_BASE_NATSERVER_H_
OLDNEW
« no previous file with comments | « webrtc/base/nat_unittest.cc ('k') | webrtc/base/natserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698