Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: net/tools/quic/quic_client.h

Issue 2369863004: Move more members from QuicClient to QuicClientBase and change (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/end_to_end_test.cc ('k') | net/tools/quic/quic_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // A toy client, which connects to a specified port and sends QUIC 5 // A toy client, which connects to a specified port and sends QUIC
6 // request to that endpoint. 6 // request to that endpoint.
7 7
8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_ 8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_
9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_ 9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_
10 10
(...skipping 22 matching lines...) Expand all
33 class QuicEpollConnectionHelper; 33 class QuicEpollConnectionHelper;
34 34
35 namespace test { 35 namespace test {
36 class QuicClientPeer; 36 class QuicClientPeer;
37 } // namespace test 37 } // namespace test
38 38
39 class QuicClient : public QuicClientBase, 39 class QuicClient : public QuicClientBase,
40 public EpollCallbackInterface, 40 public EpollCallbackInterface,
41 public ProcessPacketInterface { 41 public ProcessPacketInterface {
42 public: 42 public:
43 class ResponseListener {
44 public:
45 ResponseListener() {}
46 virtual ~ResponseListener() {}
47 virtual void OnCompleteResponse(QuicStreamId id,
48 const SpdyHeaderBlock& response_headers,
49 const std::string& response_body) = 0;
50 };
51
52 // Create a quic client, which will have events managed by an externally owned 43 // Create a quic client, which will have events managed by an externally owned
53 // EpollServer. 44 // EpollServer.
54 QuicClient(IPEndPoint server_address, 45 QuicClient(IPEndPoint server_address,
55 const QuicServerId& server_id, 46 const QuicServerId& server_id,
56 const QuicVersionVector& supported_versions, 47 const QuicVersionVector& supported_versions,
57 EpollServer* epoll_server, 48 EpollServer* epoll_server,
58 std::unique_ptr<ProofVerifier> proof_verifier); 49 std::unique_ptr<ProofVerifier> proof_verifier);
59 QuicClient(IPEndPoint server_address, 50 QuicClient(IPEndPoint server_address,
60 const QuicServerId& server_id, 51 const QuicServerId& server_id,
61 const QuicVersionVector& supported_versions, 52 const QuicVersionVector& supported_versions,
62 const QuicConfig& config, 53 const QuicConfig& config,
63 EpollServer* epoll_server, 54 EpollServer* epoll_server,
64 std::unique_ptr<ProofVerifier> proof_verifier); 55 std::unique_ptr<ProofVerifier> proof_verifier);
65 56
66 ~QuicClient() override; 57 ~QuicClient() override;
67 58
68 // From QuicClientBase 59 // From QuicClientBase
69 bool Initialize() override; 60 bool Initialize() override;
70 bool WaitForEvents() override; 61 bool WaitForEvents() override;
71 QuicSpdyClientStream* CreateReliableClientStream() override;
72 62
73 // "Connect" to the QUIC server, including performing synchronous crypto 63 // "Connect" to the QUIC server, including performing synchronous crypto
74 // handshake. 64 // handshake.
75 bool Connect(); 65 bool Connect();
76 66
77 // Start the crypto handshake. This can be done in place of the synchronous 67 // Start the crypto handshake. This can be done in place of the synchronous
78 // Connect(), but callers are responsible for making sure the crypto handshake 68 // Connect(), but callers are responsible for making sure the crypto handshake
79 // completes. 69 // completes.
80 void StartConnect(); 70 void StartConnect();
81 71
(...skipping 20 matching lines...) Expand all
102 // From EpollCallbackInterface 92 // From EpollCallbackInterface
103 void OnRegistration(EpollServer* eps, int fd, int event_mask) override {} 93 void OnRegistration(EpollServer* eps, int fd, int event_mask) override {}
104 void OnModification(int fd, int event_mask) override {} 94 void OnModification(int fd, int event_mask) override {}
105 void OnEvent(int fd, EpollEvent* event) override; 95 void OnEvent(int fd, EpollEvent* event) override;
106 // |fd_| can be unregistered without the client being disconnected. This 96 // |fd_| can be unregistered without the client being disconnected. This
107 // happens in b3m QuicProber where we unregister |fd_| to feed in events to 97 // happens in b3m QuicProber where we unregister |fd_| to feed in events to
108 // the client from the SelectServer. 98 // the client from the SelectServer.
109 void OnUnregistration(int fd, bool replaced) override {} 99 void OnUnregistration(int fd, bool replaced) override {}
110 void OnShutdown(EpollServer* eps, int fd) override {} 100 void OnShutdown(EpollServer* eps, int fd) override {}
111 101
112 // QuicSpdyStream::Visitor
113 void OnClose(QuicSpdyStream* stream) override;
114
115 // If the client has at least one UDP socket, return address of the latest 102 // If the client has at least one UDP socket, return address of the latest
116 // created one. Otherwise, return an empty socket address. 103 // created one. Otherwise, return an empty socket address.
117 const IPEndPoint GetLatestClientAddress() const; 104 const IPEndPoint GetLatestClientAddress() const;
118 105
119 // If the client has at least one UDP socket, return the latest created one. 106 // If the client has at least one UDP socket, return the latest created one.
120 // Otherwise, return -1. 107 // Otherwise, return -1.
121 int GetLatestFD() const; 108 int GetLatestFD() const;
122 109
123 void set_bind_to_address(const IPAddress& address) {
124 bind_to_address_ = address;
125 }
126
127 const IPAddress& bind_to_address() const { return bind_to_address_; }
128
129 void set_local_port(int local_port) { local_port_ = local_port; }
130
131 const IPEndPoint& server_address() const { return server_address_; }
132
133 void set_server_address(const IPEndPoint& server_address) {
134 server_address_ = server_address;
135 }
136
137 // Takes ownership of the std::listener.
138 void set_response_listener(ResponseListener* listener) {
139 response_listener_.reset(listener);
140 }
141
142 void set_store_response(bool val) { store_response_ = val; }
143
144 size_t latest_response_code() const;
145 const std::string& latest_response_headers() const;
146 const SpdyHeaderBlock& latest_response_header_block() const;
147 const std::string& latest_response_body() const;
148 const std::string& latest_response_trailers() const;
149
150 protected: 110 protected:
151 // Implements ProcessPacketInterface. This will be called for each received 111 // Implements ProcessPacketInterface. This will be called for each received
152 // packet. 112 // packet.
153 void ProcessPacket(const IPEndPoint& self_address, 113 void ProcessPacket(const IPEndPoint& self_address,
154 const IPEndPoint& peer_address, 114 const IPEndPoint& peer_address,
155 const QuicReceivedPacket& packet) override; 115 const QuicReceivedPacket& packet) override;
156 116
157 virtual QuicPacketWriter* CreateQuicPacketWriter(); 117 virtual QuicPacketWriter* CreateQuicPacketWriter();
158 118
159 // If |fd| is an open UDP socket, unregister and close it. Otherwise, do 119 // If |fd| is an open UDP socket, unregister and close it. Otherwise, do
(...skipping 12 matching lines...) Expand all
172 private: 132 private:
173 friend class net::test::QuicClientPeer; 133 friend class net::test::QuicClientPeer;
174 134
175 // Used during initialization: creates the UDP socket FD, sets socket options, 135 // Used during initialization: creates the UDP socket FD, sets socket options,
176 // and binds the socket to our address. 136 // and binds the socket to our address.
177 bool CreateUDPSocketAndBind(); 137 bool CreateUDPSocketAndBind();
178 138
179 // Actually clean up |fd|. 139 // Actually clean up |fd|.
180 void CleanUpUDPSocketImpl(int fd); 140 void CleanUpUDPSocketImpl(int fd);
181 141
182 // Address of the server.
183 IPEndPoint server_address_;
184
185 // If initialized, the address to bind to.
186 IPAddress bind_to_address_;
187
188 // Local port to bind to. Initialize to 0.
189 int local_port_;
190
191 // Listens for events on the client socket. 142 // Listens for events on the client socket.
192 EpollServer* epoll_server_; 143 EpollServer* epoll_server_;
193 144
194 // Map mapping created UDP sockets to their addresses. By using linked hash 145 // Map mapping created UDP sockets to their addresses. By using linked hash
195 // map, the order of socket creation can be recorded. 146 // map, the order of socket creation can be recorded.
196 linked_hash_map<int, IPEndPoint> fd_address_map_; 147 linked_hash_map<int, IPEndPoint> fd_address_map_;
197 148
198 // Listens for full responses.
199 std::unique_ptr<ResponseListener> response_listener_;
200
201 // Tracks if the client is initialized to connect. 149 // Tracks if the client is initialized to connect.
202 bool initialized_; 150 bool initialized_;
203 151
204 // If overflow_supported_ is true, this will be the number of packets dropped 152 // If overflow_supported_ is true, this will be the number of packets dropped
205 // during the lifetime of the server. 153 // during the lifetime of the server.
206 QuicPacketCount packets_dropped_; 154 QuicPacketCount packets_dropped_;
207 155
208 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped 156 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
209 // because the socket would otherwise overflow. 157 // because the socket would otherwise overflow.
210 bool overflow_supported_; 158 bool overflow_supported_;
211 159
212 // If true, store the latest response code, headers, and body.
213 bool store_response_;
214 // HTTP response code from most recent response.
215 int latest_response_code_;
216 // HTTP/2 headers from most recent response.
217 std::string latest_response_headers_;
218 // HTTP/2 header black from most recent response.
219 SpdyHeaderBlock latest_response_header_block_;
220 // Body of most recent response.
221 std::string latest_response_body_;
222 // HTTP/2 trailers from most recent response.
223 std::string latest_response_trailers_;
224
225 // Point to a QuicPacketReader object on the heap. The reader allocates more 160 // Point to a QuicPacketReader object on the heap. The reader allocates more
226 // space than allowed on the stack. 161 // space than allowed on the stack.
227 // 162 //
228 // TODO(rtenneti): Chromium code doesn't use |packet_reader_|. Add support for 163 // TODO(rtenneti): Chromium code doesn't use |packet_reader_|. Add support for
229 // QuicPacketReader 164 // QuicPacketReader
230 std::unique_ptr<QuicPacketReader> packet_reader_; 165 std::unique_ptr<QuicPacketReader> packet_reader_;
231 166
232 DISALLOW_COPY_AND_ASSIGN(QuicClient); 167 DISALLOW_COPY_AND_ASSIGN(QuicClient);
233 }; 168 };
234 169
235 } // namespace net 170 } // namespace net
236 171
237 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ 172 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_
OLDNEW
« no previous file with comments | « net/tools/quic/end_to_end_test.cc ('k') | net/tools/quic/quic_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698