Rename VirtualSocketServer::SetDefaultRoute --> SetDefaultSourceAddress

and make docs a bit clearer.

Bug: None
Change-Id: I73504de96384012d18c00c527835fabab03a3791
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/230544
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Jonas Oreland <jonaso@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#34895}
diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc
index 455dcb9..4925c26 100644
--- a/p2p/client/basic_port_allocator_unittest.cc
+++ b/p2p/client/basic_port_allocator_unittest.cc
@@ -176,17 +176,17 @@
                     rtc::AdapterType type) {
     network_manager_.AddInterface(addr, if_name, type);
   }
-  // The default route is the public address that STUN server will observe when
-  // the endpoint is sitting on the public internet and the local port is bound
-  // to the "any" address. This may be different from the default local address
-  // which the endpoint observes. This can occur if the route to the public
-  // endpoint like 8.8.8.8 (specified as the default local address) is
-  // different from the route to the STUN server (the default route).
-  void AddInterfaceAsDefaultRoute(const SocketAddress& addr) {
+  // The default source address is the public address that STUN server will
+  // observe when the endpoint is sitting on the public internet and the local
+  // port is bound to the "any" address. Intended for simulating the situation
+  // that client binds the "any" address, and that's also the address returned
+  // by getsockname/GetLocalAddress, so that the client can learn the actual
+  // local address only from the STUN response.
+  void AddInterfaceAsDefaultSourceAddresss(const SocketAddress& addr) {
     AddInterface(addr);
     // When a binding comes from the any address, the `addr` will be used as the
     // srflx address.
-    vss_->SetDefaultRoute(addr.ipaddr());
+    vss_->SetDefaultSourceAddress(addr.ipaddr());
   }
   void RemoveInterface(const SocketAddress& addr) {
     network_manager_.RemoveInterface(addr);
@@ -1322,7 +1322,7 @@
 TEST_F(BasicPortAllocatorTest,
        TestDisableAdapterEnumerationWithoutNatLocalhostCandDisabledDiffRoute) {
   ResetWithStunServerNoNat(kStunAddr);
-  AddInterfaceAsDefaultRoute(kClientAddr);
+  AddInterfaceAsDefaultSourceAddresss(kClientAddr);
   ASSERT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
   session_->set_flags(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE);
   // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN
diff --git a/rtc_base/virtual_socket_server.cc b/rtc_base/virtual_socket_server.cc
index db6f97c..d2bf56e 100644
--- a/rtc_base/virtual_socket_server.cc
+++ b/rtc_base/virtual_socket_server.cc
@@ -723,7 +723,7 @@
     return it->second;
   }
 
-  IPAddress default_ip = GetDefaultRoute(addr.ipaddr().family());
+  IPAddress default_ip = GetDefaultSourceAddress(addr.ipaddr().family());
   if (!IPIsUnspec(default_ip) && addr.ipaddr() == default_ip) {
     // If we can't find a binding for the packet which is sent to the interface
     // corresponding to the default route, it should match a binding with the
@@ -1016,7 +1016,7 @@
   // to the default route here such that the recipient will see the default
   // route.
   SocketAddress sender_addr = sender->GetLocalAddress();
-  IPAddress default_ip = GetDefaultRoute(sender_addr.ipaddr().family());
+  IPAddress default_ip = GetDefaultSourceAddress(sender_addr.ipaddr().family());
   if (sender_addr.IsAnyIP() && !IPIsUnspec(default_ip)) {
     sender_addr.SetIP(default_ip);
   }
@@ -1227,21 +1227,21 @@
   return false;
 }
 
-IPAddress VirtualSocketServer::GetDefaultRoute(int family) {
+IPAddress VirtualSocketServer::GetDefaultSourceAddress(int family) {
   if (family == AF_INET) {
-    return default_route_v4_;
+    return default_source_address_v4_;
   }
   if (family == AF_INET6) {
-    return default_route_v6_;
+    return default_source_address_v6_;
   }
   return IPAddress();
 }
-void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) {
+void VirtualSocketServer::SetDefaultSourceAddress(const IPAddress& from_addr) {
   RTC_DCHECK(!IPIsAny(from_addr));
   if (from_addr.family() == AF_INET) {
-    default_route_v4_ = from_addr;
+    default_source_address_v4_ = from_addr;
   } else if (from_addr.family() == AF_INET6) {
-    default_route_v6_ = from_addr;
+    default_source_address_v6_ = from_addr;
   }
 }
 
diff --git a/rtc_base/virtual_socket_server.h b/rtc_base/virtual_socket_server.h
index 490511b..77ddb76 100644
--- a/rtc_base/virtual_socket_server.h
+++ b/rtc_base/virtual_socket_server.h
@@ -163,10 +163,12 @@
   explicit VirtualSocketServer(ThreadProcessingFakeClock* fake_clock);
   ~VirtualSocketServer() override;
 
-  // The default route indicates which local address to use when a socket is
-  // bound to the 'any' address, e.g. 0.0.0.0.
-  IPAddress GetDefaultRoute(int family);
-  void SetDefaultRoute(const IPAddress& from_addr);
+  // The default source address specifies which local address to use when a
+  // socket is bound to the 'any' address, e.g. 0.0.0.0. (If not set, the 'any'
+  // address is used as the source address on outgoing virtual packets, exposed
+  // to recipient's RecvFrom).
+  IPAddress GetDefaultSourceAddress(int family);
+  void SetDefaultSourceAddress(const IPAddress& from_addr);
 
   // Limits the network bandwidth (maximum bytes per second).  Zero means that
   // all sends occur instantly.  Defaults to 0.
@@ -411,8 +413,8 @@
   AddressMap* bindings_;
   ConnectionMap* connections_;
 
-  IPAddress default_route_v4_;
-  IPAddress default_route_v6_;
+  IPAddress default_source_address_v4_;
+  IPAddress default_source_address_v6_;
 
   uint32_t bandwidth_;
   uint32_t network_capacity_;
diff --git a/rtc_base/virtual_socket_unittest.cc b/rtc_base/virtual_socket_unittest.cc
index 44e7288..2c34033 100644
--- a/rtc_base/virtual_socket_unittest.cc
+++ b/rtc_base/virtual_socket_unittest.cc
@@ -189,36 +189,36 @@
   }
 
   // Test a client can bind to the any address, and all sent packets will have
-  // the default route as the source address. Also, it can receive packets sent
-  // to the default route.
-  void TestDefaultRoute(const IPAddress& default_route) {
-    ss_.SetDefaultRoute(default_route);
+  // the default source address. Also, it can receive packets sent to the
+  // default address.
+  void TestDefaultSourceAddress(const IPAddress& default_address) {
+    ss_.SetDefaultSourceAddress(default_address);
 
     // Create client1 bound to the any address.
-    Socket* socket = ss_.CreateSocket(default_route.family(), SOCK_DGRAM);
-    socket->Bind(EmptySocketAddressWithFamily(default_route.family()));
+    Socket* socket = ss_.CreateSocket(default_address.family(), SOCK_DGRAM);
+    socket->Bind(EmptySocketAddressWithFamily(default_address.family()));
     SocketAddress client1_any_addr = socket->GetLocalAddress();
     EXPECT_TRUE(client1_any_addr.IsAnyIP());
     auto client1 = std::make_unique<TestClient>(
         std::make_unique<AsyncUDPSocket>(socket), &fake_clock_);
 
-    // Create client2 bound to the default route.
-    Socket* socket2 = ss_.CreateSocket(default_route.family(), SOCK_DGRAM);
-    socket2->Bind(SocketAddress(default_route, 0));
+    // Create client2 bound to the address route.
+    Socket* socket2 = ss_.CreateSocket(default_address.family(), SOCK_DGRAM);
+    socket2->Bind(SocketAddress(default_address, 0));
     SocketAddress client2_addr = socket2->GetLocalAddress();
     EXPECT_FALSE(client2_addr.IsAnyIP());
     auto client2 = std::make_unique<TestClient>(
         std::make_unique<AsyncUDPSocket>(socket2), &fake_clock_);
 
-    // Client1 sends to client2, client2 should see the default route as
+    // Client1 sends to client2, client2 should see the default address as
     // client1's address.
     SocketAddress client1_addr;
     EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr));
     EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr));
     EXPECT_EQ(client1_addr,
-              SocketAddress(default_route, client1_any_addr.port()));
+              SocketAddress(default_address, client1_any_addr.port()));
 
-    // Client2 can send back to client1's default route address.
+    // Client2 can send back to client1's default address.
     EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr));
     EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr));
   }
@@ -871,14 +871,14 @@
 
 TEST_F(VirtualSocketServerTest, TestDefaultRoute_v4) {
   IPAddress ipv4_default_addr(0x01020304);
-  TestDefaultRoute(ipv4_default_addr);
+  TestDefaultSourceAddress(ipv4_default_addr);
 }
 
 TEST_F(VirtualSocketServerTest, TestDefaultRoute_v6) {
   IPAddress ipv6_default_addr;
   EXPECT_TRUE(
       IPFromString("2401:fa00:4:1000:be30:5bff:fee5:c3", &ipv6_default_addr));
-  TestDefaultRoute(ipv6_default_addr);
+  TestDefaultSourceAddress(ipv6_default_addr);
 }
 
 TEST_F(VirtualSocketServerTest, connect_v4) {