blob: 59233839d5249f441f5720828f5e29ac36ebf7ce [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
Yixin Wang1f24e4052017-11-21 17:48:1012#include "net/quic/core/quic_bandwidth.h"
jri3c1d5ca2017-06-02 04:52:2313#include "net/quic/core/quic_error_codes.h"
Yixin Wang1f24e4052017-11-21 17:48:1014#include "net/quic/core/quic_time.h"
jri3c1d5ca2017-06-02 04:52:2315#include "net/quic/core/quic_types.h"
jri3ad08a482017-06-03 02:24:5416#include "net/quic/platform/api/quic_export.h"
zhihuang33e7a9c2016-10-31 20:04:3817#include "net/quic/quartc/quartc_stream_interface.h"
18
19namespace net {
20
Fan Yang2a1699a2017-07-25 16:44:5521// Structure holding stats exported by a QuartcSession.
22struct QUIC_EXPORT_PRIVATE QuartcSessionStats {
23 // Bandwidth estimate in bits per second.
Yixin Wang1f24e4052017-11-21 17:48:1024 QuicBandwidth bandwidth_estimate = QuicBandwidth::Zero();
25
26 // Smoothed round-trip time.
27 QuicTime::Delta smoothed_rtt = QuicTime::Delta::Zero();
Fan Yang2a1699a2017-07-25 16:44:5528};
29
zhihuang33e7a9c2016-10-31 20:04:3830// Given a PacketTransport, provides a way to send and receive separate streams
31// of reliable, in-order, encrypted data. For example, this can build on top of
32// a WebRTC IceTransport for sending and receiving data over QUIC.
jri3c1d5ca2017-06-02 04:52:2333class QUIC_EXPORT_PRIVATE QuartcSessionInterface {
zhihuang33e7a9c2016-10-31 20:04:3834 public:
35 virtual ~QuartcSessionInterface() {}
36
37 virtual void StartCryptoHandshake() = 0;
38
39 // Only needed when using SRTP with QuicTransport
40 // Key Exporter interface from RFC 5705
41 // Arguments are:
42 // label -- the exporter label.
43 // part of the RFC defining each exporter usage (IN)
44 // context/context_len -- a context to bind to for this connection;
45 // optional, can be NULL, 0 (IN)
46 // use_context -- whether to use the context value
47 // (needed to distinguish no context from
48 // zero-length ones).
49 // result -- where to put the computed value
50 // result_len -- the length of the computed value
51 virtual bool ExportKeyingMaterial(const std::string& label,
52 const uint8_t* context,
53 size_t context_len,
54 bool used_context,
55 uint8_t* result,
56 size_t result_len) = 0;
57
Victor Vasiliev12296702017-10-17 10:32:4758 // Closes the connection with the given human-readable error details.
59 // The connection closes with the QUIC_CONNECTION_CANCELLED error code to
60 // indicate the application closed it.
61 //
62 // Informs the peer that the connection has been closed. This prevents the
63 // peer from waiting until the connection times out.
64 //
65 // Cleans up the underlying QuicConnection's state. Closing the connection
66 // makes it safe to delete the QuartcSession.
67 virtual void CloseConnection(const std::string& error_details) = 0;
68
zhihuang33e7a9c2016-10-31 20:04:3869 // For forward-compatibility. More parameters could be added through the
70 // struct without changing the API.
71 struct OutgoingStreamParameters {};
72
73 virtual QuartcStreamInterface* CreateOutgoingStream(
74 const OutgoingStreamParameters& params) = 0;
75
jri3c1d5ca2017-06-02 04:52:2376 // If the given stream is still open, sends a reset frame to cancel it.
77 // Note: This method cancels a stream by QuicStreamId rather than by pointer
78 // (or by a method on QuartcStreamInterface) because QuartcSession (and not
79 // the caller) owns the streams. Streams may finish and be deleted before the
80 // caller tries to cancel them, rendering the caller's pointers invalid.
81 virtual void CancelStream(QuicStreamId stream_id) = 0;
82
Michael Warres74ee3ce2017-10-09 15:26:3783 // This method verifies if a stream is still open and stream pointer can be
84 // used. When true is returned, the interface pointer is good for making a
85 // call immediately on the same thread, but may be rendered invalid by ANY
86 // other QUIC activity.
87 virtual bool IsOpenStream(QuicStreamId stream_id) = 0;
88
Fan Yang2a1699a2017-07-25 16:44:5589 // Gets stats associated with this Quartc session.
90 virtual QuartcSessionStats GetStats() = 0;
91
zhihuang33e7a9c2016-10-31 20:04:3892 // Send and receive packets, like a virtual UDP socket. For example, this
93 // could be implemented by WebRTC's IceTransport.
94 class PacketTransport {
95 public:
96 virtual ~PacketTransport() {}
97
zhihuang33e7a9c2016-10-31 20:04:3898 // Called by the QuartcPacketWriter when writing packets to the network.
99 // Return the number of written bytes. Return 0 if the write is blocked.
100 virtual int Write(const char* buffer, size_t buf_len) = 0;
101 };
102
103 // Called when CanWrite() changes from false to true.
104 virtual void OnTransportCanWrite() = 0;
105
106 // Called when a packet has been received and should be handled by the
107 // QuicConnection.
108 virtual bool OnTransportReceived(const char* data, size_t data_len) = 0;
109
110 // Callbacks called by the QuartcSession to notify the user of the
111 // QuartcSession of certain events.
112 class Delegate {
113 public:
114 virtual ~Delegate() {}
115
116 // Called when the crypto handshake is complete.
117 virtual void OnCryptoHandshakeComplete() = 0;
118
119 // Called when a new stream is received from the remote endpoint.
120 virtual void OnIncomingStream(QuartcStreamInterface* stream) = 0;
121
122 // Called when the connection is closed. This means all of the streams will
123 // be closed and no new streams can be created.
124 // TODO(zhihuang): Create mapping from integer error code to WebRTC error
125 // code.
126 virtual void OnConnectionClosed(int error_code, bool from_remote) = 0;
127
128 // TODO(zhihuang): Add proof verification.
129 };
130
131 // The |delegate| is not owned by QuartcSession.
132 virtual void SetDelegate(Delegate* delegate) = 0;
133};
134
135} // namespace net
136
137#endif // NET_QUIC_QUARTC_QUARTC_SESSION_INTERFACE_H_