Commit 88ba9d16 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Move browser side WebRTC code to services/network so that it can work with the network service.

P2PSocketDispatcherHost is now split into two. The code that owns and manages P2PSocket classes moves to services/network's P2PSocketManager. There are corresponding trusted Mojo interfaces for the two to communicate.

Bug: 844146
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I5bb9265c4eba5a5bc7d4cb0bd0707c7b535e4c1c
Reviewed-on: https://chromium-review.googlesource.com/1161568Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580764}
parent caa5d06b
...@@ -98,7 +98,6 @@ jumbo_source_set("browser") { ...@@ -98,7 +98,6 @@ jumbo_source_set("browser") {
"//gpu/ipc:gl_in_process_context", "//gpu/ipc:gl_in_process_context",
"//gpu/ipc/host", "//gpu/ipc/host",
"//gpu/vulkan:buildflags", "//gpu/vulkan:buildflags",
"//jingle:jingle_glue",
"//media", "//media",
"//media:media_buildflags", "//media:media_buildflags",
"//media/capture", "//media/capture",
...@@ -179,7 +178,6 @@ jumbo_source_set("browser") { ...@@ -179,7 +178,6 @@ jumbo_source_set("browser") {
"//third_party/libyuv", "//third_party/libyuv",
"//third_party/re2", "//third_party/re2",
"//third_party/sqlite", "//third_party/sqlite",
"//third_party/webrtc/media:rtc_media_base",
"//third_party/webrtc/modules/desktop_capture:primitives", "//third_party/webrtc/modules/desktop_capture:primitives",
"//third_party/webrtc/rtc_base:rtc_base", "//third_party/webrtc/rtc_base:rtc_base",
"//third_party/zlib", "//third_party/zlib",
...@@ -1445,16 +1443,6 @@ jumbo_source_set("browser") { ...@@ -1445,16 +1443,6 @@ jumbo_source_set("browser") {
"renderer_host/overscroll_controller_delegate.h", "renderer_host/overscroll_controller_delegate.h",
"renderer_host/p2p/socket_dispatcher_host.cc", "renderer_host/p2p/socket_dispatcher_host.cc",
"renderer_host/p2p/socket_dispatcher_host.h", "renderer_host/p2p/socket_dispatcher_host.h",
"renderer_host/p2p/socket_host.cc",
"renderer_host/p2p/socket_host.h",
"renderer_host/p2p/socket_host_tcp.cc",
"renderer_host/p2p/socket_host_tcp.h",
"renderer_host/p2p/socket_host_tcp_server.cc",
"renderer_host/p2p/socket_host_tcp_server.h",
"renderer_host/p2p/socket_host_throttler.cc",
"renderer_host/p2p/socket_host_throttler.h",
"renderer_host/p2p/socket_host_udp.cc",
"renderer_host/p2p/socket_host_udp.h",
"renderer_host/render_frame_metadata_provider_impl.cc", "renderer_host/render_frame_metadata_provider_impl.cc",
"renderer_host/render_frame_metadata_provider_impl.h", "renderer_host/render_frame_metadata_provider_impl.h",
"renderer_host/render_message_filter.cc", "renderer_host/render_message_filter.cc",
......
...@@ -12,127 +12,56 @@ ...@@ -12,127 +12,56 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/containers/flat_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "content/browser/renderer_host/p2p/socket_host_throttler.h"
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/network_change_notifier.h"
#include "services/network/public/cpp/p2p_socket_type.h"
#include "services/network/public/mojom/p2p.mojom.h" #include "services/network/public/mojom/p2p.mojom.h"
#include "services/network/public/mojom/p2p_trusted.mojom.h"
namespace net {
class URLRequestContextGetter;
}
namespace network {
class ProxyResolvingClientSocketFactory;
}
namespace content { namespace content {
class P2PSocketHost; // Responsible for P2P sockets. Lives on the UI thread.
class P2PSocketDispatcherHost class P2PSocketDispatcherHost
: public base::RefCountedThreadSafe<P2PSocketDispatcherHost, : public network::mojom::P2PTrustedSocketManagerClient {
BrowserThread::DeleteOnIOThread>,
public net::NetworkChangeNotifier::NetworkChangeObserver,
public network::mojom::P2PSocketManager {
public: public:
P2PSocketDispatcherHost(int render_process_id, explicit P2PSocketDispatcherHost(int render_process_id);
net::URLRequestContextGetter* url_context); ~P2PSocketDispatcherHost() override;
// net::NetworkChangeNotifier::NetworkChangeObserver overrides. // Starts the RTP packet header dumping.
void OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) override;
// Starts the RTP packet header dumping. Must be called on the IO thread.
void StartRtpDump( void StartRtpDump(
bool incoming, bool incoming,
bool outgoing, bool outgoing,
const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback); const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback);
// Stops the RTP packet header dumping. Must be Called on the UI thread. // Stops the RTP packet header dumping.
void StopRtpDumpOnUIThread(bool incoming, bool outgoing); void StopRtpDump(bool incoming, bool outgoing);
void BindRequest(network::mojom::P2PSocketManagerRequest request); void BindRequest(network::mojom::P2PSocketManagerRequest request);
void AddAcceptedConnection( base::WeakPtr<P2PSocketDispatcherHost> GetWeakPtr();
std::unique_ptr<P2PSocketHost> accepted_connection);
void SocketDestroyed(P2PSocketHost* socket);
private: private:
friend class base::RefCountedThreadSafe<P2PSocketDispatcherHost>; // network::mojom::P2PTrustedSocketManagerClient overrides:
friend class base::DeleteHelper<P2PSocketDispatcherHost>; void InvalidSocketPortRangeRequested() override;
friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; void DumpPacket(const std::vector<uint8_t>& packet_header,
uint64_t packet_length,
~P2PSocketDispatcherHost() override; bool incoming) override;
class DnsRequest;
void DoGetNetworkList();
void SendNetworkList(const net::NetworkInterfaceList& list,
const net::IPAddress& default_ipv4_local_address,
const net::IPAddress& default_ipv6_local_address);
// network::mojom::P2PSocketManager overrides:
void StartNetworkNotifications(
network::mojom::P2PNetworkNotificationClientPtr client) override;
void GetHostAddress(const std::string& host_name,
network::mojom::P2PSocketManager::GetHostAddressCallback
callback) override;
void CreateSocket(network::P2PSocketType type,
const net::IPEndPoint& local_address,
const network::P2PPortRange& port_range,
const network::P2PHostAndIPEndPoint& remote_address,
network::mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest request) override;
void NetworkNotificationClientConnectionError();
// This connects a UDP socket to a public IP address and gets local
// address. Since it binds to the "any" address (0.0.0.0 or ::) internally, it
// retrieves the default local address.
net::IPAddress GetDefaultLocalAddress(int family);
void OnAddressResolved(
DnsRequest* request,
network::mojom::P2PSocketManager::GetHostAddressCallback callback,
const net::IPAddressList& addresses);
void StopRtpDumpOnIOThread(bool incoming, bool outgoing);
int render_process_id_; int render_process_id_;
scoped_refptr<net::URLRequestContextGetter> url_context_;
// Initialized on browser IO thread.
std::unique_ptr<network::ProxyResolvingClientSocketFactory>
proxy_resolving_socket_factory_;
base::flat_map<P2PSocketHost*, std::unique_ptr<P2PSocketHost>> sockets_;
std::set<std::unique_ptr<DnsRequest>> dns_requests_; bool dump_incoming_rtp_packet_ = false;
P2PMessageThrottler throttler_; bool dump_outgoing_rtp_packet_ = false;
net::IPAddress default_ipv4_local_address_;
net::IPAddress default_ipv6_local_address_;
bool dump_incoming_rtp_packet_;
bool dump_outgoing_rtp_packet_;
RenderProcessHost::WebRtcRtpPacketCallback packet_callback_; RenderProcessHost::WebRtcRtpPacketCallback packet_callback_;
// Used to call DoGetNetworkList, which may briefly block since getting the mojo::Binding<network::mojom::P2PTrustedSocketManagerClient> binding_;
// default local address involves creating a dummy socket. network::mojom::P2PTrustedSocketManagerPtr trusted_socket_manager_;
const scoped_refptr<base::SequencedTaskRunner> network_list_task_runner_;
mojo::Binding<network::mojom::P2PSocketManager> binding_;
network::mojom::P2PNetworkNotificationClientPtr network_notification_client_; network::mojom::P2PNetworkNotificationClientPtr network_notification_client_;
base::WeakPtrFactory<P2PSocketDispatcherHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcherHost); DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcherHost);
}; };
......
...@@ -1855,7 +1855,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { ...@@ -1855,7 +1855,7 @@ void RenderProcessHostImpl::CreateMessageFilters() {
#endif #endif
p2p_socket_dispatcher_host_ = p2p_socket_dispatcher_host_ =
new P2PSocketDispatcherHost(GetID(), request_context.get()); std::make_unique<P2PSocketDispatcherHost>(GetID());
AddFilter(new TraceMessageFilter(GetID())); AddFilter(new TraceMessageFilter(GetID()));
AddFilter(new ResolveProxyMsgHelper(GetID())); AddFilter(new ResolveProxyMsgHelper(GetID()));
...@@ -2034,8 +2034,10 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { ...@@ -2034,8 +2034,10 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
base::Unretained(storage_partition_impl_->GetAppCacheService()), base::Unretained(storage_partition_impl_->GetAppCacheService()),
GetID())); GetID()));
registry->AddInterface(base::BindRepeating( AddUIThreadInterface(
&P2PSocketDispatcherHost::BindRequest, p2p_socket_dispatcher_host_)); registry.get(),
base::BindRepeating(&P2PSocketDispatcherHost::BindRequest,
base::Unretained(p2p_socket_dispatcher_host_.get())));
AddUIThreadInterface(registry.get(), base::Bind(&FieldTrialRecorder::Create)); AddUIThreadInterface(registry.get(), base::Bind(&FieldTrialRecorder::Create));
...@@ -3393,18 +3395,13 @@ RenderProcessHostImpl::StartRtpDump( ...@@ -3393,18 +3395,13 @@ RenderProcessHostImpl::StartRtpDump(
bool incoming, bool incoming,
bool outgoing, bool outgoing,
const WebRtcRtpPacketCallback& packet_callback) { const WebRtcRtpPacketCallback& packet_callback) {
if (!p2p_socket_dispatcher_host_.get()) p2p_socket_dispatcher_host_->StartRtpDump(incoming, outgoing,
return WebRtcStopRtpDumpCallback(); packet_callback);
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::BindOnce(&P2PSocketDispatcherHost::StartRtpDump,
p2p_socket_dispatcher_host_, incoming,
outgoing, packet_callback));
if (stop_rtp_dump_callback_.is_null()) { if (stop_rtp_dump_callback_.is_null()) {
stop_rtp_dump_callback_ = stop_rtp_dump_callback_ =
base::Bind(&P2PSocketDispatcherHost::StopRtpDumpOnUIThread, base::Bind(&P2PSocketDispatcherHost::StopRtpDump,
p2p_socket_dispatcher_host_); p2p_socket_dispatcher_host_->GetWeakPtr());
} }
return stop_rtp_dump_callback_; return stop_rtp_dump_callback_;
} }
......
...@@ -763,7 +763,7 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -763,7 +763,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
BrowserThread::DeleteOnIOThread> BrowserThread::DeleteOnIOThread>
audio_output_stream_factory_context_; audio_output_stream_factory_context_;
scoped_refptr<P2PSocketDispatcherHost> p2p_socket_dispatcher_host_; std::unique_ptr<P2PSocketDispatcherHost> p2p_socket_dispatcher_host_;
// Must be accessed on UI thread. // Must be accessed on UI thread.
std::vector<int> aec_dump_consumers_; std::vector<int> aec_dump_consumers_;
......
...@@ -1498,11 +1498,6 @@ test("content_unittests") { ...@@ -1498,11 +1498,6 @@ test("content_unittests") {
"../browser/renderer_host/media/video_capture_manager_unittest.cc", "../browser/renderer_host/media/video_capture_manager_unittest.cc",
"../browser/renderer_host/media/video_capture_unittest.cc", "../browser/renderer_host/media/video_capture_unittest.cc",
"../browser/renderer_host/overscroll_controller_unittest.cc", "../browser/renderer_host/overscroll_controller_unittest.cc",
"../browser/renderer_host/p2p/socket_host_tcp_server_unittest.cc",
"../browser/renderer_host/p2p/socket_host_tcp_unittest.cc",
"../browser/renderer_host/p2p/socket_host_test_utils.cc",
"../browser/renderer_host/p2p/socket_host_test_utils.h",
"../browser/renderer_host/p2p/socket_host_udp_unittest.cc",
"../browser/renderer_host/render_process_host_unittest.cc", "../browser/renderer_host/render_process_host_unittest.cc",
"../browser/renderer_host/render_view_host_unittest.cc", "../browser/renderer_host/render_view_host_unittest.cc",
"../browser/renderer_host/render_widget_host_input_event_router_unittest.cc", "../browser/renderer_host/render_widget_host_input_event_router_unittest.cc",
......
...@@ -9,8 +9,6 @@ static_library("jingle_glue") { ...@@ -9,8 +9,6 @@ static_library("jingle_glue") {
sources = [ sources = [
"glue/chrome_async_socket.cc", "glue/chrome_async_socket.cc",
"glue/chrome_async_socket.h", "glue/chrome_async_socket.h",
"glue/fake_ssl_client_socket.cc",
"glue/fake_ssl_client_socket.h",
"glue/resolving_client_socket_factory.h", "glue/resolving_client_socket_factory.h",
"glue/task_pump.cc", "glue/task_pump.cc",
"glue/task_pump.h", "glue/task_pump.h",
...@@ -25,6 +23,7 @@ static_library("jingle_glue") { ...@@ -25,6 +23,7 @@ static_library("jingle_glue") {
"//third_party/webrtc_overrides", "//third_party/webrtc_overrides",
] ]
deps = [ deps = [
":jingle_fake_socket",
"//base", "//base",
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//net", "//net",
...@@ -42,6 +41,19 @@ static_library("jingle_glue") { ...@@ -42,6 +41,19 @@ static_library("jingle_glue") {
} }
} }
# These files are separated into their own target to avoid a circular dependency
# since services/network depends on this.
static_library("jingle_fake_socket") {
sources = [
"glue/fake_ssl_client_socket.cc",
"glue/fake_ssl_client_socket.h",
]
deps = [
"//base",
"//net",
]
}
# A library for sending and receiving peer-issued notifications. # A library for sending and receiving peer-issued notifications.
static_library("notifier") { static_library("notifier") {
sources = [ sources = [
......
...@@ -62,6 +62,18 @@ component("network_service") { ...@@ -62,6 +62,18 @@ component("network_service") {
"network_service_network_delegate.h", "network_service_network_delegate.h",
"network_usage_accumulator.cc", "network_usage_accumulator.cc",
"network_usage_accumulator.h", "network_usage_accumulator.h",
"p2p/socket.cc",
"p2p/socket.h",
"p2p/socket_manager.cc",
"p2p/socket_manager.h",
"p2p/socket_tcp.cc",
"p2p/socket_tcp.h",
"p2p/socket_tcp_server.cc",
"p2p/socket_tcp_server.h",
"p2p/socket_throttler.cc",
"p2p/socket_throttler.h",
"p2p/socket_udp.cc",
"p2p/socket_udp.h",
"proxy_config_service_mojo.cc", "proxy_config_service_mojo.cc",
"proxy_config_service_mojo.h", "proxy_config_service_mojo.h",
"proxy_lookup_request.cc", "proxy_lookup_request.cc",
...@@ -150,6 +162,7 @@ component("network_service") { ...@@ -150,6 +162,7 @@ component("network_service") {
"//components/network_session_configurator/common", "//components/network_session_configurator/common",
"//components/os_crypt", "//components/os_crypt",
"//components/prefs", "//components/prefs",
"//jingle:jingle_fake_socket",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//net", "//net",
...@@ -159,6 +172,10 @@ component("network_service") { ...@@ -159,6 +172,10 @@ component("network_service") {
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//services/service_manager/public/mojom", "//services/service_manager/public/mojom",
"//services/service_manager/sandbox:sandbox", "//services/service_manager/sandbox:sandbox",
"//third_party/webrtc/media:rtc_media_base",
"//third_party/webrtc/rtc_base",
"//third_party/webrtc_overrides",
"//third_party/webrtc_overrides:init_webrtc",
"//url", "//url",
] ]
...@@ -220,6 +237,11 @@ source_set("tests") { ...@@ -220,6 +237,11 @@ source_set("tests") {
"network_quality_estimator_manager_unittest.cc", "network_quality_estimator_manager_unittest.cc",
"network_service_unittest.cc", "network_service_unittest.cc",
"network_usage_accumulator_unittest.cc", "network_usage_accumulator_unittest.cc",
"p2p/socket_tcp_server_unittest.cc",
"p2p/socket_tcp_unittest.cc",
"p2p/socket_test_utils.cc",
"p2p/socket_test_utils.h",
"p2p/socket_udp_unittest.cc",
"proxy_config_service_mojo_unittest.cc", "proxy_config_service_mojo_unittest.cc",
"proxy_resolving_client_socket_unittest.cc", "proxy_resolving_client_socket_unittest.cc",
"proxy_resolving_socket_mojo_unittest.cc", "proxy_resolving_socket_mojo_unittest.cc",
...@@ -263,6 +285,7 @@ source_set("tests") { ...@@ -263,6 +285,7 @@ source_set("tests") {
"//base", "//base",
"//components/certificate_transparency", "//components/certificate_transparency",
"//components/network_session_configurator/browser", "//components/network_session_configurator/browser",
"//jingle:jingle_fake_socket",
"//mojo/core/embedder", "//mojo/core/embedder",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include "services/network/mojo_net_log.h" #include "services/network/mojo_net_log.h"
#include "services/network/network_service.h" #include "services/network/network_service.h"
#include "services/network/network_service_network_delegate.h" #include "services/network/network_service_network_delegate.h"
#include "services/network/p2p/socket_manager.h"
#include "services/network/proxy_config_service_mojo.h" #include "services/network/proxy_config_service_mojo.h"
#include "services/network/proxy_lookup_request.h" #include "services/network/proxy_lookup_request.h"
#include "services/network/proxy_resolving_socket_factory_mojo.h" #include "services/network/proxy_resolving_socket_factory_mojo.h"
...@@ -879,6 +880,20 @@ void NetworkContext::PreconnectSockets(uint32_t num_streams, ...@@ -879,6 +880,20 @@ void NetworkContext::PreconnectSockets(uint32_t num_streams,
base::saturated_cast<int32_t>(num_streams), request_info); base::saturated_cast<int32_t>(num_streams), request_info);
} }
void NetworkContext::CreateP2PSocketManager(
mojom::P2PTrustedSocketManagerClientPtr client,
mojom::P2PTrustedSocketManagerRequest trusted_socket_manager,
mojom::P2PSocketManagerRequest socket_manager_request) {
std::unique_ptr<P2PSocketManager> socket_manager =
std::make_unique<P2PSocketManager>(
std::move(client), std::move(trusted_socket_manager),
std::move(socket_manager_request),
base::Bind(&NetworkContext::DestroySocketManager,
base::Unretained(this)),
url_request_context_);
socket_managers_[socket_manager.get()] = std::move(socket_manager);
}
void NetworkContext::ResetURLLoaderFactories() { void NetworkContext::ResetURLLoaderFactories() {
for (const auto& factory : url_loader_factories_) for (const auto& factory : url_loader_factories_)
factory->ClearBindings(); factory->ClearBindings();
...@@ -1295,4 +1310,10 @@ GURL NetworkContext::GetHSTSRedirect(const GURL& original_url) { ...@@ -1295,4 +1310,10 @@ GURL NetworkContext::GetHSTSRedirect(const GURL& original_url) {
return original_url.ReplaceComponents(replacements); return original_url.ReplaceComponents(replacements);
} }
void NetworkContext::DestroySocketManager(P2PSocketManager* socket_manager) {
auto iter = socket_managers_.find(socket_manager);
DCHECK(iter != socket_managers_.end());
socket_managers_.erase(iter);
}
} // namespace network } // namespace network
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/component_export.h" #include "base/component_export.h"
#include "base/containers/flat_map.h"
#include "base/containers/unique_ptr_adapters.h" #include "base/containers/unique_ptr_adapters.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -56,6 +57,7 @@ namespace network { ...@@ -56,6 +57,7 @@ namespace network {
class CookieManager; class CookieManager;
class ExpectCTReporter; class ExpectCTReporter;
class NetworkService; class NetworkService;
class P2PSocketManager;
class ProxyLookupRequest; class ProxyLookupRequest;
class ResolveHostRequest; class ResolveHostRequest;
class ResourceScheduler; class ResourceScheduler;
...@@ -219,6 +221,10 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext ...@@ -219,6 +221,10 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext
const GURL& url, const GURL& url,
int32_t load_flags, int32_t load_flags,
bool privacy_mode_enabled) override; bool privacy_mode_enabled) override;
void CreateP2PSocketManager(
mojom::P2PTrustedSocketManagerClientPtr client,
mojom::P2PTrustedSocketManagerRequest trusted_socket_manager,
mojom::P2PSocketManagerRequest socket_manager_request) override;
void ResetURLLoaderFactories() override; void ResetURLLoaderFactories() override;
// Destroys |request| when a proxy lookup completes. // Destroys |request| when a proxy lookup completes.
...@@ -265,6 +271,8 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext ...@@ -265,6 +271,8 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext
GURL GetHSTSRedirect(const GURL& original_url); GURL GetHSTSRedirect(const GURL& original_url);
void DestroySocketManager(P2PSocketManager* socket_manager);
NetworkService* const network_service_; NetworkService* const network_service_;
std::unique_ptr<ResourceScheduler> resource_scheduler_; std::unique_ptr<ResourceScheduler> resource_scheduler_;
...@@ -310,6 +318,9 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext ...@@ -310,6 +318,9 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext
base::UniquePtrComparator> base::UniquePtrComparator>
url_loader_factories_; url_loader_factories_;
base::flat_map<P2PSocketManager*, std::unique_ptr<P2PSocketManager>>
socket_managers_;
mojo::StrongBindingSet<mojom::NetLogExporter> net_log_exporter_bindings_; mojo::StrongBindingSet<mojom::NetLogExporter> net_log_exporter_bindings_;
mojo::StrongBindingSet<mojom::RestrictedCookieManager> mojo::StrongBindingSet<mojom::RestrictedCookieManager>
......
include_rules = [ include_rules = [
"+jingle/glue", "+jingle/glue",
"+third_party/webrtc/media/base",
"+third_party/webrtc/rtc_base",
] ]
sergeyu@chromium.org
juberti@chromium.org
# COMPONENT: Blink>WebRTC
...@@ -2,18 +2,16 @@ ...@@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ #ifndef SERVICES_NETWORK_P2P_SOCKET_H_
#define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ #define SERVICES_NETWORK_P2P_SOCKET_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
#include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "net/base/ip_endpoint.h" #include "net/base/ip_endpoint.h"
#include "net/socket/datagram_socket.h" #include "net/socket/datagram_socket.h"
...@@ -22,33 +20,30 @@ ...@@ -22,33 +20,30 @@
#include "services/network/public/mojom/p2p.mojom.h" #include "services/network/public/mojom/p2p.mojom.h"
namespace net { namespace net {
class URLRequestContextGetter; class NetLog;
} }
namespace network { namespace network {
class ProxyResolvingClientSocketFactory; class ProxyResolvingClientSocketFactory;
} class P2PSocketManager;
namespace content {
class P2PSocketDispatcherHost;
class P2PMessageThrottler; class P2PMessageThrottler;
// Base class for P2P sockets. // Base class for P2P sockets.
class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket { class COMPONENT_EXPORT(NETWORK_SERVICE) P2PSocket : public mojom::P2PSocket {
public: public:
static const int kStunHeaderSize = 20; static const int kStunHeaderSize = 20;
static const size_t kMaximumPacketSize = 32768; static const size_t kMaximumPacketSize = 32768;
// Creates P2PSocketHost of the specific type. // Creates P2PSocket of the specific type.
static P2PSocketHost* Create(P2PSocketDispatcherHost* socket_dispatcher_host, static P2PSocket* Create(
network::mojom::P2PSocketClientPtr client, P2PSocketManager* socket_manager,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketClientPtr client,
network::P2PSocketType type, mojom::P2PSocketRequest socket,
net::URLRequestContextGetter* url_context, P2PSocketType type,
network::ProxyResolvingClientSocketFactory* net::NetLog* net_log,
proxy_resolving_socket_factory, ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory,
P2PMessageThrottler* throttler); P2PMessageThrottler* throttler);
~P2PSocketHost() override; ~P2PSocket() override;
// Initalizes the socket. Returns false when initialization fails. // Initalizes the socket. Returns false when initialization fails.
// |min_port| and |max_port| specify the valid range of allowed ports. // |min_port| and |max_port| specify the valid range of allowed ports.
...@@ -62,19 +57,16 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket { ...@@ -62,19 +57,16 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket {
virtual bool Init(const net::IPEndPoint& local_address, virtual bool Init(const net::IPEndPoint& local_address,
uint16_t min_port, uint16_t min_port,
uint16_t max_port, uint16_t max_port,
const network::P2PHostAndIPEndPoint& remote_address) = 0; const P2PHostAndIPEndPoint& remote_address) = 0;
void StartRtpDump( void StartRtpDump(bool incoming, bool outgoing);
bool incoming,
bool outgoing,
const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback);
void StopRtpDump(bool incoming, bool outgoing); void StopRtpDump(bool incoming, bool outgoing);
network::mojom::P2PSocketClientPtr ReleaseClientForTesting(); mojom::P2PSocketClientPtr ReleaseClientForTesting();
network::mojom::P2PSocketRequest ReleaseBindingForTesting(); mojom::P2PSocketRequest ReleaseBindingForTesting();
protected: protected:
friend class P2PSocketHostTcpTestBase; friend class P2PSocketTcpTestBase;
// This should match suffix IPProtocolType defined in histograms.xml. // This should match suffix IPProtocolType defined in histograms.xml.
enum ProtocolType { UDP = 0x1, TCP = 0x2 }; enum ProtocolType { UDP = 0x1, TCP = 0x2 };
...@@ -112,10 +104,10 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket { ...@@ -112,10 +104,10 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket {
STATE_ERROR, STATE_ERROR,
}; };
P2PSocketHost(P2PSocketDispatcherHost* socket_dispatcher_host, P2PSocket(P2PSocketManager* socket_manager,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketRequest socket,
ProtocolType protocol_type); ProtocolType protocol_type);
// Verifies that the packet |data| has a valid STUN header. In case // Verifies that the packet |data| has a valid STUN header. In case
// of success stores type of the message in |type|. // of success stores type of the message in |type|.
...@@ -126,28 +118,21 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket { ...@@ -126,28 +118,21 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket {
static void ReportSocketError(int result, const char* histogram_name); static void ReportSocketError(int result, const char* histogram_name);
// Calls |packet_dump_callback_| to record the RTP header. // Calls |socket_manager_| to record the RTP header.
void DumpRtpPacket(const int8_t* packet, size_t length, bool incoming); void DumpRtpPacket(const int8_t* packet, size_t length, bool incoming);
// A helper to dump the packet on the IO thread.
void DumpRtpPacketOnIOThread(std::unique_ptr<uint8_t[]> packet_header,
size_t header_length,
size_t packet_length,
bool incoming);
// Used by subclasses to track the metrics of delayed bytes and packets. // Used by subclasses to track the metrics of delayed bytes and packets.
void IncrementDelayedPackets(); void IncrementDelayedPackets();
void IncrementTotalSentPackets(); void IncrementTotalSentPackets();
void IncrementDelayedBytes(uint32_t size); void IncrementDelayedBytes(uint32_t size);
void DecrementDelayedBytes(uint32_t size); void DecrementDelayedBytes(uint32_t size);
P2PSocketDispatcherHost* socket_dispatcher_host_; P2PSocketManager* socket_manager_;
network::mojom::P2PSocketClientPtr client_; mojom::P2PSocketClientPtr client_;
mojo::Binding<network::mojom::P2PSocket> binding_; mojo::Binding<mojom::P2PSocket> binding_;
State state_; State state_;
bool dump_incoming_rtp_packet_; bool dump_incoming_rtp_packet_;
bool dump_outgoing_rtp_packet_; bool dump_outgoing_rtp_packet_;
RenderProcessHost::WebRtcRtpPacketCallback packet_dump_callback_;
ProtocolType protocol_type_; ProtocolType protocol_type_;
...@@ -163,11 +148,11 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket { ...@@ -163,11 +148,11 @@ class CONTENT_EXPORT P2PSocketHost : public network::mojom::P2PSocket {
int32_t send_bytes_delayed_max_; int32_t send_bytes_delayed_max_;
int32_t send_bytes_delayed_cur_; int32_t send_bytes_delayed_cur_;
base::WeakPtrFactory<P2PSocketHost> weak_ptr_factory_; base::WeakPtrFactory<P2PSocket> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(P2PSocketHost); DISALLOW_COPY_AND_ASSIGN(P2PSocket);
}; };
} // namespace content } // namespace network
#endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ #endif // SERVICES_NETWORK_P2P_SOCKET_H_
This diff is collapsed.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_NETWORK_P2P_SOCKET_MANAGER_H_
#define SERVICES_NETWORK_P2P_SOCKET_MANAGER_H_
#include <stdint.h>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/network_change_notifier.h"
#include "services/network/p2p/socket_throttler.h"
#include "services/network/public/cpp/p2p_socket_type.h"
#include "services/network/public/mojom/p2p.mojom.h"
#include "services/network/public/mojom/p2p_trusted.mojom.h"
namespace net {
class URLRequestContext;
}
namespace network {
class ProxyResolvingClientSocketFactory;
}
namespace network {
class P2PSocket;
// Owns all the P2P socket instances and dispatches Mojo calls from the
// (untrusted) child and (trusted) browser process.
class P2PSocketManager
: public net::NetworkChangeNotifier::NetworkChangeObserver,
public mojom::P2PSocketManager,
public mojom::P2PTrustedSocketManager {
public:
using DeleteCallback =
base::OnceCallback<void(P2PSocketManager* socket_manager)>;
// |delete_callback| tells the P2PSocketManager's owner to destroy the
// P2PSocketManager. The P2PSocketManager must be destroyed before the
// |url_request_context|.
P2PSocketManager(
mojom::P2PTrustedSocketManagerClientPtr trusted_socket_manager_client,
mojom::P2PTrustedSocketManagerRequest trusted_socket_manager_request,
mojom::P2PSocketManagerRequest socket_manager_request,
DeleteCallback delete_callback,
net::URLRequestContext* url_request_context);
~P2PSocketManager() override;
// net::NetworkChangeNotifier::NetworkChangeObserver overrides.
void OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) override;
// The following methods are called by the socket implementations.
// Called when a new socket is created due to an incoming connection.
void AddAcceptedConnection(std::unique_ptr<P2PSocket> accepted_connection);
// Tells the SocketManager to destroy the given socket.
void DestroySocket(P2PSocket* socket);
// Called when packet logging is enabled.
void DumpPacket(const int8_t* packet_header,
size_t header_length,
size_t packet_length,
bool incoming);
private:
class DnsRequest;
static void DoGetNetworkList(
const base::WeakPtr<P2PSocketManager>& socket_manager,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
void SendNetworkList(const net::NetworkInterfaceList& list,
const net::IPAddress& default_ipv4_local_address,
const net::IPAddress& default_ipv6_local_address);
// mojom::P2PSocketManager overrides:
void StartNetworkNotifications(
mojom::P2PNetworkNotificationClientPtr client) override;
void GetHostAddress(
const std::string& host_name,
mojom::P2PSocketManager::GetHostAddressCallback callback) override;
void CreateSocket(P2PSocketType type,
const net::IPEndPoint& local_address,
const P2PPortRange& port_range,
const P2PHostAndIPEndPoint& remote_address,
mojom::P2PSocketClientPtr client,
mojom::P2PSocketRequest request) override;
// mojom::P2PTrustedSocketManager overrides:
void StartRtpDump(bool incoming, bool outgoing) override;
void StopRtpDump(bool incoming, bool outgoing) override;
void NetworkNotificationClientConnectionError();
// This connects a UDP socket to a public IP address and gets local
// address. Since it binds to the "any" address (0.0.0.0 or ::) internally, it
// retrieves the default local address.
static net::IPAddress GetDefaultLocalAddress(int family);
void OnAddressResolved(
DnsRequest* request,
mojom::P2PSocketManager::GetHostAddressCallback callback,
const net::IPAddressList& addresses);
void OnConnectionError();
DeleteCallback delete_callback_;
net::URLRequestContext* url_request_context_;
std::unique_ptr<ProxyResolvingClientSocketFactory>
proxy_resolving_socket_factory_;
base::flat_map<P2PSocket*, std::unique_ptr<P2PSocket>> sockets_;
std::set<std::unique_ptr<DnsRequest>> dns_requests_;
P2PMessageThrottler throttler_;
bool dump_incoming_rtp_packet_ = false;
bool dump_outgoing_rtp_packet_ = false;
// Used to call DoGetNetworkList, which may briefly block since getting the
// default local address involves creating a dummy socket.
const scoped_refptr<base::SequencedTaskRunner> network_list_task_runner_;
mojom::P2PTrustedSocketManagerClientPtr trusted_socket_manager_client_;
mojo::Binding<mojom::P2PTrustedSocketManager> trusted_socket_manager_binding_;
mojo::Binding<mojom::P2PSocketManager> socket_manager_binding_;
mojom::P2PNetworkNotificationClientPtr network_notification_client_;
base::WeakPtrFactory<P2PSocketManager> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(P2PSocketManager);
};
} // namespace network
#endif // SERVICES_NETWORK_P2P_SOCKET_MANAGER_H_
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ #ifndef SERVICES_NETWORK_P2P_SOCKET_TCP_H_
#define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_ #define SERVICES_NETWORK_P2P_SOCKET_TCP_H_
#include <stdint.h> #include <stdint.h>
...@@ -11,58 +11,53 @@ ...@@ -11,58 +11,53 @@
#include <vector> #include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/component_export.h"
#include "base/containers/queue.h" #include "base/containers/queue.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/browser/renderer_host/p2p/socket_host.h"
#include "net/base/completion_callback.h" #include "net/base/completion_callback.h"
#include "net/base/ip_endpoint.h" #include "net/base/ip_endpoint.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/p2p/socket.h"
#include "services/network/public/cpp/p2p_socket_type.h" #include "services/network/public/cpp/p2p_socket_type.h"
namespace network {
class ProxyResolvingClientSocketFactory;
} // namespace network
namespace net { namespace net {
class DrainableIOBuffer; class DrainableIOBuffer;
class GrowableIOBuffer; class GrowableIOBuffer;
class StreamSocket; class StreamSocket;
class URLRequestContextGetter;
} // namespace net } // namespace net
namespace content { namespace network {
class ProxyResolvingClientSocketFactory;
class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { class COMPONENT_EXPORT(NETWORK_SERVICE) P2PSocketTcpBase : public P2PSocket {
public: public:
P2PSocketHostTcpBase(P2PSocketDispatcherHost* socket_dispatcher_host, P2PSocketTcpBase(
network::mojom::P2PSocketClientPtr client, P2PSocketManager* socket_manager,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketClientPtr client,
network::P2PSocketType type, mojom::P2PSocketRequest socket,
net::URLRequestContextGetter* url_context, P2PSocketType type,
network::ProxyResolvingClientSocketFactory* ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory);
proxy_resolving_socket_factory); ~P2PSocketTcpBase() override;
~P2PSocketHostTcpBase() override;
bool InitAccepted(const net::IPEndPoint& remote_address, bool InitAccepted(const net::IPEndPoint& remote_address,
std::unique_ptr<net::StreamSocket> socket); std::unique_ptr<net::StreamSocket> socket);
// P2PSocketHost overrides. // P2PSocket overrides.
bool Init(const net::IPEndPoint& local_address, bool Init(const net::IPEndPoint& local_address,
uint16_t min_port, uint16_t min_port,
uint16_t max_port, uint16_t max_port,
const network::P2PHostAndIPEndPoint& remote_address) override; const P2PHostAndIPEndPoint& remote_address) override;
// network::mojom::P2PSocket implementation: // mojom::P2PSocket implementation:
void AcceptIncomingTcpConnection( void AcceptIncomingTcpConnection(const net::IPEndPoint& remote_address,
const net::IPEndPoint& remote_address, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketRequest socket) override;
network::mojom::P2PSocketRequest socket) override;
void Send(const std::vector<int8_t>& data, void Send(const std::vector<int8_t>& data,
const network::P2PPacketInfo& packet_info, const P2PPacketInfo& packet_info,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
override; override;
void SetOption(network::P2PSocketOption option, int32_t value) override; void SetOption(P2PSocketOption option, int32_t value) override;
protected: protected:
struct SendBuffer { struct SendBuffer {
...@@ -91,8 +86,8 @@ class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { ...@@ -91,8 +86,8 @@ class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost {
void OnError(); void OnError();
private: private:
friend class P2PSocketHostTcpTestBase; friend class P2PSocketTcpTestBase;
friend class P2PSocketHostTcpServerTest; friend class P2PSocketTcpServerTest;
void DidCompleteRead(int result); void DidCompleteRead(int result);
void DoRead(); void DoRead();
...@@ -109,7 +104,7 @@ class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { ...@@ -109,7 +104,7 @@ class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost {
void OnOpen(); void OnOpen();
bool DoSendSocketCreateMsg(); bool DoSendSocketCreateMsg();
network::P2PHostAndIPEndPoint remote_address_; P2PHostAndIPEndPoint remote_address_;
std::unique_ptr<net::StreamSocket> socket_; std::unique_ptr<net::StreamSocket> socket_;
scoped_refptr<net::GrowableIOBuffer> read_buffer_; scoped_refptr<net::GrowableIOBuffer> read_buffer_;
...@@ -119,24 +114,22 @@ class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost { ...@@ -119,24 +114,22 @@ class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost {
bool write_pending_; bool write_pending_;
bool connected_; bool connected_;
network::P2PSocketType type_; P2PSocketType type_;
scoped_refptr<net::URLRequestContextGetter> url_context_; ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory_;
network::ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory_;
DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpBase); DISALLOW_COPY_AND_ASSIGN(P2PSocketTcpBase);
}; };
class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { class COMPONENT_EXPORT(NETWORK_SERVICE) P2PSocketTcp : public P2PSocketTcpBase {
public: public:
P2PSocketHostTcp(P2PSocketDispatcherHost* socket_dispatcher_host, P2PSocketTcp(
network::mojom::P2PSocketClientPtr client, P2PSocketManager* socket_manager,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketClientPtr client,
network::P2PSocketType type, mojom::P2PSocketRequest socket,
net::URLRequestContextGetter* url_context, P2PSocketType type,
network::ProxyResolvingClientSocketFactory* ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory);
proxy_resolving_socket_factory);
~P2PSocketHostTcp() override; ~P2PSocketTcp() override;
protected: protected:
int ProcessInput(char* input, int input_len) override; int ProcessInput(char* input, int input_len) override;
...@@ -147,24 +140,24 @@ class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase { ...@@ -147,24 +140,24 @@ class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHostTcpBase {
const net::NetworkTrafficAnnotationTag traffic_annotation) override; const net::NetworkTrafficAnnotationTag traffic_annotation) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp); DISALLOW_COPY_AND_ASSIGN(P2PSocketTcp);
}; };
// P2PSocketHostStunTcp class provides the framing of STUN messages when used // P2PSocketStunTcp class provides the framing of STUN messages when used
// with TURN. These messages will not have length at front of the packet and // with TURN. These messages will not have length at front of the packet and
// are padded to multiple of 4 bytes. // are padded to multiple of 4 bytes.
// Formatting of messages is defined in RFC5766. // Formatting of messages is defined in RFC5766.
class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { class COMPONENT_EXPORT(NETWORK_SERVICE) P2PSocketStunTcp
: public P2PSocketTcpBase {
public: public:
P2PSocketHostStunTcp(P2PSocketDispatcherHost* socket_dispatcher_host, P2PSocketStunTcp(
network::mojom::P2PSocketClientPtr client, P2PSocketManager* socket_manager,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketClientPtr client,
network::P2PSocketType type, mojom::P2PSocketRequest socket,
net::URLRequestContextGetter* url_context, P2PSocketType type,
network::ProxyResolvingClientSocketFactory* ProxyResolvingClientSocketFactory* proxy_resolving_socket_factory);
proxy_resolving_socket_factory);
~P2PSocketHostStunTcp() override; ~P2PSocketStunTcp() override;
protected: protected:
int ProcessInput(char* input, int input_len) override; int ProcessInput(char* input, int input_len) override;
...@@ -177,10 +170,9 @@ class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase { ...@@ -177,10 +170,9 @@ class CONTENT_EXPORT P2PSocketHostStunTcp : public P2PSocketHostTcpBase {
private: private:
int GetExpectedPacketSize(const int8_t* data, int len, int* pad_bytes); int GetExpectedPacketSize(const int8_t* data, int len, int* pad_bytes);
DISALLOW_COPY_AND_ASSIGN(P2PSocketHostStunTcp); DISALLOW_COPY_AND_ASSIGN(P2PSocketStunTcp);
}; };
} // namespace network
} // namespace content #endif // SERVICES_NETWORK_P2P_SOCKET_TCP_H_
#endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_H_
...@@ -2,41 +2,40 @@ ...@@ -2,41 +2,40 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" #include "services/network/p2p/socket_tcp_server.h"
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
#include "content/browser/renderer_host/p2p/socket_host_tcp.h"
#include "net/base/address_list.h" #include "net/base/address_list.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/log/net_log_source.h" #include "net/log/net_log_source.h"
#include "net/socket/stream_socket.h" #include "net/socket/stream_socket.h"
#include "services/network/p2p/socket_manager.h"
#include "services/network/p2p/socket_tcp.h"
#include "services/network/public/cpp/p2p_param_traits.h" #include "services/network/public/cpp/p2p_param_traits.h"
namespace { namespace {
const int kListenBacklog = 5; const int kListenBacklog = 5;
} // namespace } // namespace
namespace content { namespace network {
P2PSocketHostTcpServer::P2PSocketHostTcpServer( P2PSocketTcpServer::P2PSocketTcpServer(P2PSocketManager* socket_manager,
P2PSocketDispatcherHost* socket_dispatcher_host, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketRequest socket,
network::mojom::P2PSocketRequest socket, P2PSocketType client_type)
network::P2PSocketType client_type) : P2PSocket(socket_manager,
: P2PSocketHost(socket_dispatcher_host, std::move(client),
std::move(client), std::move(socket),
std::move(socket), P2PSocket::TCP),
P2PSocketHost::TCP),
client_type_(client_type), client_type_(client_type),
socket_(new net::TCPServerSocket(nullptr, net::NetLogSource())), socket_(new net::TCPServerSocket(nullptr, net::NetLogSource())),
accept_callback_(base::BindRepeating(&P2PSocketHostTcpServer::OnAccepted, accept_callback_(base::BindRepeating(&P2PSocketTcpServer::OnAccepted,
base::Unretained(this))) {} base::Unretained(this))) {}
P2PSocketHostTcpServer::~P2PSocketHostTcpServer() { P2PSocketTcpServer::~P2PSocketTcpServer() {
if (state_ == STATE_OPEN) { if (state_ == STATE_OPEN) {
DCHECK(socket_.get()); DCHECK(socket_.get());
socket_.reset(); socket_.reset();
...@@ -44,11 +43,10 @@ P2PSocketHostTcpServer::~P2PSocketHostTcpServer() { ...@@ -44,11 +43,10 @@ P2PSocketHostTcpServer::~P2PSocketHostTcpServer() {
} }
// TODO(guidou): Add support for port range. // TODO(guidou): Add support for port range.
bool P2PSocketHostTcpServer::Init( bool P2PSocketTcpServer::Init(const net::IPEndPoint& local_address,
const net::IPEndPoint& local_address, uint16_t min_port,
uint16_t min_port, uint16_t max_port,
uint16_t max_port, const P2PHostAndIPEndPoint& remote_address) {
const network::P2PHostAndIPEndPoint& remote_address) {
DCHECK_EQ(state_, STATE_UNINITIALIZED); DCHECK_EQ(state_, STATE_UNINITIALIZED);
int result = socket_->Listen(local_address, kListenBacklog); int result = socket_->Listen(local_address, kListenBacklog);
...@@ -60,7 +58,7 @@ bool P2PSocketHostTcpServer::Init( ...@@ -60,7 +58,7 @@ bool P2PSocketHostTcpServer::Init(
result = socket_->GetLocalAddress(&local_address_); result = socket_->GetLocalAddress(&local_address_);
if (result < 0) { if (result < 0) {
LOG(ERROR) << "P2PSocketHostTcpServer::Init(): can't to get local address: " LOG(ERROR) << "P2PSocketTcpServer::Init(): can't to get local address: "
<< result; << result;
OnError(); OnError();
return false; return false;
...@@ -75,11 +73,11 @@ bool P2PSocketHostTcpServer::Init( ...@@ -75,11 +73,11 @@ bool P2PSocketHostTcpServer::Init(
return true; return true;
} }
std::unique_ptr<P2PSocketHostTcpBase> std::unique_ptr<P2PSocketTcpBase>
P2PSocketHostTcpServer::AcceptIncomingTcpConnectionInternal( P2PSocketTcpServer::AcceptIncomingTcpConnectionInternal(
const net::IPEndPoint& remote_address, const net::IPEndPoint& remote_address,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest request) { mojom::P2PSocketRequest request) {
auto it = accepted_sockets_.find(remote_address); auto it = accepted_sockets_.find(remote_address);
if (it == accepted_sockets_.end()) if (it == accepted_sockets_.end())
return nullptr; return nullptr;
...@@ -87,15 +85,14 @@ P2PSocketHostTcpServer::AcceptIncomingTcpConnectionInternal( ...@@ -87,15 +85,14 @@ P2PSocketHostTcpServer::AcceptIncomingTcpConnectionInternal(
std::unique_ptr<net::StreamSocket> socket = std::move(it->second); std::unique_ptr<net::StreamSocket> socket = std::move(it->second);
accepted_sockets_.erase(it); accepted_sockets_.erase(it);
std::unique_ptr<P2PSocketHostTcpBase> result; std::unique_ptr<P2PSocketTcpBase> result;
if (client_type_ == network::P2P_SOCKET_TCP_CLIENT) { if (client_type_ == P2P_SOCKET_TCP_CLIENT) {
result.reset(new P2PSocketHostTcp(socket_dispatcher_host_, result.reset(new P2PSocketTcp(socket_manager_, std::move(client),
std::move(client), std::move(request), std::move(request), client_type_, nullptr));
client_type_, nullptr, nullptr));
} else { } else {
result.reset(new P2PSocketHostStunTcp(socket_dispatcher_host_, result.reset(new P2PSocketStunTcp(socket_manager_, std::move(client),
std::move(client), std::move(request), std::move(request), client_type_,
client_type_, nullptr, nullptr)); nullptr));
} }
if (!result->InitAccepted(remote_address, std::move(socket))) if (!result->InitAccepted(remote_address, std::move(socket)))
return nullptr; return nullptr;
...@@ -103,7 +100,7 @@ P2PSocketHostTcpServer::AcceptIncomingTcpConnectionInternal( ...@@ -103,7 +100,7 @@ P2PSocketHostTcpServer::AcceptIncomingTcpConnectionInternal(
return result; return result;
} }
void P2PSocketHostTcpServer::OnError() { void P2PSocketTcpServer::OnError() {
socket_.reset(); socket_.reset();
if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN) { if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN) {
...@@ -114,7 +111,7 @@ void P2PSocketHostTcpServer::OnError() { ...@@ -114,7 +111,7 @@ void P2PSocketHostTcpServer::OnError() {
state_ = STATE_ERROR; state_ = STATE_ERROR;
} }
void P2PSocketHostTcpServer::DoAccept() { void P2PSocketTcpServer::DoAccept() {
while (true) { while (true) {
int result = socket_->Accept(&accept_socket_, accept_callback_); int result = socket_->Accept(&accept_socket_, accept_callback_);
if (result == net::ERR_IO_PENDING) { if (result == net::ERR_IO_PENDING) {
...@@ -125,7 +122,7 @@ void P2PSocketHostTcpServer::DoAccept() { ...@@ -125,7 +122,7 @@ void P2PSocketHostTcpServer::DoAccept() {
} }
} }
void P2PSocketHostTcpServer::HandleAcceptResult(int result) { void P2PSocketTcpServer::HandleAcceptResult(int result) {
if (result < 0) { if (result < 0) {
if (result != net::ERR_IO_PENDING) if (result != net::ERR_IO_PENDING)
OnError(); OnError();
...@@ -142,34 +139,33 @@ void P2PSocketHostTcpServer::HandleAcceptResult(int result) { ...@@ -142,34 +139,33 @@ void P2PSocketHostTcpServer::HandleAcceptResult(int result) {
client_->IncomingTcpConnection(address); client_->IncomingTcpConnection(address);
} }
void P2PSocketHostTcpServer::OnAccepted(int result) { void P2PSocketTcpServer::OnAccepted(int result) {
HandleAcceptResult(result); HandleAcceptResult(result);
if (result == net::OK) if (result == net::OK)
DoAccept(); DoAccept();
} }
void P2PSocketHostTcpServer::AcceptIncomingTcpConnection( void P2PSocketTcpServer::AcceptIncomingTcpConnection(
const net::IPEndPoint& remote_address, const net::IPEndPoint& remote_address,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest request) { mojom::P2PSocketRequest request) {
std::unique_ptr<P2PSocketHostTcpBase> socket = std::unique_ptr<P2PSocketTcpBase> socket =
AcceptIncomingTcpConnectionInternal(remote_address, std::move(client), AcceptIncomingTcpConnectionInternal(remote_address, std::move(client),
std::move(request)); std::move(request));
if (socket) if (socket)
socket_dispatcher_host_->AddAcceptedConnection(std::move(socket)); socket_manager_->AddAcceptedConnection(std::move(socket));
} }
void P2PSocketHostTcpServer::Send( void P2PSocketTcpServer::Send(
const std::vector<int8_t>& data, const std::vector<int8_t>& data,
const network::P2PPacketInfo& packet_info, const P2PPacketInfo& packet_info,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
NOTREACHED(); NOTREACHED();
delete this; delete this;
} }
void P2PSocketHostTcpServer::SetOption(network::P2PSocketOption option, void P2PSocketTcpServer::SetOption(P2PSocketOption option, int32_t value) {
int32_t value) {
// Currently we don't have use case tcp server sockets are used for p2p. // Currently we don't have use case tcp server sockets are used for p2p.
} }
} // namespace content } // namespace network
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_SERVER_H_ #ifndef SERVICES_NETWORK_P2P_SOCKET_TCP_SERVER_H_
#define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_SERVER_H_ #define SERVICES_NETWORK_P2P_SOCKET_TCP_SERVER_H_
#include <stdint.h> #include <stdint.h>
...@@ -12,54 +12,52 @@ ...@@ -12,54 +12,52 @@
#include <vector> #include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/browser/renderer_host/p2p/socket_host.h"
#include "content/common/content_export.h"
#include "ipc/ipc_sender.h"
#include "net/base/completion_repeating_callback.h" #include "net/base/completion_repeating_callback.h"
#include "net/socket/tcp_server_socket.h" #include "net/socket/tcp_server_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/p2p/socket.h"
#include "services/network/public/cpp/p2p_socket_type.h" #include "services/network/public/cpp/p2p_socket_type.h"
namespace net { namespace net {
class StreamSocket; class StreamSocket;
} // namespace net } // namespace net
namespace content { namespace network {
class P2PSocketHostTcpBase; class P2PSocketTcpBase;
class CONTENT_EXPORT P2PSocketHostTcpServer : public P2PSocketHost { class COMPONENT_EXPORT(NETWORK_SERVICE) P2PSocketTcpServer : public P2PSocket {
public: public:
P2PSocketHostTcpServer(P2PSocketDispatcherHost* socket_dispatcher_host, P2PSocketTcpServer(P2PSocketManager* socket_manager,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketRequest socket,
network::P2PSocketType client_type); P2PSocketType client_type);
~P2PSocketHostTcpServer() override; ~P2PSocketTcpServer() override;
// P2PSocketHost overrides. // P2PSocket overrides.
bool Init(const net::IPEndPoint& local_address, bool Init(const net::IPEndPoint& local_address,
uint16_t min_port, uint16_t min_port,
uint16_t max_port, uint16_t max_port,
const network::P2PHostAndIPEndPoint& remote_address) override; const P2PHostAndIPEndPoint& remote_address) override;
// network::mojom::P2PSocket implementation: // mojom::P2PSocket implementation:
void AcceptIncomingTcpConnection( void AcceptIncomingTcpConnection(const net::IPEndPoint& remote_address,
const net::IPEndPoint& remote_address, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketRequest request) override;
network::mojom::P2PSocketRequest request) override;
void Send(const std::vector<int8_t>& data, void Send(const std::vector<int8_t>& data,
const network::P2PPacketInfo& packet_info, const P2PPacketInfo& packet_info,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
override; override;
void SetOption(network::P2PSocketOption option, int32_t value) override; void SetOption(P2PSocketOption option, int32_t value) override;
private: private:
friend class P2PSocketHostTcpServerTest; friend class P2PSocketTcpServerTest;
std::unique_ptr<P2PSocketHostTcpBase> AcceptIncomingTcpConnectionInternal( std::unique_ptr<P2PSocketTcpBase> AcceptIncomingTcpConnectionInternal(
const net::IPEndPoint& remote_address, const net::IPEndPoint& remote_address,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest request); mojom::P2PSocketRequest request);
void OnError(); void OnError();
...@@ -69,7 +67,7 @@ class CONTENT_EXPORT P2PSocketHostTcpServer : public P2PSocketHost { ...@@ -69,7 +67,7 @@ class CONTENT_EXPORT P2PSocketHostTcpServer : public P2PSocketHost {
// Callback for Accept(). // Callback for Accept().
void OnAccepted(int result); void OnAccepted(int result);
const network::P2PSocketType client_type_; const P2PSocketType client_type_;
std::unique_ptr<net::ServerSocket> socket_; std::unique_ptr<net::ServerSocket> socket_;
net::IPEndPoint local_address_; net::IPEndPoint local_address_;
...@@ -79,9 +77,9 @@ class CONTENT_EXPORT P2PSocketHostTcpServer : public P2PSocketHost { ...@@ -79,9 +77,9 @@ class CONTENT_EXPORT P2PSocketHostTcpServer : public P2PSocketHost {
const net::CompletionRepeatingCallback accept_callback_; const net::CompletionRepeatingCallback accept_callback_;
DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcpServer); DISALLOW_COPY_AND_ASSIGN(P2PSocketTcpServer);
}; };
} // namespace content } // namespace network
#endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TCP_SERVER_H_ #endif // SERVICES_NETWORK_P2P_SOCKET_TCP_SERVER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" #include "services/network/p2p/socket_tcp_server.h"
#include <stdint.h> #include <stdint.h>
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "content/browser/renderer_host/p2p/socket_host_tcp.h"
#include "content/browser/renderer_host/p2p/socket_host_test_utils.h"
#include "net/base/completion_once_callback.h" #include "net/base/completion_once_callback.h"
#include "services/network/p2p/socket_tcp.h"
#include "services/network/p2p/socket_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -82,28 +82,28 @@ class FakeServerSocket : public net::ServerSocket { ...@@ -82,28 +82,28 @@ class FakeServerSocket : public net::ServerSocket {
} // namespace } // namespace
namespace content { namespace network {
class P2PSocketHostTcpServerTest : public testing::Test { class P2PSocketTcpServerTest : public testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
network::mojom::P2PSocketClientPtr socket_client; mojom::P2PSocketClientPtr socket_client;
auto socket_client_request = mojo::MakeRequest(&socket_client); auto socket_client_request = mojo::MakeRequest(&socket_client);
network::mojom::P2PSocketPtr socket; mojom::P2PSocketPtr socket;
auto socket_request = mojo::MakeRequest(&socket); auto socket_request = mojo::MakeRequest(&socket);
fake_client_.reset(new FakeSocketClient(std::move(socket), fake_client_.reset(new FakeSocketClient(std::move(socket),
std::move(socket_client_request))); std::move(socket_client_request)));
socket_ = new FakeServerSocket(); socket_ = new FakeServerSocket();
socket_host_.reset(new P2PSocketHostTcpServer( socket_host_.reset(new P2PSocketTcpServer(nullptr, std::move(socket_client),
nullptr, std::move(socket_client), std::move(socket_request), std::move(socket_request),
network::P2P_SOCKET_TCP_CLIENT)); P2P_SOCKET_TCP_CLIENT));
socket_host_->socket_.reset(socket_); socket_host_->socket_.reset(socket_);
EXPECT_CALL(*fake_client_.get(), SocketCreated(_, _)).Times(1); EXPECT_CALL(*fake_client_.get(), SocketCreated(_, _)).Times(1);
network::P2PHostAndIPEndPoint dest; P2PHostAndIPEndPoint dest;
dest.ip_address = ParseAddress(kTestIpAddress1, kTestPort1); dest.ip_address = ParseAddress(kTestIpAddress1, kTestPort1);
socket_host_->Init(ParseAddress(kTestLocalIpAddress, 0), 0, 0, dest); socket_host_->Init(ParseAddress(kTestLocalIpAddress, 0), 0, 0, dest);
...@@ -112,16 +112,16 @@ class P2PSocketHostTcpServerTest : public testing::Test { ...@@ -112,16 +112,16 @@ class P2PSocketHostTcpServerTest : public testing::Test {
} }
// Needed by the child classes because only this class is a friend // Needed by the child classes because only this class is a friend
// of P2PSocketHostTcp. // of P2PSocketTcp.
net::StreamSocket* GetSocketFormTcpSocketHost(P2PSocketHostTcpBase* host) { net::StreamSocket* GetSocketFormTcpSocket(P2PSocketTcpBase* host) {
return host->socket_.get(); return host->socket_.get();
} }
std::unique_ptr<P2PSocketHostTcpBase> AcceptIncomingTcpConnection( std::unique_ptr<P2PSocketTcpBase> AcceptIncomingTcpConnection(
const net::IPEndPoint& address) { const net::IPEndPoint& address) {
network::mojom::P2PSocketClientPtr socket_client; mojom::P2PSocketClientPtr socket_client;
auto socket_client_request = mojo::MakeRequest(&socket_client); auto socket_client_request = mojo::MakeRequest(&socket_client);
network::mojom::P2PSocketPtr socket; mojom::P2PSocketPtr socket;
auto socket_request = mojo::MakeRequest(&socket); auto socket_request = mojo::MakeRequest(&socket);
return socket_host_->AcceptIncomingTcpConnectionInternal( return socket_host_->AcceptIncomingTcpConnectionInternal(
...@@ -131,11 +131,11 @@ class P2PSocketHostTcpServerTest : public testing::Test { ...@@ -131,11 +131,11 @@ class P2PSocketHostTcpServerTest : public testing::Test {
base::test::ScopedTaskEnvironment scoped_task_environment_; base::test::ScopedTaskEnvironment scoped_task_environment_;
FakeServerSocket* socket_; // Owned by |socket_host_|. FakeServerSocket* socket_; // Owned by |socket_host_|.
std::unique_ptr<FakeSocketClient> fake_client_; std::unique_ptr<FakeSocketClient> fake_client_;
std::unique_ptr<P2PSocketHostTcpServer> socket_host_; std::unique_ptr<P2PSocketTcpServer> socket_host_;
}; };
// Accept incoming connection. // Accept incoming connection.
TEST_F(P2PSocketHostTcpServerTest, Accept) { TEST_F(P2PSocketTcpServerTest, Accept) {
FakeSocket* incoming = new FakeSocket(nullptr); FakeSocket* incoming = new FakeSocket(nullptr);
incoming->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); incoming->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1));
net::IPEndPoint addr = ParseAddress(kTestIpAddress1, kTestPort1); net::IPEndPoint addr = ParseAddress(kTestIpAddress1, kTestPort1);
...@@ -144,17 +144,15 @@ TEST_F(P2PSocketHostTcpServerTest, Accept) { ...@@ -144,17 +144,15 @@ TEST_F(P2PSocketHostTcpServerTest, Accept) {
EXPECT_CALL(*fake_client_.get(), IncomingTcpConnection(addr)).Times(1); EXPECT_CALL(*fake_client_.get(), IncomingTcpConnection(addr)).Times(1);
socket_->AddIncoming(incoming); socket_->AddIncoming(incoming);
std::unique_ptr<P2PSocketHostTcpBase> new_host( std::unique_ptr<P2PSocketTcpBase> new_host(AcceptIncomingTcpConnection(addr));
AcceptIncomingTcpConnection(addr));
ASSERT_TRUE(new_host.get() != nullptr); ASSERT_TRUE(new_host.get() != nullptr);
EXPECT_EQ(incoming, GetSocketFormTcpSocketHost(new_host.get())); EXPECT_EQ(incoming, GetSocketFormTcpSocket(new_host.get()));
new_host.release(); // Deletes itself on connection error.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
// Accept 2 simultaneous connections. // Accept 2 simultaneous connections.
TEST_F(P2PSocketHostTcpServerTest, Accept2) { TEST_F(P2PSocketTcpServerTest, Accept2) {
FakeSocket* incoming1 = new FakeSocket(nullptr); FakeSocket* incoming1 = new FakeSocket(nullptr);
incoming1->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1)); incoming1->SetLocalAddress(ParseAddress(kTestLocalIpAddress, kTestPort1));
net::IPEndPoint addr1 = ParseAddress(kTestIpAddress1, kTestPort1); net::IPEndPoint addr1 = ParseAddress(kTestIpAddress1, kTestPort1);
...@@ -169,20 +167,18 @@ TEST_F(P2PSocketHostTcpServerTest, Accept2) { ...@@ -169,20 +167,18 @@ TEST_F(P2PSocketHostTcpServerTest, Accept2) {
socket_->AddIncoming(incoming1); socket_->AddIncoming(incoming1);
socket_->AddIncoming(incoming2); socket_->AddIncoming(incoming2);
std::unique_ptr<P2PSocketHostTcpBase> new_host1( std::unique_ptr<P2PSocketTcpBase> new_host1(
AcceptIncomingTcpConnection(addr1)); AcceptIncomingTcpConnection(addr1));
ASSERT_TRUE(new_host1.get() != nullptr); ASSERT_TRUE(new_host1.get() != nullptr);
EXPECT_EQ(incoming1, GetSocketFormTcpSocketHost( EXPECT_EQ(incoming1, GetSocketFormTcpSocket(
reinterpret_cast<P2PSocketHostTcp*>(new_host1.get()))); reinterpret_cast<P2PSocketTcp*>(new_host1.get())));
std::unique_ptr<P2PSocketHostTcpBase> new_host2( std::unique_ptr<P2PSocketTcpBase> new_host2(
AcceptIncomingTcpConnection(addr2)); AcceptIncomingTcpConnection(addr2));
ASSERT_TRUE(new_host2.get() != nullptr); ASSERT_TRUE(new_host2.get() != nullptr);
EXPECT_EQ(incoming2, GetSocketFormTcpSocketHost( EXPECT_EQ(incoming2, GetSocketFormTcpSocket(
reinterpret_cast<P2PSocketHostTcp*>(new_host2.get()))); reinterpret_cast<P2PSocketTcp*>(new_host2.get())));
new_host1.release(); // Deletes itself on connection error.
new_host2.release(); // Deletes itself on connection error.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
} // namespace content } // namespace network
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/renderer_host/p2p/socket_host_test_utils.h" #include "services/network/p2p/socket_test_utils.h"
#include <stddef.h> #include <stddef.h>
...@@ -15,24 +15,22 @@ ...@@ -15,24 +15,22 @@
#include "net/base/ip_address.h" #include "net/base/ip_address.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
namespace network {
const int kStunHeaderSize = 20; const int kStunHeaderSize = 20;
const uint16_t kStunBindingRequest = 0x0001; const uint16_t kStunBindingRequest = 0x0001;
const uint16_t kStunBindingResponse = 0x0102; const uint16_t kStunBindingResponse = 0x0102;
const uint16_t kStunBindingError = 0x0111; const uint16_t kStunBindingError = 0x0111;
const uint32_t kStunMagicCookie = 0x2112A442; const uint32_t kStunMagicCookie = 0x2112A442;
MockIPCSender::MockIPCSender() { }
MockIPCSender::~MockIPCSender() { }
FakeSocket::FakeSocket(std::string* written_data) FakeSocket::FakeSocket(std::string* written_data)
: read_pending_(false), : read_pending_(false),
input_pos_(0), input_pos_(0),
written_data_(written_data), written_data_(written_data),
async_write_(false), async_write_(false),
write_pending_(false) { write_pending_(false) {}
}
FakeSocket::~FakeSocket() { } FakeSocket::~FakeSocket() {}
void FakeSocket::AppendInputData(const char* data, int data_size) { void FakeSocket::AppendInputData(const char* data, int data_size) {
input_data_.insert(input_data_.end(), data, data + data_size); input_data_.insert(input_data_.end(), data, data + data_size);
...@@ -61,9 +59,9 @@ int FakeSocket::Read(net::IOBuffer* buf, ...@@ -61,9 +59,9 @@ int FakeSocket::Read(net::IOBuffer* buf,
int buf_len, int buf_len,
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK(buf); DCHECK(buf);
if (input_pos_ < static_cast<int>(input_data_.size())){ if (input_pos_ < static_cast<int>(input_data_.size())) {
int result = std::min(buf_len, int result =
static_cast<int>(input_data_.size()) - input_pos_); std::min(buf_len, static_cast<int>(input_data_.size()) - input_pos_);
memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result); memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result);
input_pos_ += result; input_pos_ += result;
return result; return result;
...@@ -95,8 +93,8 @@ int FakeSocket::Write( ...@@ -95,8 +93,8 @@ int FakeSocket::Write(
} }
if (written_data_) { if (written_data_) {
written_data_->insert(written_data_->end(), written_data_->insert(written_data_->end(), buf->data(),
buf->data(), buf->data() + buf_len); buf->data() + buf_len);
} }
return buf_len; return buf_len;
} }
...@@ -107,8 +105,8 @@ void FakeSocket::DoAsyncWrite(scoped_refptr<net::IOBuffer> buf, ...@@ -107,8 +105,8 @@ void FakeSocket::DoAsyncWrite(scoped_refptr<net::IOBuffer> buf,
write_pending_ = false; write_pending_ = false;
if (written_data_) { if (written_data_) {
written_data_->insert(written_data_->end(), written_data_->insert(written_data_->end(), buf->data(),
buf->data(), buf->data() + buf_len); buf->data() + buf_len);
} }
std::move(callback).Run(buf_len); std::move(callback).Run(buf_len);
} }
...@@ -179,9 +177,8 @@ int64_t FakeSocket::GetTotalReceivedBytes() const { ...@@ -179,9 +177,8 @@ int64_t FakeSocket::GetTotalReceivedBytes() const {
return 0; return 0;
} }
FakeSocketClient::FakeSocketClient( FakeSocketClient::FakeSocketClient(mojom::P2PSocketPtr socket,
network::mojom::P2PSocketPtr socket, mojom::P2PSocketClientRequest client_request)
network::mojom::P2PSocketClientRequest client_request)
: socket_(std::move(socket)), binding_(this, std::move(client_request)) { : socket_(std::move(socket)), binding_(this, std::move(client_request)) {
binding_.set_connection_error_handler( binding_.set_connection_error_handler(
base::BindLambdaForTesting([&]() { connection_error_ = true; })); base::BindLambdaForTesting([&]() { connection_error_ = true; }));
...@@ -226,3 +223,5 @@ net::IPEndPoint ParseAddress(const std::string& ip_str, uint16_t port) { ...@@ -226,3 +223,5 @@ net::IPEndPoint ParseAddress(const std::string& ip_str, uint16_t port) {
EXPECT_TRUE(ip.AssignFromIPLiteral(ip_str)); EXPECT_TRUE(ip.AssignFromIPLiteral(ip_str));
return net::IPEndPoint(ip, port); return net::IPEndPoint(ip, port);
} }
} // namespace network
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ #ifndef SERVICES_NETWORK_P2P_SOCKET_TEST_UTILS_H_
#define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ #define SERVICES_NETWORK_P2P_SOCKET_TEST_UTILS_H_
#include <stdint.h> #include <stdint.h>
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <tuple> #include <tuple>
#include <vector> #include <vector>
#include "ipc/ipc_sender.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/log/net_log_with_source.h" #include "net/log/net_log_with_source.h"
...@@ -22,20 +21,14 @@ ...@@ -22,20 +21,14 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace network {
const char kTestLocalIpAddress[] = "123.44.22.4"; const char kTestLocalIpAddress[] = "123.44.22.4";
const char kTestIpAddress1[] = "123.44.22.31"; const char kTestIpAddress1[] = "123.44.22.31";
const uint16_t kTestPort1 = 234; const uint16_t kTestPort1 = 234;
const char kTestIpAddress2[] = "133.11.22.33"; const char kTestIpAddress2[] = "133.11.22.33";
const uint16_t kTestPort2 = 543; const uint16_t kTestPort2 = 543;
class MockIPCSender : public IPC::Sender {
public:
MockIPCSender();
~MockIPCSender() override;
MOCK_METHOD1(Send, bool(IPC::Message* msg));
};
class FakeSocket : public net::StreamSocket { class FakeSocket : public net::StreamSocket {
public: public:
FakeSocket(std::string* written_data); FakeSocket(std::string* written_data);
...@@ -100,16 +93,16 @@ class FakeSocket : public net::StreamSocket { ...@@ -100,16 +93,16 @@ class FakeSocket : public net::StreamSocket {
net::NetLogWithSource net_log_; net::NetLogWithSource net_log_;
}; };
class FakeSocketClient : public network::mojom::P2PSocketClient { class FakeSocketClient : public mojom::P2PSocketClient {
public: public:
FakeSocketClient(network::mojom::P2PSocketPtr socket, FakeSocketClient(mojom::P2PSocketPtr socket,
network::mojom::P2PSocketClientRequest client_request); mojom::P2PSocketClientRequest client_request);
~FakeSocketClient() override; ~FakeSocketClient() override;
// network::mojom::P2PSocketClient interface. // mojom::P2PSocketClient interface.
MOCK_METHOD2(SocketCreated, MOCK_METHOD2(SocketCreated,
void(const net::IPEndPoint&, const net::IPEndPoint&)); void(const net::IPEndPoint&, const net::IPEndPoint&));
MOCK_METHOD1(SendComplete, void(const network::P2PSendPacketMetrics&)); MOCK_METHOD1(SendComplete, void(const P2PSendPacketMetrics&));
MOCK_METHOD1(IncomingTcpConnection, void(const net::IPEndPoint&)); MOCK_METHOD1(IncomingTcpConnection, void(const net::IPEndPoint&));
MOCK_METHOD3(DataReceived, MOCK_METHOD3(DataReceived,
void(const net::IPEndPoint&, void(const net::IPEndPoint&,
...@@ -119,8 +112,8 @@ class FakeSocketClient : public network::mojom::P2PSocketClient { ...@@ -119,8 +112,8 @@ class FakeSocketClient : public network::mojom::P2PSocketClient {
bool connection_error() { return connection_error_; } bool connection_error() { return connection_error_; }
private: private:
network::mojom::P2PSocketPtr socket_; mojom::P2PSocketPtr socket_;
mojo::Binding<network::mojom::P2PSocketClient> binding_; mojo::Binding<mojom::P2PSocketClient> binding_;
bool connection_error_ = false; bool connection_error_ = false;
}; };
...@@ -141,4 +134,6 @@ MATCHER_P2(MatchSendPacketMetrics, rtc_packet_id, test_start_time, "") { ...@@ -141,4 +134,6 @@ MATCHER_P2(MatchSendPacketMetrics, rtc_packet_id, test_start_time, "") {
arg.send_time <= base::TimeTicks::Now(); arg.send_time <= base::TimeTicks::Now();
} }
#endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ } // namespace network
#endif // SERVICES_NETWORK_P2P_SOCKET_TEST_UTILS_H_
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/renderer_host/p2p/socket_host_throttler.h" #include "services/network/p2p/socket_throttler.h"
#include <utility> #include <utility>
#include "third_party/webrtc/rtc_base/data_rate_limiter.h" #include "third_party/webrtc/rtc_base/data_rate_limiter.h"
#include "third_party/webrtc/rtc_base/timeutils.h" #include "third_party/webrtc/rtc_base/timeutils.h"
namespace content { namespace network {
namespace { namespace {
const int kMaxIceMessageBandwidth = 256 * 1024; const int kMaxIceMessageBandwidth = 256 * 1024;
...@@ -20,16 +20,14 @@ const int kMaxIceMessageBandwidth = 256 * 1024; ...@@ -20,16 +20,14 @@ const int kMaxIceMessageBandwidth = 256 * 1024;
P2PMessageThrottler::P2PMessageThrottler() P2PMessageThrottler::P2PMessageThrottler()
: rate_limiter_(new rtc::DataRateLimiter(kMaxIceMessageBandwidth, 1.0)) {} : rate_limiter_(new rtc::DataRateLimiter(kMaxIceMessageBandwidth, 1.0)) {}
P2PMessageThrottler::~P2PMessageThrottler() { P2PMessageThrottler::~P2PMessageThrottler() {}
}
void P2PMessageThrottler::SetSendIceBandwidth(int bandwidth_kbps) { void P2PMessageThrottler::SetSendIceBandwidth(int bandwidth_kbps) {
rate_limiter_.reset(new rtc::DataRateLimiter(bandwidth_kbps, 1.0)); rate_limiter_.reset(new rtc::DataRateLimiter(bandwidth_kbps, 1.0));
} }
bool P2PMessageThrottler::DropNextPacket(size_t packet_len) { bool P2PMessageThrottler::DropNextPacket(size_t packet_len) {
double now = double now = rtc::TimeNanos() / static_cast<double>(rtc::kNumNanosecsPerSec);
rtc::TimeNanos() / static_cast<double>(rtc::kNumNanosecsPerSec);
if (!rate_limiter_->CanUse(packet_len, now)) { if (!rate_limiter_->CanUse(packet_len, now)) {
// Exceeding the send rate, this packet should be dropped. // Exceeding the send rate, this packet should be dropped.
return true; return true;
...@@ -39,4 +37,4 @@ bool P2PMessageThrottler::DropNextPacket(size_t packet_len) { ...@@ -39,4 +37,4 @@ bool P2PMessageThrottler::DropNextPacket(size_t packet_len) {
return false; return false;
} }
} // namespace content } // namespace network
...@@ -2,27 +2,27 @@ ...@@ -2,27 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_THROTTLER_H_ #ifndef SERVICES_NETWORK_P2P_SOCKET_THROTTLER_H_
#define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_THROTTLER_H_ #define SERVICES_NETWORK_P2P_SOCKET_THROTTLER_H_
#include <stddef.h> #include <stddef.h>
#include <memory> #include <memory>
#include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/common/content_export.h"
namespace rtc { namespace rtc {
class DataRateLimiter; class DataRateLimiter;
} }
namespace content { namespace network {
// A very simple message throtller. User of this class must drop the packet if // A very simple message throtller. User of this class must drop the packet if
// DropNextPacket returns false for that packet. This method verifies the // DropNextPacket returns false for that packet. This method verifies the
// current sendrate against the required sendrate. // current sendrate against the required sendrate.
class CONTENT_EXPORT P2PMessageThrottler { class COMPONENT_EXPORT(NETWORK_SERVICE) P2PMessageThrottler {
public: public:
P2PMessageThrottler(); P2PMessageThrottler();
virtual ~P2PMessageThrottler(); virtual ~P2PMessageThrottler();
...@@ -36,6 +36,6 @@ class CONTENT_EXPORT P2PMessageThrottler { ...@@ -36,6 +36,6 @@ class CONTENT_EXPORT P2PMessageThrottler {
DISALLOW_COPY_AND_ASSIGN(P2PMessageThrottler); DISALLOW_COPY_AND_ASSIGN(P2PMessageThrottler);
}; };
} // namespace content } // namespace network
#endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_THROTTLER_H_ #endif // SERVICES_NETWORK_P2P_SOCKET_THROTTLER_H_
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ #ifndef SERVICES_NETWORK_P2P_SOCKET_UDP_H_
#define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ #define SERVICES_NETWORK_P2P_SOCKET_UDP_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -14,15 +14,15 @@ ...@@ -14,15 +14,15 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/component_export.h"
#include "base/containers/circular_deque.h" #include "base/containers/circular_deque.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/browser/renderer_host/p2p/socket_host.h"
#include "content/common/content_export.h"
#include "net/base/ip_endpoint.h" #include "net/base/ip_endpoint.h"
#include "net/socket/diff_serv_code_point.h" #include "net/socket/diff_serv_code_point.h"
#include "net/socket/udp_server_socket.h" #include "net/socket/udp_server_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/p2p/socket.h"
#include "services/network/public/cpp/p2p_socket_type.h" #include "services/network/public/cpp/p2p_socket_type.h"
#include "third_party/webrtc/rtc_base/asyncpacketsocket.h" #include "third_party/webrtc/rtc_base/asyncpacketsocket.h"
...@@ -30,47 +30,46 @@ namespace net { ...@@ -30,47 +30,46 @@ namespace net {
class NetLog; class NetLog;
} // namespace net } // namespace net
namespace content { namespace network {
class P2PMessageThrottler; class P2PMessageThrottler;
class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost { class COMPONENT_EXPORT(NETWORK_SERVICE) P2PSocketUdp : public P2PSocket {
public: public:
typedef base::Callback<std::unique_ptr<net::DatagramServerSocket>( typedef base::Callback<std::unique_ptr<net::DatagramServerSocket>(
net::NetLog* net_log)> net::NetLog* net_log)>
DatagramServerSocketFactory; DatagramServerSocketFactory;
P2PSocketHostUdp(P2PSocketDispatcherHost* socket_dispatcher_host, P2PSocketUdp(P2PSocketManager* socket_manager,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketRequest socket,
P2PMessageThrottler* throttler, P2PMessageThrottler* throttler,
net::NetLog* net_log, net::NetLog* net_log,
const DatagramServerSocketFactory& socket_factory); const DatagramServerSocketFactory& socket_factory);
P2PSocketHostUdp(P2PSocketDispatcherHost* socket_dispatcher_host, P2PSocketUdp(P2PSocketManager* socket_manager,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketRequest socket, mojom::P2PSocketRequest socket,
P2PMessageThrottler* throttler, P2PMessageThrottler* throttler,
net::NetLog* net_log); net::NetLog* net_log);
~P2PSocketHostUdp() override; ~P2PSocketUdp() override;
// P2PSocketHost overrides. // P2PSocket overrides.
bool Init(const net::IPEndPoint& local_address, bool Init(const net::IPEndPoint& local_address,
uint16_t min_port, uint16_t min_port,
uint16_t max_port, uint16_t max_port,
const network::P2PHostAndIPEndPoint& remote_address) override; const P2PHostAndIPEndPoint& remote_address) override;
// network::mojom::P2PSocket implementation: // mojom::P2PSocket implementation:
void AcceptIncomingTcpConnection( void AcceptIncomingTcpConnection(const net::IPEndPoint& remote_address,
const net::IPEndPoint& remote_address, mojom::P2PSocketClientPtr client,
network::mojom::P2PSocketClientPtr client, mojom::P2PSocketRequest socket) override;
network::mojom::P2PSocketRequest socket) override;
void Send(const std::vector<int8_t>& data, void Send(const std::vector<int8_t>& data,
const network::P2PPacketInfo& packet_info, const P2PPacketInfo& packet_info,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
override; override;
void SetOption(network::P2PSocketOption option, int32_t value) override; void SetOption(P2PSocketOption option, int32_t value) override;
private: private:
friend class P2PSocketHostUdpTest; friend class P2PSocketUdpTest;
typedef std::set<net::IPEndPoint> ConnectedPeerSet; typedef std::set<net::IPEndPoint> ConnectedPeerSet;
...@@ -127,9 +126,9 @@ class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost { ...@@ -127,9 +126,9 @@ class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost {
// Callback object that returns a new socket when invoked. // Callback object that returns a new socket when invoked.
DatagramServerSocketFactory socket_factory_; DatagramServerSocketFactory socket_factory_;
DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp); DISALLOW_COPY_AND_ASSIGN(P2PSocketUdp);
}; };
} // namespace content } // namespace network
#endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_UDP_H_ #endif // SERVICES_NETWORK_P2P_SOCKET_UDP_H_
...@@ -117,7 +117,7 @@ component("cpp_base") { ...@@ -117,7 +117,7 @@ component("cpp_base") {
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
"//net", "//net",
"//services/network/public/mojom:mojom_shared", "//services/network/public/mojom:mojom_shared",
"//third_party/webrtc/rtc_base:rtc_base", "//third_party/webrtc/rtc_base",
"//third_party/webrtc_overrides", "//third_party/webrtc_overrides",
"//third_party/webrtc_overrides:init_webrtc", "//third_party/webrtc_overrides:init_webrtc",
] ]
......
...@@ -88,6 +88,7 @@ mojom("mojom") { ...@@ -88,6 +88,7 @@ mojom("mojom") {
"network_service_test.mojom", "network_service_test.mojom",
"network_types.mojom", "network_types.mojom",
"p2p.mojom", "p2p.mojom",
"p2p_trusted.mojom",
"proxy_config.mojom", "proxy_config.mojom",
"proxy_config_with_annotation.mojom", "proxy_config_with_annotation.mojom",
"proxy_lookup_client.mojom", "proxy_lookup_client.mojom",
......
...@@ -16,6 +16,8 @@ import "services/network/public/mojom/ct_log_info.mojom"; ...@@ -16,6 +16,8 @@ import "services/network/public/mojom/ct_log_info.mojom";
import "services/network/public/mojom/host_resolver.mojom"; import "services/network/public/mojom/host_resolver.mojom";
import "services/network/public/mojom/mutable_network_traffic_annotation_tag.mojom"; import "services/network/public/mojom/mutable_network_traffic_annotation_tag.mojom";
import "services/network/public/mojom/network_param.mojom"; import "services/network/public/mojom/network_param.mojom";
import "services/network/public/mojom/p2p.mojom";
import "services/network/public/mojom/p2p_trusted.mojom";
import "services/network/public/mojom/proxy_config.mojom"; import "services/network/public/mojom/proxy_config.mojom";
import "services/network/public/mojom/proxy_config_with_annotation.mojom"; import "services/network/public/mojom/proxy_config_with_annotation.mojom";
import "services/network/public/mojom/proxy_lookup_client.mojom"; import "services/network/public/mojom/proxy_lookup_client.mojom";
...@@ -533,6 +535,11 @@ interface NetworkContext { ...@@ -533,6 +535,11 @@ interface NetworkContext {
int32 load_flags, int32 load_flags,
bool privacy_mode_enabled); bool privacy_mode_enabled);
// Creates a P2PSocketManager instance, used for WebRTC.
CreateP2PSocketManager(P2PTrustedSocketManagerClient client,
P2PTrustedSocketManager& trusted_socket_manager,
P2PSocketManager& socket_manager);
// Destroys all URLLoaderFactory bindings, which should then be regenerated. // Destroys all URLLoaderFactory bindings, which should then be regenerated.
// This should be called if there is a change to the proxies which should be // This should be called if there is a change to the proxies which should be
// used on URLLoaders. // used on URLLoaders.
...@@ -557,9 +564,9 @@ interface NetworkContext { ...@@ -557,9 +564,9 @@ interface NetworkContext {
// TODO(crbug.com/821021): Create (or move) a version of this API in some sort // TODO(crbug.com/821021): Create (or move) a version of this API in some sort
// of separate (and possibly restrictable) HostResolver mojo interface that // of separate (and possibly restrictable) HostResolver mojo interface that
// can be shared with processes without access to NetworkContext. // can be shared with processes without access to NetworkContext.
ResolveHost(HostPortPair host, ResolveHost(HostPortPair host,
ResolveHostHandle&? control_handle, ResolveHostHandle&? control_handle,
ResolveHostClient response_client); ResolveHostClient response_client);
[Sync] [Sync]
// Adds explicitly-specified data as if it was processed from an // Adds explicitly-specified data as if it was processed from an
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module network.mojom;
import "services/network/public/mojom/p2p.mojom";
// Trusted interfaces for socket-related communication between the browser and
// network process
// From the network process to the browser process.
interface P2PTrustedSocketManagerClient {
// Called when the P2PSocketManager client requests socket creation with a
// port that's in an invalid range.
InvalidSocketPortRangeRequested();
// Called when packet dumping is enabled.
DumpPacket(array<uint8> packet_header,
uint64 packet_length,
bool incoming);
};
// From the browser process to the network process.
interface P2PTrustedSocketManager {
// Start or stop dumping of packet headers.
StartRtpDump(bool incoming, bool outgoing);
StopRtpDump(bool incoming, bool outgoing);
};
...@@ -118,6 +118,10 @@ class TestNetworkContext : public mojom::NetworkContext { ...@@ -118,6 +118,10 @@ class TestNetworkContext : public mojom::NetworkContext {
const GURL& url, const GURL& url,
int32_t load_flags, int32_t load_flags,
bool privacy_mode_enabled) override {} bool privacy_mode_enabled) override {}
void CreateP2PSocketManager(
mojom::P2PTrustedSocketManagerClientPtr client,
mojom::P2PTrustedSocketManagerRequest trusted_socket_manager,
mojom::P2PSocketManagerRequest socket_manager_request) override {}
void ResetURLLoaderFactories() override {} void ResetURLLoaderFactories() override {}
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment