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

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: fix a sizeof 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"
15 #include "net/base/ip_address_number.h"
14 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
15 #include "net/base/network_interfaces.h" 17 #include "net/base/network_interfaces.h"
16 #include "net/base/sys_addrinfo.h" 18 #include "net/base/sys_addrinfo.h"
17 #include "net/dns/single_request_host_resolver.h" 19 #include "net/dns/single_request_host_resolver.h"
18 #include "net/log/net_log.h" 20 #include "net/log/net_log.h"
21 #include "net/socket/client_socket_factory.h"
22 #include "net/udp/datagram_client_socket.h"
19 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
20 24
21 using content::BrowserMessageFilter; 25 using content::BrowserMessageFilter;
22 using content::BrowserThread; 26 using content::BrowserThread;
23 27
24 namespace content { 28 namespace content {
25 29
30 namespace {
31
32 // Used by GetDefaultLocalAddress as the target to connect to for getting the
33 // default local address. They are public DNS servers on the internet.
34 const uint8_t kPublicIPv4Host[] = {8, 8, 8, 8};
35 const uint8_t kPublicIPv6Host[] = {
36 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0, 0, 0, 0, 0, 0, 0, 0, 0x88, 0x88};
37 const int kPublicPort = 53; // DNS port.
38
39 } // namespace
40
26 const size_t kMaximumPacketSize = 32768; 41 const size_t kMaximumPacketSize = 32768;
27 42
28 class P2PSocketDispatcherHost::DnsRequest { 43 class P2PSocketDispatcherHost::DnsRequest {
29 public: 44 public:
30 typedef base::Callback<void(const net::IPAddressList&)> DoneCallback; 45 typedef base::Callback<void(const net::IPAddressList&)> DoneCallback;
31 46
32 DnsRequest(int32 request_id, net::HostResolver* host_resolver) 47 DnsRequest(int32 request_id, net::HostResolver* host_resolver)
33 : request_id_(request_id), 48 : request_id_(request_id),
34 resolver_(host_resolver) { 49 resolver_(host_resolver) {
35 } 50 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 delete it->second; 329 delete it->second;
315 sockets_.erase(it); 330 sockets_.erase(it);
316 } else { 331 } else {
317 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id."; 332 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id.";
318 } 333 }
319 } 334 }
320 335
321 void P2PSocketDispatcherHost::DoGetNetworkList() { 336 void P2PSocketDispatcherHost::DoGetNetworkList() {
322 net::NetworkInterfaceList list; 337 net::NetworkInterfaceList list;
323 net::GetNetworkList(&list, net::EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES); 338 net::GetNetworkList(&list, net::EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES);
339 default_ipv4_local_address_ = GetDefaultLocalAddress(AF_INET);
340 default_ipv6_local_address_ = GetDefaultLocalAddress(AF_INET6);
324 BrowserThread::PostTask( 341 BrowserThread::PostTask(
325 BrowserThread::IO, FROM_HERE, base::Bind( 342 BrowserThread::IO, FROM_HERE,
326 &P2PSocketDispatcherHost::SendNetworkList, this, list)); 343 base::Bind(&P2PSocketDispatcherHost::SendNetworkList, this, list,
344 default_ipv4_local_address_, default_ipv6_local_address_));
327 } 345 }
328 346
329 void P2PSocketDispatcherHost::SendNetworkList( 347 void P2PSocketDispatcherHost::SendNetworkList(
330 const net::NetworkInterfaceList& list) { 348 const net::NetworkInterfaceList& list,
331 Send(new P2PMsg_NetworkListChanged(list)); 349 const net::IPAddressNumber& default_ipv4_local_address,
350 const net::IPAddressNumber& default_ipv6_local_address) {
351 Send(new P2PMsg_NetworkListChanged(list, default_ipv4_local_address,
352 default_ipv6_local_address));
353 }
354
355 net::IPAddressNumber P2PSocketDispatcherHost::GetDefaultLocalAddress(
356 int family) {
357 DCHECK(family == AF_INET || family == AF_INET6);
358
359 // Creation and connection of a UDP socket might be janky.
360 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
361
362 scoped_ptr<net::DatagramClientSocket> socket(
363 net::ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket(
364 net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), NULL,
365 net::NetLog::Source()));
366
367 net::IPAddressNumber ip_address_number;
368 if (family == AF_INET) {
369 ip_address_number.assign(kPublicIPv4Host,
370 kPublicIPv4Host + net::kIPv4AddressSize);
371 } else {
372 ip_address_number.assign(kPublicIPv6Host,
373 kPublicIPv6Host + net::kIPv6AddressSize);
374 }
375
376 if (socket->Connect(net::IPEndPoint(ip_address_number, kPublicPort)) !=
377 net::OK) {
378 return net::IPAddressNumber();
379 }
380
381 net::IPEndPoint local_address;
382 if (socket->GetLocalAddress(&local_address) != net::OK)
383 return net::IPAddressNumber();
384
385 return local_address.address();
332 } 386 }
333 387
334 void P2PSocketDispatcherHost::OnAddressResolved( 388 void P2PSocketDispatcherHost::OnAddressResolved(
335 DnsRequest* request, 389 DnsRequest* request,
336 const net::IPAddressList& addresses) { 390 const net::IPAddressList& addresses) {
337 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); 391 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses));
338 392
339 dns_requests_.erase(request); 393 dns_requests_.erase(request);
340 delete request; 394 delete request;
341 } 395 }
(...skipping 10 matching lines...) Expand all
352 406
353 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) 407 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_)
354 packet_callback_.Reset(); 408 packet_callback_.Reset();
355 409
356 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) 410 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it)
357 it->second->StopRtpDump(incoming, outgoing); 411 it->second->StopRtpDump(incoming, outgoing);
358 } 412 }
359 } 413 }
360 414
361 } // namespace content 415 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_dispatcher_host.h ('k') | content/common/p2p_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698