wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 1 | // Copyright (c) 2019 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 | |
| 5 | #include "net/third_party/quiche/src/quic/qbone/qbone_client_session.h" |
| 6 | |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/qbone/qbone_constants.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | |
| 14 | QboneClientSession::QboneClientSession( |
| 15 | QuicConnection* connection, |
| 16 | QuicCryptoClientConfig* quic_crypto_client_config, |
| 17 | QuicSession::Visitor* owner, |
| 18 | const QuicConfig& config, |
| 19 | const ParsedQuicVersionVector& supported_versions, |
| 20 | const QuicServerId& server_id, |
| 21 | QbonePacketWriter* writer, |
| 22 | QboneClientControlStream::Handler* handler) |
| 23 | : QboneSessionBase(connection, owner, config, supported_versions, writer), |
| 24 | server_id_(server_id), |
| 25 | quic_crypto_client_config_(quic_crypto_client_config), |
| 26 | handler_(handler) {} |
| 27 | |
| 28 | QboneClientSession::~QboneClientSession() {} |
| 29 | |
| 30 | std::unique_ptr<QuicCryptoStream> QboneClientSession::CreateCryptoStream() { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 31 | return std::make_unique<QuicCryptoClientStream>( |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 32 | server_id_, this, nullptr, quic_crypto_client_config_, this); |
| 33 | } |
| 34 | |
| 35 | void QboneClientSession::Initialize() { |
| 36 | // Initialize must be called first, as that's what generates the crypto |
| 37 | // stream. |
| 38 | QboneSessionBase::Initialize(); |
| 39 | static_cast<QuicCryptoClientStreamBase*>(GetMutableCryptoStream()) |
| 40 | ->CryptoConnect(); |
| 41 | // Register the reserved control stream. |
| 42 | QuicStreamId next_id = GetNextOutgoingBidirectionalStreamId(); |
renjietang | d1d0085 | 2019-09-06 10:43:12 -0700 | [diff] [blame] | 43 | DCHECK_EQ(next_id, QboneConstants::GetControlStreamId(transport_version())); |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 44 | auto control_stream = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 45 | std::make_unique<QboneClientControlStream>(this, handler_); |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 46 | control_stream_ = control_stream.get(); |
renjietang | 5c729f0 | 2019-09-06 12:43:48 -0700 | [diff] [blame] | 47 | ActivateStream(std::move(control_stream)); |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | int QboneClientSession::GetNumSentClientHellos() const { |
| 51 | return static_cast<const QuicCryptoClientStreamBase*>(GetCryptoStream()) |
| 52 | ->num_sent_client_hellos(); |
| 53 | } |
| 54 | |
| 55 | int QboneClientSession::GetNumReceivedServerConfigUpdates() const { |
| 56 | return static_cast<const QuicCryptoClientStreamBase*>(GetCryptoStream()) |
| 57 | ->num_scup_messages_received(); |
| 58 | } |
| 59 | |
| 60 | bool QboneClientSession::SendServerRequest(const QboneServerRequest& request) { |
| 61 | if (!control_stream_) { |
| 62 | QUIC_BUG << "Cannot send server request before control stream is created."; |
| 63 | return false; |
| 64 | } |
| 65 | return control_stream_->SendRequest(request); |
| 66 | } |
| 67 | |
| 68 | void QboneClientSession::ProcessPacketFromNetwork(QuicStringPiece packet) { |
| 69 | SendPacketToPeer(packet); |
| 70 | } |
| 71 | |
| 72 | void QboneClientSession::ProcessPacketFromPeer(QuicStringPiece packet) { |
| 73 | writer_->WritePacketToNetwork(packet.data(), packet.size()); |
| 74 | } |
| 75 | |
| 76 | void QboneClientSession::OnProofValid( |
| 77 | const QuicCryptoClientConfig::CachedState& cached) {} |
| 78 | |
| 79 | void QboneClientSession::OnProofVerifyDetailsAvailable( |
| 80 | const ProofVerifyDetails& verify_details) {} |
| 81 | |
| 82 | bool QboneClientSession::HasActiveRequests() const { |
| 83 | return (stream_map().size() - num_incoming_static_streams() - |
| 84 | num_outgoing_static_streams()) > 0; |
| 85 | } |
| 86 | |
| 87 | } // namespace quic |