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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 654 }
655 } 655 }
656 656
657 return Bind(socket, *addr); 657 return Bind(socket, *addr);
658 } 658 }
659 659
660 VirtualSocket* VirtualSocketServer::LookupBinding(const SocketAddress& addr) { 660 VirtualSocket* VirtualSocketServer::LookupBinding(const SocketAddress& addr) {
661 SocketAddress normalized(addr.ipaddr().Normalized(), 661 SocketAddress normalized(addr.ipaddr().Normalized(),
662 addr.port()); 662 addr.port());
663 AddressMap::iterator it = bindings_->find(normalized); 663 AddressMap::iterator it = bindings_->find(normalized);
664 return (bindings_->end() != it) ? it->second : NULL; 664 VirtualSocket* socket = (bindings_->end() != it) ? it->second : NULL;
665 if (socket || addr.ipaddr() != GetDefaultRoute(addr.ipaddr().family())) {
666 return socket;
667 }
668
669 // 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.
670 // AddPacketToNetwork where we translate the any address to the default
671 // interface.
672 SocketAddress sock_addr =
673 EmptySocketAddressWithFamily(addr.ipaddr().family());
674 sock_addr.SetPort(addr.port());
675 return LookupBinding(sock_addr);
665 } 676 }
666 677
667 int VirtualSocketServer::Unbind(const SocketAddress& addr, 678 int VirtualSocketServer::Unbind(const SocketAddress& addr,
668 VirtualSocket* socket) { 679 VirtualSocket* socket) {
669 SocketAddress normalized(addr.ipaddr().Normalized(), 680 SocketAddress normalized(addr.ipaddr().Normalized(),
670 addr.port()); 681 addr.port());
671 ASSERT((*bindings_)[normalized] == socket); 682 ASSERT((*bindings_)[normalized] == socket);
672 bindings_->erase(bindings_->find(normalized)); 683 bindings_->erase(bindings_->find(normalized));
673 return 0; 684 return 0;
674 } 685 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 871
861 sender->network_size_ += entry.size; 872 sender->network_size_ += entry.size;
862 uint32 send_delay = SendDelay(static_cast<uint32>(sender->network_size_)); 873 uint32 send_delay = SendDelay(static_cast<uint32>(sender->network_size_));
863 entry.done_time = cur_time + send_delay; 874 entry.done_time = cur_time + send_delay;
864 sender->network_.push_back(entry); 875 sender->network_.push_back(entry);
865 876
866 // Find the delay for crossing the many virtual hops of the network. 877 // Find the delay for crossing the many virtual hops of the network.
867 uint32 transit_delay = GetRandomTransitDelay(); 878 uint32 transit_delay = GetRandomTransitDelay();
868 879
869 // Post the packet as a message to be delivered (on our own thread) 880 // Post the packet as a message to be delivered (on our own thread)
870 Packet* p = new Packet(data, data_size, sender->local_addr_); 881 // 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.
882 // address, translate it to the default interface here such that the STUN
883 // server will see a valid interface.
884 Packet* p = new Packet(data, data_size,
885 GetDefaultRouteIfNecessary(sender->local_addr_));
886
871 uint32 ts = TimeAfter(send_delay + transit_delay); 887 uint32 ts = TimeAfter(send_delay + transit_delay);
872 if (ordered) { 888 if (ordered) {
873 // Ensure that new packets arrive after previous ones 889 // Ensure that new packets arrive after previous ones
874 // TODO: consider ordering on a per-socket basis, since this 890 // TODO: consider ordering on a per-socket basis, since this
875 // introduces artifical delay. 891 // introduces artifical delay.
876 ts = TimeMax(ts, network_delay_); 892 ts = TimeMax(ts, network_delay_);
877 } 893 }
878 msg_queue_->PostAt(ts, recipient, MSG_ID_PACKET, p); 894 msg_queue_->PostAt(ts, recipient, MSG_ID_PACKET, p);
879 network_delay_ = TimeMax(ts, network_delay_); 895 network_delay_ = TimeMax(ts, network_delay_);
880 } 896 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 if (local_ip.family() == AF_INET6 && local->was_any()) { 1089 if (local_ip.family() == AF_INET6 && local->was_any()) {
1074 return true; 1090 return true;
1075 } 1091 }
1076 if (remote_ip.family() == AF_INET6 && remote->was_any()) { 1092 if (remote_ip.family() == AF_INET6 && remote->was_any()) {
1077 return true; 1093 return true;
1078 } 1094 }
1079 1095
1080 return false; 1096 return false;
1081 } 1097 }
1082 1098
1099 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.
1100 const SocketAddress& addr) {
1101 IPAddress default_ip = GetDefaultRoute(addr.ipaddr().family());
1102 if (!addr.IsAnyIP() || IPIsUnspec(default_ip)) {
1103 return addr;
1104 }
1105 SocketAddress address = addr;
1106 address.SetIP(default_ip);
1107 return address;
1108 }
1109
1110 const IPAddress VirtualSocketServer::GetDefaultRoute(int family) {
1111 if (family == AF_INET) {
1112 return default_route_v4_;
1113 }
1114 if (family == AF_INET6) {
1115 return default_route_v6_;
1116 }
1117 return IPAddress();
1118 }
1119 void VirtualSocketServer::SetDefaultRoute(const IPAddress& ipaddr) {
1120 if (ipaddr.family() == AF_INET) {
1121 default_route_v4_ = ipaddr;
1122 } else if (ipaddr.family() == AF_INET6) {
1123 default_route_v6_ = ipaddr;
1124 }
1125 }
1126
1083 } // namespace rtc 1127 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698