| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 const rtc::SocketAddress& base_address) { | 138 const rtc::SocketAddress& base_address) { |
| 139 std::ostringstream ost; | 139 std::ostringstream ost; |
| 140 ost << type << base_address.ipaddr().ToString() << protocol << relay_protocol; | 140 ost << type << base_address.ipaddr().ToString() << protocol << relay_protocol; |
| 141 return rtc::ToString<uint32_t>(rtc::ComputeCrc32(ost.str())); | 141 return rtc::ToString<uint32_t>(rtc::ComputeCrc32(ost.str())); |
| 142 } | 142 } |
| 143 | 143 |
| 144 Port::Port(rtc::Thread* thread, | 144 Port::Port(rtc::Thread* thread, |
| 145 const std::string& type, | 145 const std::string& type, |
| 146 rtc::PacketSocketFactory* factory, | 146 rtc::PacketSocketFactory* factory, |
| 147 rtc::Network* network, | 147 rtc::Network* network, |
| 148 const rtc::IPAddress& ip, | |
| 149 const std::string& username_fragment, | 148 const std::string& username_fragment, |
| 150 const std::string& password) | 149 const std::string& password) |
| 151 : thread_(thread), | 150 : thread_(thread), |
| 152 factory_(factory), | 151 factory_(factory), |
| 153 type_(type), | 152 type_(type), |
| 154 send_retransmit_count_attribute_(false), | 153 send_retransmit_count_attribute_(false), |
| 155 network_(network), | 154 network_(network), |
| 156 ip_(ip), | |
| 157 min_port_(0), | 155 min_port_(0), |
| 158 max_port_(0), | 156 max_port_(0), |
| 159 component_(ICE_CANDIDATE_COMPONENT_DEFAULT), | 157 component_(ICE_CANDIDATE_COMPONENT_DEFAULT), |
| 160 generation_(0), | 158 generation_(0), |
| 161 ice_username_fragment_(username_fragment), | 159 ice_username_fragment_(username_fragment), |
| 162 password_(password), | 160 password_(password), |
| 163 timeout_delay_(kPortTimeoutDelay), | 161 timeout_delay_(kPortTimeoutDelay), |
| 164 enable_port_packets_(false), | 162 enable_port_packets_(false), |
| 165 ice_role_(ICEROLE_UNKNOWN), | 163 ice_role_(ICEROLE_UNKNOWN), |
| 166 tiebreaker_(0), | 164 tiebreaker_(0), |
| 167 shared_socket_(true) { | 165 shared_socket_(true) { |
| 168 Construct(); | 166 Construct(); |
| 169 } | 167 } |
| 170 | 168 |
| 171 Port::Port(rtc::Thread* thread, | 169 Port::Port(rtc::Thread* thread, |
| 172 const std::string& type, | 170 const std::string& type, |
| 173 rtc::PacketSocketFactory* factory, | 171 rtc::PacketSocketFactory* factory, |
| 174 rtc::Network* network, | 172 rtc::Network* network, |
| 175 const rtc::IPAddress& ip, | |
| 176 uint16_t min_port, | 173 uint16_t min_port, |
| 177 uint16_t max_port, | 174 uint16_t max_port, |
| 178 const std::string& username_fragment, | 175 const std::string& username_fragment, |
| 179 const std::string& password) | 176 const std::string& password) |
| 180 : thread_(thread), | 177 : thread_(thread), |
| 181 factory_(factory), | 178 factory_(factory), |
| 182 type_(type), | 179 type_(type), |
| 183 send_retransmit_count_attribute_(false), | 180 send_retransmit_count_attribute_(false), |
| 184 network_(network), | 181 network_(network), |
| 185 ip_(ip), | |
| 186 min_port_(min_port), | 182 min_port_(min_port), |
| 187 max_port_(max_port), | 183 max_port_(max_port), |
| 188 component_(ICE_CANDIDATE_COMPONENT_DEFAULT), | 184 component_(ICE_CANDIDATE_COMPONENT_DEFAULT), |
| 189 generation_(0), | 185 generation_(0), |
| 190 ice_username_fragment_(username_fragment), | 186 ice_username_fragment_(username_fragment), |
| 191 password_(password), | 187 password_(password), |
| 192 timeout_delay_(kPortTimeoutDelay), | 188 timeout_delay_(kPortTimeoutDelay), |
| 193 enable_port_packets_(false), | 189 enable_port_packets_(false), |
| 194 ice_role_(ICEROLE_UNKNOWN), | 190 ice_role_(ICEROLE_UNKNOWN), |
| 195 tiebreaker_(0), | 191 tiebreaker_(0), |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 << addr.ToSensitiveString(); | 460 << addr.ToSensitiveString(); |
| 465 return true; | 461 return true; |
| 466 } | 462 } |
| 467 | 463 |
| 468 // Return the STUN message found. | 464 // Return the STUN message found. |
| 469 *out_msg = std::move(stun_msg); | 465 *out_msg = std::move(stun_msg); |
| 470 return true; | 466 return true; |
| 471 } | 467 } |
| 472 | 468 |
| 473 bool Port::IsCompatibleAddress(const rtc::SocketAddress& addr) { | 469 bool Port::IsCompatibleAddress(const rtc::SocketAddress& addr) { |
| 474 int family = ip().family(); | 470 // Get a representative IP for the Network this port is configured to use. |
| 471 rtc::IPAddress ip = network_->GetBestIP(); |
| 475 // We use single-stack sockets, so families must match. | 472 // We use single-stack sockets, so families must match. |
| 476 if (addr.family() != family) { | 473 if (addr.family() != ip.family()) { |
| 477 return false; | 474 return false; |
| 478 } | 475 } |
| 479 // Link-local IPv6 ports can only connect to other link-local IPv6 ports. | 476 // Link-local IPv6 ports can only connect to other link-local IPv6 ports. |
| 480 if (family == AF_INET6 && | 477 if (ip.family() == AF_INET6 && |
| 481 (IPIsLinkLocal(ip()) != IPIsLinkLocal(addr.ipaddr()))) { | 478 (IPIsLinkLocal(ip) != IPIsLinkLocal(addr.ipaddr()))) { |
| 482 return false; | 479 return false; |
| 483 } | 480 } |
| 484 return true; | 481 return true; |
| 485 } | 482 } |
| 486 | 483 |
| 487 bool Port::ParseStunUsername(const StunMessage* stun_msg, | 484 bool Port::ParseStunUsername(const StunMessage* stun_msg, |
| 488 std::string* local_ufrag, | 485 std::string* local_ufrag, |
| 489 std::string* remote_ufrag) const { | 486 std::string* remote_ufrag) const { |
| 490 // The packet must include a username that either begins or ends with our | 487 // The packet must include a username that either begins or ends with our |
| 491 // fragment. It should begin with our fragment if it is a request and it | 488 // fragment. It should begin with our fragment if it is a request and it |
| (...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 RTC_DCHECK(sent < 0); | 1630 RTC_DCHECK(sent < 0); |
| 1634 error_ = port_->GetError(); | 1631 error_ = port_->GetError(); |
| 1635 stats_.sent_discarded_packets++; | 1632 stats_.sent_discarded_packets++; |
| 1636 } else { | 1633 } else { |
| 1637 send_rate_tracker_.AddSamples(sent); | 1634 send_rate_tracker_.AddSamples(sent); |
| 1638 } | 1635 } |
| 1639 return sent; | 1636 return sent; |
| 1640 } | 1637 } |
| 1641 | 1638 |
| 1642 } // namespace cricket | 1639 } // namespace cricket |
| OLD | NEW |