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

Side by Side Diff: webrtc/p2p/base/fakeportallocator.h

Issue 2097653002: Add virtual Initialize methods to PortAllocator and NetworkManager. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing typo in test. Created 4 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/network.h ('k') | webrtc/p2p/base/portallocator.h » ('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 2010 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2010 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
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 bool sent_binding_response_ = false; 83 bool sent_binding_response_ = false;
84 }; 84 };
85 85
86 // A FakePortAllocatorSession can be used with either a real or fake socket 86 // A FakePortAllocatorSession can be used with either a real or fake socket
87 // factory. It gathers a single loopback port, using IPv6 if available and 87 // factory. It gathers a single loopback port, using IPv6 if available and
88 // not disabled. 88 // not disabled.
89 class FakePortAllocatorSession : public PortAllocatorSession { 89 class FakePortAllocatorSession : public PortAllocatorSession {
90 public: 90 public:
91 FakePortAllocatorSession(PortAllocator* allocator, 91 FakePortAllocatorSession(PortAllocator* allocator,
92 rtc::Thread* worker_thread, 92 rtc::Thread* network_thread,
93 rtc::PacketSocketFactory* factory, 93 rtc::PacketSocketFactory* factory,
94 const std::string& content_name, 94 const std::string& content_name,
95 int component, 95 int component,
96 const std::string& ice_ufrag, 96 const std::string& ice_ufrag,
97 const std::string& ice_pwd) 97 const std::string& ice_pwd)
98 : PortAllocatorSession(content_name, 98 : PortAllocatorSession(content_name,
99 component, 99 component,
100 ice_ufrag, 100 ice_ufrag,
101 ice_pwd, 101 ice_pwd,
102 allocator->flags()), 102 allocator->flags()),
103 worker_thread_(worker_thread), 103 network_thread_(network_thread),
104 factory_(factory), 104 factory_(factory),
105 ipv4_network_("network", 105 ipv4_network_("network",
106 "unittest", 106 "unittest",
107 rtc::IPAddress(INADDR_LOOPBACK), 107 rtc::IPAddress(INADDR_LOOPBACK),
108 32), 108 32),
109 ipv6_network_("network", 109 ipv6_network_("network",
110 "unittest", 110 "unittest",
111 rtc::IPAddress(in6addr_loopback), 111 rtc::IPAddress(in6addr_loopback),
112 64), 112 64),
113 port_(), 113 port_(),
114 running_(false), 114 running_(false),
115 port_config_count_(0), 115 port_config_count_(0),
116 stun_servers_(allocator->stun_servers()), 116 stun_servers_(allocator->stun_servers()),
117 turn_servers_(allocator->turn_servers()) { 117 turn_servers_(allocator->turn_servers()) {
118 ipv4_network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); 118 ipv4_network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK));
119 ipv6_network_.AddIP(rtc::IPAddress(in6addr_loopback)); 119 ipv6_network_.AddIP(rtc::IPAddress(in6addr_loopback));
120 } 120 }
121 121
122 void SetCandidateFilter(uint32_t filter) override { 122 void SetCandidateFilter(uint32_t filter) override {
123 candidate_filter_ = filter; 123 candidate_filter_ = filter;
124 } 124 }
125 125
126 void StartGettingPorts() override { 126 void StartGettingPorts() override {
127 if (!port_) { 127 if (!port_) {
128 rtc::Network& network = 128 rtc::Network& network =
129 (rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6)) 129 (rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6))
130 ? ipv6_network_ 130 ? ipv6_network_
131 : ipv4_network_; 131 : ipv4_network_;
132 port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network, 132 port_.reset(TestUDPPort::Create(network_thread_, factory_, &network,
133 network.GetBestIP(), 0, 0, username(), 133 network.GetBestIP(), 0, 0, username(),
134 password(), std::string(), false)); 134 password(), std::string(), false));
135 port_->SignalDestroyed.connect( 135 port_->SignalDestroyed.connect(
136 this, &FakePortAllocatorSession::OnPortDestroyed); 136 this, &FakePortAllocatorSession::OnPortDestroyed);
137 AddPort(port_.get()); 137 AddPort(port_.get());
138 } 138 }
139 ++port_config_count_; 139 ++port_config_count_;
140 running_ = true; 140 running_ = true;
141 } 141 }
142 142
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 SignalCandidatesReady(this, candidates); 188 SignalCandidatesReady(this, candidates);
189 189
190 allocation_done_ = true; 190 allocation_done_ = true;
191 SignalCandidatesAllocationDone(this); 191 SignalCandidatesAllocationDone(this);
192 } 192 }
193 void OnPortDestroyed(cricket::PortInterface* port) { 193 void OnPortDestroyed(cricket::PortInterface* port) {
194 // Don't want to double-delete port if it deletes itself. 194 // Don't want to double-delete port if it deletes itself.
195 port_.release(); 195 port_.release();
196 } 196 }
197 197
198 rtc::Thread* worker_thread_; 198 rtc::Thread* network_thread_;
199 rtc::PacketSocketFactory* factory_; 199 rtc::PacketSocketFactory* factory_;
200 rtc::Network ipv4_network_; 200 rtc::Network ipv4_network_;
201 rtc::Network ipv6_network_; 201 rtc::Network ipv6_network_;
202 std::unique_ptr<cricket::Port> port_; 202 std::unique_ptr<cricket::Port> port_;
203 bool running_; 203 bool running_;
204 int port_config_count_; 204 int port_config_count_;
205 std::vector<Candidate> candidates_; 205 std::vector<Candidate> candidates_;
206 std::vector<PortInterface*> ready_ports_; 206 std::vector<PortInterface*> ready_ports_;
207 bool allocation_done_ = false; 207 bool allocation_done_ = false;
208 ServerAddresses stun_servers_; 208 ServerAddresses stun_servers_;
209 std::vector<RelayServerConfig> turn_servers_; 209 std::vector<RelayServerConfig> turn_servers_;
210 uint32_t candidate_filter_ = CF_ALL; 210 uint32_t candidate_filter_ = CF_ALL;
211 int transport_info_update_count_ = 0; 211 int transport_info_update_count_ = 0;
212 }; 212 };
213 213
214 class FakePortAllocator : public cricket::PortAllocator { 214 class FakePortAllocator : public cricket::PortAllocator {
215 public: 215 public:
216 FakePortAllocator(rtc::Thread* worker_thread, 216 FakePortAllocator(rtc::Thread* network_thread,
217 rtc::PacketSocketFactory* factory) 217 rtc::PacketSocketFactory* factory)
218 : worker_thread_(worker_thread), factory_(factory) { 218 : network_thread_(network_thread), factory_(factory) {
219 if (factory_ == NULL) { 219 if (factory_ == NULL) {
220 owned_factory_.reset(new rtc::BasicPacketSocketFactory(worker_thread_)); 220 owned_factory_.reset(new rtc::BasicPacketSocketFactory(network_thread_));
221 factory_ = owned_factory_.get(); 221 factory_ = owned_factory_.get();
222 } 222 }
223 } 223 }
224 224
225 void Initialize() override {
226 // Port allocator should be initialized on the network thread.
227 RTC_CHECK(network_thread_->IsCurrent());
228 initialized_ = true;
229 }
230
225 void SetNetworkIgnoreMask(int network_ignore_mask) override {} 231 void SetNetworkIgnoreMask(int network_ignore_mask) override {}
226 232
227 cricket::PortAllocatorSession* CreateSessionInternal( 233 cricket::PortAllocatorSession* CreateSessionInternal(
228 const std::string& content_name, 234 const std::string& content_name,
229 int component, 235 int component,
230 const std::string& ice_ufrag, 236 const std::string& ice_ufrag,
231 const std::string& ice_pwd) override { 237 const std::string& ice_pwd) override {
232 return new FakePortAllocatorSession(this, worker_thread_, factory_, 238 return new FakePortAllocatorSession(this, network_thread_, factory_,
233 content_name, component, ice_ufrag, 239 content_name, component, ice_ufrag,
234 ice_pwd); 240 ice_pwd);
235 } 241 }
236 242
243 bool initialized() const { return initialized_; }
244
237 private: 245 private:
238 rtc::Thread* worker_thread_; 246 rtc::Thread* network_thread_;
239 rtc::PacketSocketFactory* factory_; 247 rtc::PacketSocketFactory* factory_;
240 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_; 248 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_;
249 bool initialized_ = false;
241 }; 250 };
242 251
243 } // namespace cricket 252 } // namespace cricket
244 253
245 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ 254 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_
OLDNEW
« no previous file with comments | « webrtc/base/network.h ('k') | webrtc/p2p/base/portallocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698