Commit 3f8b2db5 authored by Victor Vasiliev's avatar Victor Vasiliev Committed by Commit Bot

Reconcile code differences between google3 and Chromium QUIC code

Merge internal change: 237089889

R=rch@chromium.org

Change-Id: I8051e8cb9260833d678884a0affcb272ada8cd12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1507194
Commit-Queue: Victor Vasiliev <vasilvv@chromium.org>
Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638707}
parent 0a942fb1
......@@ -3061,6 +3061,7 @@ if (is_linux) {
"third_party/quic/core/quic_epoll_connection_helper.h",
"third_party/quic/core/quic_packet_reader.cc",
"third_party/quic/core/quic_packet_reader.h",
"third_party/quic/platform/api/quic_default_buffer_allocator.h",
"third_party/quic/platform/api/quic_default_proof_providers.h",
"third_party/quic/platform/api/quic_system_event_loop.h",
"third_party/quic/platform/impl/batch_writer/quic_batch_writer_base.cc",
......@@ -3071,6 +3072,7 @@ if (is_linux) {
"third_party/quic/platform/impl/batch_writer/quic_gso_batch_writer.h",
"third_party/quic/platform/impl/batch_writer/quic_sendmmsg_batch_writer.cc",
"third_party/quic/platform/impl/batch_writer/quic_sendmmsg_batch_writer.h",
"third_party/quic/platform/impl/quic_default_buffer_allocator_impl.h",
"third_party/quic/platform/impl/quic_default_proof_providers_impl.cc",
"third_party/quic/platform/impl/quic_default_proof_providers_impl.h",
"third_party/quic/platform/impl/quic_epoll_clock.cc",
......@@ -3343,8 +3345,6 @@ source_set("quic_test_tools") {
sources += [
"third_party/quic/test_tools/bad_packet_writer.cc",
"third_party/quic/test_tools/bad_packet_writer.h",
"third_party/quic/test_tools/fake_epoll_server.cc",
"third_party/quic/test_tools/fake_epoll_server.h",
"third_party/quic/test_tools/limited_mtu_test_writer.cc",
"third_party/quic/test_tools/limited_mtu_test_writer.h",
"third_party/quic/test_tools/packet_dropping_test_writer.cc",
......@@ -3361,6 +3361,8 @@ source_set("quic_test_tools") {
"third_party/quic/test_tools/quic_test_server.h",
"third_party/quic/test_tools/server_thread.cc",
"third_party/quic/test_tools/server_thread.h",
"tools/epoll_server/fake_epoll_server.cc",
"tools/epoll_server/fake_epoll_server.h",
]
deps += [
":epoll_quic_tools",
......
......@@ -9,7 +9,6 @@
#include "base/macros.h"
#include "net/third_party/quic/core/quic_utils.h"
#include "net/third_party/quic/platform/api/quic_arraysize.h"
#include "net/third_party/quic/platform/api/quic_singleton.h"
namespace quic {
......@@ -142,17 +141,10 @@ class CommonCertSetsQUIC : public CommonCertSets {
return false;
}
static CommonCertSetsQUIC* GetInstance() {
return QuicSingleton<CommonCertSetsQUIC>::get();
}
private:
CommonCertSetsQUIC() {}
CommonCertSetsQUIC(const CommonCertSetsQUIC&) = delete;
CommonCertSetsQUIC& operator=(const CommonCertSetsQUIC&) = delete;
~CommonCertSetsQUIC() override {}
friend QuicSingletonFriend<CommonCertSetsQUIC>;
};
} // anonymous namespace
......@@ -161,7 +153,8 @@ CommonCertSets::~CommonCertSets() {}
// static
const CommonCertSets* CommonCertSets::GetInstanceQUIC() {
return CommonCertSetsQUIC::GetInstance();
static CommonCertSetsQUIC* certs = new CommonCertSetsQUIC();
return certs;
}
} // namespace quic
......@@ -6,7 +6,6 @@
#include "base/macros.h"
#include "net/third_party/quic/platform/api/quic_bug_tracker.h"
#include "net/third_party/quic/platform/api/quic_singleton.h"
#include "third_party/boringssl/src/include/openssl/rand.h"
namespace quic {
......@@ -15,25 +14,16 @@ namespace {
class DefaultRandom : public QuicRandom {
public:
static DefaultRandom* GetInstance();
// QuicRandom implementation
void RandBytes(void* data, size_t len) override;
uint64_t RandUint64() override;
private:
DefaultRandom() {}
DefaultRandom(const DefaultRandom&) = delete;
DefaultRandom& operator=(const DefaultRandom&) = delete;
~DefaultRandom() override {}
friend QuicSingletonFriend<DefaultRandom>;
// QuicRandom implementation
void RandBytes(void* data, size_t len) override;
uint64_t RandUint64() override;
};
DefaultRandom* DefaultRandom::GetInstance() {
return QuicSingleton<DefaultRandom>::get();
}
void DefaultRandom::RandBytes(void* data, size_t len) {
RAND_bytes(reinterpret_cast<uint8_t*>(data), len);
}
......@@ -48,7 +38,8 @@ uint64_t DefaultRandom::RandUint64() {
// static
QuicRandom* QuicRandom::GetInstance() {
return DefaultRandom::GetInstance();
static DefaultRandom* random = new DefaultRandom();
return random;
}
} // namespace quic
......@@ -4,6 +4,8 @@
#include "net/third_party/quic/core/quic_epoll_alarm_factory.h"
#include <type_traits>
#include "net/third_party/quic/core/quic_arena_scoped_ptr.h"
namespace quic {
......@@ -42,10 +44,12 @@ class QuicEpollAlarm : public QuicAlarm {
private:
class EpollAlarmImpl : public QuicEpollAlarmBase {
public:
using int64_epoll = decltype(QuicEpollAlarmBase().OnAlarm());
explicit EpollAlarmImpl(QuicEpollAlarm* alarm) : alarm_(alarm) {}
// Use the same integer type as the base class.
int64_t /* allow-non-std-int */ OnAlarm() override {
int64_epoll OnAlarm() override {
QuicEpollAlarmBase::OnAlarm();
alarm_->Fire();
// Fire will take care of registering the alarm, if needed.
......
......@@ -17,6 +17,7 @@
#include "net/third_party/quic/core/quic_packets.h"
#include "net/third_party/quic/core/quic_simple_buffer_allocator.h"
#include "net/third_party/quic/core/quic_time.h"
#include "net/third_party/quic/platform/api/quic_default_buffer_allocator.h"
#include "net/third_party/quic/platform/api/quic_epoll.h"
#include "net/third_party/quic/platform/impl/quic_epoll_clock.h"
......@@ -24,8 +25,6 @@ namespace quic {
class QuicRandom;
using QuicStreamBufferAllocator = SimpleBufferAllocator;
enum class QuicAllocator { SIMPLE, BUFFER_POOL };
class QuicEpollConnectionHelper : public QuicConnectionHelperInterface {
......@@ -46,7 +45,7 @@ class QuicEpollConnectionHelper : public QuicConnectionHelperInterface {
QuicRandom* random_generator_;
// Set up allocators. They take up minimal memory before use.
// Allocator for stream send buffers.
QuicStreamBufferAllocator stream_buffer_allocator_;
QuicDefaultBufferAllocator stream_buffer_allocator_;
SimpleBufferAllocator simple_buffer_allocator_;
QuicAllocator allocator_type_;
};
......
......@@ -65,7 +65,7 @@ bool QuicPacketReader::ReadAndDispatchPackets(
const QuicClock& clock,
ProcessPacketInterface* processor,
QuicPacketCount* packets_dropped) {
#if MMSG_MORE
#if MMSG_MORE_NO_ANDROID
return ReadAndDispatchManyPackets(fd, port, clock, processor,
packets_dropped);
#else
......@@ -80,7 +80,7 @@ bool QuicPacketReader::ReadAndDispatchManyPackets(
const QuicClock& clock,
ProcessPacketInterface* processor,
QuicPacketCount* packets_dropped) {
#if MMSG_MORE
#if MMSG_MORE_NO_ANDROID
// Re-set the length fields in case recvmmsg has changed them.
for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) {
DCHECK_LE(kMaxPacketSize, packets_[i].iov.iov_len);
......
......@@ -19,8 +19,6 @@
#include "net/third_party/quic/platform/api/quic_socket_address.h"
#include "net/third_party/quic/platform/impl/quic_socket_utils.h"
#define MMSG_MORE 0
namespace quic {
#if MMSG_MORE
......
......@@ -13,6 +13,8 @@ namespace quic {
// Used to generate filtered supported versions based on flags.
class QUIC_EXPORT_PRIVATE QuicVersionManager {
public:
// |supported_versions| should be sorted in the order of preference (typically
// highest supported version to the lowest supported version).
explicit QuicVersionManager(ParsedQuicVersionVector supported_versions);
virtual ~QuicVersionManager();
......@@ -20,7 +22,8 @@ class QUIC_EXPORT_PRIVATE QuicVersionManager {
// TODO(nharper): Remove this method once it is unused.
const QuicTransportVersionVector& GetSupportedTransportVersions();
// Returns currently supported QUIC versions.
// Returns currently supported QUIC versions. This vector has the same order
// as the versions passed to the constructor.
const ParsedQuicVersionVector& GetSupportedVersions();
protected:
......
......@@ -8,7 +8,6 @@
#include "net/third_party/quic/core/tls_client_handshaker.h"
#include "net/third_party/quic/platform/api/quic_arraysize.h"
#include "net/third_party/quic/platform/api/quic_bug_tracker.h"
#include "net/third_party/quic/platform/api/quic_singleton.h"
#include "third_party/boringssl/src/include/openssl/crypto.h"
#include "third_party/boringssl/src/include/openssl/ssl.h"
......@@ -19,7 +18,8 @@ namespace {
class SslIndexSingleton {
public:
static SslIndexSingleton* GetInstance() {
return QuicSingleton<SslIndexSingleton>::get();
static SslIndexSingleton* instance = new SslIndexSingleton();
return instance;
}
int HandshakerIndex() const { return ssl_ex_data_index_handshaker_; }
......@@ -35,8 +35,6 @@ class SslIndexSingleton {
SslIndexSingleton(const SslIndexSingleton&) = delete;
SslIndexSingleton& operator=(const SslIndexSingleton&) = delete;
friend QuicSingletonFriend<SslIndexSingleton>;
int ssl_ex_data_index_handshaker_;
};
......
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_THIRD_PARTY_QUIC_PLATFORM_API_QUIC_DEFAULT_BUFFER_ALLOCATOR_H_
#define NET_THIRD_PARTY_QUIC_PLATFORM_API_QUIC_DEFAULT_BUFFER_ALLOCATOR_H_
#include "net/third_party/quic/platform/impl/quic_default_buffer_allocator_impl.h"
namespace quic {
using QuicDefaultBufferAllocator = QuicStreamBufferAllocatorImpl;
}
#endif // NET_THIRD_PARTY_QUIC_PLATFORM_API_QUIC_DEFAULT_BUFFER_ALLOCATOR_H_
......@@ -11,4 +11,6 @@ inline void QuicRunSystemEventLoopIteration() {
QuicRunSystemEventLoopIterationImpl();
}
using QuicSystemEventLoop = QuicSystemEventLoopImpl;
#endif // NET_THIRD_PARTY_QUIC_PLATFORM_API_QUIC_SYSTEM_EVENT_LOOP_H_
#ifndef NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_DEFAULT_BUFFER_ALLOCATOR_IMPL_H_
#define NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_DEFAULT_BUFFER_ALLOCATOR_IMPL_H_
#include "net/third_party/quic/core/quic_simple_buffer_allocator.h"
namespace quic {
using QuicStreamBufferAllocatorImpl = SimpleBufferAllocator;
} // namespace quic
#endif /* NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_DEFAULT_BUFFER_ALLOCATOR_IMPL_H_ \
*/
......@@ -6,7 +6,7 @@
#include "net/third_party/quic/platform/api/quic_flags.h"
#include "net/third_party/quic/platform/api/quic_test.h"
#include "net/third_party/quic/test_tools/fake_epoll_server.h"
#include "net/tools/epoll_server/fake_epoll_server.h"
namespace quic {
namespace test {
......
......@@ -5,7 +5,7 @@
#ifndef NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_EPOLL_TEST_TOOLS_IMPL_H_
#define NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_EPOLL_TEST_TOOLS_IMPL_H_
#include "net/third_party/quic/test_tools/fake_epoll_server.h"
#include "net/tools/epoll_server/fake_epoll_server.h"
using QuicFakeEpollServerImpl = quic::test::FakeEpollServer;
......
......@@ -31,8 +31,11 @@ QuicSocketAddressImpl::QuicSocketAddressImpl(
}
QuicSocketAddressImpl::QuicSocketAddressImpl(const struct sockaddr& saddr) {
QUIC_BUG << "QuicSocketAddressImpl(const struct sockaddr& saddr) is not "
"implemented.";
if (saddr.sa_family == AF_INET) {
CHECK(socket_address_.FromSockAddr(&saddr, sizeof(struct sockaddr_in)));
} else if (saddr.sa_family == AF_INET6) {
CHECK(socket_address_.FromSockAddr(&saddr, sizeof(struct sockaddr_in6)));
}
}
bool operator==(const QuicSocketAddressImpl& lhs,
......
......@@ -19,6 +19,9 @@
#include "net/third_party/quic/core/quic_bandwidth.h"
#include "net/third_party/quic/core/quic_types.h"
#define MMSG_MORE 0
#define MMSG_MORE_NO_ANDROID 0
namespace quic {
class QuicIpAddress;
class QuicSocketAddress;
......
......@@ -5,10 +5,22 @@
#ifndef NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_SYSTEM_EVENT_LOOP_IMPL_H_
#define NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_SYSTEM_EVENT_LOOP_IMPL_H_
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/task/task_scheduler/task_scheduler.h"
inline void QuicRunSystemEventLoopIterationImpl() {
base::RunLoop().RunUntilIdle();
}
class QuicSystemEventLoopImpl {
public:
QuicSystemEventLoopImpl(std::string context_name) {
base::TaskScheduler::CreateAndStartWithDefaultParams(context_name);
}
private:
base::MessageLoopForIO message_loop_;
};
#endif // NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_SYSTEM_EVENT_LOOP_IMPL_H_
......@@ -80,7 +80,8 @@ TEST_F(QuartcEndpointTest, ClientCreatesSessionAsynchronously) {
// Tests that the server can negotiate for an older QUIC version if the client
// attempts to connect using a newer version.
TEST_F(QuartcEndpointTest, DISABLED_ServerNegotiatesForOldVersion) {
TEST_F(QuartcEndpointTest,
QUIC_TEST_DISABLED_IN_CHROME(ServerNegotiatesForOldVersion)) {
// Note: for this test, we need support for two versions. Which two shouldn't
// matter, but they must be enabled so that the version manager doesn't filter
// them out.
......@@ -124,7 +125,8 @@ TEST_F(QuartcEndpointTest, DISABLED_ServerNegotiatesForOldVersion) {
// Tests that the server can accept connections from clients that use older
// QUIC versions.
TEST_F(QuartcEndpointTest, DISABLED_ServerAcceptsOldVersion) {
TEST_F(QuartcEndpointTest,
QUIC_TEST_DISABLED_IN_CHROME(ServerAcceptsOldVersion)) {
// Note: for this test, we need support for two versions. Which two shouldn't
// matter, but they must be enabled so that the version manager doesn't filter
// them out.
......
......@@ -8,100 +8,143 @@
//
// Some usage examples:
//
// TODO(rtenneti): make --host optional by getting IP Address of URL's host.
//
// Get IP address of the www.google.com
// IP=`dig www.google.com +short | head -1`
//
// Standard request/response:
// quic_client http://www.google.com --host=${IP}
// quic_client http://www.google.com --quiet --host=${IP}
// quic_client https://www.google.com --port=443 --host=${IP}
// quic_client www.google.com
// quic_client www.google.com --quiet
// quic_client www.google.com --port=443
//
// Use a specific version:
// quic_client http://www.google.com --quic_version=23 --host=${IP}
// quic_client www.google.com --quic_version=23
//
// Send a POST instead of a GET:
// quic_client http://www.google.com --body="this is a POST body" --host=${IP}
// quic_client www.google.com --body="this is a POST body"
//
// Append additional headers to the request:
// quic_client http://www.google.com --host=${IP}
// --headers="Header-A: 1234; Header-B: 5678"
// quic_client www.google.com --headers="Header-A: 1234; Header-B: 5678"
//
// Connect to a host different to the URL being requested:
// Get IP address of the www.google.com
// quic_client mail.google.com --host=www.google.com
//
// Connect to a specific IP:
// IP=`dig www.google.com +short | head -1`
// quic_client mail.google.com --host=${IP}
// quic_client www.google.com --host=${IP}
//
// Send repeated requests and change ephemeral port between requests
// quic_client www.google.com --num_requests=10
//
// Try to connect to a host which does not speak QUIC:
// Get IP address of the www.example.com
// IP=`dig www.example.com +short | head -1`
// quic_client http://www.example.com --host=${IP}
// quic_client www.example.com
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <iostream>
#include <memory>
#include <vector>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/task/task_scheduler/task_scheduler.h"
#include "net/base/net_errors.h"
#include "net/base/privacy_mode.h"
#include "net/third_party/quic/core/quic_packets.h"
#include "net/third_party/quic/core/quic_server_id.h"
#include "net/third_party/quic/core/quic_utils.h"
#include "net/third_party/quic/platform/api/quic_default_proof_providers.h"
#include "net/third_party/quic/platform/api/quic_flags.h"
#include "net/third_party/quic/platform/api/quic_ptr_util.h"
#include "net/third_party/quic/platform/api/quic_socket_address.h"
#include "net/third_party/quic/platform/api/quic_str_cat.h"
#include "net/third_party/quic/platform/api/quic_string.h"
#include "net/third_party/quic/platform/api/quic_string_piece.h"
#include "net/third_party/quic/platform/api/quic_system_event_loop.h"
#include "net/third_party/quic/platform/api/quic_text_utils.h"
#include "net/third_party/quic/tools/quic_client.h"
#include "net/third_party/quic/tools/quic_url.h"
#include "net/third_party/quiche/src/spdy/core/spdy_header_block.h"
#include "net/tools/epoll_server/epoll_server.h"
#include "net/tools/quic/synchronous_host_resolver.h"
using quic::ProofVerifier;
namespace {
using quic::QuicSocketAddress;
using quic::QuicString;
using quic::QuicStringPiece;
using quic::QuicTextUtils;
using quic::QuicUrl;
using spdy::SpdyHeaderBlock;
using std::cerr;
using std::cout;
using std::endl;
using std::string;
class FakeProofVerifier : public quic::ProofVerifier {
public:
~FakeProofVerifier() override {}
quic::QuicAsyncStatus VerifyProof(
const std::string& /*hostname*/,
const uint16_t /*port*/,
const std::string& /*server_config*/,
quic::QuicTransportVersion /*quic_version*/,
quic::QuicStringPiece /*chlo_hash*/,
const std::vector<std::string>& /*certs*/,
const std::string& /*cert_sct*/,
const std::string& /*signature*/,
const quic::ProofVerifyContext* /*context*/,
std::string* /*error_details*/,
std::unique_ptr<quic::ProofVerifyDetails>* /*details*/,
std::unique_ptr<quic::ProofVerifierCallback> /*callback*/) override {
return quic::QUIC_SUCCESS;
}
quic::QuicAsyncStatus VerifyCertChain(
const std::string& /*hostname*/,
const std::vector<std::string>& /*certs*/,
const quic::ProofVerifyContext* /*context*/,
std::string* /*error_details*/,
std::unique_ptr<quic::ProofVerifyDetails>* /*details*/,
std::unique_ptr<quic::ProofVerifierCallback> /*callback*/) override {
return quic::QUIC_SUCCESS;
}
std::unique_ptr<quic::ProofVerifyContext> CreateDefaultContext() override {
return nullptr;
}
};
QuicSocketAddress LookupAddress(QuicString host, QuicString port) {
addrinfo hint;
memset(&hint, 0, sizeof(hint));
hint.ai_protocol = IPPROTO_UDP;
addrinfo* info_list = nullptr;
int result = getaddrinfo(host.c_str(), port.c_str(), &hint, &info_list);
if (result != 0) {
QUIC_LOG(ERROR) << "Failed to look up " << host << ": "
<< gai_strerror(result);
return QuicSocketAddress();
}
CHECK(info_list != nullptr);
std::unique_ptr<addrinfo, void (*)(addrinfo*)> info_list_owned(info_list,
freeaddrinfo);
return QuicSocketAddress(*info_list->ai_addr);
}
} // namespace
DEFINE_QUIC_COMMAND_LINE_FLAG(
string,
std::string,
host,
"",
"The IP or hostname the quic client will connect to.");
"The IP or hostname to connect to. If not provided, the host "
"will be derived from the provided URL.");
DEFINE_QUIC_COMMAND_LINE_FLAG(int32_t, port, 0, "The port to connect to.");
DEFINE_QUIC_COMMAND_LINE_FLAG(string,
DEFINE_QUIC_COMMAND_LINE_FLAG(std::string,
body,
"",
"If set, send a POST with this body.");
DEFINE_QUIC_COMMAND_LINE_FLAG(
string,
std::string,
body_hex,
"",
"If set, contents are converted from hex to ascii, before sending as body "
"of a POST. e.g. --body_hex=\"68656c6c6f\"");
"If set, contents are converted from hex to ascii, before "
"sending as body of a POST. e.g. --body_hex=\"68656c6c6f\"");
DEFINE_QUIC_COMMAND_LINE_FLAG(
string,
std::string,
headers,
"",
"A semicolon separated list of key:value pairs to add to request headers.");
"A semicolon separated list of key:value pairs to "
"add to request headers.");
DEFINE_QUIC_COMMAND_LINE_FLAG(bool,
quiet,
......@@ -112,23 +155,23 @@ DEFINE_QUIC_COMMAND_LINE_FLAG(
int32_t,
quic_version,
-1,
"QUIC version to speak, e.g. 21. If not set, then all available versions "
"are offered in the handshake.");
"QUIC version to speak, e.g. 21. If not set, then all available "
"versions are offered in the handshake.");
DEFINE_QUIC_COMMAND_LINE_FLAG(
bool,
version_mismatch_ok,
false,
"If true, a version mismatch in the handshake is not considered a failure. "
"Useful for probing a server to determine if it speaks any version of "
"QUIC.");
"If true, a version mismatch in the handshake is not considered a "
"failure. Useful for probing a server to determine if it speaks "
"any version of QUIC.");
DEFINE_QUIC_COMMAND_LINE_FLAG(
bool,
redirect_is_success,
true,
"If true, an HTTP response code of 3xx is considered to be a successful "
"response, otherwise a failure.");
"If true, an HTTP response code of 3xx is considered to be a "
"successful response, otherwise a failure.");
DEFINE_QUIC_COMMAND_LINE_FLAG(int32_t,
initial_mtu,
......@@ -141,84 +184,31 @@ DEFINE_QUIC_COMMAND_LINE_FLAG(
1,
"How many sequential requests to make on a single connection.");
DEFINE_QUIC_COMMAND_LINE_FLAG(bool,
disable_certificate_verification,
false,
"If true, don't verify the server certificate.");
DEFINE_QUIC_COMMAND_LINE_FLAG(
bool,
drop_response_body,
false,
"If true, drop response body immediately after it is received.");
DEFINE_QUIC_COMMAND_LINE_FLAG(bool,
disable_certificate_verification,
false,
"If true, do not verify certificates.");
class FakeProofVerifier : public ProofVerifier {
public:
quic::QuicAsyncStatus VerifyProof(
const string& /*hostname*/,
const uint16_t /*port*/,
const string& /*server_config*/,
quic::QuicTransportVersion /*quic_version*/,
QuicStringPiece /*chlo_hash*/,
const std::vector<string>& /*certs*/,
const string& /*cert_sct*/,
const string& /*signature*/,
const quic::ProofVerifyContext* /*context*/,
string* /*error_details*/,
std::unique_ptr<quic::ProofVerifyDetails>* /*details*/,
std::unique_ptr<quic::ProofVerifierCallback> /*callback*/) override {
return quic::QUIC_SUCCESS;
}
quic::QuicAsyncStatus VerifyCertChain(
const std::string& /*hostname*/,
const std::vector<std::string>& /*certs*/,
const quic::ProofVerifyContext* /*verify_context*/,
std::string* /*error_details*/,
std::unique_ptr<quic::ProofVerifyDetails>* /*verify_details*/,
std::unique_ptr<quic::ProofVerifierCallback> /*callback*/) override {
return quic::QUIC_SUCCESS;
}
std::unique_ptr<quic::ProofVerifyContext> CreateDefaultContext() override {
return nullptr;
}
};
int main(int argc, char* argv[]) {
base::TaskScheduler::CreateAndStartWithDefaultParams("quic_client");
const char* usage =
"Usage: epoll_quic_client [options] <url>\n"
"\n"
"<url> with scheme must be provided (e.g. http://www.google.com)\n";
QuicSystemEventLoop event_loop("quic_client");
const char* usage = "Usage: quic_client [options] <url>";
// All non-flag arguments should be interpreted as URLs to fetch.
std::vector<QuicString> urls =
quic::QuicParseCommandLineFlags(usage, argc, argv);
if (urls.empty()) {
if (urls.size() != 1) {
quic::QuicPrintCommandLineFlagHelp(usage);
exit(0);
}
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
CHECK(logging::InitLogging(settings));
VLOG(1) << "server host: " << GetQuicFlag(FLAGS_host)
<< " port: " << GetQuicFlag(FLAGS_port)
<< " body: " << GetQuicFlag(FLAGS_body)
<< " headers: " << GetQuicFlag(FLAGS_headers)
<< " quiet: " << GetQuicFlag(FLAGS_quiet)
<< " quic-version: " << GetQuicFlag(FLAGS_quic_version)
<< " version_mismatch_ok: " << GetQuicFlag(FLAGS_version_mismatch_ok)
<< " redirect_is_success: " << GetQuicFlag(FLAGS_redirect_is_success)
<< " initial_mtu: " << GetQuicFlag(FLAGS_initial_mtu);
base::AtExitManager exit_manager;
base::MessageLoopForIO message_loop;
// Determine IP address to connect to from supplied hostname.
quic::QuicIpAddress ip_addr;
QuicUrl url(urls[0], "https");
string host = GetQuicFlag(FLAGS_host);
std::string host = GetQuicFlag(FLAGS_host);
if (host.empty()) {
host = url.host();
}
......@@ -226,20 +216,14 @@ int main(int argc, char* argv[]) {
if (port == 0) {
port = url.port();
}
if (!ip_addr.FromString(host)) {
net::AddressList addresses;
int rv = net::SynchronousHostResolver::Resolve(host, &addresses);
if (rv != net::OK) {
LOG(ERROR) << "Unable to resolve '" << host
<< "' : " << net::ErrorToShortString(rv);
// Determine IP address to connect to from supplied hostname.
QuicSocketAddress addr = LookupAddress(host, quic::QuicStrCat(port));
if (!addr.IsInitialized()) {
return 1;
}
ip_addr =
quic::QuicIpAddress(quic::QuicIpAddressImpl(addresses[0].address()));
}
string host_port = quic::QuicStrCat(ip_addr.ToString(), ":", port);
VLOG(1) << "Resolved " << host << " to " << host_port << endl;
std::cerr << "Resolved " << url.ToString() << " to " << addr.ToString()
<< std::endl;
// Build the client, and try to connect.
quic::QuicEpollServer epoll_server;
......@@ -251,42 +235,41 @@ int main(int argc, char* argv[]) {
quic::PROTOCOL_QUIC_CRYPTO, static_cast<quic::QuicTransportVersion>(
GetQuicFlag(FLAGS_quic_version))));
}
const int32_t num_requests = GetQuicFlag(FLAGS_num_requests);
// For secure QUIC we need to verify the cert chain.
std::unique_ptr<ProofVerifier> proof_verifier;
const int32_t num_requests(GetQuicFlag(FLAGS_num_requests));
std::unique_ptr<quic::ProofVerifier> proof_verifier;
if (GetQuicFlag(FLAGS_disable_certificate_verification)) {
proof_verifier = quic::QuicMakeUnique<FakeProofVerifier>();
} else {
proof_verifier = quic::CreateDefaultProofVerifier();
}
quic::QuicClient client(quic::QuicSocketAddress(ip_addr, port), server_id,
versions, &epoll_server, std::move(proof_verifier));
client.set_initial_max_packet_length(GetQuicFlag(FLAGS_initial_mtu) != 0
? GetQuicFlag(FLAGS_initial_mtu)
: quic::kDefaultMaxPacketSize);
quic::QuicClient client(addr, server_id, versions, &epoll_server,
std::move(proof_verifier));
int32_t initial_mtu = GetQuicFlag(FLAGS_initial_mtu);
client.set_initial_max_packet_length(
initial_mtu != 0 ? initial_mtu : quic::kDefaultMaxPacketSize);
client.set_drop_response_body(GetQuicFlag(FLAGS_drop_response_body));
if (!client.Initialize()) {
cerr << "Failed to initialize client." << endl;
std::cerr << "Failed to initialize client." << std::endl;
return 1;
}
if (!client.Connect()) {
quic::QuicErrorCode error = client.session()->error();
if (error == quic::QUIC_INVALID_VERSION) {
cout << "Server talks QUIC, but none of the versions supported by "
std::cerr << "Server talks QUIC, but none of the versions supported by "
<< "this client: " << ParsedQuicVersionVectorToString(versions)
<< endl;
<< std::endl;
// 0: No error.
// 20: Failed to connect due to QUIC_INVALID_VERSION.
return GetQuicFlag(FLAGS_version_mismatch_ok) ? 0 : 20;
}
cerr << "Failed to connect to " << host_port
<< ". Error: " << quic::QuicErrorCodeToString(error) << endl;
std::cerr << "Failed to connect to " << addr.ToString()
<< ". Error: " << quic::QuicErrorCodeToString(error) << std::endl;
return 1;
}
cout << "Connected to " << host_port << endl;
std::cerr << "Connected to " << addr.ToString() << std::endl;
// Construct the string body from flags, if provided.
string body = GetQuicFlag(FLAGS_body);
std::string body = GetQuicFlag(FLAGS_body);
if (!GetQuicFlag(FLAGS_body_hex).empty()) {
DCHECK(GetQuicFlag(FLAGS_body).empty())
<< "Only set one of --body and --body_hex.";
......@@ -322,62 +305,67 @@ int main(int argc, char* argv[]) {
// Print request and response details.
if (!GetQuicFlag(FLAGS_quiet)) {
cout << "Request:" << endl;
cout << "headers:" << header_block.DebugString();
std::cout << "Request:" << std::endl;
std::cout << "headers:" << header_block.DebugString();
if (!GetQuicFlag(FLAGS_body_hex).empty()) {
// Print the user provided hex, rather than binary body.
cout << "body:\n"
std::cout << "body:\n"
<< QuicTextUtils::HexDump(
QuicTextUtils::HexDecode(GetQuicFlag(FLAGS_body_hex)))
<< endl;
<< std::endl;
} else {
cout << "body: " << body << endl;
std::cout << "body: " << body << std::endl;
}
cout << endl;
std::cout << std::endl;
if (!client.preliminary_response_headers().empty()) {
cout << "Preliminary response headers: "
<< client.preliminary_response_headers() << endl;
cout << endl;
std::cout << "Preliminary response headers: "
<< client.preliminary_response_headers() << std::endl;
std::cout << std::endl;
}
cout << "Response:" << endl;
cout << "headers: " << client.latest_response_headers() << endl;
string response_body = client.latest_response_body();
std::cout << "Response:" << std::endl;
std::cout << "headers: " << client.latest_response_headers() << std::endl;
std::string response_body = client.latest_response_body();
if (!GetQuicFlag(FLAGS_body_hex).empty()) {
// Assume response is binary data.
cout << "body:\n" << QuicTextUtils::HexDump(response_body) << endl;
std::cout << "body:\n"
<< QuicTextUtils::HexDump(response_body) << std::endl;
} else {
cout << "body: " << response_body << endl;
std::cout << "body: " << response_body << std::endl;
}
cout << "trailers: " << client.latest_response_trailers() << endl;
std::cout << "trailers: " << client.latest_response_trailers()
<< std::endl;
}
if (!client.connected()) {
cerr << "Request caused connection failure. Error: "
<< quic::QuicErrorCodeToString(client.session()->error()) << endl;
std::cerr << "Request caused connection failure. Error: "
<< quic::QuicErrorCodeToString(client.session()->error())
<< std::endl;
return 1;
}
size_t response_code = client.latest_response_code();
if (response_code >= 200 && response_code < 300) {
cout << "Request succeeded (" << response_code << ")." << endl;
std::cerr << "Request succeeded (" << response_code << ")." << std::endl;
} else if (response_code >= 300 && response_code < 400) {
if (GetQuicFlag(FLAGS_redirect_is_success)) {
cout << "Request succeeded (redirect " << response_code << ")." << endl;
std::cerr << "Request succeeded (redirect " << response_code << ")."
<< std::endl;
} else {
cout << "Request failed (redirect " << response_code << ")." << endl;
std::cerr << "Request failed (redirect " << response_code << ")."
<< std::endl;
return 1;
}
} else {
cerr << "Request failed (" << response_code << ")." << endl;
std::cerr << "Request failed (" << response_code << ")." << std::endl;
return 1;
}
// Change the ephemeral port if there are more requests to do.
if (i + 1 < num_requests) {
if (!client.ChangeEphemeralPort()) {
cout << "Failed to change ephemeral port." << endl;
std::cerr << "Failed to change ephemeral port." << std::endl;
return 1;
}
}
......
......@@ -12,48 +12,31 @@
// Usage: quic_packet_printer server|client <hex dump of packet>
//
// Example input:
// quic_packet_printer server 0c6b810308320f24c004a939a38a2e3fd6ca589917f200400
// 201b80b0100501c0700060003023d0000001c00556e656e637279707465642073747265616d2
// 064617461207365656e
// quic_packet_printer server 0c6b810308320f24c004a939a38a2e3fd6ca589917f200400201b80b0100501c0700060003023d0000001c00556e656e637279707465642073747265616d2064617461207365656e
//
// Example output:
// OnPacket
// OnUnauthenticatedPublicHeader
// OnUnauthenticatedHeader: { connection_id: 13845207862000976235,
// connection_id_length:8, packet_number_length:1, multipath_flag: 0,
// reset_flag: 0, version_flag: 0, path_id: , packet_number: 4}
// OnUnauthenticatedHeader: { connection_id: 13845207862000976235, connection_id_length:8, packet_number_length:1, multipath_flag: 0, reset_flag: 0, version_flag: 0, path_id: , packet_number: 4 }
// OnDecryptedPacket
// OnPacketHeader
// OnAckFrame: largest_observed: 1 ack_delay_time: 3000
// missing_packets: [ ] is_truncated: 0 received_packets: [ 1 at 466016 ]
// OnAckFrame: largest_observed: 1 ack_delay_time: 3000 missing_packets: [ ] is_truncated: 0 received_packets: [ 1 at 466016 ]
// OnStopWaitingFrame
// OnConnectionCloseFrame: error_code { 61 } error_details { Unencrypted stream
// data seen }
// OnConnectionCloseFrame: error_code { 61 } error_details { Unencrypted stream data seen }
// clang-format on
#include <iostream>
#include <string>
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "net/third_party/quic/core/quic_framer.h"
#include "net/third_party/quic/core/quic_utils.h"
#include "net/third_party/quic/platform/api/quic_flags.h"
#include "net/third_party/quic/platform/api/quic_text_utils.h"
// If set, specify the QUIC version to use.
quic::QuicString FLAGS_quic_version = "";
namespace {
quic::QuicString ArgToString(base::CommandLine::StringType arg) {
#if defined(OS_WIN)
return base::UTF16ToASCII(arg);
#else
return arg;
#endif
}
} // namespace
DEFINE_QUIC_COMMAND_LINE_FLAG(std::string,
quic_version,
"",
"If set, specify the QUIC version to use.");
namespace quic {
......@@ -224,40 +207,35 @@ class QuicPacketPrinter : public QuicFramerVisitorInterface {
} // namespace quic
int main(int argc, char* argv[]) {
base::CommandLine::Init(argc, argv);
base::CommandLine* line = base::CommandLine::ForCurrentProcess();
const base::CommandLine::StringVector& args = line->GetArgs();
const char* usage = "Usage: quic_packet_printer client|server <hex>";
std::vector<quic::QuicString> args =
quic::QuicParseCommandLineFlags(usage, argc, argv);
if (args.size() != 3) {
std::cerr << "Missing argument " << argc << ". (Usage: " << argv[0]
<< " client|server <hex>\n";
if (args.size() < 2) {
quic::QuicPrintCommandLineFlagHelp(usage);
return 1;
}
if (line->HasSwitch("quic_version")) {
FLAGS_quic_version = line->GetSwitchValueASCII("quic_version");
}
quic::QuicString perspective_string = ArgToString(args[0]);
quic::QuicString perspective_string = args[0];
quic::Perspective perspective;
if (perspective_string == "client") {
perspective = quic::Perspective::IS_CLIENT;
} else if (perspective_string == "server") {
perspective = quic::Perspective::IS_SERVER;
} else {
std::cerr << "Invalid perspective. " << perspective_string
<< " Usage: " << args[0] << " client|server <hex>\n";
std::cerr << "Invalid perspective" << std::endl;
quic::QuicPrintCommandLineFlagHelp(usage);
return 1;
}
quic::QuicString hex = quic::QuicTextUtils::HexDecode(argv[2]);
quic::QuicString hex = quic::QuicTextUtils::HexDecode(args[1]);
quic::ParsedQuicVersionVector versions = quic::AllSupportedVersions();
// Fake a time since we're not actually generating acks.
quic::QuicTime start(quic::QuicTime::Zero());
quic::QuicFramer framer(versions, start, perspective);
if (!FLAGS_quic_version.empty()) {
if (!GetQuicFlag(FLAGS_quic_version).empty()) {
for (quic::ParsedQuicVersion version : versions) {
if (quic::QuicVersionToString(version.transport_version) ==
FLAGS_quic_version) {
GetQuicFlag(FLAGS_quic_version)) {
framer.set_version(version);
}
}
......
......@@ -7,28 +7,27 @@
#include <iostream>
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "net/third_party/quic/core/crypto/crypto_handshake.h"
#include "net/third_party/quic/core/crypto/crypto_utils.h"
#include "net/third_party/quic/platform/api/quic_flags.h"
#include "net/third_party/quic/platform/api/quic_text_utils.h"
using base::CommandLine;
using quic::HandshakeFailureReason;
using quic::CryptoUtils;
using quic::HandshakeFailureReason;
using quic::MAX_FAILURE_REASON;
int main(int argc, char* argv[]) {
CommandLine::Init(argc, argv);
CommandLine* line = CommandLine::ForCurrentProcess();
const CommandLine::StringVector& args = line->GetArgs();
const char* usage = "Usage: quic_reject_reason_decoder <packed_reason>";
std::vector<quic::QuicString> args =
quic::QuicParseCommandLineFlags(usage, argc, argv);
if (args.size() != 1) {
std::cerr << "Missing argument (Usage: " << argv[0] << " <packed_reason>\n";
std::cerr << usage << std::endl;
return 1;
}
uint32_t packed_error = 0;
if (!base::StringToUint(args[0], &packed_error)) {
if (!quic::QuicTextUtils::StringToUint32(args[0], &packed_error)) {
std::cerr << "Unable to parse: " << args[0] << "\n";
return 2;
}
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/third_party/quic/test_tools/fake_epoll_server.h"
#include "net/tools/epoll_server/fake_epoll_server.h"
namespace quic {
namespace test {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_THIRD_PARTY_QUIC_TEST_TOOLS_FAKE_EPOLL_SERVER_H_
#define NET_THIRD_PARTY_QUIC_TEST_TOOLS_FAKE_EPOLL_SERVER_H_
#ifndef NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
#define NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
#include <stddef.h>
#include <stdint.h>
......@@ -112,4 +112,4 @@ class FakeEpollServer : public FakeTimeEpollServer {
} // namespace test
} // namespace quic
#endif // NET_THIRD_PARTY_QUIC_TEST_TOOLS_FAKE_EPOLL_SERVER_H_
#endif // NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment