Add 16-bit network id to the candidate signaling.
Also include that in the stun-ping request as part of the
network-info attribute.
Change the network cost to be 16 bits.
BUG=
Review URL: https://codereview.webrtc.org/1815473002
Cr-Commit-Position: refs/heads/master@{#12110}
diff --git a/webrtc/api/webrtcsdp.cc b/webrtc/api/webrtcsdp.cc
index 4a296d9..93d4acc 100644
--- a/webrtc/api/webrtcsdp.cc
+++ b/webrtc/api/webrtcsdp.cc
@@ -127,6 +127,7 @@
static const char kAttributeCandidateUfrag[] = "ufrag";
static const char kAttributeCandidatePwd[] = "pwd";
static const char kAttributeCandidateGeneration[] = "generation";
+static const char kAttributeCandidateNetworkId[] = "network-id";
static const char kAttributeCandidateNetworkCost[] = "network-cost";
static const char kAttributeFingerprint[] = "fingerprint";
static const char kAttributeSetup[] = "setup";
@@ -1092,7 +1093,8 @@
std::string username;
std::string password;
uint32_t generation = 0;
- uint32_t network_cost = 0;
+ uint16_t network_id = 0;
+ uint16_t network_cost = 0;
for (size_t i = current_position; i + 1 < fields.size(); ++i) {
// RFC 5245
// *(SP extension-att-name SP extension-att-value)
@@ -1104,10 +1106,15 @@
username = fields[++i];
} else if (fields[i] == kAttributeCandidatePwd) {
password = fields[++i];
+ } else if (fields[i] == kAttributeCandidateNetworkId) {
+ if (!GetValueFromString(first_line, fields[++i], &network_id, error)) {
+ return false;
+ }
} else if (fields[i] == kAttributeCandidateNetworkCost) {
if (!GetValueFromString(first_line, fields[++i], &network_cost, error)) {
return false;
}
+ network_cost = std::min(network_cost, cricket::kMaxNetworkCost);
} else {
// Skip the unknown extension.
++i;
@@ -1116,10 +1123,9 @@
*candidate = Candidate(component_id, cricket::ProtoToString(protocol),
address, priority, username, password, candidate_type,
- generation, foundation);
+ generation, foundation, network_id, network_cost);
candidate->set_related_address(related_address);
candidate->set_tcptype(tcptype);
- candidate->set_network_cost(std::min(network_cost, cricket::kMaxNetworkCost));
return true;
}
@@ -1814,6 +1820,9 @@
if (include_ufrag && !it->username().empty()) {
os << " " << kAttributeCandidateUfrag << " " << it->username();
}
+ if (it->network_id() > 0) {
+ os << " " << kAttributeCandidateNetworkId << " " << it->network_id();
+ }
if (it->network_cost() > 0) {
os << " " << kAttributeCandidateNetworkCost << " " << it->network_cost();
}
diff --git a/webrtc/api/webrtcsdp_unittest.cc b/webrtc/api/webrtcsdp_unittest.cc
index 9559701..c527204 100644
--- a/webrtc/api/webrtcsdp_unittest.cc
+++ b/webrtc/api/webrtcsdp_unittest.cc
@@ -2058,6 +2058,19 @@
candidate_with_ufrag));
message = webrtc::SdpSerializeCandidate(*jcandidate_);
EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
+
+ Candidate candidate_with_network_info(candidates_.front());
+ candidate_with_network_info.set_network_id(1);
+ jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
+ candidate_with_network_info));
+ message = webrtc::SdpSerializeCandidate(*jcandidate_);
+ EXPECT_EQ(std::string(kRawCandidate) + " network-id 1", message);
+ candidate_with_network_info.set_network_cost(999);
+ jcandidate_.reset(new JsepIceCandidate(std::string("audio"), 0,
+ candidate_with_network_info));
+ message = webrtc::SdpSerializeCandidate(*jcandidate_);
+ EXPECT_EQ(std::string(kRawCandidate) + " network-id 1 network-cost 999",
+ message);
}
// TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing
@@ -2325,6 +2338,7 @@
EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
EXPECT_TRUE(jcandidate.candidate().IsEquivalent(jcandidate_->candidate()));
+ EXPECT_EQ(0, jcandidate.candidate().network_cost());
// Candidate line without generation extension.
sdp = kSdpOneCandidate;
@@ -2336,6 +2350,22 @@
expected.set_generation(0);
EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
+ // Candidate with network id and/or cost.
+ sdp = kSdpOneCandidate;
+ Replace(" generation 2", " generation 2 network-id 2", &sdp);
+ EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
+ EXPECT_EQ(kDummyMid, jcandidate.sdp_mid());
+ EXPECT_EQ(kDummyIndex, jcandidate.sdp_mline_index());
+ expected = jcandidate_->candidate();
+ expected.set_network_id(2);
+ EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
+ EXPECT_EQ(0, jcandidate.candidate().network_cost());
+ // Add network cost
+ Replace(" network-id 2", " network-id 2 network-cost 9", &sdp);
+ EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
+ EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected));
+ EXPECT_EQ(9, jcandidate.candidate().network_cost());
+
sdp = kSdpTcpActiveCandidate;
EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate));
// Make a cricket::Candidate equivalent to kSdpTcpCandidate string.