OLD | NEW |
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_P2P_CLIENT_BASICPORTALLOCATOR_H_ | 11 #ifndef WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
12 #define WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ | 12 #define WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/p2p/base/port.h" | |
18 #include "webrtc/p2p/base/portallocator.h" | 17 #include "webrtc/p2p/base/portallocator.h" |
19 #include "webrtc/base/messagequeue.h" | 18 #include "webrtc/base/messagequeue.h" |
20 #include "webrtc/base/network.h" | 19 #include "webrtc/base/network.h" |
21 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
22 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
23 | 22 |
24 namespace cricket { | 23 namespace cricket { |
25 | 24 |
26 struct RelayCredentials { | |
27 RelayCredentials() {} | |
28 RelayCredentials(const std::string& username, | |
29 const std::string& password) | |
30 : username(username), | |
31 password(password) { | |
32 } | |
33 | |
34 std::string username; | |
35 std::string password; | |
36 }; | |
37 | |
38 typedef std::vector<ProtocolAddress> PortList; | |
39 struct RelayServerConfig { | |
40 RelayServerConfig(RelayType type) : type(type), priority(0) {} | |
41 | |
42 RelayType type; | |
43 PortList ports; | |
44 RelayCredentials credentials; | |
45 int priority; | |
46 }; | |
47 | |
48 class BasicPortAllocator : public PortAllocator { | 25 class BasicPortAllocator : public PortAllocator { |
49 public: | 26 public: |
50 BasicPortAllocator(rtc::NetworkManager* network_manager, | 27 BasicPortAllocator(rtc::NetworkManager* network_manager, |
51 rtc::PacketSocketFactory* socket_factory); | 28 rtc::PacketSocketFactory* socket_factory); |
52 explicit BasicPortAllocator(rtc::NetworkManager* network_manager); | 29 explicit BasicPortAllocator(rtc::NetworkManager* network_manager); |
53 BasicPortAllocator(rtc::NetworkManager* network_manager, | 30 BasicPortAllocator(rtc::NetworkManager* network_manager, |
54 rtc::PacketSocketFactory* socket_factory, | 31 rtc::PacketSocketFactory* socket_factory, |
55 const ServerAddresses& stun_servers); | 32 const ServerAddresses& stun_servers); |
56 BasicPortAllocator(rtc::NetworkManager* network_manager, | 33 BasicPortAllocator(rtc::NetworkManager* network_manager, |
57 const ServerAddresses& stun_servers, | 34 const ServerAddresses& stun_servers, |
58 const rtc::SocketAddress& relay_server_udp, | 35 const rtc::SocketAddress& relay_server_udp, |
59 const rtc::SocketAddress& relay_server_tcp, | 36 const rtc::SocketAddress& relay_server_tcp, |
60 const rtc::SocketAddress& relay_server_ssl); | 37 const rtc::SocketAddress& relay_server_ssl); |
61 virtual ~BasicPortAllocator(); | 38 virtual ~BasicPortAllocator(); |
62 | 39 |
| 40 void SetIceServers( |
| 41 const ServerAddresses& stun_servers, |
| 42 const std::vector<RelayServerConfig>& turn_servers) override { |
| 43 stun_servers_ = stun_servers; |
| 44 turn_servers_ = turn_servers; |
| 45 } |
| 46 |
63 rtc::NetworkManager* network_manager() { return network_manager_; } | 47 rtc::NetworkManager* network_manager() { return network_manager_; } |
64 | 48 |
65 // If socket_factory() is set to NULL each PortAllocatorSession | 49 // If socket_factory() is set to NULL each PortAllocatorSession |
66 // creates its own socket factory. | 50 // creates its own socket factory. |
67 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } | 51 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } |
68 | 52 |
69 const ServerAddresses& stun_servers() const { | 53 const ServerAddresses& stun_servers() const { |
70 return stun_servers_; | 54 return stun_servers_; |
71 } | 55 } |
72 | 56 |
73 const std::vector<RelayServerConfig>& relays() const { | 57 const std::vector<RelayServerConfig>& turn_servers() const { |
74 return relays_; | 58 return turn_servers_; |
75 } | 59 } |
76 virtual void AddRelay(const RelayServerConfig& relay) { | 60 virtual void AddTurnServer(const RelayServerConfig& turn_server) { |
77 relays_.push_back(relay); | 61 turn_servers_.push_back(turn_server); |
78 } | 62 } |
79 | 63 |
80 virtual PortAllocatorSession* CreateSessionInternal( | 64 virtual PortAllocatorSession* CreateSessionInternal( |
81 const std::string& content_name, | 65 const std::string& content_name, |
82 int component, | 66 int component, |
83 const std::string& ice_ufrag, | 67 const std::string& ice_ufrag, |
84 const std::string& ice_pwd); | 68 const std::string& ice_pwd); |
85 | 69 |
86 private: | 70 private: |
87 void Construct(); | 71 void Construct(); |
88 | 72 |
89 rtc::NetworkManager* network_manager_; | 73 rtc::NetworkManager* network_manager_; |
90 rtc::PacketSocketFactory* socket_factory_; | 74 rtc::PacketSocketFactory* socket_factory_; |
91 const ServerAddresses stun_servers_; | 75 ServerAddresses stun_servers_; |
92 std::vector<RelayServerConfig> relays_; | 76 std::vector<RelayServerConfig> turn_servers_; |
93 bool allow_tcp_listen_; | 77 bool allow_tcp_listen_; |
94 }; | 78 }; |
95 | 79 |
96 struct PortConfiguration; | 80 struct PortConfiguration; |
97 class AllocationSequence; | 81 class AllocationSequence; |
98 | 82 |
99 class BasicPortAllocatorSession : public PortAllocatorSession, | 83 class BasicPortAllocatorSession : public PortAllocatorSession, |
100 public rtc::MessageHandler { | 84 public rtc::MessageHandler { |
101 public: | 85 public: |
102 BasicPortAllocatorSession(BasicPortAllocator* allocator, | 86 BasicPortAllocatorSession(BasicPortAllocator* allocator, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 bool running_; // set when StartGetAllPorts is called | 181 bool running_; // set when StartGetAllPorts is called |
198 bool allocation_sequences_created_; | 182 bool allocation_sequences_created_; |
199 std::vector<PortConfiguration*> configs_; | 183 std::vector<PortConfiguration*> configs_; |
200 std::vector<AllocationSequence*> sequences_; | 184 std::vector<AllocationSequence*> sequences_; |
201 std::vector<PortData> ports_; | 185 std::vector<PortData> ports_; |
202 | 186 |
203 friend class AllocationSequence; | 187 friend class AllocationSequence; |
204 }; | 188 }; |
205 | 189 |
206 // Records configuration information useful in creating ports. | 190 // Records configuration information useful in creating ports. |
| 191 // TODO(deadbeef): Rename "relay" to "turn_server" in this struct. |
207 struct PortConfiguration : public rtc::MessageData { | 192 struct PortConfiguration : public rtc::MessageData { |
208 // TODO(jiayl): remove |stun_address| when Chrome is updated. | 193 // TODO(jiayl): remove |stun_address| when Chrome is updated. |
209 rtc::SocketAddress stun_address; | 194 rtc::SocketAddress stun_address; |
210 ServerAddresses stun_servers; | 195 ServerAddresses stun_servers; |
211 std::string username; | 196 std::string username; |
212 std::string password; | 197 std::string password; |
213 | 198 |
214 typedef std::vector<RelayServerConfig> RelayList; | 199 typedef std::vector<RelayServerConfig> RelayList; |
215 RelayList relays; | 200 RelayList relays; |
216 | 201 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 rtc::scoped_ptr<rtc::AsyncPacketSocket> udp_socket_; | 312 rtc::scoped_ptr<rtc::AsyncPacketSocket> udp_socket_; |
328 // There will be only one udp port per AllocationSequence. | 313 // There will be only one udp port per AllocationSequence. |
329 UDPPort* udp_port_; | 314 UDPPort* udp_port_; |
330 std::vector<TurnPort*> turn_ports_; | 315 std::vector<TurnPort*> turn_ports_; |
331 int phase_; | 316 int phase_; |
332 }; | 317 }; |
333 | 318 |
334 } // namespace cricket | 319 } // namespace cricket |
335 | 320 |
336 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ | 321 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
OLD | NEW |