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

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

Issue 1668073002: Add network cost as part of the connection comparison. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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
Index: webrtc/p2p/base/port.cc
diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc
index 7993cc02bc082819340ca1e80b974dd91716f995..0f6a750d2efb8fd19e99e2eacb9224cbcf095981 100644
--- a/webrtc/p2p/base/port.cc
+++ b/webrtc/p2p/base/port.cc
@@ -195,6 +195,9 @@ void Port::Construct() {
ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH);
password_ = rtc::CreateRandomString(ICE_PWD_LENGTH);
}
+ // TODO(honghaiz): Make it configurable.
+ network_cost_ = (network_->type() == rtc::ADAPTER_TYPE_CELLULAR) ? 99 : 0;
pthatcher1 2016/02/04 23:16:20 Yeah, I definitely would prefer an enum, something
juberti2 2016/02/04 23:31:10 I don't really like the enum since it's not easily
pthatcher1 2016/02/04 23:51:18 The algorithm we have designed so far only works f
honghaiz3 2016/02/05 01:36:46 Perhaps, we can use enum to define a few integer v
pthatcher1 2016/02/05 01:42:35 Thinking about this some more: I do now see merit
+
LOG_J(LS_INFO, this) << "Port created";
}
@@ -250,6 +253,7 @@ void Port::AddAddress(const rtc::SocketAddress& address,
c.set_password(password_);
c.set_network_name(network_->name());
c.set_network_type(network_->type());
+ c.set_network_cost(network_cost_);
c.set_generation(generation_);
c.set_related_address(related_address);
c.set_foundation(
@@ -692,6 +696,11 @@ class ConnectionRequest : public StunRequest {
static_cast<uint32_t>(connection_->pings_since_last_response_.size() -
1)));
}
+ uint32_t network_cost = connection_->port()->network_cost();
+ if (network_cost > 0) {
+ request->AddAttribute(
+ new StunUInt32Attribute(STUN_ATTR_NETWORK_COST, network_cost));
+ }
// Adding ICE_CONTROLLED or ICE_CONTROLLING attribute based on the role.
if (connection_->port()->GetIceRole() == ICEROLE_CONTROLLING) {
@@ -1151,6 +1160,11 @@ std::string Connection::ToDebugId() const {
return ss.str();
}
+int Connection::ComputeNetworkCost() const {
pthatcher1 2016/02/04 23:16:20 Everwhere you have "networkcost", please just make
juberti2 2016/02/04 23:31:10 Not sure about this. Network cost seems clearer th
pthatcher1 2016/02/04 23:51:18 I don't feel strongly one way or the other, I just
honghaiz3 2016/02/05 01:36:46 When I put "cost" in the sdp, I intended to save a
pthatcher1 2016/02/12 00:07:12 Saving bytes in SDP is of minor importance. If so
honghaiz3 2016/02/12 19:28:43 Done.
+ // TODO(honghaiz): Will add rtt as part of the network cost.
+ return local_candidate().network_cost() + remote_candidate_.network_cost();
+}
+
std::string Connection::ToString() const {
const char CONNECT_STATE_ABBREV[2] = {
'-', // not connected (false)
@@ -1389,6 +1403,7 @@ void Connection::MaybeAddPrflxCandidate(ConnectionRequest* request,
new_local_candidate.set_password(local_candidate().password());
new_local_candidate.set_network_name(local_candidate().network_name());
new_local_candidate.set_network_type(local_candidate().network_type());
+ new_local_candidate.set_network_cost(local_candidate().network_cost());
new_local_candidate.set_related_address(local_candidate().address());
new_local_candidate.set_foundation(ComputeFoundation(
PRFLX_PORT_TYPE, local_candidate().protocol(),

Powered by Google App Engine
This is Rietveld 408576698