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