blob: 25bf9dcdf1567dce221590f29f160d040eaf68e9 [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();
fayang9c41f8b2020-10-30 13:13:06 -070030 stream_->WriteCryptoData(session_->use_write_or_buffer_data_at_level()
31 ? level
32 : session_->connection()->encryption_level(),
QUICHE teama6ef0a62019-03-07 20:34:33 -050033 data.AsStringPiece());
34}
35
36void QuicCryptoHandshaker::OnError(CryptoFramer* framer) {
37 QUIC_DLOG(WARNING) << "Error processing crypto data: "
38 << QuicErrorCodeToString(framer->error());
39}
40
41void QuicCryptoHandshaker::OnHandshakeMessage(
42 const CryptoHandshakeMessage& message) {
43 QUIC_DVLOG(1) << ENDPOINT << "Received " << message.DebugString();
44 session()->OnCryptoHandshakeMessageReceived(message);
45}
46
47CryptoMessageParser* QuicCryptoHandshaker::crypto_message_parser() {
48 return &crypto_framer_;
49}
50
nharper486a8a92019-08-28 16:25:10 -070051size_t QuicCryptoHandshaker::BufferSizeLimitForLevel(EncryptionLevel) const {
52 return GetQuicFlag(FLAGS_quic_max_buffered_crypto_bytes);
53}
54
QUICHE teama6ef0a62019-03-07 20:34:33 -050055#undef ENDPOINT // undef for jumbo builds
56} // namespace quic