Chromium Code Reviews| Index: webrtc/base/virtualsocketserver.cc |
| diff --git a/webrtc/base/virtualsocketserver.cc b/webrtc/base/virtualsocketserver.cc |
| index 9b0e48d1d86b1f025ee72de61cda3a8f352c02d9..841fc95998796a60bd9abc85b2c487abbc0d2122 100644 |
| --- a/webrtc/base/virtualsocketserver.cc |
| +++ b/webrtc/base/virtualsocketserver.cc |
| @@ -17,6 +17,7 @@ |
| #include <map> |
| #include <vector> |
| +#include "webrtc/base/checks.h" |
| #include "webrtc/base/common.h" |
| #include "webrtc/base/logging.h" |
| #include "webrtc/base/physicalsocketserver.h" |
| @@ -661,7 +662,21 @@ 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; |
| + if (it != bindings_->end()) { |
| + return it->second; |
| + } |
| + |
| + if (addr.ipaddr() == GetDefaultRoute(addr.ipaddr().family())) { |
| + // 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 |
| + // correct port to the any address. |
| + SocketAddress sock_addr = |
| + EmptySocketAddressWithFamily(addr.ipaddr().family()); |
| + sock_addr.SetPort(addr.port()); |
| + return LookupBinding(sock_addr); |
|
juberti1
2015/08/13 21:23:59
Is there any chance this could infinitely recurse
guoweis_webrtc
2015/08/14 05:24:25
If the addr is Unspec, yes, it'll be a infinite lo
|
| + } |
| + |
| + return nullptr; |
| } |
| int VirtualSocketServer::Unbind(const SocketAddress& addr, |
| @@ -866,8 +881,18 @@ void VirtualSocketServer::AddPacketToNetwork(VirtualSocket* sender, |
| // Find the delay for crossing the many virtual hops of the network. |
| uint32 transit_delay = GetRandomTransitDelay(); |
| + // When the incoming packet is from a binding of the any address, translate it |
| + // to the default route here such that the STUN server will see the default |
|
juberti1
2015/08/13 21:23:59
"STUN server" -> "recipient"
guoweis_webrtc
2015/08/14 05:24:25
Done.
|
| + // route. |
| + SocketAddress sender_addr = sender->local_addr_; |
| + IPAddress default_ip = GetDefaultRoute(sender_addr.ipaddr().family()); |
| + if (sender_addr.IsAnyIP() && !IPIsUnspec(default_ip)) { |
| + sender_addr.SetIP(default_ip); |
| + } |
| + |
| // Post the packet as a message to be delivered (on our own thread) |
| - Packet* p = new Packet(data, data_size, sender->local_addr_); |
| + Packet* p = new Packet(data, data_size, sender_addr); |
| + |
| uint32 ts = TimeAfter(send_delay + transit_delay); |
| if (ordered) { |
| // Ensure that new packets arrive after previous ones |
| @@ -1080,4 +1105,22 @@ bool VirtualSocketServer::CanInteractWith(VirtualSocket* local, |
| return false; |
| } |
| +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& from_addr) { |
| + DCHECK(!IPIsAny(from_addr)); |
| + if (from_addr.family() == AF_INET) { |
| + default_route_v4_ = from_addr; |
| + } else if (from_addr.family() == AF_INET6) { |
| + default_route_v6_ = from_addr; |
| + } |
| +} |
| + |
| } // namespace rtc |