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

Side by Side Diff: content/browser/renderer_host/p2p/socket_dispatcher_host.cc

Issue 1405963021: Add support for default local address in IpcNetworkManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update test cases. Created 5 years, 1 month 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" 5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/browser/renderer_host/p2p/socket_host.h" 9 #include "content/browser/renderer_host/p2p/socket_host.h"
10 #include "content/common/p2p_messages.h" 10 #include "content/common/p2p_messages.h"
11 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/resource_context.h" 12 #include "content/public/browser/resource_context.h"
12 #include "net/base/address_list.h" 13 #include "net/base/address_list.h"
13 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
15 #include "net/base/network_interfaces.h" 16 #include "net/base/network_interfaces.h"
16 #include "net/base/sys_addrinfo.h" 17 #include "net/base/sys_addrinfo.h"
17 #include "net/dns/single_request_host_resolver.h" 18 #include "net/dns/single_request_host_resolver.h"
18 #include "net/log/net_log.h" 19 #include "net/log/net_log.h"
20 #include "net/udp/udp_client_socket.h"
19 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
20 22
21 using content::BrowserMessageFilter; 23 using content::BrowserMessageFilter;
22 using content::BrowserThread; 24 using content::BrowserThread;
23 25
24 namespace content { 26 namespace content {
25 27
28 namespace {
29
30 // Used by GetDefaultLocalAddress as the target to connect to for getting the
31 // default local address. They are public DNS servers on the internet.
32 const char kPublicIPv4Host[] = "8.8.8.8";
33 const char kPublicIPv6Host[] = "[2001:4860:4860::8888]";
34 const int kPublicPort = 53; // DNS port.
35
36 } // namespace
37
26 const size_t kMaximumPacketSize = 32768; 38 const size_t kMaximumPacketSize = 32768;
27 39
28 class P2PSocketDispatcherHost::DnsRequest { 40 class P2PSocketDispatcherHost::DnsRequest {
29 public: 41 public:
30 typedef base::Callback<void(const net::IPAddressList&)> DoneCallback; 42 typedef base::Callback<void(const net::IPAddressList&)> DoneCallback;
31 43
32 DnsRequest(int32 request_id, net::HostResolver* host_resolver) 44 DnsRequest(int32 request_id, net::HostResolver* host_resolver)
33 : request_id_(request_id), 45 : request_id_(request_id),
34 resolver_(host_resolver) { 46 resolver_(host_resolver) {
35 } 47 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 delete it->second; 326 delete it->second;
315 sockets_.erase(it); 327 sockets_.erase(it);
316 } else { 328 } else {
317 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id."; 329 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id.";
318 } 330 }
319 } 331 }
320 332
321 void P2PSocketDispatcherHost::DoGetNetworkList() { 333 void P2PSocketDispatcherHost::DoGetNetworkList() {
322 net::NetworkInterfaceList list; 334 net::NetworkInterfaceList list;
323 net::GetNetworkList(&list, net::EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES); 335 net::GetNetworkList(&list, net::EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES);
336 default_ipv4_local_address_ = GetDefaultLocalAddress(AF_INET);
337 default_ipv6_local_address_ = GetDefaultLocalAddress(AF_INET6);
324 BrowserThread::PostTask( 338 BrowserThread::PostTask(
325 BrowserThread::IO, FROM_HERE, base::Bind( 339 BrowserThread::IO, FROM_HERE,
326 &P2PSocketDispatcherHost::SendNetworkList, this, list)); 340 base::Bind(&P2PSocketDispatcherHost::SendNetworkList, this, list,
341 default_ipv4_local_address_, default_ipv6_local_address_));
327 } 342 }
328 343
329 void P2PSocketDispatcherHost::SendNetworkList( 344 void P2PSocketDispatcherHost::SendNetworkList(
330 const net::NetworkInterfaceList& list) { 345 const net::NetworkInterfaceList& list,
331 Send(new P2PMsg_NetworkListChanged(list)); 346 const net::IPEndPoint& default_ipv4_local_address,
347 const net::IPEndPoint& default_ipv6_local_address) {
348 Send(new P2PMsg_NetworkListChanged(list, default_ipv4_local_address,
349 default_ipv6_local_address));
350 }
351
352 net::IPEndPoint P2PSocketDispatcherHost::GetDefaultLocalAddress(int family) {
353 DCHECK(family == AF_INET || family == AF_INET6);
354
355 // Please see crbug.com/455942. We want to make sure we're not on these 2
Sergey Ulanov 2015/11/10 22:44:17 This bug reference is confusing here - the bug is
guoweis_webrtc 2015/11/11 00:11:51 Done.
356 // threads.
357 DCHECK(!::content::BrowserThread::CurrentlyOn(BrowserThread::UI));
Sergey Ulanov 2015/11/10 22:44:16 This code is always called on the FILE thread, so
guoweis_webrtc 2015/11/11 00:11:51 Done.
358 DCHECK(!::content::BrowserThread::CurrentlyOn(BrowserThread::IO));
359
360 net::IPEndPoint local_address;
Sergey Ulanov 2015/11/10 22:44:16 nit: Move this just before GetLocalAddress() call
guoweis_webrtc 2015/11/11 00:11:51 Done.
361 net::IPAddressNumber ip_address_number;
362
363 scoped_ptr<net::UDPClientSocket> socket(new net::UDPClientSocket(
Sergey Ulanov 2015/11/10 22:44:16 Please use net::ClientSocketFactory::GetDefaultFac
guoweis_webrtc 2015/11/11 00:11:51 Done.
364 net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), NULL,
365 net::NetLog::Source()));
366
367 if (!net::ParseURLHostnameToNumber(
Sergey Ulanov 2015/11/10 22:44:16 net::IPAddressNumber is just an std::vector<uint8_
guoweis_webrtc 2015/11/11 00:11:51 Done.
368 family == AF_INET ? kPublicIPv4Host : kPublicIPv6Host,
369 &ip_address_number)) {
370 return net::IPEndPoint();
Sergey Ulanov 2015/11/10 22:44:16 this would need to be marked NOTREACHED(), but it
guoweis_webrtc 2015/11/11 00:11:51 Done.
371 }
372
373 if (socket->Connect(net::IPEndPoint(ip_address_number, kPublicPort)) !=
374 net::OK) {
375 return net::IPEndPoint();
376 }
377
378 if (socket->GetLocalAddress(&local_address) != net::OK)
379 return net::IPEndPoint();
380
381 return local_address;
332 } 382 }
333 383
334 void P2PSocketDispatcherHost::OnAddressResolved( 384 void P2PSocketDispatcherHost::OnAddressResolved(
335 DnsRequest* request, 385 DnsRequest* request,
336 const net::IPAddressList& addresses) { 386 const net::IPAddressList& addresses) {
337 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); 387 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses));
338 388
339 dns_requests_.erase(request); 389 dns_requests_.erase(request);
340 delete request; 390 delete request;
341 } 391 }
(...skipping 10 matching lines...) Expand all
352 402
353 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) 403 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_)
354 packet_callback_.Reset(); 404 packet_callback_.Reset();
355 405
356 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) 406 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it)
357 it->second->StopRtpDump(incoming, outgoing); 407 it->second->StopRtpDump(incoming, outgoing);
358 } 408 }
359 } 409 }
360 410
361 } // namespace content 411 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698