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 #include "net/quic/quic_crypto_stream.h"
9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/quic_connection.h"
12 #include "net/quic/quic_session.h"
13 #include "net/quic/quic_utils.h"
16 using base::StringPiece
;
20 QuicCryptoStream::QuicCryptoStream(QuicSession
* session
)
21 : ReliableQuicStream(kCryptoStreamId
, session
),
22 encryption_established_(false),
23 handshake_confirmed_(false) {
24 crypto_framer_
.set_visitor(this);
28 void QuicCryptoStream::OnError(CryptoFramer
* framer
) {
29 DLOG(WARNING
) << "Error processing crypto data: "
30 << QuicUtils::ErrorToString(framer
->error());
33 void QuicCryptoStream::OnHandshakeMessage(
34 const CryptoHandshakeMessage
& message
) {
35 session()->OnCryptoHandshakeMessageReceived(message
);
38 uint32
QuicCryptoStream::ProcessRawData(const char* data
,
40 // Do not process handshake messages after the handshake is confirmed.
41 if (handshake_confirmed()) {
42 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE
);
45 if (!crypto_framer_
.ProcessInput(StringPiece(data
, data_len
))) {
46 CloseConnection(crypto_framer_
.error());
52 QuicPriority
QuicCryptoStream::EffectivePriority() const {
53 return QuicUtils::HighestPriority();
56 void QuicCryptoStream::SendHandshakeMessage(
57 const CryptoHandshakeMessage
& message
) {
58 session()->OnCryptoHandshakeMessageSent(message
);
59 const QuicData
& data
= message
.GetSerialized();
60 // To make reasoning about crypto frames easier, we don't combine them with
61 // any other frames in a single packet.
62 session()->connection()->Flush();
63 // TODO(wtc): check the return value.
64 WriteOrBufferData(string(data
.data(), data
.length()), false, NULL
);
65 session()->connection()->Flush();
68 const QuicCryptoNegotiatedParameters
&
69 QuicCryptoStream::crypto_negotiated_params() const {
70 return crypto_negotiated_params_
;