From a8bc1378356454572596717faba6facb00a42d21 Mon Sep 17 00:00:00 2001 From: Tommi Date: Fri, 25 Mar 2022 13:26:29 +0100 Subject: [PATCH] Avoid touching port_ in Connection::ToString() after starting delete. Bug: webrtc:13865 Change-Id: Ia469c46642d7e305a50e57d9ea6ad873e633db4e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256808 Reviewed-by: Niels Moller Commit-Queue: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#36338} --- p2p/base/connection.cc | 52 +++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index ff6de5b121..673f0efbf9 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -1198,49 +1198,65 @@ uint32_t Connection::ComputeNetworkCost() const { std::string Connection::ToString() const { RTC_DCHECK_RUN_ON(network_thread_); - const absl::string_view CONNECT_STATE_ABBREV[2] = { + constexpr absl::string_view CONNECT_STATE_ABBREV[2] = { "-", // not connected (false) "C", // connected (true) }; - const absl::string_view RECEIVE_STATE_ABBREV[2] = { + constexpr absl::string_view RECEIVE_STATE_ABBREV[2] = { "-", // not receiving (false) "R", // receiving (true) }; - const absl::string_view WRITE_STATE_ABBREV[4] = { + constexpr absl::string_view WRITE_STATE_ABBREV[4] = { "W", // STATE_WRITABLE "w", // STATE_WRITE_UNRELIABLE "-", // STATE_WRITE_INIT "x", // STATE_WRITE_TIMEOUT }; - const absl::string_view ICESTATE[4] = { + constexpr absl::string_view ICESTATE[4] = { "W", // STATE_WAITING "I", // STATE_INPROGRESS "S", // STATE_SUCCEEDED "F" // STATE_FAILED }; - const absl::string_view SELECTED_STATE_ABBREV[2] = { + constexpr absl::string_view SELECTED_STATE_ABBREV[2] = { "-", // candidate pair not selected (false) "S", // selected (true) }; - const Candidate& local = local_candidate(); - const Candidate& remote = remote_candidate(); rtc::StringBuilder ss; - ss << "Conn[" << ToDebugId() << ":" << port_->content_name() << ":" - << port_->Network()->ToString() << ":" << local.id() << ":" - << local.component() << ":" << local.generation() << ":" << local.type() - << ":" << local.protocol() << ":" << local.address().ToSensitiveString() - << "->" << remote.id() << ":" << remote.component() << ":" - << remote.priority() << ":" << remote.type() << ":" << remote.protocol() - << ":" << remote.address().ToSensitiveString() << "|" - << CONNECT_STATE_ABBREV[connected()] << RECEIVE_STATE_ABBREV[receiving()] - << WRITE_STATE_ABBREV[write_state()] << ICESTATE[static_cast(state())] - << "|" << SELECTED_STATE_ABBREV[selected_] << "|" << remote_nomination() - << "|" << nomination_ << "|" << priority() << "|"; + ss << "Conn[" << ToDebugId(); + + if (pending_delete_) { + // No content name for pending delete, so temporarily substitute the name + // with a hash (rhyming with trash) and don't include any information about + // the network or candidates, state that belongs to a potentially deleted + // `port_`. + ss << ":#:"; + } else { + const Candidate& local = local_candidate(); + const Candidate& remote = remote_candidate(); + ss << ":" << port_->content_name() << ":" << port_->Network()->ToString() + << ":" << local.id() << ":" << local.component() << ":" + << local.generation() << ":" << local.type() << ":" << local.protocol() + << ":" << local.address().ToSensitiveString() << "->" << remote.id() + << ":" << remote.component() << ":" << remote.priority() << ":" + << remote.type() << ":" << remote.protocol() << ":" + << remote.address().ToSensitiveString() << "|"; + } + + ss << CONNECT_STATE_ABBREV[connected_] << RECEIVE_STATE_ABBREV[receiving_] + << WRITE_STATE_ABBREV[write_state_] << ICESTATE[static_cast(state_)] + << "|" << SELECTED_STATE_ABBREV[selected_] << "|" << remote_nomination_ + << "|" << nomination_ << "|"; + + if (!pending_delete_) + ss << priority() << "|"; + if (rtt_ < DEFAULT_RTT) { ss << rtt_ << "]"; } else { ss << "-]"; } + return ss.Release(); }