Re-land: C++ readability review
[chromium-blink-merge.git] / net / quic / quic_crypto_stream.cc
blob43cf497bd3c169b862a9008c9293991d0a7ea007
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"
7 #include <string>
9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/crypto/crypto_utils.h"
12 #include "net/quic/quic_connection.h"
13 #include "net/quic/quic_session.h"
14 #include "net/quic/quic_utils.h"
16 using std::string;
17 using base::StringPiece;
19 namespace net {
21 #define ENDPOINT \
22 (session()->perspective() == Perspective::IS_SERVER ? "Server: " : "Client:" \
23 " ")
25 QuicCryptoStream::QuicCryptoStream(QuicSession* session)
26 : ReliableQuicStream(kCryptoStreamId, session),
27 encryption_established_(false),
28 handshake_confirmed_(false) {
29 crypto_framer_.set_visitor(this);
30 // The crypto stream is exempt from connection level flow control.
31 DisableConnectionFlowControlForThisStream();
34 void QuicCryptoStream::OnError(CryptoFramer* framer) {
35 DLOG(WARNING) << "Error processing crypto data: "
36 << QuicUtils::ErrorToString(framer->error());
39 void QuicCryptoStream::OnHandshakeMessage(
40 const CryptoHandshakeMessage& message) {
41 DVLOG(1) << ENDPOINT << "Received " << message.DebugString();
42 session()->OnCryptoHandshakeMessageReceived(message);
45 uint32 QuicCryptoStream::ProcessRawData(const char* data,
46 uint32 data_len) {
47 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) {
48 CloseConnection(crypto_framer_.error());
49 return 0;
51 return data_len;
54 QuicPriority QuicCryptoStream::EffectivePriority() const {
55 return QuicUtils::HighestPriority();
58 void QuicCryptoStream::SendHandshakeMessage(
59 const CryptoHandshakeMessage& message) {
60 SendHandshakeMessage(message, nullptr);
63 void QuicCryptoStream::SendHandshakeMessage(
64 const CryptoHandshakeMessage& message,
65 QuicAckNotifier::DelegateInterface* delegate) {
66 DVLOG(1) << ENDPOINT << "Sending " << message.DebugString();
67 session()->OnCryptoHandshakeMessageSent(message);
68 const QuicData& data = message.GetSerialized();
69 // TODO(wtc): check the return value.
70 WriteOrBufferData(string(data.data(), data.length()), false, delegate);
73 bool QuicCryptoStream::ExportKeyingMaterial(
74 StringPiece label,
75 StringPiece context,
76 size_t result_len,
77 string* result) const {
78 if (!handshake_confirmed()) {
79 DLOG(ERROR) << "ExportKeyingMaterial was called before forward-secure"
80 << "encryption was established.";
81 return false;
83 return CryptoUtils::ExportKeyingMaterial(
84 crypto_negotiated_params_.subkey_secret,
85 label,
86 context,
87 result_len,
88 result);
91 const QuicCryptoNegotiatedParameters&
92 QuicCryptoStream::crypto_negotiated_params() const {
93 return crypto_negotiated_params_;
96 } // namespace net