Replace hostCandidate with address and port in RTCPeerConnectionIceErrorEvent

Bug: chromium:1013564
Change-Id: Ie1bb86ed6a2a7d73fe6ee666f973d809ed05a7ed
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161084
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Eldar Rello <elrello@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#30004}
diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h
index 72e20b9..2ae290c 100644
--- a/api/peer_connection_interface.h
+++ b/api/peer_connection_interface.h
@@ -1203,6 +1203,14 @@
                                    int error_code,
                                    const std::string& error_text) {}
 
+  // Gathering of an ICE candidate failed.
+  // See https://w3c.github.io/webrtc-pc/#event-icecandidateerror
+  virtual void OnIceCandidateError(const std::string& address,
+                                   int port,
+                                   const std::string& url,
+                                   int error_code,
+                                   const std::string& error_text) {}
+
   // Ice candidates have been removed.
   // TODO(honghaiz): Make this a pure virtual method when all its subclasses
   // implement it.
diff --git a/p2p/base/port.h b/p2p/base/port.h
index 84340e8..4200bed 100644
--- a/p2p/base/port.h
+++ b/p2p/base/port.h
@@ -128,16 +128,19 @@
 
 struct IceCandidateErrorEvent {
   IceCandidateErrorEvent() = default;
-  IceCandidateErrorEvent(std::string host_candidate,
+  IceCandidateErrorEvent(std::string address,
+                         int port,
                          std::string url,
                          int error_code,
                          std::string error_text)
-      : host_candidate(std::move(host_candidate)),
+      : address(std::move(address)),
+        port(port),
         url(std::move(url)),
         error_code(error_code),
         error_text(std::move(error_text)) {}
 
-  std::string host_candidate;
+  std::string address;
+  int port = 0;
   std::string url;
   int error_code = 0;
   std::string error_text;
diff --git a/p2p/base/stun_port.cc b/p2p/base/stun_port.cc
index e259e8b..4e1a1f6 100644
--- a/p2p/base/stun_port.cc
+++ b/p2p/base/stun_port.cc
@@ -544,8 +544,9 @@
   rtc::StringBuilder url;
   url << "stun:" << stun_server_addr.ToString();
   SignalCandidateError(
-      this, IceCandidateErrorEvent(GetLocalAddress().ToSensitiveString(),
-                                   url.str(), error_code, reason));
+      this, IceCandidateErrorEvent(GetLocalAddress().HostAsSensitiveURIString(),
+                                   GetLocalAddress().port(), url.str(),
+                                   error_code, reason));
   if (bind_request_failed_servers_.find(stun_server_addr) !=
       bind_request_failed_servers_.end()) {
     return;
diff --git a/p2p/base/stun_port_unittest.cc b/p2p/base/stun_port_unittest.cc
index f0a2117..dfc7236 100644
--- a/p2p/base/stun_port_unittest.cc
+++ b/p2p/base/stun_port_unittest.cc
@@ -226,9 +226,8 @@
                            cricket::SERVER_NOT_REACHABLE_ERROR, kTimeoutMs,
                            fake_clock);
   ASSERT_NE(error_event_.error_text.find("."), std::string::npos);
-  ASSERT_NE(
-      error_event_.host_candidate.find(kLocalAddr.HostAsSensitiveURIString()),
-      std::string::npos);
+  ASSERT_NE(error_event_.address.find(kLocalAddr.HostAsSensitiveURIString()),
+            std::string::npos);
   std::string server_url = "stun:" + kBadAddr.ToString();
   ASSERT_EQ(error_event_.url, server_url);
 }
diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc
index 0dc67aa..ed82e35 100644
--- a/p2p/base/turn_port.cc
+++ b/p2p/base/turn_port.cc
@@ -885,7 +885,8 @@
   thread()->Post(RTC_FROM_HERE, this, MSG_ALLOCATE_ERROR);
   SignalCandidateError(
       this,
-      IceCandidateErrorEvent(GetLocalAddress().ToSensitiveString(),
+      IceCandidateErrorEvent(GetLocalAddress().HostAsSensitiveURIString(),
+                             GetLocalAddress().port(),
                              ReconstructedServerUrl(true /* use_hostname */),
                              error_code, reason));
 }
diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc
index f9e0205..e8c1a6e 100644
--- a/p2p/base/turn_port_unittest.cc
+++ b/p2p/base/turn_port_unittest.cc
@@ -931,9 +931,9 @@
   EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, STUN_ERROR_GLOBAL_FAILURE,
                            kSimulatedRtt, fake_clock_);
   ASSERT_NE(error_event_.error_text.find("."), std::string::npos);
-  ASSERT_NE(
-      error_event_.host_candidate.find(kLocalAddr2.HostAsSensitiveURIString()),
-      std::string::npos);
+  ASSERT_NE(error_event_.address.find(kLocalAddr2.HostAsSensitiveURIString()),
+            std::string::npos);
+  ASSERT_NE(error_event_.port, 0);
   std::string server_url =
       "turn:" + kTurnTcpIntAddr.ToString() + "?transport=tcp";
   ASSERT_EQ(error_event_.url, server_url);
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 1339638..0d43da4 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -4736,14 +4736,17 @@
   Observer()->OnIceCandidate(candidate.get());
 }
 
-void PeerConnection::OnIceCandidateError(const std::string& host_candidate,
+void PeerConnection::OnIceCandidateError(const std::string& address,
+                                         int port,
                                          const std::string& url,
                                          int error_code,
                                          const std::string& error_text) {
   if (IsClosed()) {
     return;
   }
-  Observer()->OnIceCandidateError(host_candidate, url, error_code, error_text);
+  Observer()->OnIceCandidateError(address, port, url, error_code, error_text);
+  // Leftover not to break wpt test during migration to the new API.
+  Observer()->OnIceCandidateError(address + ":", url, error_code, error_text);
 }
 
 void PeerConnection::OnIceCandidatesRemoved(
@@ -6348,7 +6351,7 @@
 
 void PeerConnection::OnTransportControllerCandidateError(
     const cricket::IceCandidateErrorEvent& event) {
-  OnIceCandidateError(event.host_candidate, event.url, event.error_code,
+  OnIceCandidateError(event.address, event.port, event.url, event.error_code,
                       event.error_text);
 }
 
diff --git a/pc/peer_connection.h b/pc/peer_connection.h
index 0e1a1f8..9065982 100644
--- a/pc/peer_connection.h
+++ b/pc/peer_connection.h
@@ -569,7 +569,8 @@
   void OnIceCandidate(std::unique_ptr<IceCandidateInterface> candidate)
       RTC_RUN_ON(signaling_thread());
   // Gathering of an ICE candidate failed.
-  void OnIceCandidateError(const std::string& host_candidate,
+  void OnIceCandidateError(const std::string& address,
+                           int port,
                            const std::string& url,
                            int error_code,
                            const std::string& error_text)
diff --git a/pc/peer_connection_integrationtest.cc b/pc/peer_connection_integrationtest.cc
index dd06b65..d68b058 100644
--- a/pc/peer_connection_integrationtest.cc
+++ b/pc/peer_connection_integrationtest.cc
@@ -977,11 +977,12 @@
     SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
     last_candidate_gathered_ = candidate->candidate();
   }
-  void OnIceCandidateError(const std::string& host_candidate,
+  void OnIceCandidateError(const std::string& address,
+                           int port,
                            const std::string& url,
                            int error_code,
                            const std::string& error_text) override {
-    error_event_ = cricket::IceCandidateErrorEvent(host_candidate, url,
+    error_event_ = cricket::IceCandidateErrorEvent(address, port, url,
                                                    error_code, error_text);
   }
   void OnDataChannel(
@@ -5708,8 +5709,7 @@
   EXPECT_EQ_WAIT(401, caller()->error_event().error_code, kDefaultTimeout);
   EXPECT_EQ("Unauthorized", caller()->error_event().error_text);
   EXPECT_EQ("turn:88.88.88.0:3478?transport=udp", caller()->error_event().url);
-  EXPECT_NE(std::string::npos,
-            caller()->error_event().host_candidate.find(":"));
+  EXPECT_NE(caller()->error_event().address, "");
 }
 
 TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
diff --git a/test/peer_scenario/peer_scenario_client.cc b/test/peer_scenario/peer_scenario_client.cc
index d8f2b65..782cd21 100644
--- a/test/peer_scenario/peer_scenario_client.cc
+++ b/test/peer_scenario/peer_scenario_client.cc
@@ -79,12 +79,13 @@
     for (const auto& handler : handlers_->on_ice_candidate)
       handler(candidate);
   }
-  void OnIceCandidateError(const std::string& host_candidate,
+  void OnIceCandidateError(const std::string& address,
+                           int port,
                            const std::string& url,
                            int error_code,
                            const std::string& error_text) override {
     for (const auto& handler : handlers_->on_ice_candidate_error)
-      handler(host_candidate, url, error_code, error_text);
+      handler(address, port, url, error_code, error_text);
   }
   void OnIceCandidatesRemoved(
       const std::vector<cricket::Candidate>& candidates) override {
diff --git a/test/peer_scenario/peer_scenario_client.h b/test/peer_scenario/peer_scenario_client.h
index 404ae90..7517304 100644
--- a/test/peer_scenario/peer_scenario_client.h
+++ b/test/peer_scenario/peer_scenario_client.h
@@ -48,8 +48,11 @@
         on_ice_gathering_change;
     std::vector<std::function<void(const IceCandidateInterface*)>>
         on_ice_candidate;
-    std::vector<std::function<
-        void(const std::string&, const std::string&, int, const std::string&)>>
+    std::vector<std::function<void(const std::string&,
+                                   int,
+                                   const std::string&,
+                                   int,
+                                   const std::string&)>>
         on_ice_candidate_error;
     std::vector<std::function<void(const std::vector<cricket::Candidate>&)>>
         on_ice_candidates_removed;