OLD | NEW |
---|---|
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 network_thread_(network_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_(), | |
114 port_config_count_(0), | 113 port_config_count_(0), |
115 stun_servers_(allocator->stun_servers()), | 114 stun_servers_(allocator->stun_servers()), |
116 turn_servers_(allocator->turn_servers()) { | 115 turn_servers_(allocator->turn_servers()) { |
117 ipv4_network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); | 116 ipv4_network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); |
118 ipv6_network_.AddIP(rtc::IPAddress(in6addr_loopback)); | 117 ipv6_network_.AddIP(rtc::IPAddress(in6addr_loopback)); |
119 } | 118 } |
120 | 119 |
121 void SetCandidateFilter(uint32_t filter) override { | 120 void SetCandidateFilter(uint32_t filter) override { |
122 candidate_filter_ = filter; | 121 candidate_filter_ = filter; |
123 } | 122 } |
124 | 123 |
124 Port* CreatePort(rtc::Network* network) { | |
125 Port* port = TestUDPPort::Create(network_thread_, factory_, network, | |
126 network->GetBestIP(), 0, 0, username(), | |
127 password(), std::string(), false); | |
128 port->SignalDestroyed.connect(this, | |
129 &FakePortAllocatorSession::OnPortDestroyed); | |
skvlad
2016/10/10 18:23:04
Very minor: can this me moved to inside AddPort?
honghaiz3
2016/10/10 19:35:28
Done.
| |
130 AddPort(port); | |
131 return port; | |
132 } | |
133 | |
125 void StartGettingPorts() override { | 134 void StartGettingPorts() override { |
126 if (!port_) { | 135 if (!ipv4_port_) { |
127 rtc::Network& network = | 136 ipv4_port_.reset(CreatePort(&ipv4_network_)); |
128 (rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6)) | 137 } |
129 ? ipv6_network_ | 138 if (!ipv6_port_ && rtc::HasIPv6Enabled() && |
130 : ipv4_network_; | 139 (flags() & PORTALLOCATOR_ENABLE_IPV6)) { |
131 port_.reset(TestUDPPort::Create(network_thread_, factory_, &network, | 140 ipv6_port_.reset(CreatePort(&ipv6_network_)); |
132 network.GetBestIP(), 0, 0, username(), | |
133 password(), std::string(), false)); | |
134 port_->SignalDestroyed.connect( | |
135 this, &FakePortAllocatorSession::OnPortDestroyed); | |
136 AddPort(port_.get()); | |
137 } | 141 } |
138 ++port_config_count_; | 142 ++port_config_count_; |
139 running_ = true; | 143 running_ = true; |
140 } | 144 } |
141 | 145 |
142 void StopGettingPorts() override { running_ = false; } | 146 void StopGettingPorts() override { running_ = false; } |
143 bool IsGettingPorts() override { return running_; } | 147 bool IsGettingPorts() override { return running_; } |
144 void ClearGettingPorts() override {} | 148 void ClearGettingPorts() override {} |
145 | 149 |
146 std::vector<PortInterface*> ReadyPorts() const override { | 150 std::vector<PortInterface*> ReadyPorts() const override { |
147 return ready_ports_; | 151 return ready_ports_; |
148 } | 152 } |
149 std::vector<Candidate> ReadyCandidates() const override { | 153 std::vector<Candidate> ReadyCandidates() const override { |
150 return candidates_; | 154 return candidates_; |
151 } | 155 } |
152 void PruneAllPorts() override { port_->Prune(); } | 156 void PruneAllPorts() override { |
157 if (ipv4_port_) { | |
158 ipv4_port_->Prune(); | |
159 } | |
160 if (ipv6_port_) { | |
161 ipv6_port_->Prune(); | |
162 } | |
163 } | |
153 bool CandidatesAllocationDone() const override { return allocation_done_; } | 164 bool CandidatesAllocationDone() const override { return allocation_done_; } |
154 | 165 |
155 int port_config_count() { return port_config_count_; } | 166 int port_config_count() { return port_config_count_; } |
156 | 167 |
157 const ServerAddresses& stun_servers() const { return stun_servers_; } | 168 const ServerAddresses& stun_servers() const { return stun_servers_; } |
158 | 169 |
159 const std::vector<RelayServerConfig>& turn_servers() const { | 170 const std::vector<RelayServerConfig>& turn_servers() const { |
160 return turn_servers_; | 171 return turn_servers_; |
161 } | 172 } |
162 | 173 |
(...skipping 24 matching lines...) Expand all Loading... | |
187 void OnPortComplete(cricket::Port* port) { | 198 void OnPortComplete(cricket::Port* port) { |
188 const std::vector<Candidate>& candidates = port->Candidates(); | 199 const std::vector<Candidate>& candidates = port->Candidates(); |
189 candidates_.insert(candidates_.end(), candidates.begin(), candidates.end()); | 200 candidates_.insert(candidates_.end(), candidates.begin(), candidates.end()); |
190 SignalCandidatesReady(this, candidates); | 201 SignalCandidatesReady(this, candidates); |
191 | 202 |
192 allocation_done_ = true; | 203 allocation_done_ = true; |
193 SignalCandidatesAllocationDone(this); | 204 SignalCandidatesAllocationDone(this); |
194 } | 205 } |
195 void OnPortDestroyed(cricket::PortInterface* port) { | 206 void OnPortDestroyed(cricket::PortInterface* port) { |
196 // Don't want to double-delete port if it deletes itself. | 207 // Don't want to double-delete port if it deletes itself. |
197 port_.release(); | 208 if (port == ipv4_port_.get()) { |
209 ipv4_port_.release(); | |
210 } else if (port == ipv6_port_.get()) { | |
211 ipv6_port_.release(); | |
212 } | |
198 } | 213 } |
199 | 214 |
200 rtc::Thread* network_thread_; | 215 rtc::Thread* network_thread_; |
201 rtc::PacketSocketFactory* factory_; | 216 rtc::PacketSocketFactory* factory_; |
202 rtc::Network ipv4_network_; | 217 rtc::Network ipv4_network_; |
203 rtc::Network ipv6_network_; | 218 rtc::Network ipv6_network_; |
204 std::unique_ptr<cricket::Port> port_; | 219 std::unique_ptr<cricket::Port> ipv4_port_; |
220 std::unique_ptr<cricket::Port> ipv6_port_; | |
205 int port_config_count_; | 221 int port_config_count_; |
206 std::vector<Candidate> candidates_; | 222 std::vector<Candidate> candidates_; |
207 std::vector<PortInterface*> ready_ports_; | 223 std::vector<PortInterface*> ready_ports_; |
208 bool allocation_done_ = false; | 224 bool allocation_done_ = false; |
209 ServerAddresses stun_servers_; | 225 ServerAddresses stun_servers_; |
210 std::vector<RelayServerConfig> turn_servers_; | 226 std::vector<RelayServerConfig> turn_servers_; |
211 uint32_t candidate_filter_ = CF_ALL; | 227 uint32_t candidate_filter_ = CF_ALL; |
212 int transport_info_update_count_ = 0; | 228 int transport_info_update_count_ = 0; |
213 bool running_ = false; | 229 bool running_ = false; |
214 }; | 230 }; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 private: | 263 private: |
248 rtc::Thread* network_thread_; | 264 rtc::Thread* network_thread_; |
249 rtc::PacketSocketFactory* factory_; | 265 rtc::PacketSocketFactory* factory_; |
250 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_; | 266 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_; |
251 bool initialized_ = false; | 267 bool initialized_ = false; |
252 }; | 268 }; |
253 | 269 |
254 } // namespace cricket | 270 } // namespace cricket |
255 | 271 |
256 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ | 272 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_ |
OLD | NEW |