Chromium Code Reviews| Index: content/browser/renderer_host/p2p/socket_dispatcher_host.cc |
| diff --git a/content/browser/renderer_host/p2p/socket_dispatcher_host.cc b/content/browser/renderer_host/p2p/socket_dispatcher_host.cc |
| index c450d31964a916ea511e74735d8ae263b38d4478..f93f3c3add7a1154daf5a42927b4b5bb9d74cec4 100644 |
| --- a/content/browser/renderer_host/p2p/socket_dispatcher_host.cc |
| +++ b/content/browser/renderer_host/p2p/socket_dispatcher_host.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/stl_util.h" |
| #include "content/browser/renderer_host/p2p/socket_host.h" |
| #include "content/common/p2p_messages.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/resource_context.h" |
| #include "net/base/address_list.h" |
| #include "net/base/completion_callback.h" |
| @@ -16,6 +17,7 @@ |
| #include "net/base/sys_addrinfo.h" |
| #include "net/dns/single_request_host_resolver.h" |
| #include "net/log/net_log.h" |
| +#include "net/udp/udp_client_socket.h" |
| #include "net/url_request/url_request_context_getter.h" |
| using content::BrowserMessageFilter; |
| @@ -23,6 +25,16 @@ using content::BrowserThread; |
| namespace content { |
| +namespace { |
| + |
| +// Used by GetDefaultLocalAddress as the target to connect to for getting the |
| +// default local address. They are public DNS servers on the internet. |
| +const char kPublicIPv4Host[] = "8.8.8.8"; |
| +const char kPublicIPv6Host[] = "[2001:4860:4860::8888]"; |
| +const int kPublicPort = 53; // DNS port. |
| + |
| +} // namespace |
| + |
| const size_t kMaximumPacketSize = 32768; |
| class P2PSocketDispatcherHost::DnsRequest { |
| @@ -321,14 +333,52 @@ void P2PSocketDispatcherHost::OnDestroySocket(int socket_id) { |
| void P2PSocketDispatcherHost::DoGetNetworkList() { |
| net::NetworkInterfaceList list; |
| net::GetNetworkList(&list, net::EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES); |
| + default_ipv4_local_address_ = GetDefaultLocalAddress(AF_INET); |
| + default_ipv6_local_address_ = GetDefaultLocalAddress(AF_INET6); |
| BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, base::Bind( |
| - &P2PSocketDispatcherHost::SendNetworkList, this, list)); |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&P2PSocketDispatcherHost::SendNetworkList, this, list, |
| + default_ipv4_local_address_, default_ipv6_local_address_)); |
| } |
| void P2PSocketDispatcherHost::SendNetworkList( |
| - const net::NetworkInterfaceList& list) { |
| - Send(new P2PMsg_NetworkListChanged(list)); |
| + const net::NetworkInterfaceList& list, |
| + const net::IPEndPoint& default_ipv4_local_address, |
| + const net::IPEndPoint& default_ipv6_local_address) { |
| + Send(new P2PMsg_NetworkListChanged(list, default_ipv4_local_address, |
| + default_ipv6_local_address)); |
| +} |
| + |
| +net::IPEndPoint P2PSocketDispatcherHost::GetDefaultLocalAddress(int family) { |
| + DCHECK(family == AF_INET || family == AF_INET6); |
| + |
| + // 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.
|
| + // threads. |
| + 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.
|
| + DCHECK(!::content::BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + 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.
|
| + net::IPAddressNumber ip_address_number; |
| + |
| + 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.
|
| + net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), NULL, |
| + net::NetLog::Source())); |
| + |
| + 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.
|
| + family == AF_INET ? kPublicIPv4Host : kPublicIPv6Host, |
| + &ip_address_number)) { |
| + 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.
|
| + } |
| + |
| + if (socket->Connect(net::IPEndPoint(ip_address_number, kPublicPort)) != |
| + net::OK) { |
| + return net::IPEndPoint(); |
| + } |
| + |
| + if (socket->GetLocalAddress(&local_address) != net::OK) |
| + return net::IPEndPoint(); |
| + |
| + return local_address; |
| } |
| void P2PSocketDispatcherHost::OnAddressResolved( |