// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module blink.mojom;
// Explainer for the Direct Sockets API:
// https://github.com/WICG/direct-sockets/blob/main/docs/explainer.md
import "mojo/public/mojom/base/read_only_buffer.mojom";
import "services/network/public/mojom/host_resolver.mojom";
import "services/network/public/mojom/ip_endpoint.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/restricted_udp_socket.mojom";
import "services/network/public/mojom/tcp_socket.mojom";
import "services/network/public/mojom/udp_socket.mojom";
struct DirectTCPSocketOptions {
network.mojom.HostPortPair remote_addr;
// Sets the OS send buffer size (in bytes) for the socket. This is the
// SO_SNDBUF socket option. If not specified, OS's default value will be used.
// The value will be clamped to a reasonable range.
int32? send_buffer_size;
// Sets the OS receive buffer size (in bytes) for the socket. This is the
// SO_RCVBUF socket option. If not specified, OS's default value will be used.
// The value will be clamped to a reasonable range.
int32? receive_buffer_size;
bool no_delay = false;
network.mojom.TCPKeepAliveOptions? keep_alive_options;
network.mojom.DnsQueryType? dns_query_type;
};
struct DirectConnectedUDPSocketOptions {
network.mojom.HostPortPair remote_addr;
// Sets the OS send buffer size (in bytes) for the socket. This is the
// SO_SNDBUF socket option. If not specified, OS's default value will be used.
// The value will be clamped to a reasonable range.
int32? send_buffer_size;
// Sets the OS receive buffer size (in bytes) for the socket. This is the
// SO_RCVBUF socket option. If not specified, OS's default value will be used.
// The value will be clamped to a reasonable range.
int32? receive_buffer_size;
network.mojom.DnsQueryType? dns_query_type;
};
struct DirectBoundUDPSocketOptions {
network.mojom.IPEndPoint local_addr;
// Sets the OS send buffer size (in bytes) for the socket. This is the
// SO_SNDBUF socket option. If not specified, OS's default value will be used.
// The value will be clamped to a reasonable range.
int32? send_buffer_size;
// Sets the OS receive buffer size (in bytes) for the socket. This is the
// SO_RCVBUF socket option. If not specified, OS's default value will be used.
// The value will be clamped to a reasonable range.
int32? receive_buffer_size;
// Sets IPV6_V6ONLY on the socket to enable/disable dual stack mode.
// |true| restricts incoming connections to IPv6 only; |false| allows both
// IPv4/IPv6 connections. Leaving this value unset results in platform default
// being applied (|true| on Windows, |false| on Posix).
bool? ipv6_only;
};
struct DirectTCPServerSocketOptions {
network.mojom.IPEndPoint local_addr;
// Sets IPV6_V6ONLY on the socket to enable/disable dual stack mode.
// |true| restricts incoming connections to IPv6 only; |false| allows both
// IPv4/IPv6 connections. Leaving this value unset results in platform default
// being applied (|true| on Windows, |false| on Posix).
bool? ipv6_only;
// |backlog| defines the size of the OS accept queue. If not specified, will
// be substituted by a reasonable default.
uint32? backlog;
};
// This wraps network.mojom.NetworkContext and handles extra work such as
// permission checking, chooser showing, etc.
// The browser process implements the interface, and the renderer process
// sends messages to it.
interface DirectSocketsService {
// Creates a connected TCP socket.
// |result| is a net::Error code (net::OK on success).
// |observer| if non-null will be used to listen for any network connection
// error on the newly established connection.
// Caller is to use |send_stream| to send data and |receive_stream|
// to receive data over the connection.
OpenTCPSocket(
DirectTCPSocketOptions options,
pending_receiver<network.mojom.TCPConnectedSocket> receiver,
pending_remote<network.mojom.SocketObserver>? observer)
=> (int32 result,
network.mojom.IPEndPoint? local_addr,
network.mojom.IPEndPoint? peer_addr,
handle<data_pipe_consumer>? receive_stream,
handle<data_pipe_producer>? send_stream);
// Creates a Connected Restricted UDP socket.
// Caller can supply a |listener| to listen for incoming datagrams.
//
// On success |result| is net::OK. |local_addr| is the real local address
// used, |peer_addr| is the resolved address the socket is connected to.
//
// On failure |result| is a negative network error code.
// |local_addr| and |peer_addr| are null.
OpenConnectedUDPSocket(
DirectConnectedUDPSocketOptions options,
pending_receiver<network.mojom.RestrictedUDPSocket> receiver,
pending_remote<network.mojom.UDPSocketListener>? listener)
=> (int32 result,
network.mojom.IPEndPoint? local_addr,
network.mojom.IPEndPoint? peer_addr);
// Creates a Bound Restricted UDP socket.
// Caller can supply a |listener| to listen for incoming datagrams.
//
// On success |result| is net::OK. |local_addr| is the real local address
// used.
//
// On failure |result| is a negative network error code, |local_addr| is null.
OpenBoundUDPSocket(
DirectBoundUDPSocketOptions options,
pending_receiver<network.mojom.RestrictedUDPSocket> receiver,
pending_remote<network.mojom.UDPSocketListener>? listener)
=> (int32 result,
network.mojom.IPEndPoint? local_addr);
// Creates a listening (server) TCP socket configured with |options|.
//
// On success, |result| is net::OK and |local_addr| is set to the real local
// address used.
// On failure, |result| is a negative network error code. |local_addr| is
// null.
OpenTCPServerSocket(
DirectTCPServerSocketOptions options,
pending_receiver<network.mojom.TCPServerSocket> receiver)
=> (int32 result, network.mojom.IPEndPoint? local_addr);
};