Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / quic / quic_crypto_server_stream.h
blob94c031899148f429df7e111e60a2845b9133668c
1 // Copyright (c) 2012 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.
5 #ifndef NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
6 #define NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_
8 #include <string>
10 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/crypto/quic_crypto_server_config.h"
12 #include "net/quic/quic_config.h"
13 #include "net/quic/quic_crypto_stream.h"
15 namespace net {
17 class CachedNetworkParameters;
18 class CryptoHandshakeMessage;
19 class QuicCryptoServerConfig;
20 class QuicCryptoServerStream;
21 class QuicSession;
23 namespace test {
24 class CryptoTestUtils;
25 } // namespace test
27 // Receives a notification when the server hello (SHLO) has been ACKed by the
28 // peer. At this point we disable HANDSHAKE_MODE in the sent packet manager.
29 class NET_EXPORT_PRIVATE ServerHelloNotifier : public
30 QuicAckNotifier::DelegateInterface {
31 public:
32 explicit ServerHelloNotifier(QuicCryptoServerStream* stream)
33 : server_stream_(stream) {}
35 // QuicAckNotifier::DelegateInterface implementation
36 virtual void OnAckNotification(
37 int num_original_packets,
38 int num_original_bytes,
39 int num_retransmitted_packets,
40 int num_retransmitted_bytes,
41 QuicTime::Delta delta_largest_observed) OVERRIDE;
43 private:
44 virtual ~ServerHelloNotifier() {}
46 QuicCryptoServerStream* server_stream_;
48 DISALLOW_COPY_AND_ASSIGN(ServerHelloNotifier);
51 class NET_EXPORT_PRIVATE QuicCryptoServerStream : public QuicCryptoStream {
52 public:
53 QuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config,
54 QuicSession* session);
55 virtual ~QuicCryptoServerStream();
57 // Cancel any outstanding callbacks, such as asynchronous validation of client
58 // hello.
59 void CancelOutstandingCallbacks();
61 // CryptoFramerVisitorInterface implementation
62 virtual void OnHandshakeMessage(
63 const CryptoHandshakeMessage& message) OVERRIDE;
65 // GetBase64SHA256ClientChannelID sets |*output| to the base64 encoded,
66 // SHA-256 hash of the client's ChannelID key and returns true, if the client
67 // presented a ChannelID. Otherwise it returns false.
68 bool GetBase64SHA256ClientChannelID(std::string* output) const;
70 uint8 num_handshake_messages() const { return num_handshake_messages_; }
72 int num_server_config_update_messages_sent() const {
73 return num_server_config_update_messages_sent_;
76 // Sends the latest server config and source-address token to the client.
77 virtual void SendServerConfigUpdate(
78 const CachedNetworkParameters* cached_network_params);
80 // Called by the ServerHello AckNotifier once the SHLO has been ACKed by the
81 // client.
82 void OnServerHelloAcked();
84 protected:
85 virtual QuicErrorCode ProcessClientHello(
86 const CryptoHandshakeMessage& message,
87 const ValidateClientHelloResultCallback::Result& result,
88 CryptoHandshakeMessage* reply,
89 std::string* error_details);
91 // Hook that allows the server to set QuicConfig defaults just
92 // before going through the parameter negotiation step.
93 virtual void OverrideQuicConfigDefaults(QuicConfig* config);
95 private:
96 friend class test::CryptoTestUtils;
98 class ValidateCallback : public ValidateClientHelloResultCallback {
99 public:
100 explicit ValidateCallback(QuicCryptoServerStream* parent);
101 // To allow the parent to detach itself from the callback before deletion.
102 void Cancel();
104 // From ValidateClientHelloResultCallback
105 virtual void RunImpl(const CryptoHandshakeMessage& client_hello,
106 const Result& result) OVERRIDE;
108 private:
109 QuicCryptoServerStream* parent_;
111 DISALLOW_COPY_AND_ASSIGN(ValidateCallback);
114 // Invoked by ValidateCallback::RunImpl once initial validation of
115 // the client hello is complete. Finishes processing of the client
116 // hello message and handles handshake success/failure.
117 void FinishProcessingHandshakeMessage(
118 const CryptoHandshakeMessage& message,
119 const ValidateClientHelloResultCallback::Result& result);
121 // crypto_config_ contains crypto parameters for the handshake.
122 const QuicCryptoServerConfig& crypto_config_;
124 // Pointer to the active callback that will receive the result of
125 // the client hello validation request and forward it to
126 // FinishProcessingHandshakeMessage for processing. NULL if no
127 // handshake message is being validated.
128 ValidateCallback* validate_client_hello_cb_;
130 // Number of handshake messages received by this stream.
131 uint8 num_handshake_messages_;
133 // Number of server config update (SCUP) messages sent by this stream.
134 int num_server_config_update_messages_sent_;
136 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerStream);
139 } // namespace net
141 #endif // NET_QUIC_QUIC_CRYPTO_SERVER_STREAM_H_