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

Side by Side Diff: webrtc/p2p/client/basicportallocator.h

Issue 1414313003: Reland of Adding the ability to change ICE servers through SetConfiguration. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding "override" to applicable methods to fix compile warning. Created 5 years, 1 month 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/p2p/base/portallocator.h ('k') | webrtc/p2p/client/basicportallocator.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_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 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) override;
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,
103 const std::string& content_name, 87 const std::string& content_name,
104 int component, 88 int component,
105 const std::string& ice_ufrag, 89 const std::string& ice_ufrag,
106 const std::string& ice_pwd); 90 const std::string& ice_pwd);
107 ~BasicPortAllocatorSession(); 91 ~BasicPortAllocatorSession();
108 92
109 virtual BasicPortAllocator* allocator() { return allocator_; } 93 virtual BasicPortAllocator* allocator() { return allocator_; }
110 rtc::Thread* network_thread() { return network_thread_; } 94 rtc::Thread* network_thread() { return network_thread_; }
111 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } 95 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; }
112 96
113 virtual void StartGettingPorts(); 97 void StartGettingPorts() override;
114 virtual void StopGettingPorts(); 98 void StopGettingPorts() override;
115 virtual void ClearGettingPorts(); 99 void ClearGettingPorts() override;
116 virtual bool IsGettingPorts() { return running_; } 100 bool IsGettingPorts() override { return running_; }
117 101
118 protected: 102 protected:
119 // Starts the process of getting the port configurations. 103 // Starts the process of getting the port configurations.
120 virtual void GetPortConfigurations(); 104 virtual void GetPortConfigurations();
121 105
122 // Adds a port configuration that is now ready. Once we have one for each 106 // Adds a port configuration that is now ready. Once we have one for each
123 // network (or a timeout occurs), we will start allocating ports. 107 // network (or a timeout occurs), we will start allocating ports.
124 virtual void ConfigReady(PortConfiguration* config); 108 virtual void ConfigReady(PortConfiguration* config);
125 109
126 // MessageHandler. Can be overriden if message IDs do not conflict. 110 // MessageHandler. Can be overriden if message IDs do not conflict.
127 virtual void OnMessage(rtc::Message *message); 111 void OnMessage(rtc::Message* message) override;
128 112
129 private: 113 private:
130 class PortData { 114 class PortData {
131 public: 115 public:
132 PortData() : port_(NULL), sequence_(NULL), state_(STATE_INIT) {} 116 PortData() : port_(NULL), sequence_(NULL), state_(STATE_INIT) {}
133 PortData(Port* port, AllocationSequence* seq) 117 PortData(Port* port, AllocationSequence* seq)
134 : port_(port), sequence_(seq), state_(STATE_INIT) { 118 : port_(port), sequence_(seq), state_(STATE_INIT) {
135 } 119 }
136 120
137 Port* port() { return port_; } 121 Port* port() { return port_; }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/portallocator.h ('k') | webrtc/p2p/client/basicportallocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698