Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(991)

Unified Diff: webrtc/p2p/base/stunport.cc

Issue 1976683003: Update the type and cost of existing networks if its type is found later by network monitor (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Minor changes Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | webrtc/p2p/base/stunport_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/stunport.cc
diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc
index 8ed8c44887238ca5e260113783a96e21e6731a76..15c00957efd32be85d8afb2e76ec3b20e2c90f80 100644
--- a/webrtc/p2p/base/stunport.cc
+++ b/webrtc/p2p/base/stunport.cc
@@ -25,22 +25,14 @@ namespace cricket {
// TODO: Move these to a common place (used in relayport too)
const int KEEPALIVE_DELAY = 10 * 1000; // 10 seconds - sort timeouts
const int RETRY_TIMEOUT = 50 * 1000; // 50 seconds
-// Lifetime chosen for STUN ports on low-cost networks.
-const int INFINITE_LIFETIME = -1;
-// Lifetime for STUN ports on high-cost networks: 2 minutes
-const int HIGH_COST_PORT_KEEPALIVE_LIFETIME = 2 * 60 * 1000;
// Handles a binding request sent to the STUN server.
class StunBindingRequest : public StunRequest {
public:
StunBindingRequest(UDPPort* port,
const rtc::SocketAddress& addr,
- int64_t start_time,
- int lifetime)
- : port_(port),
- server_addr_(addr),
- start_time_(start_time),
- lifetime_(lifetime) {}
+ int64_t start_time)
+ : port_(port), server_addr_(addr), start_time_(start_time) {}
virtual ~StunBindingRequest() {
}
@@ -67,7 +59,7 @@ class StunBindingRequest : public StunRequest {
// The keep-alive requests will be stopped after its lifetime has passed.
if (WithinLifetime(rtc::TimeMillis())) {
port_->requests_.SendDelayed(
- new StunBindingRequest(port_, server_addr_, start_time_, lifetime_),
+ new StunBindingRequest(port_, server_addr_, start_time_),
port_->stun_keepalive_delay());
}
}
@@ -89,7 +81,7 @@ class StunBindingRequest : public StunRequest {
if (WithinLifetime(now) &&
rtc::TimeDiff(now, start_time_) < RETRY_TIMEOUT) {
port_->requests_.SendDelayed(
- new StunBindingRequest(port_, server_addr_, start_time_, lifetime_),
+ new StunBindingRequest(port_, server_addr_, start_time_),
port_->stun_keepalive_delay());
}
}
@@ -105,14 +97,13 @@ class StunBindingRequest : public StunRequest {
// Returns true if |now| is within the lifetime of the request (a negative
// lifetime means infinite).
bool WithinLifetime(int64_t now) const {
- return lifetime_ < 0 || rtc::TimeDiff(now, start_time_) <= lifetime_;
+ int lifetime = port_->stun_keepalive_lifetime();
+ return lifetime < 0 || rtc::TimeDiff(now, start_time_) <= lifetime;
}
UDPPort* port_;
const rtc::SocketAddress server_addr_;
int64_t start_time_;
- // The time duration for which this request will be rescheduled.
- int lifetime_;
};
UDPPort::AddressResolver::AddressResolver(
@@ -220,12 +211,7 @@ UDPPort::UDPPort(rtc::Thread* thread,
}
bool UDPPort::Init() {
- // If this is a zero-cost network, it will keep on sending STUN binding
- // requests indefinitely to keep the NAT binding alive. Otherwise, stop
- // sending STUN binding requests after HIGH_COST_PORT_KEEPALIVE_LIFETIME.
- stun_keepalive_lifetime_ = (network_cost() == 0)
- ? INFINITE_LIFETIME
- : HIGH_COST_PORT_KEEPALIVE_LIFETIME;
+ stun_keepalive_lifetime_ = GetStunKeepaliveLifetime();
if (!SharedSocket()) {
ASSERT(socket_ == NULL);
socket_ = socket_factory()->CreateUdpSocket(
@@ -299,6 +285,11 @@ int UDPPort::SendTo(const void* data, size_t size,
return sent;
}
+void UDPPort::UpdateNetworkCost() {
+ Port::UpdateNetworkCost();
+ stun_keepalive_lifetime_ = GetStunKeepaliveLifetime();
+}
+
int UDPPort::SetOption(rtc::Socket::Option opt, int value) {
return socket_->SetOption(opt, value);
}
@@ -411,8 +402,8 @@ void UDPPort::SendStunBindingRequest(const rtc::SocketAddress& stun_addr) {
} else if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND) {
// Check if |server_addr_| is compatible with the port's ip.
if (IsCompatibleAddress(stun_addr)) {
- requests_.Send(new StunBindingRequest(this, stun_addr, rtc::TimeMillis(),
- stun_keepalive_lifetime_));
+ requests_.Send(
+ new StunBindingRequest(this, stun_addr, rtc::TimeMillis()));
} else {
// Since we can't send stun messages to the server, we should mark this
// port ready.
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | webrtc/p2p/base/stunport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698