1// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5module network.mojom;
6
7import "mojo/public/mojom/base/read_only_buffer.mojom";
8import "url/mojom/url.mojom";
9
10// A mojo interface for https://wicg.github.io/web-transport/#quic-transport.
11interface QuicTransport {
12  // A datagram message is sent from the client. The response message represents
13  // whether the peer has sent or discarded the datagram.
14  SendDatagram(mojo_base.mojom.ReadOnlyBuffer data) => (bool result);
15
16  // Stream creation initiated by the client. |succeeded| represents whether
17  // the stream is created successfully, and |stream_id| is meaningful only
18  // when |succeeded| is true. |writable| is nullable, to support both
19  // unidirectional and bidirectional streams.
20  CreateStream(handle<data_pipe_consumer> readable,
21               handle<data_pipe_producer>? writable) =>
22      (bool succeeded, uint32 stream_id);
23
24  // Accepts a bidirectional stream created by the server.
25  AcceptBidirectionalStream() => (uint32 stream_id,
26                  handle<data_pipe_consumer> readable,
27                  handle<data_pipe_producer> writable);
28
29  // Accepts a unidirectional stream created by the server.
30  AcceptUnidirectionalStream() => (uint32 stream_id,
31                  handle<data_pipe_consumer> readable);
32
33  // Expresses that the client will not write data to the stream for
34  // |stream_id|. After calling this function on a stream, the client will not
35  // be able to write any data to the stream, but it may be able to use other
36  // functions such as reading data from the stream.
37  SendFin(uint32 stream_id);
38};
39
40// A mojo interface for the client of QuicTransport.
41interface QuicTransportClient {
42  // A datagram message is sent from the server.
43  OnDatagramReceived(mojo_base.mojom.ReadOnlyBuffer data);
44
45  // Notifies that the server will not write data to the Stream for |stream_id|.
46  // |fin_received| is true when FIN is received from the server.
47  // Note that OnIncomingStreamClosed and OnOutgoingStreamClosed can both be
48  // dispatched to the same stream, if it is a bidirectional stream.
49  OnIncomingStreamClosed(uint32 stream_id, bool fin_received);
50};
51
52// Used to create a QuicTransport connection. This is split from QuicTransport
53// so that the handshake part can be intercepted, by Chrome extensions for
54// example.
55interface QuicTransportHandshakeClient {
56  // Called when the handshake succeeds.
57  OnConnectionEstablished(pending_remote<QuicTransport> transport,
58                          pending_receiver<QuicTransportClient> client);
59
60  // Called when the handshake fails.
61  OnHandshakeFailed();
62};
63