vasilvv | d88f162 | 2019-11-04 13:50:53 -0800 | [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 | #ifndef QUICHE_QUIC_TOOLS_QUIC_TRANSPORT_SIMPLE_SERVER_SESSION_H_ |
| 6 | #define QUICHE_QUIC_TOOLS_QUIC_TRANSPORT_SIMPLE_SERVER_SESSION_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "url/origin.h" |
| 12 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 13 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
| 14 | #include "net/third_party/quiche/src/quic/platform/api/quic_containers.h" |
| 15 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 16 | #include "net/third_party/quiche/src/quic/quic_transport/quic_transport_server_session.h" |
| 17 | #include "net/third_party/quiche/src/quic/quic_transport/quic_transport_stream.h" |
| 18 | |
| 19 | namespace quic { |
| 20 | |
| 21 | // QuicTransport simple server is a non-production server that can be used for |
| 22 | // testing QuicTransport. It has two modes that can be changed using the |
| 23 | // command line flags, "echo" and "discard". |
| 24 | class QuicTransportSimpleServerSession |
| 25 | : public QuicTransportServerSession, |
| 26 | QuicTransportServerSession::ServerVisitor { |
| 27 | public: |
| 28 | enum Mode { |
| 29 | // In DISCARD mode, any data on incoming streams is discarded and no |
| 30 | // outgoing streams are initiated. |
| 31 | DISCARD, |
| 32 | // In ECHO mode, any data sent on a bidirectional stream is echoed back. |
| 33 | // Any data sent on a unidirectional stream is buffered, and echoed back on |
| 34 | // a server-initiated unidirectional stream that is sent as soon as a FIN is |
| 35 | // received on the incoming stream. |
| 36 | ECHO, |
| 37 | }; |
| 38 | |
| 39 | QuicTransportSimpleServerSession( |
| 40 | QuicConnection* connection, |
| 41 | bool owns_connection, |
| 42 | Visitor* owner, |
| 43 | const QuicConfig& config, |
| 44 | const ParsedQuicVersionVector& supported_versions, |
| 45 | const QuicCryptoServerConfig* crypto_config, |
| 46 | QuicCompressedCertsCache* compressed_certs_cache, |
vasilvv | d88f162 | 2019-11-04 13:50:53 -0800 | [diff] [blame] | 47 | std::vector<url::Origin> accepted_origins); |
| 48 | ~QuicTransportSimpleServerSession(); |
| 49 | |
| 50 | void OnIncomingDataStream(QuicTransportStream* stream) override; |
| 51 | void OnCanCreateNewOutgoingStream(bool unidirectional) override; |
| 52 | bool CheckOrigin(url::Origin origin) override; |
vasilvv | 7857189 | 2019-12-06 07:14:57 -0800 | [diff] [blame] | 53 | bool ProcessPath(const GURL& url) override; |
vasilvv | 2b0ab24 | 2020-01-07 07:32:09 -0800 | [diff] [blame] | 54 | void OnMessageReceived(quiche::QuicheStringPiece message) override; |
vasilvv | d88f162 | 2019-11-04 13:50:53 -0800 | [diff] [blame] | 55 | |
| 56 | void EchoStreamBack(const std::string& data) { |
| 57 | streams_to_echo_back_.push_back(data); |
| 58 | MaybeEchoStreamsBack(); |
| 59 | } |
| 60 | |
| 61 | private: |
| 62 | void MaybeEchoStreamsBack(); |
| 63 | |
vasilvv | d88f162 | 2019-11-04 13:50:53 -0800 | [diff] [blame] | 64 | const bool owns_connection_; |
| 65 | Mode mode_; |
| 66 | std::vector<url::Origin> accepted_origins_; |
| 67 | QuicDeque<std::string> streams_to_echo_back_; |
| 68 | }; |
| 69 | |
| 70 | } // namespace quic |
| 71 | |
| 72 | #endif // QUICHE_QUIC_TOOLS_QUIC_TRANSPORT_SIMPLE_SERVER_SESSION_H_ |