| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return error_; | 299 return error_; |
| 300 } | 300 } |
| 301 | 301 |
| 302 void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket, | 302 void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket, |
| 303 const rtc::SocketAddress& address) { | 303 const rtc::SocketAddress& address) { |
| 304 // When adapter enumeration is disabled and binding to the any address, the | 304 // When adapter enumeration is disabled and binding to the any address, the |
| 305 // default local address will be issued as a candidate instead if | 305 // default local address will be issued as a candidate instead if |
| 306 // |emit_local_for_anyaddress| is true. This is to allow connectivity for | 306 // |emit_local_for_anyaddress| is true. This is to allow connectivity for |
| 307 // applications which absolutely requires a HOST candidate. | 307 // applications which absolutely requires a HOST candidate. |
| 308 rtc::SocketAddress addr = address; | 308 rtc::SocketAddress addr = address; |
| 309 |
| 310 // If MaybeSetDefaultLocalAddress fails, we keep the "any" IP so that at |
| 311 // least the port is listening. |
| 309 MaybeSetDefaultLocalAddress(&addr); | 312 MaybeSetDefaultLocalAddress(&addr); |
| 310 | 313 |
| 311 AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "", | 314 AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "", |
| 312 LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, false); | 315 LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, false); |
| 313 MaybePrepareStunCandidate(); | 316 MaybePrepareStunCandidate(); |
| 314 } | 317 } |
| 315 | 318 |
| 316 void UDPPort::OnReadPacket(rtc::AsyncPacketSocket* socket, | 319 void UDPPort::OnReadPacket(rtc::AsyncPacketSocket* socket, |
| 317 const char* data, | 320 const char* data, |
| 318 size_t size, | 321 size_t size, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 requests_.Send(new StunBindingRequest(this, true, stun_addr)); | 400 requests_.Send(new StunBindingRequest(this, true, stun_addr)); |
| 398 } else { | 401 } else { |
| 399 // Since we can't send stun messages to the server, we should mark this | 402 // Since we can't send stun messages to the server, we should mark this |
| 400 // port ready. | 403 // port ready. |
| 401 LOG(LS_WARNING) << "STUN server address is incompatible."; | 404 LOG(LS_WARNING) << "STUN server address is incompatible."; |
| 402 OnStunBindingOrResolveRequestFailed(stun_addr); | 405 OnStunBindingOrResolveRequestFailed(stun_addr); |
| 403 } | 406 } |
| 404 } | 407 } |
| 405 } | 408 } |
| 406 | 409 |
| 407 void UDPPort::MaybeSetDefaultLocalAddress(rtc::SocketAddress* addr) const { | 410 bool UDPPort::MaybeSetDefaultLocalAddress(rtc::SocketAddress* addr) const { |
| 408 if (!addr->IsAnyIP() || !emit_local_for_anyaddress_ || | 411 if (!addr->IsAnyIP() || !emit_local_for_anyaddress_ || |
| 409 !Network()->default_local_address_provider()) { | 412 !Network()->default_local_address_provider()) { |
| 410 return; | 413 return true; |
| 411 } | 414 } |
| 412 rtc::IPAddress default_address; | 415 rtc::IPAddress default_address; |
| 413 bool result = | 416 bool result = |
| 414 Network()->default_local_address_provider()->GetDefaultLocalAddress( | 417 Network()->default_local_address_provider()->GetDefaultLocalAddress( |
| 415 addr->family(), &default_address); | 418 addr->family(), &default_address); |
| 416 RTC_DCHECK(result && !default_address.IsNil()); | 419 if (!result || default_address.IsNil()) { |
| 420 return false; |
| 421 } |
| 422 |
| 417 addr->SetIP(default_address); | 423 addr->SetIP(default_address); |
| 424 return true; |
| 418 } | 425 } |
| 419 | 426 |
| 420 void UDPPort::OnStunBindingRequestSucceeded( | 427 void UDPPort::OnStunBindingRequestSucceeded( |
| 421 const rtc::SocketAddress& stun_server_addr, | 428 const rtc::SocketAddress& stun_server_addr, |
| 422 const rtc::SocketAddress& stun_reflected_addr) { | 429 const rtc::SocketAddress& stun_reflected_addr) { |
| 423 if (bind_request_succeeded_servers_.find(stun_server_addr) != | 430 if (bind_request_succeeded_servers_.find(stun_server_addr) != |
| 424 bind_request_succeeded_servers_.end()) { | 431 bind_request_succeeded_servers_.end()) { |
| 425 return; | 432 return; |
| 426 } | 433 } |
| 427 bind_request_succeeded_servers_.insert(stun_server_addr); | 434 bind_request_succeeded_servers_.insert(stun_server_addr); |
| 428 | 435 |
| 429 // If socket is shared and |stun_reflected_addr| is equal to local socket | 436 // If socket is shared and |stun_reflected_addr| is equal to local socket |
| 430 // address, or if the same address has been added by another STUN server, | 437 // address, or if the same address has been added by another STUN server, |
| 431 // then discarding the stun address. | 438 // then discarding the stun address. |
| 432 // For STUN, related address is the local socket address. | 439 // For STUN, related address is the local socket address. |
| 433 if ((!SharedSocket() || stun_reflected_addr != socket_->GetLocalAddress()) && | 440 if ((!SharedSocket() || stun_reflected_addr != socket_->GetLocalAddress()) && |
| 434 !HasCandidateWithAddress(stun_reflected_addr)) { | 441 !HasCandidateWithAddress(stun_reflected_addr)) { |
| 435 | 442 |
| 436 rtc::SocketAddress related_address = socket_->GetLocalAddress(); | 443 rtc::SocketAddress related_address = socket_->GetLocalAddress(); |
| 437 MaybeSetDefaultLocalAddress(&related_address); | 444 // If we can't stamp the related address correctly, empty it to avoid leak. |
| 438 if (!(candidate_filter() & CF_HOST)) { | 445 if (!MaybeSetDefaultLocalAddress(&related_address) || |
| 446 !(candidate_filter() & CF_HOST)) { |
| 439 // If candidate filter doesn't have CF_HOST specified, empty raddr to | 447 // If candidate filter doesn't have CF_HOST specified, empty raddr to |
| 440 // avoid local address leakage. | 448 // avoid local address leakage. |
| 441 related_address = rtc::EmptySocketAddressWithFamily( | 449 related_address = rtc::EmptySocketAddressWithFamily( |
| 442 related_address.family()); | 450 related_address.family()); |
| 443 } | 451 } |
| 444 | 452 |
| 445 AddAddress(stun_reflected_addr, socket_->GetLocalAddress(), related_address, | 453 AddAddress(stun_reflected_addr, socket_->GetLocalAddress(), related_address, |
| 446 UDP_PROTOCOL_NAME, "", "", STUN_PORT_TYPE, | 454 UDP_PROTOCOL_NAME, "", "", STUN_PORT_TYPE, |
| 447 ICE_TYPE_PREFERENCE_SRFLX, 0, false); | 455 ICE_TYPE_PREFERENCE_SRFLX, 0, false); |
| 448 } | 456 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 const std::vector<Candidate>& existing_candidates = Candidates(); | 504 const std::vector<Candidate>& existing_candidates = Candidates(); |
| 497 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); | 505 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); |
| 498 for (; it != existing_candidates.end(); ++it) { | 506 for (; it != existing_candidates.end(); ++it) { |
| 499 if (it->address() == addr) | 507 if (it->address() == addr) |
| 500 return true; | 508 return true; |
| 501 } | 509 } |
| 502 return false; | 510 return false; |
| 503 } | 511 } |
| 504 | 512 |
| 505 } // namespace cricket | 513 } // namespace cricket |
| OLD | NEW |