blob: 53511ad6d9b37559eada2dc4685a9d0141a3d6d4 [file] [log] [blame]
wubf975eac2019-08-19 19:41:01 -07001// 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_server_session.h"
6
bnc463f2352019-10-10 04:49:34 -07007#include <utility>
8
wubf975eac2019-08-19 19:41:01 -07009#include "net/third_party/quiche/src/quic/core/quic_connection_id.h"
10#include "net/third_party/quiche/src/quic/core/quic_types.h"
11#include "net/third_party/quiche/src/quic/core/quic_utils.h"
wubf975eac2019-08-19 19:41:01 -070012#include "net/third_party/quiche/src/quic/qbone/qbone_constants.h"
dmcardled70b99e2019-12-12 09:52:39 -080013#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
wubf975eac2019-08-19 19:41:01 -070014
15namespace quic {
16
17bool QboneCryptoServerStreamHelper::CanAcceptClientHello(
18 const CryptoHandshakeMessage& chlo,
19 const QuicSocketAddress& client_address,
20 const QuicSocketAddress& peer_address,
21 const QuicSocketAddress& self_address,
22 string* error_details) const {
dschinazib3b51de2019-12-19 16:52:04 -080023 quiche::QuicheStringPiece alpn;
wubf975eac2019-08-19 19:41:01 -070024 chlo.GetStringPiece(quic::kALPN, &alpn);
25 if (alpn != QboneConstants::kQboneAlpn) {
26 *error_details = "ALPN-indicated protocol is not qbone";
27 return false;
28 }
29 return true;
30}
31
32QboneServerSession::QboneServerSession(
33 const quic::ParsedQuicVersionVector& supported_versions,
34 QuicConnection* connection,
35 Visitor* owner,
36 const QuicConfig& config,
37 const QuicCryptoServerConfig* quic_crypto_server_config,
38 QuicCompressedCertsCache* compressed_certs_cache,
39 QbonePacketWriter* writer,
40 QuicIpAddress self_ip,
41 QuicIpAddress client_ip,
42 size_t client_ip_subnet_length,
43 QboneServerControlStream::Handler* handler)
44 : QboneSessionBase(connection, owner, config, supported_versions, writer),
45 processor_(self_ip, client_ip, client_ip_subnet_length, this, this),
46 quic_crypto_server_config_(quic_crypto_server_config),
47 compressed_certs_cache_(compressed_certs_cache),
48 handler_(handler) {}
49
50QboneServerSession::~QboneServerSession() {}
51
52std::unique_ptr<QuicCryptoStream> QboneServerSession::CreateCryptoStream() {
nharpere5e28f92020-01-03 14:10:07 -080053 return CreateCryptoServerStream(quic_crypto_server_config_,
54 compressed_certs_cache_, this,
55 &stream_helper_);
wubf975eac2019-08-19 19:41:01 -070056}
57
58void QboneServerSession::Initialize() {
59 QboneSessionBase::Initialize();
60 // Register the reserved control stream.
61 auto control_stream =
vasilvv0fc587f2019-09-06 13:33:08 -070062 std::make_unique<QboneServerControlStream>(this, handler_);
wubf975eac2019-08-19 19:41:01 -070063 control_stream_ = control_stream.get();
renjietang5c729f02019-09-06 12:43:48 -070064 ActivateStream(std::move(control_stream));
wubf975eac2019-08-19 19:41:01 -070065}
66
67bool QboneServerSession::SendClientRequest(const QboneClientRequest& request) {
68 if (!control_stream_) {
69 QUIC_BUG << "Cannot send client request before control stream is created.";
70 return false;
71 }
72 return control_stream_->SendRequest(request);
73}
74
dmcardled70b99e2019-12-12 09:52:39 -080075void QboneServerSession::ProcessPacketFromNetwork(
76 quiche::QuicheStringPiece packet) {
wubf975eac2019-08-19 19:41:01 -070077 string buffer = string(packet);
78 processor_.ProcessPacket(&buffer,
79 QbonePacketProcessor::Direction::FROM_NETWORK);
80}
81
dmcardled70b99e2019-12-12 09:52:39 -080082void QboneServerSession::ProcessPacketFromPeer(
83 quiche::QuicheStringPiece packet) {
wubf975eac2019-08-19 19:41:01 -070084 string buffer = string(packet);
85 processor_.ProcessPacket(&buffer,
QUICHE team234c8772019-12-06 14:14:12 -080086 QbonePacketProcessor::Direction::FROM_OFF_NETWORK);
wubf975eac2019-08-19 19:41:01 -070087}
88
dmcardled70b99e2019-12-12 09:52:39 -080089void QboneServerSession::SendPacketToClient(quiche::QuicheStringPiece packet) {
wubf975eac2019-08-19 19:41:01 -070090 SendPacketToPeer(packet);
91}
92
dmcardled70b99e2019-12-12 09:52:39 -080093void QboneServerSession::SendPacketToNetwork(quiche::QuicheStringPiece packet) {
wubf975eac2019-08-19 19:41:01 -070094 DCHECK(writer_ != nullptr);
95 writer_->WritePacketToNetwork(packet.data(), packet.size());
96}
97
98} // namespace quic