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

Unified Diff: webrtc/base/virtualsocketserver.cc

Issue 1274013002: Bug 4865: Enable connectivity when the remote peer is on public internet. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 months 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/base/virtualsocketserver.cc
diff --git a/webrtc/base/virtualsocketserver.cc b/webrtc/base/virtualsocketserver.cc
index 9b0e48d1d86b1f025ee72de61cda3a8f352c02d9..77403a4cd411cc2477b4adf88e43f857dca9062b 100644
--- a/webrtc/base/virtualsocketserver.cc
+++ b/webrtc/base/virtualsocketserver.cc
@@ -661,7 +661,18 @@ VirtualSocket* VirtualSocketServer::LookupBinding(const SocketAddress& addr) {
SocketAddress normalized(addr.ipaddr().Normalized(),
addr.port());
AddressMap::iterator it = bindings_->find(normalized);
- return (bindings_->end() != it) ? it->second : NULL;
+ VirtualSocket* socket = (bindings_->end() != it) ? it->second : NULL;
+ if (socket || addr.ipaddr() != GetDefaultRoute(addr.ipaddr().family())) {
+ return socket;
+ }
+
+ // HACK(any_address): If we can't find a binding, maybe this is resulted from
juberti1 2015/08/06 23:43:21 I don't think this is a hack. If a packet is sent
guoweis_webrtc 2015/08/07 18:03:43 Remove the HACK comment.
+ // AddPacketToNetwork where we translate the any address to the default
+ // interface.
+ SocketAddress sock_addr =
+ EmptySocketAddressWithFamily(addr.ipaddr().family());
+ sock_addr.SetPort(addr.port());
+ return LookupBinding(sock_addr);
}
int VirtualSocketServer::Unbind(const SocketAddress& addr,
@@ -867,7 +878,12 @@ void VirtualSocketServer::AddPacketToNetwork(VirtualSocket* sender,
uint32 transit_delay = GetRandomTransitDelay();
// Post the packet as a message to be delivered (on our own thread)
- Packet* p = new Packet(data, data_size, sender->local_addr_);
+ // HACK(any_address): when the incoming packet is from a binding of the any
juberti1 2015/08/06 23:43:21 I don't really think this is a hack - this seems l
guoweis_webrtc 2015/08/07 18:03:43 Done.
+ // address, translate it to the default interface here such that the STUN
+ // server will see a valid interface.
+ Packet* p = new Packet(data, data_size,
+ GetDefaultRouteIfNecessary(sender->local_addr_));
+
uint32 ts = TimeAfter(send_delay + transit_delay);
if (ordered) {
// Ensure that new packets arrive after previous ones
@@ -1080,4 +1096,32 @@ bool VirtualSocketServer::CanInteractWith(VirtualSocket* local,
return false;
}
+const SocketAddress VirtualSocketServer::GetDefaultRouteIfNecessary(
juberti1 2015/08/06 23:43:21 Nothing else calls this function, so I think it wo
guoweis_webrtc 2015/08/07 18:03:43 Done.
+ const SocketAddress& addr) {
+ IPAddress default_ip = GetDefaultRoute(addr.ipaddr().family());
+ if (!addr.IsAnyIP() || IPIsUnspec(default_ip)) {
+ return addr;
+ }
+ SocketAddress address = addr;
+ address.SetIP(default_ip);
+ return address;
+}
+
+const IPAddress VirtualSocketServer::GetDefaultRoute(int family) {
+ if (family == AF_INET) {
+ return default_route_v4_;
+ }
+ if (family == AF_INET6) {
+ return default_route_v6_;
+ }
+ return IPAddress();
+}
+void VirtualSocketServer::SetDefaultRoute(const IPAddress& ipaddr) {
+ if (ipaddr.family() == AF_INET) {
+ default_route_v4_ = ipaddr;
+ } else if (ipaddr.family() == AF_INET6) {
+ default_route_v6_ = ipaddr;
+ }
+}
+
} // namespace rtc

Powered by Google App Engine
This is Rietveld 408576698