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) { ...@@ -3061,6 +3061,7 @@ if (is_linux) {
"third_party/quic/core/quic_epoll_connection_helper.h", "third_party/quic/core/quic_epoll_connection_helper.h",
"third_party/quic/core/quic_packet_reader.cc", "third_party/quic/core/quic_packet_reader.cc",
"third_party/quic/core/quic_packet_reader.h", "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_default_proof_providers.h",
"third_party/quic/platform/api/quic_system_event_loop.h", "third_party/quic/platform/api/quic_system_event_loop.h",
"third_party/quic/platform/impl/batch_writer/quic_batch_writer_base.cc", "third_party/quic/platform/impl/batch_writer/quic_batch_writer_base.cc",
...@@ -3071,6 +3072,7 @@ if (is_linux) { ...@@ -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_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.cc",
"third_party/quic/platform/impl/batch_writer/quic_sendmmsg_batch_writer.h", "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.cc",
"third_party/quic/platform/impl/quic_default_proof_providers_impl.h", "third_party/quic/platform/impl/quic_default_proof_providers_impl.h",
"third_party/quic/platform/impl/quic_epoll_clock.cc", "third_party/quic/platform/impl/quic_epoll_clock.cc",
...@@ -3343,8 +3345,6 @@ source_set("quic_test_tools") { ...@@ -3343,8 +3345,6 @@ source_set("quic_test_tools") {
sources += [ sources += [
"third_party/quic/test_tools/bad_packet_writer.cc", "third_party/quic/test_tools/bad_packet_writer.cc",
"third_party/quic/test_tools/bad_packet_writer.h", "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.cc",
"third_party/quic/test_tools/limited_mtu_test_writer.h", "third_party/quic/test_tools/limited_mtu_test_writer.h",
"third_party/quic/test_tools/packet_dropping_test_writer.cc", "third_party/quic/test_tools/packet_dropping_test_writer.cc",
...@@ -3361,6 +3361,8 @@ source_set("quic_test_tools") { ...@@ -3361,6 +3361,8 @@ source_set("quic_test_tools") {
"third_party/quic/test_tools/quic_test_server.h", "third_party/quic/test_tools/quic_test_server.h",
"third_party/quic/test_tools/server_thread.cc", "third_party/quic/test_tools/server_thread.cc",
"third_party/quic/test_tools/server_thread.h", "third_party/quic/test_tools/server_thread.h",
"tools/epoll_server/fake_epoll_server.cc",
"tools/epoll_server/fake_epoll_server.h",
] ]
deps += [ deps += [
":epoll_quic_tools", ":epoll_quic_tools",
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "net/third_party/quic/core/quic_utils.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_arraysize.h"
#include "net/third_party/quic/platform/api/quic_singleton.h"
namespace quic { namespace quic {
...@@ -142,17 +141,10 @@ class CommonCertSetsQUIC : public CommonCertSets { ...@@ -142,17 +141,10 @@ class CommonCertSetsQUIC : public CommonCertSets {
return false; return false;
} }
static CommonCertSetsQUIC* GetInstance() {
return QuicSingleton<CommonCertSetsQUIC>::get();
}
private:
CommonCertSetsQUIC() {} CommonCertSetsQUIC() {}
CommonCertSetsQUIC(const CommonCertSetsQUIC&) = delete; CommonCertSetsQUIC(const CommonCertSetsQUIC&) = delete;
CommonCertSetsQUIC& operator=(const CommonCertSetsQUIC&) = delete; CommonCertSetsQUIC& operator=(const CommonCertSetsQUIC&) = delete;
~CommonCertSetsQUIC() override {} ~CommonCertSetsQUIC() override {}
friend QuicSingletonFriend<CommonCertSetsQUIC>;
}; };
} // anonymous namespace } // anonymous namespace
...@@ -161,7 +153,8 @@ CommonCertSets::~CommonCertSets() {} ...@@ -161,7 +153,8 @@ CommonCertSets::~CommonCertSets() {}
// static // static
const CommonCertSets* CommonCertSets::GetInstanceQUIC() { const CommonCertSets* CommonCertSets::GetInstanceQUIC() {
return CommonCertSetsQUIC::GetInstance(); static CommonCertSetsQUIC* certs = new CommonCertSetsQUIC();
return certs;
} }
} // namespace quic } // namespace quic
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "net/third_party/quic/platform/api/quic_bug_tracker.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" #include "third_party/boringssl/src/include/openssl/rand.h"
namespace quic { namespace quic {
...@@ -15,25 +14,16 @@ namespace { ...@@ -15,25 +14,16 @@ namespace {
class DefaultRandom : public QuicRandom { class DefaultRandom : public QuicRandom {
public: public:
static DefaultRandom* GetInstance();
// QuicRandom implementation
void RandBytes(void* data, size_t len) override;
uint64_t RandUint64() override;
private:
DefaultRandom() {} DefaultRandom() {}
DefaultRandom(const DefaultRandom&) = delete; DefaultRandom(const DefaultRandom&) = delete;
DefaultRandom& operator=(const DefaultRandom&) = delete; DefaultRandom& operator=(const DefaultRandom&) = delete;
~DefaultRandom() override {} ~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) { void DefaultRandom::RandBytes(void* data, size_t len) {
RAND_bytes(reinterpret_cast<uint8_t*>(data), len); RAND_bytes(reinterpret_cast<uint8_t*>(data), len);
} }
...@@ -48,7 +38,8 @@ uint64_t DefaultRandom::RandUint64() { ...@@ -48,7 +38,8 @@ uint64_t DefaultRandom::RandUint64() {
// static // static
QuicRandom* QuicRandom::GetInstance() { QuicRandom* QuicRandom::GetInstance() {
return DefaultRandom::GetInstance(); static DefaultRandom* random = new DefaultRandom();
return random;
} }
} // namespace quic } // namespace quic
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "net/third_party/quic/core/quic_epoll_alarm_factory.h" #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" #include "net/third_party/quic/core/quic_arena_scoped_ptr.h"
namespace quic { namespace quic {
...@@ -42,10 +44,12 @@ class QuicEpollAlarm : public QuicAlarm { ...@@ -42,10 +44,12 @@ class QuicEpollAlarm : public QuicAlarm {
private: private:
class EpollAlarmImpl : public QuicEpollAlarmBase { class EpollAlarmImpl : public QuicEpollAlarmBase {
public: public:
using int64_epoll = decltype(QuicEpollAlarmBase().OnAlarm());
explicit EpollAlarmImpl(QuicEpollAlarm* alarm) : alarm_(alarm) {} explicit EpollAlarmImpl(QuicEpollAlarm* alarm) : alarm_(alarm) {}
// Use the same integer type as the base class. // Use the same integer type as the base class.
int64_t /* allow-non-std-int */ OnAlarm() override { int64_epoll OnAlarm() override {
QuicEpollAlarmBase::OnAlarm(); QuicEpollAlarmBase::OnAlarm();
alarm_->Fire(); alarm_->Fire();
// Fire will take care of registering the alarm, if needed. // Fire will take care of registering the alarm, if needed.
...@@ -78,8 +82,8 @@ QuicArenaScopedPtr<QuicAlarm> QuicEpollAlarmFactory::CreateAlarm( ...@@ -78,8 +82,8 @@ QuicArenaScopedPtr<QuicAlarm> QuicEpollAlarmFactory::CreateAlarm(
if (arena != nullptr) { if (arena != nullptr) {
return arena->New<QuicEpollAlarm>(epoll_server_, std::move(delegate)); return arena->New<QuicEpollAlarm>(epoll_server_, std::move(delegate));
} }
return QuicArenaScopedPtr<QuicAlarm>( return QuicArenaScopedPtr<QuicAlarm>(
new QuicEpollAlarm(epoll_server_, std::move(delegate))); new QuicEpollAlarm(epoll_server_, std::move(delegate)));
} }
} // namespace quic } // namespace quic
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "net/third_party/quic/core/quic_packets.h" #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_simple_buffer_allocator.h"
#include "net/third_party/quic/core/quic_time.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/api/quic_epoll.h"
#include "net/third_party/quic/platform/impl/quic_epoll_clock.h" #include "net/third_party/quic/platform/impl/quic_epoll_clock.h"
...@@ -24,8 +25,6 @@ namespace quic { ...@@ -24,8 +25,6 @@ namespace quic {
class QuicRandom; class QuicRandom;
using QuicStreamBufferAllocator = SimpleBufferAllocator;
enum class QuicAllocator { SIMPLE, BUFFER_POOL }; enum class QuicAllocator { SIMPLE, BUFFER_POOL };
class QuicEpollConnectionHelper : public QuicConnectionHelperInterface { class QuicEpollConnectionHelper : public QuicConnectionHelperInterface {
...@@ -46,7 +45,7 @@ class QuicEpollConnectionHelper : public QuicConnectionHelperInterface { ...@@ -46,7 +45,7 @@ class QuicEpollConnectionHelper : public QuicConnectionHelperInterface {
QuicRandom* random_generator_; QuicRandom* random_generator_;
// Set up allocators. They take up minimal memory before use. // Set up allocators. They take up minimal memory before use.
// Allocator for stream send buffers. // Allocator for stream send buffers.
QuicStreamBufferAllocator stream_buffer_allocator_; QuicDefaultBufferAllocator stream_buffer_allocator_;
SimpleBufferAllocator simple_buffer_allocator_; SimpleBufferAllocator simple_buffer_allocator_;
QuicAllocator allocator_type_; QuicAllocator allocator_type_;
}; };
......
...@@ -65,7 +65,7 @@ bool QuicPacketReader::ReadAndDispatchPackets( ...@@ -65,7 +65,7 @@ bool QuicPacketReader::ReadAndDispatchPackets(
const QuicClock& clock, const QuicClock& clock,
ProcessPacketInterface* processor, ProcessPacketInterface* processor,
QuicPacketCount* packets_dropped) { QuicPacketCount* packets_dropped) {
#if MMSG_MORE #if MMSG_MORE_NO_ANDROID
return ReadAndDispatchManyPackets(fd, port, clock, processor, return ReadAndDispatchManyPackets(fd, port, clock, processor,
packets_dropped); packets_dropped);
#else #else
...@@ -80,7 +80,7 @@ bool QuicPacketReader::ReadAndDispatchManyPackets( ...@@ -80,7 +80,7 @@ bool QuicPacketReader::ReadAndDispatchManyPackets(
const QuicClock& clock, const QuicClock& clock,
ProcessPacketInterface* processor, ProcessPacketInterface* processor,
QuicPacketCount* packets_dropped) { QuicPacketCount* packets_dropped) {
#if MMSG_MORE #if MMSG_MORE_NO_ANDROID
// Re-set the length fields in case recvmmsg has changed them. // Re-set the length fields in case recvmmsg has changed them.
for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) {
DCHECK_LE(kMaxPacketSize, packets_[i].iov.iov_len); DCHECK_LE(kMaxPacketSize, packets_[i].iov.iov_len);
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
#include "net/third_party/quic/platform/api/quic_socket_address.h" #include "net/third_party/quic/platform/api/quic_socket_address.h"
#include "net/third_party/quic/platform/impl/quic_socket_utils.h" #include "net/third_party/quic/platform/impl/quic_socket_utils.h"
#define MMSG_MORE 0
namespace quic { namespace quic {
#if MMSG_MORE #if MMSG_MORE
......
...@@ -13,6 +13,8 @@ namespace quic { ...@@ -13,6 +13,8 @@ namespace quic {
// Used to generate filtered supported versions based on flags. // Used to generate filtered supported versions based on flags.
class QUIC_EXPORT_PRIVATE QuicVersionManager { class QUIC_EXPORT_PRIVATE QuicVersionManager {
public: 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); explicit QuicVersionManager(ParsedQuicVersionVector supported_versions);
virtual ~QuicVersionManager(); virtual ~QuicVersionManager();
...@@ -20,7 +22,8 @@ class QUIC_EXPORT_PRIVATE QuicVersionManager { ...@@ -20,7 +22,8 @@ class QUIC_EXPORT_PRIVATE QuicVersionManager {
// TODO(nharper): Remove this method once it is unused. // TODO(nharper): Remove this method once it is unused.
const QuicTransportVersionVector& GetSupportedTransportVersions(); 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(); const ParsedQuicVersionVector& GetSupportedVersions();
protected: protected:
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "net/third_party/quic/core/tls_client_handshaker.h" #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_arraysize.h"
#include "net/third_party/quic/platform/api/quic_bug_tracker.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/crypto.h"
#include "third_party/boringssl/src/include/openssl/ssl.h" #include "third_party/boringssl/src/include/openssl/ssl.h"
...@@ -19,7 +18,8 @@ namespace { ...@@ -19,7 +18,8 @@ namespace {
class SslIndexSingleton { class SslIndexSingleton {
public: public:
static SslIndexSingleton* GetInstance() { static SslIndexSingleton* GetInstance() {
return QuicSingleton<SslIndexSingleton>::get(); static SslIndexSingleton* instance = new SslIndexSingleton();
return instance;
} }
int HandshakerIndex() const { return ssl_ex_data_index_handshaker_; } int HandshakerIndex() const { return ssl_ex_data_index_handshaker_; }
...@@ -35,8 +35,6 @@ class SslIndexSingleton { ...@@ -35,8 +35,6 @@ class SslIndexSingleton {
SslIndexSingleton(const SslIndexSingleton&) = delete; SslIndexSingleton(const SslIndexSingleton&) = delete;
SslIndexSingleton& operator=(const SslIndexSingleton&) = delete; SslIndexSingleton& operator=(const SslIndexSingleton&) = delete;
friend QuicSingletonFriend<SslIndexSingleton>;
int ssl_ex_data_index_handshaker_; 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() { ...@@ -11,4 +11,6 @@ inline void QuicRunSystemEventLoopIteration() {
QuicRunSystemEventLoopIterationImpl(); QuicRunSystemEventLoopIterationImpl();
} }
using QuicSystemEventLoop = QuicSystemEventLoopImpl;
#endif // NET_THIRD_PARTY_QUIC_PLATFORM_API_QUIC_SYSTEM_EVENT_LOOP_H_ #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 @@ ...@@ -6,7 +6,7 @@
#include "net/third_party/quic/platform/api/quic_flags.h" #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/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 quic {
namespace test { namespace test {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_EPOLL_TEST_TOOLS_IMPL_H_ #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_ #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; using QuicFakeEpollServerImpl = quic::test::FakeEpollServer;
......
...@@ -31,8 +31,11 @@ QuicSocketAddressImpl::QuicSocketAddressImpl( ...@@ -31,8 +31,11 @@ QuicSocketAddressImpl::QuicSocketAddressImpl(
} }
QuicSocketAddressImpl::QuicSocketAddressImpl(const struct sockaddr& saddr) { QuicSocketAddressImpl::QuicSocketAddressImpl(const struct sockaddr& saddr) {
QUIC_BUG << "QuicSocketAddressImpl(const struct sockaddr& saddr) is not " if (saddr.sa_family == AF_INET) {
"implemented."; 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, bool operator==(const QuicSocketAddressImpl& lhs,
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include "net/third_party/quic/core/quic_bandwidth.h" #include "net/third_party/quic/core/quic_bandwidth.h"
#include "net/third_party/quic/core/quic_types.h" #include "net/third_party/quic/core/quic_types.h"
#define MMSG_MORE 0
#define MMSG_MORE_NO_ANDROID 0
namespace quic { namespace quic {
class QuicIpAddress; class QuicIpAddress;
class QuicSocketAddress; class QuicSocketAddress;
......
...@@ -5,10 +5,22 @@ ...@@ -5,10 +5,22 @@
#ifndef NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_SYSTEM_EVENT_LOOP_IMPL_H_ #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_ #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/run_loop.h"
#include "base/task/task_scheduler/task_scheduler.h"
inline void QuicRunSystemEventLoopIterationImpl() { inline void QuicRunSystemEventLoopIterationImpl() {
base::RunLoop().RunUntilIdle(); 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_ #endif // NET_THIRD_PARTY_QUIC_PLATFORM_IMPL_QUIC_SYSTEM_EVENT_LOOP_IMPL_H_
...@@ -80,7 +80,8 @@ TEST_F(QuartcEndpointTest, ClientCreatesSessionAsynchronously) { ...@@ -80,7 +80,8 @@ TEST_F(QuartcEndpointTest, ClientCreatesSessionAsynchronously) {
// Tests that the server can negotiate for an older QUIC version if the client // Tests that the server can negotiate for an older QUIC version if the client
// attempts to connect using a newer version. // 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 // 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 // matter, but they must be enabled so that the version manager doesn't filter
// them out. // them out.
...@@ -124,7 +125,8 @@ TEST_F(QuartcEndpointTest, DISABLED_ServerNegotiatesForOldVersion) { ...@@ -124,7 +125,8 @@ TEST_F(QuartcEndpointTest, DISABLED_ServerNegotiatesForOldVersion) {
// Tests that the server can accept connections from clients that use older // Tests that the server can accept connections from clients that use older
// QUIC versions. // 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 // 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 // matter, but they must be enabled so that the version manager doesn't filter
// them out. // them out.
......
...@@ -8,100 +8,143 @@ ...@@ -8,100 +8,143 @@
// //
// Some usage examples: // 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: // Standard request/response:
// quic_client http://www.google.com --host=${IP} // quic_client www.google.com
// quic_client http://www.google.com --quiet --host=${IP} // quic_client www.google.com --quiet
// quic_client https://www.google.com --port=443 --host=${IP} // quic_client www.google.com --port=443
// //
// Use a specific version: // 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: // 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: // Append additional headers to the request:
// quic_client http://www.google.com --host=${IP} // quic_client www.google.com --headers="Header-A: 1234; Header-B: 5678"
// --headers="Header-A: 1234; Header-B: 5678"
// //
// Connect to a host different to the URL being requested: // 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` // 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 // Send repeated requests and change ephemeral port between requests
// quic_client www.google.com --num_requests=10 // quic_client www.google.com --num_requests=10
// //
// Try to connect to a host which does not speak QUIC: // Try to connect to a host which does not speak QUIC:
// Get IP address of the www.example.com // quic_client www.example.com
// IP=`dig www.example.com +short | head -1`
// quic_client http://www.example.com --host=${IP} #include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <iostream> #include <iostream>
#include <memory>
#include <vector> #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_packets.h"
#include "net/third_party/quic/core/quic_server_id.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_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_ptr_util.h"
#include "net/third_party/quic/platform/api/quic_socket_address.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_str_cat.h"
#include "net/third_party/quic/platform/api/quic_string.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_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/platform/api/quic_text_utils.h"
#include "net/third_party/quic/tools/quic_client.h" #include "net/third_party/quic/tools/quic_client.h"
#include "net/third_party/quic/tools/quic_url.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::QuicString;
using quic::QuicStringPiece; using quic::QuicStringPiece;
using quic::QuicTextUtils; using quic::QuicTextUtils;
using quic::QuicUrl; using quic::QuicUrl;
using spdy::SpdyHeaderBlock;
using std::cerr; class FakeProofVerifier : public quic::ProofVerifier {
using std::cout; public:
using std::endl; ~FakeProofVerifier() override {}
using std::string; 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( DEFINE_QUIC_COMMAND_LINE_FLAG(
string, std::string,
host, 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(int32_t, port, 0, "The port to connect to.");
DEFINE_QUIC_COMMAND_LINE_FLAG(string, DEFINE_QUIC_COMMAND_LINE_FLAG(std::string,
body, body,
"", "",
"If set, send a POST with this body."); "If set, send a POST with this body.");
DEFINE_QUIC_COMMAND_LINE_FLAG( DEFINE_QUIC_COMMAND_LINE_FLAG(
string, std::string,
body_hex, body_hex,
"", "",
"If set, contents are converted from hex to ascii, before sending as body " "If set, contents are converted from hex to ascii, before "
"of a POST. e.g. --body_hex=\"68656c6c6f\""); "sending as body of a POST. e.g. --body_hex=\"68656c6c6f\"");
DEFINE_QUIC_COMMAND_LINE_FLAG( DEFINE_QUIC_COMMAND_LINE_FLAG(
string, std::string,
headers, 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, DEFINE_QUIC_COMMAND_LINE_FLAG(bool,
quiet, quiet,
...@@ -112,23 +155,23 @@ DEFINE_QUIC_COMMAND_LINE_FLAG( ...@@ -112,23 +155,23 @@ DEFINE_QUIC_COMMAND_LINE_FLAG(
int32_t, int32_t,
quic_version, quic_version,
-1, -1,
"QUIC version to speak, e.g. 21. If not set, then all available versions " "QUIC version to speak, e.g. 21. If not set, then all available "
"are offered in the handshake."); "versions are offered in the handshake.");
DEFINE_QUIC_COMMAND_LINE_FLAG( DEFINE_QUIC_COMMAND_LINE_FLAG(
bool, bool,
version_mismatch_ok, version_mismatch_ok,
false, false,
"If true, a version mismatch in the handshake is not considered a failure. " "If true, a version mismatch in the handshake is not considered a "
"Useful for probing a server to determine if it speaks any version of " "failure. Useful for probing a server to determine if it speaks "
"QUIC."); "any version of QUIC.");
DEFINE_QUIC_COMMAND_LINE_FLAG( DEFINE_QUIC_COMMAND_LINE_FLAG(
bool, bool,
redirect_is_success, redirect_is_success,
true, true,
"If true, an HTTP response code of 3xx is considered to be a successful " "If true, an HTTP response code of 3xx is considered to be a "
"response, otherwise a failure."); "successful response, otherwise a failure.");
DEFINE_QUIC_COMMAND_LINE_FLAG(int32_t, DEFINE_QUIC_COMMAND_LINE_FLAG(int32_t,
initial_mtu, initial_mtu,
...@@ -141,84 +184,31 @@ DEFINE_QUIC_COMMAND_LINE_FLAG( ...@@ -141,84 +184,31 @@ DEFINE_QUIC_COMMAND_LINE_FLAG(
1, 1,
"How many sequential requests to make on a single connection."); "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( DEFINE_QUIC_COMMAND_LINE_FLAG(
bool, bool,
drop_response_body, drop_response_body,
false, false,
"If true, drop response body immediately after it is received."); "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[]) { int main(int argc, char* argv[]) {
base::TaskScheduler::CreateAndStartWithDefaultParams("quic_client"); QuicSystemEventLoop event_loop("quic_client");
const char* usage = const char* usage = "Usage: quic_client [options] <url>";
"Usage: epoll_quic_client [options] <url>\n"
"\n" // All non-flag arguments should be interpreted as URLs to fetch.
"<url> with scheme must be provided (e.g. http://www.google.com)\n";
std::vector<QuicString> urls = std::vector<QuicString> urls =
quic::QuicParseCommandLineFlags(usage, argc, argv); quic::QuicParseCommandLineFlags(usage, argc, argv);
if (urls.empty()) { if (urls.size() != 1) {
quic::QuicPrintCommandLineFlagHelp(usage); quic::QuicPrintCommandLineFlagHelp(usage);
exit(0); 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"); QuicUrl url(urls[0], "https");
string host = GetQuicFlag(FLAGS_host); std::string host = GetQuicFlag(FLAGS_host);
if (host.empty()) { if (host.empty()) {
host = url.host(); host = url.host();
} }
...@@ -226,20 +216,14 @@ int main(int argc, char* argv[]) { ...@@ -226,20 +216,14 @@ int main(int argc, char* argv[]) {
if (port == 0) { if (port == 0) {
port = url.port(); 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);
return 1;
}
ip_addr =
quic::QuicIpAddress(quic::QuicIpAddressImpl(addresses[0].address()));
}
string host_port = quic::QuicStrCat(ip_addr.ToString(), ":", port); // Determine IP address to connect to from supplied hostname.
VLOG(1) << "Resolved " << host << " to " << host_port << endl; QuicSocketAddress addr = LookupAddress(host, quic::QuicStrCat(port));
if (!addr.IsInitialized()) {
return 1;
}
std::cerr << "Resolved " << url.ToString() << " to " << addr.ToString()
<< std::endl;
// Build the client, and try to connect. // Build the client, and try to connect.
quic::QuicEpollServer epoll_server; quic::QuicEpollServer epoll_server;
...@@ -251,42 +235,41 @@ int main(int argc, char* argv[]) { ...@@ -251,42 +235,41 @@ int main(int argc, char* argv[]) {
quic::PROTOCOL_QUIC_CRYPTO, static_cast<quic::QuicTransportVersion>( quic::PROTOCOL_QUIC_CRYPTO, static_cast<quic::QuicTransportVersion>(
GetQuicFlag(FLAGS_quic_version)))); GetQuicFlag(FLAGS_quic_version))));
} }
const int32_t num_requests = GetQuicFlag(FLAGS_num_requests); const int32_t num_requests(GetQuicFlag(FLAGS_num_requests));
// For secure QUIC we need to verify the cert chain. std::unique_ptr<quic::ProofVerifier> proof_verifier;
std::unique_ptr<ProofVerifier> proof_verifier;
if (GetQuicFlag(FLAGS_disable_certificate_verification)) { if (GetQuicFlag(FLAGS_disable_certificate_verification)) {
proof_verifier = quic::QuicMakeUnique<FakeProofVerifier>(); proof_verifier = quic::QuicMakeUnique<FakeProofVerifier>();
} else { } else {
proof_verifier = quic::CreateDefaultProofVerifier(); proof_verifier = quic::CreateDefaultProofVerifier();
} }
quic::QuicClient client(quic::QuicSocketAddress(ip_addr, port), server_id, quic::QuicClient client(addr, server_id, versions, &epoll_server,
versions, &epoll_server, std::move(proof_verifier)); std::move(proof_verifier));
client.set_initial_max_packet_length(GetQuicFlag(FLAGS_initial_mtu) != 0 int32_t initial_mtu = GetQuicFlag(FLAGS_initial_mtu);
? GetQuicFlag(FLAGS_initial_mtu) client.set_initial_max_packet_length(
: quic::kDefaultMaxPacketSize); initial_mtu != 0 ? initial_mtu : quic::kDefaultMaxPacketSize);
client.set_drop_response_body(GetQuicFlag(FLAGS_drop_response_body)); client.set_drop_response_body(GetQuicFlag(FLAGS_drop_response_body));
if (!client.Initialize()) { if (!client.Initialize()) {
cerr << "Failed to initialize client." << endl; std::cerr << "Failed to initialize client." << std::endl;
return 1; return 1;
} }
if (!client.Connect()) { if (!client.Connect()) {
quic::QuicErrorCode error = client.session()->error(); quic::QuicErrorCode error = client.session()->error();
if (error == quic::QUIC_INVALID_VERSION) { 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) << "this client: " << ParsedQuicVersionVectorToString(versions)
<< endl; << std::endl;
// 0: No error. // 0: No error.
// 20: Failed to connect due to QUIC_INVALID_VERSION. // 20: Failed to connect due to QUIC_INVALID_VERSION.
return GetQuicFlag(FLAGS_version_mismatch_ok) ? 0 : 20; return GetQuicFlag(FLAGS_version_mismatch_ok) ? 0 : 20;
} }
cerr << "Failed to connect to " << host_port std::cerr << "Failed to connect to " << addr.ToString()
<< ". Error: " << quic::QuicErrorCodeToString(error) << endl; << ". Error: " << quic::QuicErrorCodeToString(error) << std::endl;
return 1; return 1;
} }
cout << "Connected to " << host_port << endl; std::cerr << "Connected to " << addr.ToString() << std::endl;
// Construct the string body from flags, if provided. // 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()) { if (!GetQuicFlag(FLAGS_body_hex).empty()) {
DCHECK(GetQuicFlag(FLAGS_body).empty()) DCHECK(GetQuicFlag(FLAGS_body).empty())
<< "Only set one of --body and --body_hex."; << "Only set one of --body and --body_hex.";
...@@ -322,62 +305,67 @@ int main(int argc, char* argv[]) { ...@@ -322,62 +305,67 @@ int main(int argc, char* argv[]) {
// Print request and response details. // Print request and response details.
if (!GetQuicFlag(FLAGS_quiet)) { if (!GetQuicFlag(FLAGS_quiet)) {
cout << "Request:" << endl; std::cout << "Request:" << std::endl;
cout << "headers:" << header_block.DebugString(); std::cout << "headers:" << header_block.DebugString();
if (!GetQuicFlag(FLAGS_body_hex).empty()) { if (!GetQuicFlag(FLAGS_body_hex).empty()) {
// Print the user provided hex, rather than binary body. // Print the user provided hex, rather than binary body.
cout << "body:\n" std::cout << "body:\n"
<< QuicTextUtils::HexDump( << QuicTextUtils::HexDump(
QuicTextUtils::HexDecode(GetQuicFlag(FLAGS_body_hex))) QuicTextUtils::HexDecode(GetQuicFlag(FLAGS_body_hex)))
<< endl; << std::endl;
} else { } else {
cout << "body: " << body << endl; std::cout << "body: " << body << std::endl;
} }
cout << endl; std::cout << std::endl;
if (!client.preliminary_response_headers().empty()) { if (!client.preliminary_response_headers().empty()) {
cout << "Preliminary response headers: " std::cout << "Preliminary response headers: "
<< client.preliminary_response_headers() << endl; << client.preliminary_response_headers() << std::endl;
cout << endl; std::cout << std::endl;
} }
cout << "Response:" << endl; std::cout << "Response:" << std::endl;
cout << "headers: " << client.latest_response_headers() << endl; std::cout << "headers: " << client.latest_response_headers() << std::endl;
string response_body = client.latest_response_body(); std::string response_body = client.latest_response_body();
if (!GetQuicFlag(FLAGS_body_hex).empty()) { if (!GetQuicFlag(FLAGS_body_hex).empty()) {
// Assume response is binary data. // Assume response is binary data.
cout << "body:\n" << QuicTextUtils::HexDump(response_body) << endl; std::cout << "body:\n"
<< QuicTextUtils::HexDump(response_body) << std::endl;
} else { } 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()) { if (!client.connected()) {
cerr << "Request caused connection failure. Error: " std::cerr << "Request caused connection failure. Error: "
<< quic::QuicErrorCodeToString(client.session()->error()) << endl; << quic::QuicErrorCodeToString(client.session()->error())
<< std::endl;
return 1; return 1;
} }
size_t response_code = client.latest_response_code(); size_t response_code = client.latest_response_code();
if (response_code >= 200 && response_code < 300) { 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) { } else if (response_code >= 300 && response_code < 400) {
if (GetQuicFlag(FLAGS_redirect_is_success)) { if (GetQuicFlag(FLAGS_redirect_is_success)) {
cout << "Request succeeded (redirect " << response_code << ")." << endl; std::cerr << "Request succeeded (redirect " << response_code << ")."
<< std::endl;
} else { } else {
cout << "Request failed (redirect " << response_code << ")." << endl; std::cerr << "Request failed (redirect " << response_code << ")."
<< std::endl;
return 1; return 1;
} }
} else { } else {
cerr << "Request failed (" << response_code << ")." << endl; std::cerr << "Request failed (" << response_code << ")." << std::endl;
return 1; return 1;
} }
// Change the ephemeral port if there are more requests to do. // Change the ephemeral port if there are more requests to do.
if (i + 1 < num_requests) { if (i + 1 < num_requests) {
if (!client.ChangeEphemeralPort()) { if (!client.ChangeEphemeralPort()) {
cout << "Failed to change ephemeral port." << endl; std::cerr << "Failed to change ephemeral port." << std::endl;
return 1; return 1;
} }
} }
......
...@@ -12,48 +12,31 @@ ...@@ -12,48 +12,31 @@
// Usage: quic_packet_printer server|client <hex dump of packet> // Usage: quic_packet_printer server|client <hex dump of packet>
// //
// Example input: // Example input:
// quic_packet_printer server 0c6b810308320f24c004a939a38a2e3fd6ca589917f200400 // quic_packet_printer server 0c6b810308320f24c004a939a38a2e3fd6ca589917f200400201b80b0100501c0700060003023d0000001c00556e656e637279707465642073747265616d2064617461207365656e
// 201b80b0100501c0700060003023d0000001c00556e656e637279707465642073747265616d2
// 064617461207365656e
// //
// Example output: // Example output:
// OnPacket // OnPacket
// OnUnauthenticatedPublicHeader // OnUnauthenticatedPublicHeader
// OnUnauthenticatedHeader: { connection_id: 13845207862000976235, // 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 }
// connection_id_length:8, packet_number_length:1, multipath_flag: 0,
// reset_flag: 0, version_flag: 0, path_id: , packet_number: 4}
// OnDecryptedPacket // OnDecryptedPacket
// OnPacketHeader // OnPacketHeader
// OnAckFrame: largest_observed: 1 ack_delay_time: 3000 // OnAckFrame: largest_observed: 1 ack_delay_time: 3000 missing_packets: [ ] is_truncated: 0 received_packets: [ 1 at 466016 ]
// missing_packets: [ ] is_truncated: 0 received_packets: [ 1 at 466016 ]
// OnStopWaitingFrame // OnStopWaitingFrame
// OnConnectionCloseFrame: error_code { 61 } error_details { Unencrypted stream // OnConnectionCloseFrame: error_code { 61 } error_details { Unencrypted stream data seen }
// data seen }
// clang-format on // clang-format on
#include <iostream> #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_framer.h"
#include "net/third_party/quic/core/quic_utils.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" #include "net/third_party/quic/platform/api/quic_text_utils.h"
// If set, specify the QUIC version to use. DEFINE_QUIC_COMMAND_LINE_FLAG(std::string,
quic::QuicString FLAGS_quic_version = ""; quic_version,
"",
namespace { "If set, specify the QUIC version to use.");
quic::QuicString ArgToString(base::CommandLine::StringType arg) {
#if defined(OS_WIN)
return base::UTF16ToASCII(arg);
#else
return arg;
#endif
}
} // namespace
namespace quic { namespace quic {
...@@ -224,40 +207,35 @@ class QuicPacketPrinter : public QuicFramerVisitorInterface { ...@@ -224,40 +207,35 @@ class QuicPacketPrinter : public QuicFramerVisitorInterface {
} // namespace quic } // namespace quic
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
base::CommandLine::Init(argc, argv); const char* usage = "Usage: quic_packet_printer client|server <hex>";
base::CommandLine* line = base::CommandLine::ForCurrentProcess(); std::vector<quic::QuicString> args =
const base::CommandLine::StringVector& args = line->GetArgs(); quic::QuicParseCommandLineFlags(usage, argc, argv);
if (args.size() != 3) { if (args.size() < 2) {
std::cerr << "Missing argument " << argc << ". (Usage: " << argv[0] quic::QuicPrintCommandLineFlagHelp(usage);
<< " client|server <hex>\n";
return 1; return 1;
} }
if (line->HasSwitch("quic_version")) { quic::QuicString perspective_string = args[0];
FLAGS_quic_version = line->GetSwitchValueASCII("quic_version");
}
quic::QuicString perspective_string = ArgToString(args[0]);
quic::Perspective perspective; quic::Perspective perspective;
if (perspective_string == "client") { if (perspective_string == "client") {
perspective = quic::Perspective::IS_CLIENT; perspective = quic::Perspective::IS_CLIENT;
} else if (perspective_string == "server") { } else if (perspective_string == "server") {
perspective = quic::Perspective::IS_SERVER; perspective = quic::Perspective::IS_SERVER;
} else { } else {
std::cerr << "Invalid perspective. " << perspective_string std::cerr << "Invalid perspective" << std::endl;
<< " Usage: " << args[0] << " client|server <hex>\n"; quic::QuicPrintCommandLineFlagHelp(usage);
return 1; return 1;
} }
quic::QuicString hex = quic::QuicTextUtils::HexDecode(argv[2]); quic::QuicString hex = quic::QuicTextUtils::HexDecode(args[1]);
quic::ParsedQuicVersionVector versions = quic::AllSupportedVersions(); quic::ParsedQuicVersionVector versions = quic::AllSupportedVersions();
// Fake a time since we're not actually generating acks. // Fake a time since we're not actually generating acks.
quic::QuicTime start(quic::QuicTime::Zero()); quic::QuicTime start(quic::QuicTime::Zero());
quic::QuicFramer framer(versions, start, perspective); quic::QuicFramer framer(versions, start, perspective);
if (!FLAGS_quic_version.empty()) { if (!GetQuicFlag(FLAGS_quic_version).empty()) {
for (quic::ParsedQuicVersion version : versions) { for (quic::ParsedQuicVersion version : versions) {
if (quic::QuicVersionToString(version.transport_version) == if (quic::QuicVersionToString(version.transport_version) ==
FLAGS_quic_version) { GetQuicFlag(FLAGS_quic_version)) {
framer.set_version(version); framer.set_version(version);
} }
} }
......
...@@ -7,28 +7,27 @@ ...@@ -7,28 +7,27 @@
#include <iostream> #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_handshake.h"
#include "net/third_party/quic/core/crypto/crypto_utils.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::CryptoUtils;
using quic::HandshakeFailureReason;
using quic::MAX_FAILURE_REASON; using quic::MAX_FAILURE_REASON;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
CommandLine::Init(argc, argv); const char* usage = "Usage: quic_reject_reason_decoder <packed_reason>";
CommandLine* line = CommandLine::ForCurrentProcess(); std::vector<quic::QuicString> args =
const CommandLine::StringVector& args = line->GetArgs(); quic::QuicParseCommandLineFlags(usage, argc, argv);
if (args.size() != 1) { if (args.size() != 1) {
std::cerr << "Missing argument (Usage: " << argv[0] << " <packed_reason>\n"; std::cerr << usage << std::endl;
return 1; return 1;
} }
uint32_t packed_error = 0; 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"; std::cerr << "Unable to parse: " << args[0] << "\n";
return 2; return 2;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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 quic {
namespace test { namespace test {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef NET_THIRD_PARTY_QUIC_TEST_TOOLS_FAKE_EPOLL_SERVER_H_ #ifndef NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
#define NET_THIRD_PARTY_QUIC_TEST_TOOLS_FAKE_EPOLL_SERVER_H_ #define NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -112,4 +112,4 @@ class FakeEpollServer : public FakeTimeEpollServer { ...@@ -112,4 +112,4 @@ class FakeEpollServer : public FakeTimeEpollServer {
} // namespace test } // namespace test
} // namespace quic } // 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