blob: ccdf28b213f2b618231e804a6cf67aadd3cdac14 [file] [log] [blame]
vasilvvd88f1622019-11-04 13:50:53 -08001// 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
19namespace 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".
24class 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,
vasilvvd88f1622019-11-04 13:50:53 -080047 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;
vasilvv78571892019-12-06 07:14:57 -080053 bool ProcessPath(const GURL& url) override;
vasilvv2b0ab242020-01-07 07:32:09 -080054 void OnMessageReceived(quiche::QuicheStringPiece message) override;
vasilvvd88f1622019-11-04 13:50:53 -080055
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
vasilvvd88f1622019-11-04 13:50:53 -080064 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_