blob: 79142c4681ec5a4d32b9ab7defc9baa6949d9e29 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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.
4
QUICHE team5be974e2020-12-29 18:35:24 -05005#include "quic/core/quic_crypto_handshaker.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -05006
QUICHE team5be974e2020-12-29 18:35:24 -05007#include "quic/core/quic_session.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -05008
9namespace quic {
10
11#define ENDPOINT \
12 (session()->perspective() == Perspective::IS_SERVER ? "Server: " : "Client: ")
13
14QuicCryptoHandshaker::QuicCryptoHandshaker(QuicCryptoStream* stream,
15 QuicSession* session)
16 : stream_(stream), session_(session), last_sent_handshake_message_tag_(0) {
17 crypto_framer_.set_visitor(this);
18}
19
20QuicCryptoHandshaker::~QuicCryptoHandshaker() {}
21
22void QuicCryptoHandshaker::SendHandshakeMessage(
fayang9c41f8b2020-10-30 13:13:06 -070023 const CryptoHandshakeMessage& message,
24 EncryptionLevel level) {
QUICHE teama6ef0a62019-03-07 20:34:33 -050025 QUIC_DVLOG(1) << ENDPOINT << "Sending " << message.DebugString();
26 session()->NeuterUnencryptedData();
27 session()->OnCryptoHandshakeMessageSent(message);
28 last_sent_handshake_message_tag_ = message.tag();
29 const QuicData& data = message.GetSerialized();
fayange4023022021-07-26 15:11:40 -070030 stream_->WriteCryptoData(level, data.AsStringPiece());
QUICHE teama6ef0a62019-03-07 20:34:33 -050031}
32
33void QuicCryptoHandshaker::OnError(CryptoFramer* framer) {
34 QUIC_DLOG(WARNING) << "Error processing crypto data: "
35 << QuicErrorCodeToString(framer->error());
36}
37
38void QuicCryptoHandshaker::OnHandshakeMessage(
39 const CryptoHandshakeMessage& message) {
40 QUIC_DVLOG(1) << ENDPOINT << "Received " << message.DebugString();
41 session()->OnCryptoHandshakeMessageReceived(message);
42}
43
44CryptoMessageParser* QuicCryptoHandshaker::crypto_message_parser() {
45 return &crypto_framer_;
46}
47
nharper486a8a92019-08-28 16:25:10 -070048size_t QuicCryptoHandshaker::BufferSizeLimitForLevel(EncryptionLevel) const {
49 return GetQuicFlag(FLAGS_quic_max_buffered_crypto_bytes);
50}
51
QUICHE teama6ef0a62019-03-07 20:34:33 -050052#undef ENDPOINT // undef for jumbo builds
53} // namespace quic