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

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

Issue 1549633004: Fill the remote pwd in ice candidates when an ICE credential is received. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years 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/p2ptransportchannel.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
index 5101bf341117c2cebafc14f5734c6f612fd857e8..504affbf2b3a751bdf4997b26ebbcab949cdf334 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -354,10 +354,15 @@ void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag,
remote_ice_parameters_.push_back(new_ice);
}
+ // Update the pwd of remote candidate if needed.
+ for (RemoteCandidate& candidate : remote_candidates_) {
+ if (candidate.username() == ice_ufrag && candidate.password().empty()) {
pthatcher1 2015/12/28 21:33:59 Can you put a TODO in candidate.h to change userna
honghaiz3 2015/12/30 18:59:33 Added TODO... although I think there is no confusi
pthatcher1 2015/12/30 19:15:44 username() is more readable, but it's also wrong.
+ candidate.set_password(ice_pwd);
+ }
+ }
// We need to update the credentials for any peer reflexive candidates.
- std::vector<Connection*>::iterator it = connections_.begin();
- for (; it != connections_.end(); ++it) {
- (*it)->MaybeSetRemoteIceCredentials(ice_ufrag, ice_pwd);
+ for (Connection* conn : connections_) {
+ conn->MaybeSetRemoteIceCredentials(ice_ufrag, ice_pwd);
}
}
@@ -511,6 +516,7 @@ void P2PTransportChannel::OnUnknownAddress(
const Candidate* candidate = NULL;
std::string remote_password;
+ uint32_t remote_generation = 0;
for (it = remote_candidates_.begin(); it != remote_candidates_.end(); ++it) {
if (it->username() == remote_username) {
remote_password = it->password();
@@ -529,9 +535,10 @@ void P2PTransportChannel::OnUnknownAddress(
// adding remote candidate, so we need to set the password to the shared
// password if the user name matches.
if (remote_password.empty()) {
- IceParameters* current_ice = remote_ice();
- if (current_ice && remote_username == current_ice->ufrag) {
- remote_password = current_ice->pwd;
+ const IceParameters* ice_param =
+ FindRemoteIce(remote_username, &remote_generation);
+ if (ice_param != nullptr) {
+ remote_password = ice_param->pwd;
pthatcher1 2015/12/28 21:33:59 If the remote_username is empty (not signalled), d
honghaiz3 2015/12/30 18:59:33 If the remote_username is not signalled, remote uf
pthatcher1 2015/12/30 19:15:44 Sorry, when I said "not signalled", I meant "not s
}
}
@@ -564,9 +571,9 @@ void P2PTransportChannel::OnUnknownAddress(
// If the source transport address of the request does not match any
// existing remote candidates, it represents a new peer reflexive remote
// candidate.
- remote_candidate =
- Candidate(component(), ProtoToString(proto), address, 0,
- remote_username, remote_password, PRFLX_PORT_TYPE, 0U, "");
+ remote_candidate = Candidate(component(), ProtoToString(proto), address, 0,
+ remote_username, remote_password,
+ PRFLX_PORT_TYPE, remote_generation, "");
// From RFC 5245, section-7.2.1.3:
// The foundation of the candidate is set to an arbitrary value, different
@@ -626,6 +633,22 @@ void P2PTransportChannel::OnRoleConflict(PortInterface* port) {
// from Transport.
}
+const IceParameters* P2PTransportChannel::FindRemoteIce(
+ const std::string& ufrag,
+ uint32_t* generation) {
+ const auto& params = remote_ice_parameters_;
+ auto it = std::find_if(
+ params.rbegin(), params.rend(),
+ [ufrag](const IceParameters& param) { return param.ufrag == ufrag; });
+ if (it == params.rend()) {
+ // If not found, assume the next (future) generation.
+ *generation = static_cast<uint32_t>(params.size());
pthatcher1 2015/12/28 21:33:59 I find it a bit confusing that we fill in the gene
honghaiz3 2015/12/30 18:59:33 Done.
+ return nullptr;
+ }
+ *generation = params.rend() - it - 1;
+ return &(*it);
+}
+
void P2PTransportChannel::OnNominated(Connection* conn) {
ASSERT(worker_thread_ == rtc::Thread::Current());
ASSERT(ice_role_ == ICEROLE_CONTROLLED);
@@ -788,22 +811,11 @@ bool P2PTransportChannel::FindConnection(
uint32_t P2PTransportChannel::GetRemoteCandidateGeneration(
const Candidate& candidate) {
- // We need to keep track of the remote ice restart so newer
- // connections are prioritized over the older.
- const auto& params = remote_ice_parameters_;
+ // If the candidate contains ufrag, use that to find the generation.
pthatcher1 2015/12/28 21:33:59 contains ufrag => has a ufrag use that => use it
honghaiz3 2015/12/30 18:59:33 Done.
if (!candidate.username().empty()) {
- // If remote side sets the ufrag, we use that to determine the candidate
- // generation.
- // Search backward as it is more likely to find it near the end.
- auto it = std::find_if(params.rbegin(), params.rend(),
- [candidate](const IceParameters& param) {
- return param.ufrag == candidate.username();
- });
- if (it == params.rend()) {
- // If not found, assume it is the next (future) generation.
- return static_cast<uint32_t>(remote_ice_parameters_.size());
- }
- return params.rend() - it - 1;
+ uint32_t generation = 0;
+ FindRemoteIce(candidate.username(), &generation);
+ return generation;
}
// If candidate generation is set, use that.
if (candidate.generation() > 0) {

Powered by Google App Engine
This is Rietveld 408576698