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 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 rtc::Network* network, | 163 rtc::Network* network, |
164 rtc::AsyncPacketSocket* socket, | 164 rtc::AsyncPacketSocket* socket, |
165 const std::string& username, | 165 const std::string& username, |
166 const std::string& password, | 166 const std::string& password, |
167 const std::string& origin, | 167 const std::string& origin, |
168 bool emit_local_for_anyaddress) | 168 bool emit_local_for_anyaddress) |
169 : Port(thread, | 169 : Port(thread, |
170 LOCAL_PORT_TYPE, | 170 LOCAL_PORT_TYPE, |
171 factory, | 171 factory, |
172 network, | 172 network, |
173 socket->GetLocalAddress().ipaddr(), | |
174 username, | 173 username, |
175 password), | 174 password), |
176 requests_(thread), | 175 requests_(thread), |
177 socket_(socket), | 176 socket_(socket), |
178 error_(0), | 177 error_(0), |
179 ready_(false), | 178 ready_(false), |
180 stun_keepalive_delay_(KEEPALIVE_DELAY), | 179 stun_keepalive_delay_(KEEPALIVE_DELAY), |
181 emit_local_for_anyaddress_(emit_local_for_anyaddress) { | 180 emit_local_for_anyaddress_(emit_local_for_anyaddress) { |
182 requests_.set_origin(origin); | 181 requests_.set_origin(origin); |
183 } | 182 } |
184 | 183 |
185 UDPPort::UDPPort(rtc::Thread* thread, | 184 UDPPort::UDPPort(rtc::Thread* thread, |
186 rtc::PacketSocketFactory* factory, | 185 rtc::PacketSocketFactory* factory, |
187 rtc::Network* network, | 186 rtc::Network* network, |
188 const rtc::IPAddress& ip, | |
189 uint16_t min_port, | 187 uint16_t min_port, |
190 uint16_t max_port, | 188 uint16_t max_port, |
191 const std::string& username, | 189 const std::string& username, |
192 const std::string& password, | 190 const std::string& password, |
193 const std::string& origin, | 191 const std::string& origin, |
194 bool emit_local_for_anyaddress) | 192 bool emit_local_for_anyaddress) |
195 : Port(thread, | 193 : Port(thread, |
196 LOCAL_PORT_TYPE, | 194 LOCAL_PORT_TYPE, |
197 factory, | 195 factory, |
198 network, | 196 network, |
199 ip, | |
200 min_port, | 197 min_port, |
201 max_port, | 198 max_port, |
202 username, | 199 username, |
203 password), | 200 password), |
204 requests_(thread), | 201 requests_(thread), |
205 socket_(NULL), | 202 socket_(NULL), |
206 error_(0), | 203 error_(0), |
207 ready_(false), | 204 ready_(false), |
208 stun_keepalive_delay_(KEEPALIVE_DELAY), | 205 stun_keepalive_delay_(KEEPALIVE_DELAY), |
209 emit_local_for_anyaddress_(emit_local_for_anyaddress) { | 206 emit_local_for_anyaddress_(emit_local_for_anyaddress) { |
210 requests_.set_origin(origin); | 207 requests_.set_origin(origin); |
211 } | 208 } |
212 | 209 |
213 bool UDPPort::Init() { | 210 bool UDPPort::Init() { |
214 stun_keepalive_lifetime_ = GetStunKeepaliveLifetime(); | 211 stun_keepalive_lifetime_ = GetStunKeepaliveLifetime(); |
215 if (!SharedSocket()) { | 212 if (!SharedSocket()) { |
216 RTC_DCHECK(socket_ == NULL); | 213 RTC_DCHECK(socket_ == NULL); |
217 socket_ = socket_factory()->CreateUdpSocket( | 214 socket_ = socket_factory()->CreateUdpSocket( |
218 rtc::SocketAddress(ip(), 0), min_port(), max_port()); | 215 rtc::SocketAddress(Network()->GetBestIP(), 0), min_port(), max_port()); |
219 if (!socket_) { | 216 if (!socket_) { |
220 LOG_J(LS_WARNING, this) << "UDP socket creation failed"; | 217 LOG_J(LS_WARNING, this) << "UDP socket creation failed"; |
221 return false; | 218 return false; |
222 } | 219 } |
223 socket_->SignalReadPacket.connect(this, &UDPPort::OnReadPacket); | 220 socket_->SignalReadPacket.connect(this, &UDPPort::OnReadPacket); |
224 } | 221 } |
225 socket_->SignalSentPacket.connect(this, &UDPPort::OnSentPacket); | 222 socket_->SignalSentPacket.connect(this, &UDPPort::OnSentPacket); |
226 socket_->SignalReadyToSend.connect(this, &UDPPort::OnReadyToSend); | 223 socket_->SignalReadyToSend.connect(this, &UDPPort::OnReadyToSend); |
227 socket_->SignalAddressReady.connect(this, &UDPPort::OnLocalAddressReady); | 224 socket_->SignalAddressReady.connect(this, &UDPPort::OnLocalAddressReady); |
228 requests_.SignalSendPacket.connect(this, &UDPPort::OnSendPacket); | 225 requests_.SignalSendPacket.connect(this, &UDPPort::OnSendPacket); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 LOG_J(LS_INFO, this) << "Starting STUN host lookup for " | 369 LOG_J(LS_INFO, this) << "Starting STUN host lookup for " |
373 << stun_addr.ToSensitiveString(); | 370 << stun_addr.ToSensitiveString(); |
374 resolver_->Resolve(stun_addr); | 371 resolver_->Resolve(stun_addr); |
375 } | 372 } |
376 | 373 |
377 void UDPPort::OnResolveResult(const rtc::SocketAddress& input, | 374 void UDPPort::OnResolveResult(const rtc::SocketAddress& input, |
378 int error) { | 375 int error) { |
379 RTC_DCHECK(resolver_.get() != NULL); | 376 RTC_DCHECK(resolver_.get() != NULL); |
380 | 377 |
381 rtc::SocketAddress resolved; | 378 rtc::SocketAddress resolved; |
382 if (error != 0 || | 379 if (error != 0 || !resolver_->GetResolvedAddress( |
383 !resolver_->GetResolvedAddress(input, ip().family(), &resolved)) { | 380 input, Network()->GetBestIP().family(), &resolved)) { |
384 LOG_J(LS_WARNING, this) << "StunPort: stun host lookup received error " | 381 LOG_J(LS_WARNING, this) << "StunPort: stun host lookup received error " |
385 << error; | 382 << error; |
386 OnStunBindingOrResolveRequestFailed(input); | 383 OnStunBindingOrResolveRequestFailed(input); |
387 return; | 384 return; |
388 } | 385 } |
389 | 386 |
390 server_addresses_.erase(input); | 387 server_addresses_.erase(input); |
391 | 388 |
392 if (server_addresses_.find(resolved) == server_addresses_.end()) { | 389 if (server_addresses_.find(resolved) == server_addresses_.end()) { |
393 server_addresses_.insert(resolved); | 390 server_addresses_.insert(resolved); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 const std::vector<Candidate>& existing_candidates = Candidates(); | 507 const std::vector<Candidate>& existing_candidates = Candidates(); |
511 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); | 508 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); |
512 for (; it != existing_candidates.end(); ++it) { | 509 for (; it != existing_candidates.end(); ++it) { |
513 if (it->address() == addr) | 510 if (it->address() == addr) |
514 return true; | 511 return true; |
515 } | 512 } |
516 return false; | 513 return false; |
517 } | 514 } |
518 | 515 |
519 } // namespace cricket | 516 } // namespace cricket |
OLD | NEW |