From 2f3c01941bd51563ab9f2a731e81286be29f1c50 Mon Sep 17 00:00:00 2001 From: Jonas Oreland Date: Thu, 26 Mar 2020 12:59:44 +0100 Subject: [PATCH] Modify IceControllerInterface::SelectConnectionToPing - step 1 this is a NOP refactoring, that modify return type of IceControllerInterface::SelectConnectionToPing to a struct (rather than existing pair). The modification is done so that one can safely add new return values in the struct. Step 1) Create a typedef for return value. - merge downstream and change it to start using new type. Step 2) Change typedef to struct, adding constructors from old type to new type merge and change downstream to use "real" constructors Step 3) remove temporary constructors Step 4) Eat cake Each step requires a merge downstream, with corresponding changes there. Bug: chromium:1024965 Change-Id: I6ebb8658a77e0ef5c24acb382c0cb6413403c168 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/171691 Reviewed-by: Jonas Oreland Reviewed-by: Harald Alvestrand Commit-Queue: Jonas Oreland Cr-Commit-Position: refs/heads/master@{#30902} --- p2p/base/basic_ice_controller.cc | 6 +++--- p2p/base/basic_ice_controller.h | 4 ++-- p2p/base/ice_controller_interface.h | 7 +++++-- p2p/base/p2p_transport_channel.cc | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/p2p/base/basic_ice_controller.cc b/p2p/base/basic_ice_controller.cc index 09bc4f1f5f..32febb5a33 100644 --- a/p2p/base/basic_ice_controller.cc +++ b/p2p/base/basic_ice_controller.cc @@ -92,7 +92,7 @@ bool BasicIceController::HasPingableConnection() const { }); } -std::pair BasicIceController::SelectConnectionToPing( +IceControllerInterface::PingResult BasicIceController::SelectConnectionToPing( int64_t last_ping_sent_ms) { // When the selected connection is not receiving or not writable, or any // active connection has not been pinged enough times, use the weak ping @@ -110,8 +110,8 @@ std::pair BasicIceController::SelectConnectionToPing( if (rtc::TimeMillis() >= last_ping_sent_ms + ping_interval) { conn = FindNextPingableConnection(); } - int delay = std::min(ping_interval, check_receiving_interval()); - return std::make_pair(const_cast(conn), delay); + return std::make_pair(const_cast(conn), + std::min(ping_interval, check_receiving_interval())); } void BasicIceController::MarkConnectionPinged(const Connection* conn) { diff --git a/p2p/base/basic_ice_controller.h b/p2p/base/basic_ice_controller.h index ae1339fc03..2e462720f3 100644 --- a/p2p/base/basic_ice_controller.h +++ b/p2p/base/basic_ice_controller.h @@ -40,8 +40,8 @@ class BasicIceController : public IceControllerInterface { bool HasPingableConnection() const override; - std::pair SelectConnectionToPing( - int64_t last_ping_sent_ms) override; + PingResult SelectConnectionToPing(int64_t last_ping_sent_ms) override; + bool GetUseCandidateAttr(const Connection* conn, NominationMode mode, IceMode remote_ice_mode) const override; diff --git a/p2p/base/ice_controller_interface.h b/p2p/base/ice_controller_interface.h index 43bb88471b..ecfb0c845d 100644 --- a/p2p/base/ice_controller_interface.h +++ b/p2p/base/ice_controller_interface.h @@ -73,6 +73,10 @@ class IceControllerInterface { absl::optional recheck_event; }; + // A temporary typedef, so that we can migrate downstream + // to a new return value for SelectConnectionToPing. + typedef std::pair PingResult; + virtual ~IceControllerInterface() = default; // These setters are called when the state of P2PTransportChannel is mutated. @@ -90,8 +94,7 @@ class IceControllerInterface { virtual bool HasPingableConnection() const = 0; // Select a connection to Ping, or nullptr if none. - virtual std::pair SelectConnectionToPing( - int64_t last_ping_sent_ms) = 0; + virtual PingResult SelectConnectionToPing(int64_t last_ping_sent_ms) = 0; // Compute the "STUN_ATTR_USE_CANDIDATE" for |conn|. virtual bool GetUseCandidateAttr(const Connection* conn, diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 2a4ad59b55..fe6df2015f 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -1888,7 +1888,7 @@ void P2PTransportChannel::CheckAndPing() { UpdateConnectionStates(); auto result = ice_controller_->SelectConnectionToPing(last_ping_sent_ms_); - Connection* conn = result.first; + Connection* conn = const_cast(result.first); int delay = result.second; if (conn) {