Add diagnostics_writer.cc to the list of files allowed to printf.
[chromium-blink-merge.git] / net / quic / quic_crypto_stream.cc
blobfe2d311f30b2a2a418466ea1162c1d654bd0d74d
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 (is_server_ ? "Server: " : " Client: ")
23 QuicCryptoStream::QuicCryptoStream(QuicSession* session)
24 : ReliableQuicStream(kCryptoStreamId, session),
25 encryption_established_(false),
26 handshake_confirmed_(false),
27 is_server_(session->is_server()) {
28 crypto_framer_.set_visitor(this);
29 if (version() <= QUIC_VERSION_20) {
30 // Prior to QUIC_VERSION_21 the crypto stream is not subject to any flow
31 // control.
32 DisableFlowControl();
34 // The crypto stream is exempt from connection level flow control.
35 DisableConnectionFlowControlForThisStream();
38 void QuicCryptoStream::OnError(CryptoFramer* framer) {
39 DLOG(WARNING) << "Error processing crypto data: "
40 << QuicUtils::ErrorToString(framer->error());
43 void QuicCryptoStream::OnHandshakeMessage(
44 const CryptoHandshakeMessage& message) {
45 DVLOG(1) << ENDPOINT << "Received " << message.DebugString();
46 session()->OnCryptoHandshakeMessageReceived(message);
49 uint32 QuicCryptoStream::ProcessRawData(const char* data,
50 uint32 data_len) {
51 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) {
52 CloseConnection(crypto_framer_.error());
53 return 0;
55 return data_len;
58 QuicPriority QuicCryptoStream::EffectivePriority() const {
59 return QuicUtils::HighestPriority();
62 void QuicCryptoStream::SendHandshakeMessage(
63 const CryptoHandshakeMessage& message) {
64 SendHandshakeMessage(message, NULL);
67 void QuicCryptoStream::SendHandshakeMessage(
68 const CryptoHandshakeMessage& message,
69 QuicAckNotifier::DelegateInterface* delegate) {
70 DVLOG(1) << ENDPOINT << "Sending " << message.DebugString();
71 session()->OnCryptoHandshakeMessageSent(message);
72 const QuicData& data = message.GetSerialized();
73 // TODO(wtc): check the return value.
74 WriteOrBufferData(string(data.data(), data.length()), false, delegate);
77 bool QuicCryptoStream::ExportKeyingMaterial(
78 StringPiece label,
79 StringPiece context,
80 size_t result_len,
81 string* result) const {
82 if (!handshake_confirmed()) {
83 DLOG(ERROR) << "ExportKeyingMaterial was called before forward-secure"
84 << "encryption was established.";
85 return false;
87 return CryptoUtils::ExportKeyingMaterial(
88 crypto_negotiated_params_.subkey_secret,
89 label,
90 context,
91 result_len,
92 result);
95 const QuicCryptoNegotiatedParameters&
96 QuicCryptoStream::crypto_negotiated_params() const {
97 return crypto_negotiated_params_;
100 } // namespace net