| 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/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/containers/hash_tables.h" | |
| 15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 16 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 17 #include "net/quic/crypto/crypto_handshake.h" | 16 #include "net/quic/crypto/crypto_handshake.h" |
| 18 #include "net/quic/quic_config.h" | 17 #include "net/quic/quic_config.h" |
| 19 #include "net/quic/quic_framer.h" | 18 #include "net/quic/quic_framer.h" |
| 20 #include "net/quic/quic_packet_creator.h" | 19 #include "net/quic/quic_packet_creator.h" |
| 21 #include "net/tools/epoll_server/epoll_server.h" | 20 #include "net/tools/epoll_server/epoll_server.h" |
| 22 #include "net/tools/quic/quic_client_session.h" | 21 #include "net/tools/quic/quic_client_session.h" |
| 23 #include "net/tools/quic/quic_reliable_client_stream.h" | 22 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 24 | 23 |
| 25 namespace net { | 24 namespace net { |
| 26 | 25 |
| 27 class ProofVerifier; | 26 class ProofVerifier; |
| 28 | 27 |
| 29 namespace tools { | 28 namespace tools { |
| 30 | 29 |
| 31 class QuicEpollConnectionHelper; | 30 class QuicEpollConnectionHelper; |
| 32 | 31 |
| 33 namespace test { | 32 namespace test { |
| 34 class QuicClientPeer; | 33 class QuicClientPeer; |
| 35 } // namespace test | 34 } // namespace test |
| 36 | 35 |
| 37 class QuicClient : public EpollCallbackInterface, | 36 class QuicClient : public EpollCallbackInterface, |
| 38 public ReliableQuicStream::Visitor { | 37 public QuicDataStream::Visitor { |
| 39 public: | 38 public: |
| 40 QuicClient(IPEndPoint server_address, | 39 QuicClient(IPEndPoint server_address, |
| 41 const string& server_hostname, | 40 const string& server_hostname, |
| 42 const QuicVersionVector& supported_versions, | 41 const QuicVersionVector& supported_versions, |
| 43 bool print_response); | 42 bool print_response); |
| 44 QuicClient(IPEndPoint server_address, | 43 QuicClient(IPEndPoint server_address, |
| 45 const std::string& server_hostname, | 44 const std::string& server_hostname, |
| 46 const QuicConfig& config, | 45 const QuicConfig& config, |
| 47 const QuicVersionVector& supported_versions); | 46 const QuicVersionVector& supported_versions); |
| 48 | 47 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 | 68 |
| 70 // Disconnects from the QUIC server. | 69 // Disconnects from the QUIC server. |
| 71 void Disconnect(); | 70 void Disconnect(); |
| 72 | 71 |
| 73 // Sends a request simple GET for each URL in arg, and then waits for | 72 // Sends a request simple GET for each URL in arg, and then waits for |
| 74 // each to complete. | 73 // each to complete. |
| 75 void SendRequestsAndWaitForResponse(const CommandLine::StringVector& args); | 74 void SendRequestsAndWaitForResponse(const CommandLine::StringVector& args); |
| 76 | 75 |
| 77 // Returns a newly created CreateReliableClientStream, owned by the | 76 // Returns a newly created CreateReliableClientStream, owned by the |
| 78 // QuicClient. | 77 // QuicClient. |
| 79 QuicReliableClientStream* CreateReliableClientStream(); | 78 QuicSpdyClientStream* CreateReliableClientStream(); |
| 80 | 79 |
| 81 // Wait for events until the stream with the given ID is closed. | 80 // Wait for events until the stream with the given ID is closed. |
| 82 void WaitForStreamToClose(QuicStreamId id); | 81 void WaitForStreamToClose(QuicStreamId id); |
| 83 | 82 |
| 84 // Wait for events until the handshake is confirmed. | 83 // Wait for events until the handshake is confirmed. |
| 85 void WaitForCryptoHandshakeConfirmed(); | 84 void WaitForCryptoHandshakeConfirmed(); |
| 86 | 85 |
| 87 // Wait up to 50ms, and handle any events which occur. | 86 // Wait up to 50ms, and handle any events which occur. |
| 88 // Returns true if there are any outstanding requests. | 87 // Returns true if there are any outstanding requests. |
| 89 bool WaitForEvents(); | 88 bool WaitForEvents(); |
| 90 | 89 |
| 91 // From EpollCallbackInterface | 90 // From EpollCallbackInterface |
| 92 virtual void OnRegistration( | 91 virtual void OnRegistration( |
| 93 EpollServer* eps, int fd, int event_mask) OVERRIDE {} | 92 EpollServer* eps, int fd, int event_mask) OVERRIDE {} |
| 94 virtual void OnModification(int fd, int event_mask) OVERRIDE {} | 93 virtual void OnModification(int fd, int event_mask) OVERRIDE {} |
| 95 virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE; | 94 virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE; |
| 96 // |fd_| can be unregistered without the client being disconnected. This | 95 // |fd_| can be unregistered without the client being disconnected. This |
| 97 // happens in b3m QuicProber where we unregister |fd_| to feed in events to | 96 // happens in b3m QuicProber where we unregister |fd_| to feed in events to |
| 98 // the client from the SelectServer. | 97 // the client from the SelectServer. |
| 99 virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {} | 98 virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {} |
| 100 virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {} | 99 virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {} |
| 101 | 100 |
| 102 // ReliableQuicStream::Visitor | 101 // QuicDataStream::Visitor |
| 103 virtual void OnClose(ReliableQuicStream* stream) OVERRIDE; | 102 virtual void OnClose(QuicDataStream* stream) OVERRIDE; |
| 104 | 103 |
| 105 QuicPacketCreator::Options* options(); | 104 QuicPacketCreator::Options* options(); |
| 106 | 105 |
| 107 QuicClientSession* session() { return session_.get(); } | 106 QuicClientSession* session() { return session_.get(); } |
| 108 | 107 |
| 109 bool connected() const; | 108 bool connected() const; |
| 110 | 109 |
| 111 void set_bind_to_address(IPAddressNumber address) { | 110 void set_bind_to_address(IPAddressNumber address) { |
| 112 bind_to_address_ = address; | 111 bind_to_address_ = address; |
| 113 } | 112 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 virtual QuicGuid GenerateGuid(); | 146 virtual QuicGuid GenerateGuid(); |
| 148 virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper(); | 147 virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper(); |
| 149 virtual QuicPacketWriter* CreateQuicPacketWriter(); | 148 virtual QuicPacketWriter* CreateQuicPacketWriter(); |
| 150 | 149 |
| 151 private: | 150 private: |
| 152 friend class net::tools::test::QuicClientPeer; | 151 friend class net::tools::test::QuicClientPeer; |
| 153 | 152 |
| 154 // Read a UDP packet and hand it to the framer. | 153 // Read a UDP packet and hand it to the framer. |
| 155 bool ReadAndProcessPacket(); | 154 bool ReadAndProcessPacket(); |
| 156 | 155 |
| 157 // Set of streams created (and owned) by this client | |
| 158 base::hash_set<QuicReliableClientStream*> streams_; | |
| 159 | |
| 160 // Address of the server. | 156 // Address of the server. |
| 161 const IPEndPoint server_address_; | 157 const IPEndPoint server_address_; |
| 162 | 158 |
| 163 // Hostname of the server. This may be a DNS name or an IP address literal. | 159 // Hostname of the server. This may be a DNS name or an IP address literal. |
| 164 std::string server_hostname_; | 160 std::string server_hostname_; |
| 165 | 161 |
| 166 // config_ and crypto_config_ contain configuration and cached state about | 162 // config_ and crypto_config_ contain configuration and cached state about |
| 167 // servers. | 163 // servers. |
| 168 QuicConfig config_; | 164 QuicConfig config_; |
| 169 QuicCryptoClientConfig crypto_config_; | 165 QuicCryptoClientConfig crypto_config_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // when the stream is closed (in OnClose). | 208 // when the stream is closed (in OnClose). |
| 213 bool print_response_; | 209 bool print_response_; |
| 214 | 210 |
| 215 DISALLOW_COPY_AND_ASSIGN(QuicClient); | 211 DISALLOW_COPY_AND_ASSIGN(QuicClient); |
| 216 }; | 212 }; |
| 217 | 213 |
| 218 } // namespace tools | 214 } // namespace tools |
| 219 } // namespace net | 215 } // namespace net |
| 220 | 216 |
| 221 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 217 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
| OLD | NEW |