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 #ifndef QUICHE_QUIC_QBONE_QBONE_CLIENT_H_ 6 #define QUICHE_QUIC_QBONE_QBONE_CLIENT_H_ 7 8 #include "absl/strings/string_view.h" 9 #include "quiche/quic/core/io/quic_event_loop.h" 10 #include "quiche/quic/core/quic_bandwidth.h" 11 #include "quiche/quic/qbone/qbone_client_interface.h" 12 #include "quiche/quic/qbone/qbone_client_session.h" 13 #include "quiche/quic/qbone/qbone_packet_writer.h" 14 #include "quiche/quic/tools/quic_client_base.h" 15 16 namespace quic { 17 // A QboneClient encapsulates connecting to a server via an event loop 18 // and setting up a QBONE tunnel. See the QboneTestClient in qbone_client_test 19 // for usage. 20 class QboneClient : public QuicClientBase, public QboneClientInterface { 21 public: 22 // Note that the event loop, QBONE writer, and handler are owned 23 // by the caller. 24 QboneClient(QuicSocketAddress server_address, const QuicServerId& server_id, 25 const ParsedQuicVersionVector& supported_versions, 26 QuicSession::Visitor* session_owner, const QuicConfig& config, 27 QuicEventLoop* event_loop, 28 std::unique_ptr<ProofVerifier> proof_verifier, 29 QbonePacketWriter* qbone_writer, 30 QboneClientControlStream::Handler* qbone_handler); 31 ~QboneClient() override; 32 QboneClientSession* qbone_session(); 33 34 // From QboneClientInterface. Accepts a given packet from the network and 35 // sends the packet down to the QBONE connection. 36 void ProcessPacketFromNetwork(absl::string_view packet) override; 37 38 bool EarlyDataAccepted() override; 39 bool ReceivedInchoateReject() override; 40 set_max_pacing_rate(QuicBandwidth max_pacing_rate)41 void set_max_pacing_rate(QuicBandwidth max_pacing_rate) { 42 max_pacing_rate_ = max_pacing_rate; 43 } 44 max_pacing_rate()45 QuicBandwidth max_pacing_rate() const { return max_pacing_rate_; } 46 47 bool use_quarantine_mode() const; 48 void set_use_quarantine_mode(bool use_quarantine_mode); 49 50 protected: 51 int GetNumSentClientHellosFromSession() override; 52 int GetNumReceivedServerConfigUpdatesFromSession() override; 53 54 // This client does not resend saved data. This will be a no-op. 55 void ResendSavedData() override; 56 57 // This client does not resend saved data. This will be a no-op. 58 void ClearDataToResend() override; 59 60 // Takes ownership of |connection|. 61 std::unique_ptr<QuicSession> CreateQuicClientSession( 62 const ParsedQuicVersionVector& supported_versions, 63 QuicConnection* connection) override; 64 qbone_writer()65 QbonePacketWriter* qbone_writer() { return qbone_writer_; } 66 qbone_control_handler()67 QboneClientControlStream::Handler* qbone_control_handler() { 68 return qbone_handler_; 69 } 70 session_owner()71 QuicSession::Visitor* session_owner() { return session_owner_; } 72 73 bool HasActiveRequests() override; 74 75 private: 76 QbonePacketWriter* qbone_writer_; 77 QboneClientControlStream::Handler* qbone_handler_; 78 79 QuicSession::Visitor* session_owner_; 80 81 // When nonzero, the pacing rate set with`QuicConnection::SetMaxPacingRate`. 82 QuicBandwidth max_pacing_rate_; 83 84 // When true, the connection will be made in quarantine mode. 85 bool use_quarantine_mode_ = false; 86 }; 87 88 } // namespace quic 89 90 #endif // QUICHE_QUIC_QBONE_QBONE_CLIENT_H_ 91