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