blob: f8b27e055e57e8bf56202e99db09184273b0509b [file] [log] [blame]
mikescarlettcd0e4752016-02-09 01:35:471/*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_P2P_QUIC_QUICSESSION_H_
12#define WEBRTC_P2P_QUIC_QUICSESSION_H_
13
kwiberg3ec46792016-04-27 14:22:5314#include <memory>
mikescarlettcd0e4752016-02-09 01:35:4715#include <string>
16
17#include "net/quic/quic_crypto_client_stream.h"
18#include "net/quic/quic_crypto_server_stream.h"
19#include "net/quic/quic_crypto_stream.h"
20#include "net/quic/quic_session.h"
21#include "webrtc/base/constructormagic.h"
22#include "webrtc/base/sigslot.h"
23#include "webrtc/base/sslidentity.h"
24#include "webrtc/p2p/quic/reliablequicstream.h"
25
26namespace cricket {
27
28// This class provides a QUIC session over peer-to-peer transport that
29// negotiates the crypto handshake (using QuicCryptoHandshake) and provides
30// reading/writing of data using QUIC packets.
31class QuicSession : public net::QuicSession, public sigslot::has_slots<> {
32 public:
kwiberg3ec46792016-04-27 14:22:5333 QuicSession(std::unique_ptr<net::QuicConnection> connection,
mikescarlettcd0e4752016-02-09 01:35:4734 const net::QuicConfig& config);
35 ~QuicSession() override;
36
37 // Initiates client crypto handshake by sending client hello.
38 void StartClientHandshake(net::QuicCryptoClientStream* crypto_stream);
39
40 // Responds to a client who has inititated the crypto handshake.
41 void StartServerHandshake(net::QuicCryptoServerStream* crypto_stream);
42
43 // QuicSession overrides.
44 net::QuicCryptoStream* GetCryptoStream() override {
45 return crypto_stream_.get();
46 }
mikescarlettcd0e4752016-02-09 01:35:4747 ReliableQuicStream* CreateOutgoingDynamicStream(
48 net::SpdyPriority priority) override;
49
50 // QuicSession optional overrides.
51 void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override;
mikescarlett70035ca2016-04-30 01:14:3752 void CloseStream(net::QuicStreamId stream_id) override;
mikescarlettcd0e4752016-02-09 01:35:4753
54 // QuicConnectionVisitorInterface overrides.
mikescarlettf5377682016-03-29 19:14:5555 void OnConnectionClosed(net::QuicErrorCode error,
mikescarlett8d37d292016-04-29 22:35:0056 const std::string& error_details,
mikescarlettf5377682016-03-29 19:14:5557 net::ConnectionCloseSource source) override;
mikescarlettcd0e4752016-02-09 01:35:4758
59 // Exports keying material for SRTP.
60 bool ExportKeyingMaterial(base::StringPiece label,
61 base::StringPiece context,
62 size_t result_len,
mikescarlett8d37d292016-04-29 22:35:0063 std::string* result);
mikescarlettcd0e4752016-02-09 01:35:4764
65 // Decrypts an incoming QUIC packet to a data stream.
66 bool OnReadPacket(const char* data, size_t data_len);
67
68 // Called when peers have established forward-secure encryption
69 sigslot::signal0<> SignalHandshakeComplete;
70 // Called when connection closes locally, or remotely by peer.
71 sigslot::signal2<net::QuicErrorCode, bool> SignalConnectionClosed;
72 // Called when an incoming QUIC stream is created so we can process data
73 // from it by registering a listener to
74 // ReliableQuicStream::SignalDataReceived.
75 sigslot::signal1<ReliableQuicStream*> SignalIncomingStream;
76
77 protected:
78 // Sets the QUIC crypto stream and takes ownership of it.
79 void SetCryptoStream(net::QuicCryptoStream* crypto_stream);
80
81 // QuicSession override.
82 ReliableQuicStream* CreateIncomingDynamicStream(
83 net::QuicStreamId id) override;
84
mikescarlett70035ca2016-04-30 01:14:3785 virtual ReliableQuicStream* CreateDataStream(net::QuicStreamId id,
86 net::SpdyPriority priority);
mikescarlettcd0e4752016-02-09 01:35:4787
88 private:
kwiberg3ec46792016-04-27 14:22:5389 std::unique_ptr<net::QuicCryptoStream> crypto_stream_;
mikescarlett8d37d292016-04-29 22:35:0090 net::QuicClock clock_; // For recording packet receipt time
mikescarlettcd0e4752016-02-09 01:35:4791
92 RTC_DISALLOW_COPY_AND_ASSIGN(QuicSession);
93};
94
95} // namespace cricket
96
97#endif // WEBRTC_P2P_QUIC_QUICSESSION_H_