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);
27 void QuicCryptoStream::OnError(CryptoFramer
* framer
) {
28 DLOG(WARNING
) << "Error processing crypto data: "
29 << QuicUtils::ErrorToString(framer
->error());
32 void QuicCryptoStream::OnHandshakeMessage(
33 const CryptoHandshakeMessage
& message
) {
34 session()->OnCryptoHandshakeMessageReceived(message
);
37 uint32
QuicCryptoStream::ProcessRawData(const char* data
,
39 // Do not process handshake messages after the handshake is confirmed.
40 if (handshake_confirmed()) {
41 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE
);
44 if (!crypto_framer_
.ProcessInput(StringPiece(data
, data_len
))) {
45 CloseConnection(crypto_framer_
.error());
51 QuicPriority
QuicCryptoStream::EffectivePriority() const {
52 return QuicUtils::HighestPriority();
55 void QuicCryptoStream::SendHandshakeMessage(
56 const CryptoHandshakeMessage
& message
) {
57 session()->OnCryptoHandshakeMessageSent(message
);
58 const QuicData
& data
= message
.GetSerialized();
59 // To make reasoning about crypto frames easier, we don't combine them with
60 // any other frames in a single packet.
61 session()->connection()->Flush();
62 // TODO(wtc): check the return value.
63 WriteOrBufferData(string(data
.data(), data
.length()), false, NULL
);
64 session()->connection()->Flush();
67 const QuicCryptoNegotiatedParameters
&
68 QuicCryptoStream::crypto_negotiated_params() const {
69 return crypto_negotiated_params_
;