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

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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 server_->msg_queue_->Get(&msg); 279 server_->msg_queue_->Get(&msg);
280 server_->msg_queue_->Dispatch(&msg); 280 server_->msg_queue_->Dispatch(&msg);
281 } 281 }
282 } 282 }
283 283
284 // Return the packet at the front of the queue. 284 // Return the packet at the front of the queue.
285 Packet* packet = recv_buffer_.front(); 285 Packet* packet = recv_buffer_.front();
286 size_t data_read = std::min(cb, packet->size()); 286 size_t data_read = std::min(cb, packet->size());
287 memcpy(pv, packet->data(), data_read); 287 memcpy(pv, packet->data(), data_read);
288 *paddr = packet->from(); 288 *paddr = packet->from();
289 // HACK(any_address): when the incoming packet is from a binding of the any
juberti1 2015/08/06 00:35:26 Can this be done on the send side? i.e. in AddPack
pthatcher1 2015/08/06 01:06:18 I was thinking the same thing. That would be more
guoweis_webrtc 2015/08/06 08:50:06 Done.
290 // address, translate it to the default interface here such that the STUN
291 // server will see a valid interface.
292 if (paddr->IsAnyIP()) {
293 *paddr = server_->TryMapAnyAddressToDefault(*paddr);
294 }
289 295
290 if (data_read < packet->size()) { 296 if (data_read < packet->size()) {
291 packet->Consume(data_read); 297 packet->Consume(data_read);
292 } else { 298 } else {
293 recv_buffer_.pop_front(); 299 recv_buffer_.pop_front();
294 delete packet; 300 delete packet;
295 } 301 }
296 302
297 if (SOCK_STREAM == type_) { 303 if (SOCK_STREAM == type_) {
298 bool was_full = (recv_buffer_size_ == server_->recv_buffer_capacity_); 304 bool was_full = (recv_buffer_size_ == server_->recv_buffer_capacity_);
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 660 }
655 } 661 }
656 662
657 return Bind(socket, *addr); 663 return Bind(socket, *addr);
658 } 664 }
659 665
660 VirtualSocket* VirtualSocketServer::LookupBinding(const SocketAddress& addr) { 666 VirtualSocket* VirtualSocketServer::LookupBinding(const SocketAddress& addr) {
661 SocketAddress normalized(addr.ipaddr().Normalized(), 667 SocketAddress normalized(addr.ipaddr().Normalized(),
662 addr.port()); 668 addr.port());
663 AddressMap::iterator it = bindings_->find(normalized); 669 AddressMap::iterator it = bindings_->find(normalized);
664 return (bindings_->end() != it) ? it->second : NULL; 670 VirtualSocket* socket = (bindings_->end() != it) ? it->second : NULL;
671 if (socket || addr.ipaddr() != default_interface(addr.ipaddr().family())) {
672 return socket;
673 }
674
675 // HACK(any_address): If we can't find a binding, maybe this is resulted from
juberti1 2015/08/06 00:35:26 Is this still needed if we do the change I suggest
guoweis_webrtc 2015/08/06 08:50:06 yes, since the binding of the default route just d
676 // RecvFrom where we translate the any address to the default interface.
677 SocketAddress sock_addr =
678 EmptySocketAddressWithFamily(addr.ipaddr().family());
679 sock_addr.SetPort(addr.port());
680 return LookupBinding(sock_addr);
665 } 681 }
666 682
667 int VirtualSocketServer::Unbind(const SocketAddress& addr, 683 int VirtualSocketServer::Unbind(const SocketAddress& addr,
668 VirtualSocket* socket) { 684 VirtualSocket* socket) {
669 SocketAddress normalized(addr.ipaddr().Normalized(), 685 SocketAddress normalized(addr.ipaddr().Normalized(),
670 addr.port()); 686 addr.port());
671 ASSERT((*bindings_)[normalized] == socket); 687 ASSERT((*bindings_)[normalized] == socket);
672 bindings_->erase(bindings_->find(normalized)); 688 bindings_->erase(bindings_->find(normalized));
673 return 0; 689 return 0;
674 } 690 }
(...skipping 398 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::TryMapAnyAddressToDefault(
pthatcher1 2015/08/06 01:06:18 I think a better name would be GetDefaultRouteIfNe
guoweis_webrtc 2015/08/06 08:50:06 Done.
1100 const SocketAddress& addr) {
1101 IPAddress default_ip = default_interface(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
1083 } // namespace rtc 1110 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698