blob: 37c8fea9104035271a2d42bd91ff00c4f9b05173 [file] [log] [blame]
rch7b8e0afb12017-05-03 01:07:221// Copyright (c) 2017 The Chromium Authors. All rights reserved.
zhihuang33e7a9c2016-10-31 20:04:382// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_QUIC_QUARTC_QUARTC_SESSION_INTERFACE_H_
6#define NET_QUIC_QUARTC_QUARTC_SESSION_INTERFACE_H_
7
8#include <stddef.h>
9#include <stdint.h>
skvlad6bb90e792016-11-02 20:08:3710#include <string>
zhihuang33e7a9c2016-10-31 20:04:3811
jri3c1d5ca2017-06-02 04:52:2312#include "net/quic/core/quic_error_codes.h"
13#include "net/quic/core/quic_types.h"
jri3ad08a482017-06-03 02:24:5414#include "net/quic/platform/api/quic_export.h"
zhihuang33e7a9c2016-10-31 20:04:3815#include "net/quic/quartc/quartc_stream_interface.h"
16
17namespace net {
18
Fan Yang2a1699a2017-07-25 16:44:5519// Structure holding stats exported by a QuartcSession.
20struct QUIC_EXPORT_PRIVATE QuartcSessionStats {
21 // Bandwidth estimate in bits per second.
22 int64_t bandwidth_estimate_bits_per_second;
23};
24
zhihuang33e7a9c2016-10-31 20:04:3825// Given a PacketTransport, provides a way to send and receive separate streams
26// of reliable, in-order, encrypted data. For example, this can build on top of
27// a WebRTC IceTransport for sending and receiving data over QUIC.
jri3c1d5ca2017-06-02 04:52:2328class QUIC_EXPORT_PRIVATE QuartcSessionInterface {
zhihuang33e7a9c2016-10-31 20:04:3829 public:
30 virtual ~QuartcSessionInterface() {}
31
32 virtual void StartCryptoHandshake() = 0;
33
34 // Only needed when using SRTP with QuicTransport
35 // Key Exporter interface from RFC 5705
36 // Arguments are:
37 // label -- the exporter label.
38 // part of the RFC defining each exporter usage (IN)
39 // context/context_len -- a context to bind to for this connection;
40 // optional, can be NULL, 0 (IN)
41 // use_context -- whether to use the context value
42 // (needed to distinguish no context from
43 // zero-length ones).
44 // result -- where to put the computed value
45 // result_len -- the length of the computed value
46 virtual bool ExportKeyingMaterial(const std::string& label,
47 const uint8_t* context,
48 size_t context_len,
49 bool used_context,
50 uint8_t* result,
51 size_t result_len) = 0;
52
53 // For forward-compatibility. More parameters could be added through the
54 // struct without changing the API.
55 struct OutgoingStreamParameters {};
56
57 virtual QuartcStreamInterface* CreateOutgoingStream(
58 const OutgoingStreamParameters& params) = 0;
59
jri3c1d5ca2017-06-02 04:52:2360 // If the given stream is still open, sends a reset frame to cancel it.
61 // Note: This method cancels a stream by QuicStreamId rather than by pointer
62 // (or by a method on QuartcStreamInterface) because QuartcSession (and not
63 // the caller) owns the streams. Streams may finish and be deleted before the
64 // caller tries to cancel them, rendering the caller's pointers invalid.
65 virtual void CancelStream(QuicStreamId stream_id) = 0;
66
Michael Warres74ee3ce2017-10-09 15:26:3767 // This method verifies if a stream is still open and stream pointer can be
68 // used. When true is returned, the interface pointer is good for making a
69 // call immediately on the same thread, but may be rendered invalid by ANY
70 // other QUIC activity.
71 virtual bool IsOpenStream(QuicStreamId stream_id) = 0;
72
Fan Yang2a1699a2017-07-25 16:44:5573 // Gets stats associated with this Quartc session.
74 virtual QuartcSessionStats GetStats() = 0;
75
zhihuang33e7a9c2016-10-31 20:04:3876 // Send and receive packets, like a virtual UDP socket. For example, this
77 // could be implemented by WebRTC's IceTransport.
78 class PacketTransport {
79 public:
80 virtual ~PacketTransport() {}
81
82 // Called by the QuartcPacketWriter to check if the underneath transport is
83 // writable. True if packets written are expected to be sent. False if
84 // packets will be dropped.
85 virtual bool CanWrite() = 0;
86
87 // Called by the QuartcPacketWriter when writing packets to the network.
88 // Return the number of written bytes. Return 0 if the write is blocked.
89 virtual int Write(const char* buffer, size_t buf_len) = 0;
90 };
91
92 // Called when CanWrite() changes from false to true.
93 virtual void OnTransportCanWrite() = 0;
94
95 // Called when a packet has been received and should be handled by the
96 // QuicConnection.
97 virtual bool OnTransportReceived(const char* data, size_t data_len) = 0;
98
99 // Callbacks called by the QuartcSession to notify the user of the
100 // QuartcSession of certain events.
101 class Delegate {
102 public:
103 virtual ~Delegate() {}
104
105 // Called when the crypto handshake is complete.
106 virtual void OnCryptoHandshakeComplete() = 0;
107
108 // Called when a new stream is received from the remote endpoint.
109 virtual void OnIncomingStream(QuartcStreamInterface* stream) = 0;
110
111 // Called when the connection is closed. This means all of the streams will
112 // be closed and no new streams can be created.
113 // TODO(zhihuang): Create mapping from integer error code to WebRTC error
114 // code.
115 virtual void OnConnectionClosed(int error_code, bool from_remote) = 0;
116
117 // TODO(zhihuang): Add proof verification.
118 };
119
120 // The |delegate| is not owned by QuartcSession.
121 virtual void SetDelegate(Delegate* delegate) = 0;
122};
123
124} // namespace net
125
126#endif // NET_QUIC_QUARTC_QUARTC_SESSION_INTERFACE_H_