blob: 0957805fec002043903235a01c68af301eef591e [file] [log] [blame]
zhihuang33e7a9c2016-10-31 20:04:381// Copyright (c) 2016 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
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>
10
11#include "net/quic/quartc/quartc_stream_interface.h"
12
13namespace net {
14
15// Given a PacketTransport, provides a way to send and receive separate streams
16// of reliable, in-order, encrypted data. For example, this can build on top of
17// a WebRTC IceTransport for sending and receiving data over QUIC.
18class NET_EXPORT_PRIVATE QuartcSessionInterface {
19 public:
20 virtual ~QuartcSessionInterface() {}
21
22 virtual void StartCryptoHandshake() = 0;
23
24 // Only needed when using SRTP with QuicTransport
25 // Key Exporter interface from RFC 5705
26 // Arguments are:
27 // label -- the exporter label.
28 // part of the RFC defining each exporter usage (IN)
29 // context/context_len -- a context to bind to for this connection;
30 // optional, can be NULL, 0 (IN)
31 // use_context -- whether to use the context value
32 // (needed to distinguish no context from
33 // zero-length ones).
34 // result -- where to put the computed value
35 // result_len -- the length of the computed value
36 virtual bool ExportKeyingMaterial(const std::string& label,
37 const uint8_t* context,
38 size_t context_len,
39 bool used_context,
40 uint8_t* result,
41 size_t result_len) = 0;
42
43 // For forward-compatibility. More parameters could be added through the
44 // struct without changing the API.
45 struct OutgoingStreamParameters {};
46
47 virtual QuartcStreamInterface* CreateOutgoingStream(
48 const OutgoingStreamParameters& params) = 0;
49
50 // Send and receive packets, like a virtual UDP socket. For example, this
51 // could be implemented by WebRTC's IceTransport.
52 class PacketTransport {
53 public:
54 virtual ~PacketTransport() {}
55
56 // Called by the QuartcPacketWriter to check if the underneath transport is
57 // writable. True if packets written are expected to be sent. False if
58 // packets will be dropped.
59 virtual bool CanWrite() = 0;
60
61 // Called by the QuartcPacketWriter when writing packets to the network.
62 // Return the number of written bytes. Return 0 if the write is blocked.
63 virtual int Write(const char* buffer, size_t buf_len) = 0;
64 };
65
66 // Called when CanWrite() changes from false to true.
67 virtual void OnTransportCanWrite() = 0;
68
69 // Called when a packet has been received and should be handled by the
70 // QuicConnection.
71 virtual bool OnTransportReceived(const char* data, size_t data_len) = 0;
72
73 // Callbacks called by the QuartcSession to notify the user of the
74 // QuartcSession of certain events.
75 class Delegate {
76 public:
77 virtual ~Delegate() {}
78
79 // Called when the crypto handshake is complete.
80 virtual void OnCryptoHandshakeComplete() = 0;
81
82 // Called when a new stream is received from the remote endpoint.
83 virtual void OnIncomingStream(QuartcStreamInterface* stream) = 0;
84
85 // Called when the connection is closed. This means all of the streams will
86 // be closed and no new streams can be created.
87 // TODO(zhihuang): Create mapping from integer error code to WebRTC error
88 // code.
89 virtual void OnConnectionClosed(int error_code, bool from_remote) = 0;
90
91 // TODO(zhihuang): Add proof verification.
92 };
93
94 // The |delegate| is not owned by QuartcSession.
95 virtual void SetDelegate(Delegate* delegate) = 0;
96};
97
98} // namespace net
99
100#endif // NET_QUIC_QUARTC_QUARTC_SESSION_INTERFACE_H_