QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | #include "net/third_party/quiche/src/quic/tools/quic_client.h" |
| 6 | |
| 7 | #include <errno.h> |
nharper | 2eb3f38 | 2019-07-24 14:12:31 -0700 | [diff] [blame] | 8 | #include <netdb.h> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #include <netinet/in.h> |
| 10 | #include <string.h> |
| 11 | #include <sys/epoll.h> |
| 12 | #include <sys/socket.h> |
nharper | 2eb3f38 | 2019-07-24 14:12:31 -0700 | [diff] [blame] | 13 | #include <sys/types.h> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 15 | #include <utility> |
| 16 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/quic/core/crypto/quic_random.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/http/spdy_utils.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/quic_connection.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/quic_data_reader.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/quic_epoll_alarm_factory.h" |
| 22 | #include "net/third_party/quiche/src/quic/core/quic_epoll_connection_helper.h" |
| 23 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 24 | #include "net/third_party/quiche/src/quic/core/quic_server_id.h" |
| 25 | #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h" |
| 26 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 27 | #include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h" |
nharper | 2eb3f38 | 2019-07-24 14:12:31 -0700 | [diff] [blame] | 28 | #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | #include "net/third_party/quiche/src/quic/tools/quic_simple_client_session.h" |
| 30 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 31 | namespace quic { |
| 32 | |
nharper | 2eb3f38 | 2019-07-24 14:12:31 -0700 | [diff] [blame] | 33 | namespace tools { |
| 34 | |
| 35 | QuicSocketAddress LookupAddress(std::string host, std::string port) { |
| 36 | addrinfo hint; |
| 37 | memset(&hint, 0, sizeof(hint)); |
| 38 | hint.ai_protocol = IPPROTO_UDP; |
| 39 | |
| 40 | addrinfo* info_list = nullptr; |
| 41 | int result = getaddrinfo(host.c_str(), port.c_str(), &hint, &info_list); |
| 42 | if (result != 0) { |
| 43 | QUIC_LOG(ERROR) << "Failed to look up " << host << ": " |
| 44 | << gai_strerror(result); |
| 45 | return QuicSocketAddress(); |
| 46 | } |
| 47 | |
| 48 | CHECK(info_list != nullptr); |
| 49 | std::unique_ptr<addrinfo, void (*)(addrinfo*)> info_list_owned(info_list, |
| 50 | freeaddrinfo); |
| 51 | return QuicSocketAddress(info_list->ai_addr, info_list->ai_addrlen); |
| 52 | } |
| 53 | |
| 54 | } // namespace tools |
| 55 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 56 | QuicClient::QuicClient(QuicSocketAddress server_address, |
| 57 | const QuicServerId& server_id, |
| 58 | const ParsedQuicVersionVector& supported_versions, |
| 59 | QuicEpollServer* epoll_server, |
| 60 | std::unique_ptr<ProofVerifier> proof_verifier) |
| 61 | : QuicClient( |
| 62 | server_address, |
| 63 | server_id, |
| 64 | supported_versions, |
| 65 | QuicConfig(), |
| 66 | epoll_server, |
| 67 | QuicWrapUnique(new QuicClientEpollNetworkHelper(epoll_server, this)), |
nharper | 41ac9df | 2019-11-11 15:09:23 -0800 | [diff] [blame] | 68 | std::move(proof_verifier), |
| 69 | nullptr) {} |
| 70 | |
| 71 | QuicClient::QuicClient(QuicSocketAddress server_address, |
| 72 | const QuicServerId& server_id, |
| 73 | const ParsedQuicVersionVector& supported_versions, |
| 74 | QuicEpollServer* epoll_server, |
| 75 | std::unique_ptr<ProofVerifier> proof_verifier, |
| 76 | std::unique_ptr<SessionCache> session_cache) |
| 77 | : QuicClient( |
| 78 | server_address, |
| 79 | server_id, |
| 80 | supported_versions, |
| 81 | QuicConfig(), |
| 82 | epoll_server, |
| 83 | QuicWrapUnique(new QuicClientEpollNetworkHelper(epoll_server, this)), |
| 84 | std::move(proof_verifier), |
| 85 | std::move(session_cache)) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 86 | |
| 87 | QuicClient::QuicClient( |
| 88 | QuicSocketAddress server_address, |
| 89 | const QuicServerId& server_id, |
| 90 | const ParsedQuicVersionVector& supported_versions, |
| 91 | QuicEpollServer* epoll_server, |
| 92 | std::unique_ptr<QuicClientEpollNetworkHelper> network_helper, |
| 93 | std::unique_ptr<ProofVerifier> proof_verifier) |
| 94 | : QuicClient(server_address, |
| 95 | server_id, |
| 96 | supported_versions, |
| 97 | QuicConfig(), |
| 98 | epoll_server, |
| 99 | std::move(network_helper), |
nharper | 41ac9df | 2019-11-11 15:09:23 -0800 | [diff] [blame] | 100 | std::move(proof_verifier), |
| 101 | nullptr) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | |
| 103 | QuicClient::QuicClient( |
| 104 | QuicSocketAddress server_address, |
| 105 | const QuicServerId& server_id, |
| 106 | const ParsedQuicVersionVector& supported_versions, |
| 107 | const QuicConfig& config, |
| 108 | QuicEpollServer* epoll_server, |
| 109 | std::unique_ptr<QuicClientEpollNetworkHelper> network_helper, |
| 110 | std::unique_ptr<ProofVerifier> proof_verifier) |
nharper | 41ac9df | 2019-11-11 15:09:23 -0800 | [diff] [blame] | 111 | : QuicClient(server_address, |
| 112 | server_id, |
| 113 | supported_versions, |
| 114 | config, |
| 115 | epoll_server, |
| 116 | std::move(network_helper), |
| 117 | std::move(proof_verifier), |
| 118 | nullptr) {} |
| 119 | |
| 120 | QuicClient::QuicClient( |
| 121 | QuicSocketAddress server_address, |
| 122 | const QuicServerId& server_id, |
| 123 | const ParsedQuicVersionVector& supported_versions, |
| 124 | const QuicConfig& config, |
| 125 | QuicEpollServer* epoll_server, |
| 126 | std::unique_ptr<QuicClientEpollNetworkHelper> network_helper, |
| 127 | std::unique_ptr<ProofVerifier> proof_verifier, |
| 128 | std::unique_ptr<SessionCache> session_cache) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 129 | : QuicSpdyClientBase( |
| 130 | server_id, |
| 131 | supported_versions, |
| 132 | config, |
| 133 | new QuicEpollConnectionHelper(epoll_server, QuicAllocator::SIMPLE), |
| 134 | new QuicEpollAlarmFactory(epoll_server), |
| 135 | std::move(network_helper), |
nharper | 41ac9df | 2019-11-11 15:09:23 -0800 | [diff] [blame] | 136 | std::move(proof_verifier), |
| 137 | std::move(session_cache)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 138 | set_server_address(server_address); |
| 139 | } |
| 140 | |
| 141 | QuicClient::~QuicClient() = default; |
| 142 | |
| 143 | std::unique_ptr<QuicSession> QuicClient::CreateQuicClientSession( |
| 144 | const ParsedQuicVersionVector& supported_versions, |
| 145 | QuicConnection* connection) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 146 | return std::make_unique<QuicSimpleClientSession>( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 147 | *config(), supported_versions, connection, server_id(), crypto_config(), |
rch | d362a7a | 2019-05-15 17:19:26 -0700 | [diff] [blame] | 148 | push_promise_index(), drop_response_body()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | QuicClientEpollNetworkHelper* QuicClient::epoll_network_helper() { |
| 152 | return static_cast<QuicClientEpollNetworkHelper*>(network_helper()); |
| 153 | } |
| 154 | |
| 155 | const QuicClientEpollNetworkHelper* QuicClient::epoll_network_helper() const { |
| 156 | return static_cast<const QuicClientEpollNetworkHelper*>(network_helper()); |
| 157 | } |
| 158 | |
| 159 | } // namespace quic |