| 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 17 matching lines...) Expand all Loading... |
| 28 // Lifetime chosen for STUN ports on low-cost networks. | 28 // Lifetime chosen for STUN ports on low-cost networks. |
| 29 const int INFINITE_LIFETIME = -1; | 29 const int INFINITE_LIFETIME = -1; |
| 30 // Lifetime for STUN ports on high-cost networks: 2 minutes | 30 // Lifetime for STUN ports on high-cost networks: 2 minutes |
| 31 const int HIGH_COST_PORT_KEEPALIVE_LIFETIME = 2 * 60 * 1000; | 31 const int HIGH_COST_PORT_KEEPALIVE_LIFETIME = 2 * 60 * 1000; |
| 32 | 32 |
| 33 // Handles a binding request sent to the STUN server. | 33 // Handles a binding request sent to the STUN server. |
| 34 class StunBindingRequest : public StunRequest { | 34 class StunBindingRequest : public StunRequest { |
| 35 public: | 35 public: |
| 36 StunBindingRequest(UDPPort* port, | 36 StunBindingRequest(UDPPort* port, |
| 37 const rtc::SocketAddress& addr, | 37 const rtc::SocketAddress& addr, |
| 38 uint32_t start_time, | 38 int64_t start_time, |
| 39 int lifetime) | 39 int lifetime) |
| 40 : port_(port), | 40 : port_(port), |
| 41 server_addr_(addr), | 41 server_addr_(addr), |
| 42 start_time_(start_time), | 42 start_time_(start_time), |
| 43 lifetime_(lifetime) {} | 43 lifetime_(lifetime) {} |
| 44 | 44 |
| 45 virtual ~StunBindingRequest() { | 45 virtual ~StunBindingRequest() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 const rtc::SocketAddress& server_addr() const { return server_addr_; } | 48 const rtc::SocketAddress& server_addr() const { return server_addr_; } |
| 49 | 49 |
| 50 virtual void Prepare(StunMessage* request) override { | 50 virtual void Prepare(StunMessage* request) override { |
| 51 request->SetType(STUN_BINDING_REQUEST); | 51 request->SetType(STUN_BINDING_REQUEST); |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual void OnResponse(StunMessage* response) override { | 54 virtual void OnResponse(StunMessage* response) override { |
| 55 const StunAddressAttribute* addr_attr = | 55 const StunAddressAttribute* addr_attr = |
| 56 response->GetAddress(STUN_ATTR_MAPPED_ADDRESS); | 56 response->GetAddress(STUN_ATTR_MAPPED_ADDRESS); |
| 57 if (!addr_attr) { | 57 if (!addr_attr) { |
| 58 LOG(LS_ERROR) << "Binding response missing mapped address."; | 58 LOG(LS_ERROR) << "Binding response missing mapped address."; |
| 59 } else if (addr_attr->family() != STUN_ADDRESS_IPV4 && | 59 } else if (addr_attr->family() != STUN_ADDRESS_IPV4 && |
| 60 addr_attr->family() != STUN_ADDRESS_IPV6) { | 60 addr_attr->family() != STUN_ADDRESS_IPV6) { |
| 61 LOG(LS_ERROR) << "Binding address has bad family"; | 61 LOG(LS_ERROR) << "Binding address has bad family"; |
| 62 } else { | 62 } else { |
| 63 rtc::SocketAddress addr(addr_attr->ipaddr(), addr_attr->port()); | 63 rtc::SocketAddress addr(addr_attr->ipaddr(), addr_attr->port()); |
| 64 port_->OnStunBindingRequestSucceeded(server_addr_, addr); | 64 port_->OnStunBindingRequestSucceeded(server_addr_, addr); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // The keep-alive requests will be stopped after its lifetime has passed. | 67 // The keep-alive requests will be stopped after its lifetime has passed. |
| 68 if (WithinLifetime(rtc::Time())) { | 68 if (WithinLifetime(rtc::Time64())) { |
| 69 port_->requests_.SendDelayed( | 69 port_->requests_.SendDelayed( |
| 70 new StunBindingRequest(port_, server_addr_, start_time_, lifetime_), | 70 new StunBindingRequest(port_, server_addr_, start_time_, lifetime_), |
| 71 port_->stun_keepalive_delay()); | 71 port_->stun_keepalive_delay()); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void OnErrorResponse(StunMessage* response) override { | 75 virtual void OnErrorResponse(StunMessage* response) override { |
| 76 const StunErrorCodeAttribute* attr = response->GetErrorCode(); | 76 const StunErrorCodeAttribute* attr = response->GetErrorCode(); |
| 77 if (!attr) { | 77 if (!attr) { |
| 78 LOG(LS_ERROR) << "Bad allocate response error code"; | 78 LOG(LS_ERROR) << "Bad allocate response error code"; |
| 79 } else { | 79 } else { |
| 80 LOG(LS_ERROR) << "Binding error response:" | 80 LOG(LS_ERROR) << "Binding error response:" |
| 81 << " class=" << attr->eclass() | 81 << " class=" << attr->eclass() |
| 82 << " number=" << attr->number() << " reason='" | 82 << " number=" << attr->number() << " reason='" |
| 83 << attr->reason() << "'"; | 83 << attr->reason() << "'"; |
| 84 } | 84 } |
| 85 | 85 |
| 86 port_->OnStunBindingOrResolveRequestFailed(server_addr_); | 86 port_->OnStunBindingOrResolveRequestFailed(server_addr_); |
| 87 | 87 |
| 88 uint32_t now = rtc::Time(); | 88 int64_t now = rtc::Time64(); |
| 89 if (WithinLifetime(now) && | 89 if (WithinLifetime(now) && |
| 90 rtc::TimeDiff(now, start_time_) < RETRY_TIMEOUT) { | 90 rtc::TimeDiff64(now, start_time_) < RETRY_TIMEOUT) { |
| 91 port_->requests_.SendDelayed( | 91 port_->requests_.SendDelayed( |
| 92 new StunBindingRequest(port_, server_addr_, start_time_, lifetime_), | 92 new StunBindingRequest(port_, server_addr_, start_time_, lifetime_), |
| 93 port_->stun_keepalive_delay()); | 93 port_->stun_keepalive_delay()); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 virtual void OnTimeout() override { | 96 virtual void OnTimeout() override { |
| 97 LOG(LS_ERROR) << "Binding request timed out from " | 97 LOG(LS_ERROR) << "Binding request timed out from " |
| 98 << port_->GetLocalAddress().ToSensitiveString() << " (" | 98 << port_->GetLocalAddress().ToSensitiveString() << " (" |
| 99 << port_->Network()->name() << ")"; | 99 << port_->Network()->name() << ")"; |
| 100 | 100 |
| 101 port_->OnStunBindingOrResolveRequestFailed(server_addr_); | 101 port_->OnStunBindingOrResolveRequestFailed(server_addr_); |
| 102 } | 102 } |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 // Returns true if |now| is within the lifetime of the request (a negative | 105 // Returns true if |now| is within the lifetime of the request (a negative |
| 106 // lifetime means infinite). | 106 // lifetime means infinite). |
| 107 bool WithinLifetime(uint32_t now) const { | 107 bool WithinLifetime(int64_t now) const { |
| 108 return lifetime_ < 0 || rtc::TimeDiff(now, start_time_) <= lifetime_; | 108 return lifetime_ < 0 || rtc::TimeDiff64(now, start_time_) <= lifetime_; |
| 109 } | 109 } |
| 110 UDPPort* port_; | 110 UDPPort* port_; |
| 111 const rtc::SocketAddress server_addr_; | 111 const rtc::SocketAddress server_addr_; |
| 112 | 112 |
| 113 uint32_t start_time_; | 113 int64_t start_time_; |
| 114 // The time duration for which this request will be rescheduled. | 114 // The time duration for which this request will be rescheduled. |
| 115 int lifetime_; | 115 int lifetime_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 UDPPort::AddressResolver::AddressResolver( | 118 UDPPort::AddressResolver::AddressResolver( |
| 119 rtc::PacketSocketFactory* factory) | 119 rtc::PacketSocketFactory* factory) |
| 120 : socket_factory_(factory) {} | 120 : socket_factory_(factory) {} |
| 121 | 121 |
| 122 UDPPort::AddressResolver::~AddressResolver() { | 122 UDPPort::AddressResolver::~AddressResolver() { |
| 123 for (ResolverMap::iterator it = resolvers_.begin(); | 123 for (ResolverMap::iterator it = resolvers_.begin(); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| 407 void UDPPort::SendStunBindingRequest(const rtc::SocketAddress& stun_addr) { | 407 void UDPPort::SendStunBindingRequest(const rtc::SocketAddress& stun_addr) { |
| 408 if (stun_addr.IsUnresolvedIP()) { | 408 if (stun_addr.IsUnresolvedIP()) { |
| 409 ResolveStunAddress(stun_addr); | 409 ResolveStunAddress(stun_addr); |
| 410 | 410 |
| 411 } else if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND) { | 411 } else if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND) { |
| 412 // Check if |server_addr_| is compatible with the port's ip. | 412 // Check if |server_addr_| is compatible with the port's ip. |
| 413 if (IsCompatibleAddress(stun_addr)) { | 413 if (IsCompatibleAddress(stun_addr)) { |
| 414 requests_.Send(new StunBindingRequest(this, stun_addr, rtc::Time(), | 414 requests_.Send(new StunBindingRequest(this, stun_addr, rtc::Time64(), |
| 415 stun_keepalive_lifetime_)); | 415 stun_keepalive_lifetime_)); |
| 416 } else { | 416 } else { |
| 417 // Since we can't send stun messages to the server, we should mark this | 417 // Since we can't send stun messages to the server, we should mark this |
| 418 // port ready. | 418 // port ready. |
| 419 LOG(LS_WARNING) << "STUN server address is incompatible."; | 419 LOG(LS_WARNING) << "STUN server address is incompatible."; |
| 420 OnStunBindingOrResolveRequestFailed(stun_addr); | 420 OnStunBindingOrResolveRequestFailed(stun_addr); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 } | 423 } |
| 424 | 424 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 const std::vector<Candidate>& existing_candidates = Candidates(); | 519 const std::vector<Candidate>& existing_candidates = Candidates(); |
| 520 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); | 520 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); |
| 521 for (; it != existing_candidates.end(); ++it) { | 521 for (; it != existing_candidates.end(); ++it) { |
| 522 if (it->address() == addr) | 522 if (it->address() == addr) |
| 523 return true; | 523 return true; |
| 524 } | 524 } |
| 525 return false; | 525 return false; |
| 526 } | 526 } |
| 527 | 527 |
| 528 } // namespace cricket | 528 } // namespace cricket |
| OLD | NEW |