| OLD | NEW |
| 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 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
| 17 #include "net/quic/crypto/crypto_handshake.h" | 17 #include "net/quic/crypto/crypto_handshake.h" |
| 18 #include "net/quic/quic_config.h" | 18 #include "net/quic/quic_config.h" |
| 19 #include "net/quic/quic_framer.h" | 19 #include "net/quic/quic_framer.h" |
| 20 #include "net/quic/quic_packet_creator.h" | 20 #include "net/quic/quic_packet_creator.h" |
| 21 #include "net/tools/epoll_server/epoll_server.h" | 21 #include "net/tools/epoll_server/epoll_server.h" |
| 22 #include "net/tools/quic/quic_client_session.h" | 22 #include "net/tools/quic/quic_client_session.h" |
| 23 #include "net/tools/quic/quic_spdy_client_stream.h" | 23 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 class ProofVerifier; | 27 class ProofVerifier; |
| 28 class QuicSessionKey; | 28 class QuicServerId; |
| 29 | 29 |
| 30 namespace tools { | 30 namespace tools { |
| 31 | 31 |
| 32 class QuicEpollConnectionHelper; | 32 class QuicEpollConnectionHelper; |
| 33 | 33 |
| 34 namespace test { | 34 namespace test { |
| 35 class QuicClientPeer; | 35 class QuicClientPeer; |
| 36 } // namespace test | 36 } // namespace test |
| 37 | 37 |
| 38 class QuicClient : public EpollCallbackInterface, | 38 class QuicClient : public EpollCallbackInterface, |
| 39 public QuicDataStream::Visitor { | 39 public QuicDataStream::Visitor { |
| 40 public: | 40 public: |
| 41 class ResponseListener { | 41 class ResponseListener { |
| 42 public: | 42 public: |
| 43 ResponseListener() {} | 43 ResponseListener() {} |
| 44 virtual ~ResponseListener() {} | 44 virtual ~ResponseListener() {} |
| 45 virtual void OnCompleteResponse(QuicStreamId id, | 45 virtual void OnCompleteResponse(QuicStreamId id, |
| 46 const BalsaHeaders& response_headers, | 46 const BalsaHeaders& response_headers, |
| 47 const string& response_body) = 0; | 47 const string& response_body) = 0; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 QuicClient(IPEndPoint server_address, | 50 QuicClient(IPEndPoint server_address, |
| 51 const QuicSessionKey& server_key, | 51 const QuicServerId& server_id, |
| 52 const QuicVersionVector& supported_versions, | 52 const QuicVersionVector& supported_versions, |
| 53 bool print_response, | 53 bool print_response, |
| 54 uint32 initial_flow_control_window); | 54 uint32 initial_flow_control_window); |
| 55 QuicClient(IPEndPoint server_address, | 55 QuicClient(IPEndPoint server_address, |
| 56 const QuicSessionKey& server_key, | 56 const QuicServerId& server_id, |
| 57 const QuicConfig& config, | 57 const QuicConfig& config, |
| 58 const QuicVersionVector& supported_versions, | 58 const QuicVersionVector& supported_versions, |
| 59 uint32 initial_flow_control_window); | 59 uint32 initial_flow_control_window); |
| 60 | 60 |
| 61 virtual ~QuicClient(); | 61 virtual ~QuicClient(); |
| 62 | 62 |
| 63 // Initializes the client to create a connection. Should be called exactly | 63 // Initializes the client to create a connection. Should be called exactly |
| 64 // once before calling StartConnect or Connect. Returns true if the | 64 // once before calling StartConnect or Connect. Returns true if the |
| 65 // initialization succeeds, false otherwise. | 65 // initialization succeeds, false otherwise. |
| 66 bool Initialize(); | 66 bool Initialize(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 void set_local_port(int local_port) { local_port_ = local_port; } | 131 void set_local_port(int local_port) { local_port_ = local_port; } |
| 132 | 132 |
| 133 const IPEndPoint& server_address() const { return server_address_; } | 133 const IPEndPoint& server_address() const { return server_address_; } |
| 134 | 134 |
| 135 const IPEndPoint& client_address() const { return client_address_; } | 135 const IPEndPoint& client_address() const { return client_address_; } |
| 136 | 136 |
| 137 EpollServer* epoll_server() { return &epoll_server_; } | 137 EpollServer* epoll_server() { return &epoll_server_; } |
| 138 | 138 |
| 139 int fd() { return fd_; } | 139 int fd() { return fd_; } |
| 140 | 140 |
| 141 const QuicSessionKey& server_key() const { return server_key_; } | 141 const QuicServerId& server_id() const { return server_id_; } |
| 142 | 142 |
| 143 // This should only be set before the initial Connect() | 143 // This should only be set before the initial Connect() |
| 144 void set_server_key(const QuicSessionKey& server_key) { | 144 void set_server_id(const QuicServerId& server_id) { |
| 145 server_key_ = server_key; | 145 server_id_ = server_id; |
| 146 } | 146 } |
| 147 | 147 |
| 148 // SetProofVerifier sets the ProofVerifier that will be used to verify the | 148 // SetProofVerifier sets the ProofVerifier that will be used to verify the |
| 149 // server's certificate and takes ownership of |verifier|. | 149 // server's certificate and takes ownership of |verifier|. |
| 150 void SetProofVerifier(ProofVerifier* verifier) { | 150 void SetProofVerifier(ProofVerifier* verifier) { |
| 151 // TODO(rtenneti): We should set ProofVerifier in QuicClientSession. | 151 // TODO(rtenneti): We should set ProofVerifier in QuicClientSession. |
| 152 crypto_config_.SetProofVerifier(verifier); | 152 crypto_config_.SetProofVerifier(verifier); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // SetChannelIDSigner sets a ChannelIDSigner that will be called when the | 155 // SetChannelIDSigner sets a ChannelIDSigner that will be called when the |
| (...skipping 20 matching lines...) Expand all Loading... |
| 176 | 176 |
| 177 private: | 177 private: |
| 178 friend class net::tools::test::QuicClientPeer; | 178 friend class net::tools::test::QuicClientPeer; |
| 179 | 179 |
| 180 // Read a UDP packet and hand it to the framer. | 180 // Read a UDP packet and hand it to the framer. |
| 181 bool ReadAndProcessPacket(); | 181 bool ReadAndProcessPacket(); |
| 182 | 182 |
| 183 // Address of the server. | 183 // Address of the server. |
| 184 const IPEndPoint server_address_; | 184 const IPEndPoint server_address_; |
| 185 | 185 |
| 186 // |server_key_| is a tuple (hostname, port, is_https) of the server. | 186 // |server_id_| is a tuple (hostname, port, is_https) of the server. |
| 187 QuicSessionKey server_key_; | 187 QuicServerId server_id_; |
| 188 | 188 |
| 189 // config_ and crypto_config_ contain configuration and cached state about | 189 // config_ and crypto_config_ contain configuration and cached state about |
| 190 // servers. | 190 // servers. |
| 191 QuicConfig config_; | 191 QuicConfig config_; |
| 192 QuicCryptoClientConfig crypto_config_; | 192 QuicCryptoClientConfig crypto_config_; |
| 193 | 193 |
| 194 // Address of the client if the client is connected to the server. | 194 // Address of the client if the client is connected to the server. |
| 195 IPEndPoint client_address_; | 195 IPEndPoint client_address_; |
| 196 | 196 |
| 197 // If initialized, the address to bind to. | 197 // If initialized, the address to bind to. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // Size of initial flow control receive window to advertise to server. | 241 // Size of initial flow control receive window to advertise to server. |
| 242 uint32 initial_flow_control_window_; | 242 uint32 initial_flow_control_window_; |
| 243 | 243 |
| 244 DISALLOW_COPY_AND_ASSIGN(QuicClient); | 244 DISALLOW_COPY_AND_ASSIGN(QuicClient); |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 } // namespace tools | 247 } // namespace tools |
| 248 } // namespace net | 248 } // namespace net |
| 249 | 249 |
| 250 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 250 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
| OLD | NEW |