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

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..4fa2e36d5418ae74522b0f2d57ab275baaf5ec70 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,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;
+ }
pthatcher1 2015/08/07 21:28:19 I think this would be more clear as: if (it != bi
guoweis_webrtc 2015/08/13 14:17:28 Yes, it is much better. Thanks.
+
+ // 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);
}
int VirtualSocketServer::Unbind(const SocketAddress& addr,
@@ -866,8 +878,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
+ // route.
+ SocketAddress addr = sender->local_addr_;
pthatcher1 2015/08/07 21:28:19 I think "sender_addr" would be more clear than jus
guoweis_webrtc 2015/08/13 14:17:28 Done.
+ IPAddress default_ip = GetDefaultRoute(addr.ipaddr().family());
+ if (addr.IsAnyIP() && !IPIsUnspec(default_ip)) {
+ addr.SetIP(default_ip);
pthatcher1 2015/08/07 21:28:19 Since default_ip isn't used outside this scope, wh
guoweis_webrtc 2015/08/13 14:17:28 I still want to check whether IPIsUnspec. Yes, Whe
+ }
+
// 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, addr);
+
uint32 ts = TimeAfter(send_delay + transit_delay);
if (ordered) {
// Ensure that new packets arrive after previous ones
@@ -1080,4 +1102,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

Powered by Google App Engine
This is Rietveld 408576698