chromium/services/network/public/mojom/p2p.mojom

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module network.mojom;

import "mojo/public/mojom/base/unguessable_token.mojom";
import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/read_only_buffer.mojom";
import "services/network/public/mojom/network_interface.mojom";
import "services/network/public/mojom/ip_address.mojom";
import "services/network/public/mojom/ip_endpoint.mojom";
import "services/network/public/mojom/mutable_network_traffic_annotation_tag.mojom";

[Native]
enum P2PSocketType;

[Native]
struct P2PHostAndIPEndPoint;

[Native]
struct P2PPacketInfo;

[Native]
struct P2PPortRange;

[Native]
struct P2PSendPacketMetrics;

[Native]
enum P2PSocketOption;

// This enums corresponds to rtc::EcnMarking.
enum EcnMarking {
  kNotEct = 0,  // Not ECN-Capable Transport
  kEct1 = 1,    // ECN-Capable Transport
  kEct0 = 2,    // Not used by L4s (or webrtc.)
  kCe = 3,      // Congestion experienced
};

// Represents the packet received on the socket.
struct P2PReceivedPacket {
  mojo_base.mojom.ReadOnlyBuffer data;
  IPEndPoint socket_address;
  mojo_base.mojom.TimeTicks timestamp;
  EcnMarking ecn;
};

// Represents a packet sent through a socket.
struct P2PSendPacket {
  mojo_base.mojom.ReadOnlyBuffer data;
  P2PPacketInfo packet_info;
};

interface P2PNetworkNotificationClient {
  NetworkListChanged(array<NetworkInterface> networks,
                     IPAddress default_ipv4_local_address,
                     IPAddress default_ipv6_local_address);
};

interface P2PSocketManager {
  // Starts listening to network list changed events.
  StartNetworkNotifications(
      pending_remote<P2PNetworkNotificationClient> client);

  // Performs DNS hostname resolution.
  GetHostAddress(string host_name, bool enable_mdns)
      => (array<IPAddress> addresses);

  // Performs DNS hostname resolution for a specific IP address family.
  GetHostAddressWithFamily(string host_name,
                           int32 address_family,
                           bool enable_mdns) => (array<IPAddress> addresses);

  // Creates a P2PSocket
  CreateSocket(P2PSocketType type,
               IPEndPoint local_address,
               P2PPortRange port_range,
               P2PHostAndIPEndPoint remote_address,
               MutableNetworkTrafficAnnotationTag traffic_annotation,
               mojo_base.mojom.UnguessableToken? devtools_token,
               pending_remote<P2PSocketClient> client,
               pending_receiver<P2PSocket> socket);
};

interface P2PSocket {
  Send(mojo_base.mojom.ReadOnlyBuffer data,
       P2PPacketInfo packet_info);
  // Sends a batch of packets to the socket.
  SendBatch(array<P2PSendPacket> packet_batch);
  SetOption(P2PSocketOption option, int32 value);
};

interface P2PSocketClient {
  // Invoked when socket is created.
  SocketCreated(IPEndPoint local_address, IPEndPoint remote_address);

  // Invoked once for each packet after the send is complete.
  SendComplete(P2PSendPacketMetrics send_metrics);

  // Invoked once for each batch of sent packets after the send is complete.
  SendBatchComplete(array<P2PSendPacketMetrics> send_metrics_batch);

  // Invoked when packets are received on the socket.
  DataReceived(array<P2PReceivedPacket> packets);
};