1 // Copyright (c) 2012 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 // A toy client, which connects to a specified port and sends QUIC
6 // request to that endpoint.
7 
8 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_
9 #define NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_
10 
11 #include <stddef.h>
12 
13 #include <memory>
14 #include <string>
15 
16 #include "base/command_line.h"
17 #include "base/macros.h"
18 #include "net/base/ip_address.h"
19 #include "net/base/ip_endpoint.h"
20 #include "net/http/http_response_headers.h"
21 #include "net/log/net_log.h"
22 #include "net/quic/platform/impl/quic_chromium_clock.h"
23 #include "net/quic/quic_chromium_packet_reader.h"
24 #include "net/third_party/quiche/src/quic/core/http/quic_spdy_stream.h"
25 #include "net/third_party/quiche/src/quic/core/quic_config.h"
26 #include "net/third_party/quiche/src/quic/tools/quic_spdy_client_base.h"
27 #include "net/tools/quic/quic_client_message_loop_network_helper.h"
28 
29 namespace net {
30 
31 class QuicChromiumAlarmFactory;
32 class QuicChromiumConnectionHelper;
33 
34 namespace test {
35 class QuicClientPeer;
36 }  // namespace test
37 
38 class QuicSimpleClient : public quic::QuicSpdyClientBase {
39  public:
40   // Create a quic client, which will have events managed by the message loop.
41   QuicSimpleClient(quic::QuicSocketAddress server_address,
42                    const quic::QuicServerId& server_id,
43                    const quic::ParsedQuicVersionVector& supported_versions,
44                    const quic::QuicConfig& config,
45                    std::unique_ptr<quic::ProofVerifier> proof_verifier);
46 
47   ~QuicSimpleClient() override;
48 
49   std::unique_ptr<quic::QuicSession> CreateQuicClientSession(
50       const quic::ParsedQuicVersionVector& supported_versions,
51       quic::QuicConnection* connection) override;
52 
53  private:
54   friend class net::test::QuicClientPeer;
55 
56   QuicChromiumAlarmFactory* CreateQuicAlarmFactory();
57   QuicChromiumConnectionHelper* CreateQuicConnectionHelper();
58 
59   //  Used by |helper_| to time alarms.
60   quic::QuicChromiumClock clock_;
61 
62   // Tracks if the client is initialized to connect.
63   bool initialized_;
64 
65   base::WeakPtrFactory<QuicSimpleClient> weak_factory_{this};
66 
67   DISALLOW_COPY_AND_ASSIGN(QuicSimpleClient);
68 };
69 
70 }  // namespace net
71 
72 #endif  // NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_
73