Commit 216445cb authored by rch's avatar rch Committed by Commit bot

Move remaining QUIC server files from net/quic/ to net/tools/quic/.

Add targets for epoll and chromium versions of the QUIC
client and server.

Review URL: https://codereview.chromium.org/1036023002

Cr-Commit-Position: refs/heads/master@{#322507}
parent 0c256c58
......@@ -288,7 +288,7 @@
'../base/base.gyp:base',
'../net/net.gyp:net',
'../net/net.gyp:net_test_support',
'../net/net.gyp:quic_tools',
'../net/net.gyp:simple_quic_tools',
'../url/url.gyp:url_lib',
'../base/base.gyp:base_i18n',
'../third_party/icu/icu.gyp:icui18n',
......
......@@ -1139,7 +1139,7 @@ if (is_linux) {
]
}
source_set("quic_base") {
source_set("epoll_quic_tools") {
sources = [
"tools/quic/quic_client.cc",
"tools/quic/quic_client.h",
......@@ -1170,14 +1170,29 @@ if (is_linux) {
]
}
executable("quic_client") {
executable("epoll_quic_client") {
sources = [
"tools/quic/quic_client_bin.cc",
]
deps = [
":balsa",
":epoll_server",
":quic_base",
":epoll_quic_tools",
":net",
":simple_quic_tools",
"//base",
"//third_party/boringssl",
]
}
executable("epoll_quic_server") {
sources = [
"tools/quic/quic_server_bin.cc",
]
deps = [
":balsa",
":epoll_server",
":epoll_quic_tools",
":net",
":simple_quic_tools",
"//base",
......@@ -1221,25 +1236,6 @@ if (is_android || is_linux) {
}
}
# This source_set is defined even if no build targets need it,
# such as when all dependees are not buildable for the chosen OS.
source_set("quic_tools") {
sources = [
"quic/quic_per_connection_packet_writer.cc",
"quic/quic_per_connection_packet_writer.h",
"quic/quic_server.cc",
"quic/quic_server.h",
"quic/quic_server_packet_writer.cc",
"quic/quic_server_packet_writer.h",
]
deps = [
":net",
":simple_quic_tools",
"//base",
"//base/third_party/dynamic_annotations",
"//url",
]
}
source_set("simple_quic_tools") {
sources = [
"tools/quic/quic_client_session.cc",
......@@ -1254,6 +1250,12 @@ source_set("simple_quic_tools") {
"tools/quic/quic_server_session.h",
"tools/quic/quic_simple_client.cc",
"tools/quic/quic_simple_client.h",
"tools/quic/quic_simple_per_connection_packet_writer.cc",
"tools/quic/quic_simple_per_connection_packet_writer.h",
"tools/quic/quic_simple_server.cc",
"tools/quic/quic_simple_server.h",
"tools/quic/quic_simple_server_packet_writer.cc",
"tools/quic/quic_simple_server_packet_writer.h",
"tools/quic/quic_spdy_client_stream.cc",
"tools/quic/quic_spdy_client_stream.h",
"tools/quic/quic_spdy_server_stream.cc",
......@@ -1271,8 +1273,7 @@ source_set("simple_quic_tools") {
]
}
executable("simple_quic_client") {
testonly = true
executable("quic_client") {
sources = [
"tools/quic/quic_simple_client_bin.cc",
]
......@@ -1284,6 +1285,18 @@ executable("simple_quic_client") {
]
}
executable("quic_server") {
sources = [
"tools/quic/quic_simple_server_bin.cc",
]
deps = [
":net",
":simple_quic_tools",
"//base",
"//third_party/boringssl",
]
}
# TODO(GYP) make this compile on Android, we need some native test deps done.
# TODO(GYP) Also doesn't work on Windows; dependency on boringssl is wrong.
# TODO(GYP) Also doesn't work on Mac, need to figure out why not.
......@@ -1299,7 +1312,7 @@ if (!is_android && !is_win && !is_mac) {
":extras",
":http_server",
":net",
":quic_tools",
":epoll_quic_tools",
":simple_quic_tools",
":test_support",
"//base",
......@@ -1325,7 +1338,7 @@ if (!is_android && !is_win && !is_mac) {
":balsa",
":epoll_server",
":flip_in_mem_edsm_server_base",
":quic_base",
":epoll_quic_tools",
]
}
......@@ -1585,21 +1598,6 @@ if (!is_android && !is_win && !is_mac) {
}
} # !is_android && !is_win && !is_mac
if (!is_android && !is_win) {
executable("quic_server") {
sources = [
"quic/quic_server_bin.cc",
]
deps = [
":net",
":quic_tools",
":simple_quic_tools",
"//base",
"//third_party/boringssl",
]
}
}
executable("net_perftests") {
testonly = true
sources = [
......
......@@ -114,7 +114,6 @@
'net_derived_sources',
'net_extras',
'net_test_support',
'quic_tools',
'simple_quic_tools',
],
'sources': [
......@@ -123,9 +122,9 @@
'conditions': [
['os_posix == 1 and OS != "mac" and OS != "ios" and OS != "android"', {
'dependencies': [
'epoll_quic_tools',
'epoll_server',
'flip_in_mem_edsm_server_base',
'quic_base',
],
'sources': [
'<@(net_linux_test_sources)',
......@@ -772,27 +771,6 @@
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [4267, ],
},
{
# This is a temporary target which will be merged into 'net' once the
# dependency on balsa is eliminated and the classes are actually used.
'target_name': 'quic_tools',
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../url/url.gyp:url_lib',
'net',
'simple_quic_tools',
],
'sources': [
'quic/quic_per_connection_packet_writer.cc',
'quic/quic_per_connection_packet_writer.h',
'quic/quic_server.cc',
'quic/quic_server.h',
'quic/quic_server_packet_writer.cc',
'quic/quic_server_packet_writer.h',
],
},
{
'target_name': 'simple_quic_tools',
'type': 'static_library',
......@@ -815,6 +793,12 @@
'tools/quic/quic_server_session.h',
'tools/quic/quic_simple_client.cc',
'tools/quic/quic_simple_client.h',
'tools/quic/quic_simple_per_connection_packet_writer.cc',
'tools/quic/quic_simple_per_connection_packet_writer.h',
'tools/quic/quic_simple_server.cc',
'tools/quic/quic_simple_server.h',
'tools/quic/quic_simple_server_packet_writer.cc',
'tools/quic/quic_simple_server_packet_writer.h',
'tools/quic/quic_spdy_client_stream.cc',
'tools/quic/quic_spdy_client_stream.h',
'tools/quic/quic_spdy_server_stream.cc',
......@@ -1087,7 +1071,7 @@
],
},
{
'target_name': 'simple_quic_client',
'target_name': 'quic_client',
'type': 'executable',
'dependencies': [
'../base/base.gyp:base',
......@@ -1099,6 +1083,18 @@
'tools/quic/quic_simple_client_bin.cc',
],
},
{
'target_name': 'quic_server',
'type': 'executable',
'dependencies': [
'../base/base.gyp:base',
'net',
'simple_quic_tools',
],
'sources': [
'tools/quic/quic_simple_server_bin.cc',
],
},
{
'target_name': 'stress_cache',
'type': 'executable',
......@@ -1227,7 +1223,7 @@
],
},
{
'target_name': 'quic_base',
'target_name': 'epoll_quic_tools',
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
......@@ -1257,33 +1253,29 @@
],
},
{
'target_name': 'quic_client',
'target_name': 'epoll_quic_client',
'type': 'executable',
'dependencies': [
'../base/base.gyp:base',
'net',
'quic_base',
'epoll_quic_tools',
'simple_quic_tools',
],
'sources': [
'tools/quic/quic_client_bin.cc',
],
},
]
}],
['os_posix == 1 and OS != "ios" and OS != "android"', {
'targets': [
{
'target_name': 'quic_server',
'target_name': 'epoll_quic_server',
'type': 'executable',
'dependencies': [
'../base/base.gyp:base',
'net',
'quic_tools',
'epoll_quic_tools',
'simple_quic_tools',
],
'sources': [
'quic/quic_server_bin.cc',
'tools/quic/quic_server_bin.cc',
],
},
]
......
......@@ -1522,7 +1522,6 @@
'quic/quic_sent_entropy_manager_test.cc',
'quic/quic_sent_packet_manager_test.cc',
'quic/quic_server_id_test.cc',
'quic/quic_server_test.cc',
'quic/quic_session_test.cc',
'quic/quic_socket_address_coder_test.cc',
'quic/quic_stream_factory_test.cc',
......@@ -1744,6 +1743,7 @@
'tools/quic/quic_in_memory_cache_test.cc',
'tools/quic/quic_server_session_test.cc',
'tools/quic/quic_server_test.cc',
'tools/quic/quic_simple_server_test.cc',
'tools/quic/quic_spdy_client_stream_test.cc',
'tools/quic/quic_spdy_server_stream_test.cc',
'tools/quic/quic_time_wait_list_manager_test.cc',
......
// Copyright 2014 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.
//
// A binary wrapper for QuicServer. It listens forever on --port
// (default 6121) until it's killed or ctrl-cd to death.
#include <iostream>
#include "base/at_exit.h"
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "net/base/ip_endpoint.h"
#include "net/quic/quic_protocol.h"
#include "net/tools/quic/quic_in_memory_cache.h"
#include "net/tools/quic/quic_server.h"
// The port the quic server will listen on.
int32 FLAGS_port = 6121;
int main(int argc, char *argv[]) {
base::AtExitManager exit_manager;
base::MessageLoopForIO message_loop;
base::CommandLine::Init(argc, argv);
base::CommandLine* line = base::CommandLine::ForCurrentProcess();
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
CHECK(logging::InitLogging(settings));
if (line->HasSwitch("h") || line->HasSwitch("help")) {
const char* help_str =
"Usage: quic_server [options]\n"
"\n"
"Options:\n"
"-h, --help show this help message and exit\n"
"--port=<port> specify the port to listen on\n"
"--quic_in_memory_cache_dir directory containing response data\n"
" to load\n";
std::cout << help_str;
exit(0);
}
if (line->HasSwitch("quic_in_memory_cache_dir")) {
net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
line->GetSwitchValueASCII("quic_in_memory_cache_dir"));
}
if (line->HasSwitch("port")) {
if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) {
LOG(ERROR) << "--port must be an integer\n";
return 1;
}
}
net::IPAddressNumber ip;
CHECK(net::ParseIPLiteralToNumber("::", &ip));
net::QuicConfig config;
net::tools::QuicServer server(config, net::QuicSupportedVersions());
int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port));
if (rc < 0) {
return 1;
}
while (1) {
server.WaitForEvents();
}
}
......@@ -2,28 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/quic/quic_per_connection_packet_writer.h"
#include "net/tools/quic/quic_simple_per_connection_packet_writer.h"
#include "net/quic/quic_server_packet_writer.h"
#include "net/tools/quic/quic_simple_server_packet_writer.h"
namespace net {
namespace tools {
QuicPerConnectionPacketWriter::QuicPerConnectionPacketWriter(
QuicServerPacketWriter* shared_writer,
QuicSimplePerConnectionPacketWriter::QuicSimplePerConnectionPacketWriter(
QuicSimpleServerPacketWriter* shared_writer,
QuicConnection* connection)
: shared_writer_(shared_writer),
connection_(connection),
weak_factory_(this){
}
QuicPerConnectionPacketWriter::~QuicPerConnectionPacketWriter() {
QuicSimplePerConnectionPacketWriter::~QuicSimplePerConnectionPacketWriter() {
}
QuicPacketWriter* QuicPerConnectionPacketWriter::shared_writer() const {
QuicPacketWriter* QuicSimplePerConnectionPacketWriter::shared_writer() const {
return shared_writer_;
}
WriteResult QuicPerConnectionPacketWriter::WritePacket(
WriteResult QuicSimplePerConnectionPacketWriter::WritePacket(
const char* buffer,
size_t buf_len,
const IPAddressNumber& self_address,
......@@ -33,26 +34,27 @@ WriteResult QuicPerConnectionPacketWriter::WritePacket(
buf_len,
self_address,
peer_address,
base::Bind(&QuicPerConnectionPacketWriter::OnWriteComplete,
base::Bind(&QuicSimplePerConnectionPacketWriter::OnWriteComplete,
weak_factory_.GetWeakPtr()));
}
bool QuicPerConnectionPacketWriter::IsWriteBlockedDataBuffered() const {
bool QuicSimplePerConnectionPacketWriter::IsWriteBlockedDataBuffered() const {
return shared_writer_->IsWriteBlockedDataBuffered();
}
bool QuicPerConnectionPacketWriter::IsWriteBlocked() const {
bool QuicSimplePerConnectionPacketWriter::IsWriteBlocked() const {
return shared_writer_->IsWriteBlocked();
}
void QuicPerConnectionPacketWriter::SetWritable() {
void QuicSimplePerConnectionPacketWriter::SetWritable() {
shared_writer_->SetWritable();
}
void QuicPerConnectionPacketWriter::OnWriteComplete(WriteResult result) {
void QuicSimplePerConnectionPacketWriter::OnWriteComplete(WriteResult result) {
if (result.status == WRITE_STATUS_ERROR) {
connection_->OnWriteError(result.error_code);
}
}
} // namespace tools
} // namespace net
......@@ -2,27 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_QUIC_QUIC_PER_CONNECTION_PACKET_WRITER_H_
#define NET_QUIC_QUIC_PER_CONNECTION_PACKET_WRITER_H_
#ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
#define NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
#include "base/memory/weak_ptr.h"
#include "net/quic/quic_connection.h"
#include "net/quic/quic_packet_writer.h"
namespace net {
namespace tools {
class QuicServerPacketWriter;
class QuicSimpleServerPacketWriter;
// A connection-specific packet writer that notifies its connection when its
// writes to the shared QuicServerPacketWriter complete.
// This class is necessary because multiple connections can share the same
// QuicServerPacketWriter, so it has no way to know which connection to notify.
class QuicPerConnectionPacketWriter : public QuicPacketWriter {
class QuicSimplePerConnectionPacketWriter : public QuicPacketWriter {
public:
// Does not take ownership of |shared_writer| or |connection|.
QuicPerConnectionPacketWriter(QuicServerPacketWriter* shared_writer,
QuicConnection* connection);
~QuicPerConnectionPacketWriter() override;
QuicSimplePerConnectionPacketWriter(
QuicSimpleServerPacketWriter* shared_writer,
QuicConnection* connection);
~QuicSimplePerConnectionPacketWriter() override;
QuicPacketWriter* shared_writer() const;
QuicConnection* connection() const { return connection_; }
......@@ -40,14 +42,15 @@ class QuicPerConnectionPacketWriter : public QuicPacketWriter {
private:
void OnWriteComplete(WriteResult result);
QuicServerPacketWriter* shared_writer_; // Not owned.
QuicSimpleServerPacketWriter* shared_writer_; // Not owned.
QuicConnection* connection_; // Not owned.
base::WeakPtrFactory<QuicPerConnectionPacketWriter> weak_factory_;
base::WeakPtrFactory<QuicSimplePerConnectionPacketWriter> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(QuicPerConnectionPacketWriter);
DISALLOW_COPY_AND_ASSIGN(QuicSimplePerConnectionPacketWriter);
};
} // namespace tools
} // namespace net
#endif // NET_QUIC_QUIC_PER_CONNECTION_PACKET_WRITER_H_
#endif // NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
......@@ -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/quic/quic_server.h"
#include "net/tools/quic/quic_simple_server.h"
#include <string.h>
......@@ -12,15 +12,14 @@
#include "net/quic/crypto/quic_random.h"
#include "net/quic/quic_crypto_stream.h"
#include "net/quic/quic_data_reader.h"
#include "net/quic/quic_per_connection_packet_writer.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_server_packet_writer.h"
#include "net/tools/quic/quic_dispatcher.h"
#include "net/tools/quic/quic_simple_per_connection_packet_writer.h"
#include "net/tools/quic/quic_simple_server_packet_writer.h"
#include "net/udp/udp_server_socket.h"
namespace net {
using tools::QuicDispatcher;
namespace tools {
namespace {
......@@ -30,10 +29,10 @@ const char kSourceAddressTokenSecret[] = "secret";
// the limit.
const int kReadBufferSize = 2 * kMaxPacketSize;
// A packet writer factory which wraps a shared QuicServerPacketWriter
// A packet writer factory which wraps a shared QuicSimpleServerPacketWriter
// inside of a QuicPerConnectionPacketWriter. Instead of checking that
// the shared_writer is the expected writer, this could instead cast
// from QuicPacketWriter to QuicServerPacketWriter.
// from QuicPacketWriter to QuicSimpleServerPacketWriter.
class CustomPacketWriterFactory : public QuicDispatcher::PacketWriterFactory {
public:
~CustomPacketWriterFactory() override {}
......@@ -48,21 +47,21 @@ class CustomPacketWriterFactory : public QuicDispatcher::PacketWriterFactory {
LOG(DFATAL) << "writer mismatch";
return nullptr;
}
return new QuicPerConnectionPacketWriter(shared_writer_, connection);
return new QuicSimplePerConnectionPacketWriter(shared_writer_, connection);
}
void set_shared_writer(QuicServerPacketWriter* shared_writer) {
void set_shared_writer(QuicSimpleServerPacketWriter* shared_writer) {
shared_writer_ = shared_writer;
}
private:
QuicServerPacketWriter* shared_writer_; // Not owned.
QuicSimpleServerPacketWriter* shared_writer_; // Not owned.
};
} // namespace
QuicServer::QuicServer(const QuicConfig& config,
const QuicVersionVector& supported_versions)
QuicSimpleServer::QuicSimpleServer(const QuicConfig& config,
const QuicVersionVector& supported_versions)
: helper_(base::MessageLoop::current()->message_loop_proxy().get(),
&clock_,
QuicRandom::GetInstance()),
......@@ -76,7 +75,7 @@ QuicServer::QuicServer(const QuicConfig& config,
Initialize();
}
void QuicServer::Initialize() {
void QuicSimpleServer::Initialize() {
#if MMSG_MORE
use_recvmmsg_ = true;
#endif
......@@ -102,10 +101,10 @@ void QuicServer::Initialize() {
QuicCryptoServerConfig::ConfigOptions()));
}
QuicServer::~QuicServer() {
QuicSimpleServer::~QuicSimpleServer() {
}
int QuicServer::Listen(const IPEndPoint& address) {
int QuicSimpleServer::Listen(const IPEndPoint& address) {
scoped_ptr<UDPServerSocket> socket(
new UDPServerSocket(&net_log_, NetLog::Source()));
......@@ -118,8 +117,8 @@ int QuicServer::Listen(const IPEndPoint& address) {
}
// These send and receive buffer sizes are sized for a single connection,
// because the default usage of QuicServer is as a test server with one or
// two clients. Adjust higher for use with many clients.
// because the default usage of QuicSimpleServer is as a test server with
// one or two clients. Adjust higher for use with many clients.
rc = socket->SetReceiveBufferSize(
static_cast<int32>(kDefaultSocketReceiveBuffer));
if (rc < 0) {
......@@ -150,7 +149,7 @@ int QuicServer::Listen(const IPEndPoint& address) {
supported_versions_,
factory,
&helper_));
QuicServerPacketWriter* writer = new QuicServerPacketWriter(
QuicSimpleServerPacketWriter* writer = new QuicSimpleServerPacketWriter(
socket_.get(),
dispatcher_.get());
factory->set_shared_writer(writer);
......@@ -161,7 +160,7 @@ int QuicServer::Listen(const IPEndPoint& address) {
return OK;
}
void QuicServer::Shutdown() {
void QuicSimpleServer::Shutdown() {
// Before we shut down the epoll server, give all active sessions a chance to
// notify clients that they're closing.
dispatcher_->Shutdown();
......@@ -170,7 +169,7 @@ void QuicServer::Shutdown() {
socket_.reset();
}
void QuicServer::StartReading() {
void QuicSimpleServer::StartReading() {
if (read_pending_) {
return;
}
......@@ -180,7 +179,7 @@ void QuicServer::StartReading() {
read_buffer_.get(),
read_buffer_->size(),
&client_address_,
base::Bind(&QuicServer::OnReadComplete, base::Unretained(this)));
base::Bind(&QuicSimpleServer::OnReadComplete, base::Unretained(this)));
if (result == ERR_IO_PENDING) {
synchronous_read_count_ = 0;
......@@ -193,7 +192,7 @@ void QuicServer::StartReading() {
// recursion and 2) avoid blocking the thread for too long.
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&QuicServer::OnReadComplete,
base::Bind(&QuicSimpleServer::OnReadComplete,
weak_factory_.GetWeakPtr(),
result));
} else {
......@@ -201,13 +200,13 @@ void QuicServer::StartReading() {
}
}
void QuicServer::OnReadComplete(int result) {
void QuicSimpleServer::OnReadComplete(int result) {
read_pending_ = false;
if (result == 0)
result = ERR_CONNECTION_CLOSED;
if (result < 0) {
LOG(ERROR) << "QuicServer read failed: " << ErrorToString(result);
LOG(ERROR) << "QuicSimpleServer read failed: " << ErrorToString(result);
Shutdown();
return;
}
......@@ -218,4 +217,5 @@ void QuicServer::OnReadComplete(int result) {
StartReading();
}
} // namespace tools
} // namespace net
......@@ -5,8 +5,8 @@
// A toy server, which listens on a specified address for QUIC traffic and
// handles incoming responses.
#ifndef NET_QUIC_QUIC_SERVER_H_
#define NET_QUIC_QUIC_SERVER_H_
#ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
#define NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
......@@ -20,23 +20,22 @@
namespace net {
namespace test {
class QuicServerPeer;
} // namespace test
class UDPServerSocket;
namespace tools {
class QuicDispatcher;
} // namespace tools
class UDPServerSocket;
namespace test {
class QuicSimpleServerPeer;
} // namespace test
class QuicServer {
class QuicSimpleServer {
public:
QuicServer(const QuicConfig& config,
const QuicVersionVector& supported_versions);
QuicSimpleServer(const QuicConfig& config,
const QuicVersionVector& supported_versions);
virtual ~QuicServer();
virtual ~QuicSimpleServer();
// Start listening on the specified address. Returns an error code.
int Listen(const IPEndPoint& address);
......@@ -62,16 +61,16 @@ class QuicServer {
crypto_config_.SetProofSource(source);
}
tools::QuicDispatcher* dispatcher() { return dispatcher_.get(); }
QuicDispatcher* dispatcher() { return dispatcher_.get(); }
private:
friend class net::test::QuicServerPeer;
friend class test::QuicSimpleServerPeer;
// Initialize the internal state of the server.
void Initialize();
// Accepts data from the framer and demuxes clients to sessions.
scoped_ptr<tools::QuicDispatcher> dispatcher_;
scoped_ptr<QuicDispatcher> dispatcher_;
// Used by the helper_ to time alarms.
QuicClock clock_;
......@@ -114,11 +113,12 @@ class QuicServer {
// The log to use for the socket.
NetLog net_log_;
base::WeakPtrFactory<QuicServer> weak_factory_;
base::WeakPtrFactory<QuicSimpleServer> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(QuicServer);
DISALLOW_COPY_AND_ASSIGN(QuicSimpleServer);
};
} // namespace tools
} // namespace net
#endif // NET_QUIC_QUIC_SERVER_H_
#endif // NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
......@@ -15,8 +15,8 @@
#include "base/strings/string_number_conversions.h"
#include "net/base/ip_endpoint.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_server.h"
#include "net/tools/quic/quic_in_memory_cache.h"
#include "net/tools/quic/quic_simple_server.h"
// The port the quic server will listen on.
int32 FLAGS_port = 6121;
......@@ -47,7 +47,7 @@ int main(int argc, char *argv[]) {
if (line->HasSwitch("quic_in_memory_cache_dir")) {
net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
line->GetSwitchValueNative("quic_in_memory_cache_dir"));
line->GetSwitchValueASCII("quic_in_memory_cache_dir"));
}
if (line->HasSwitch("port")) {
......@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
CHECK(net::ParseIPLiteralToNumber("::", &ip));
net::QuicConfig config;
net::QuicServer server(config, net::QuicSupportedVersions());
net::tools::QuicSimpleServer server(config, net::QuicSupportedVersions());
int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port));
if (rc < 0) {
......
......@@ -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/quic/quic_server_packet_writer.h"
#include "net/tools/quic/quic_simple_server_packet_writer.h"
#include "base/callback_helpers.h"
#include "base/location.h"
......@@ -13,8 +13,9 @@
#include "net/udp/udp_server_socket.h"
namespace net {
namespace tools {
QuicServerPacketWriter::QuicServerPacketWriter(
QuicSimpleServerPacketWriter::QuicSimpleServerPacketWriter(
UDPServerSocket* socket,
QuicBlockedWriterInterface* blocked_writer)
: socket_(socket),
......@@ -23,10 +24,10 @@ QuicServerPacketWriter::QuicServerPacketWriter(
weak_factory_(this) {
}
QuicServerPacketWriter::~QuicServerPacketWriter() {
QuicSimpleServerPacketWriter::~QuicSimpleServerPacketWriter() {
}
WriteResult QuicServerPacketWriter::WritePacketWithCallback(
WriteResult QuicSimpleServerPacketWriter::WritePacketWithCallback(
const char* buffer,
size_t buf_len,
const IPAddressNumber& self_address,
......@@ -41,7 +42,7 @@ WriteResult QuicServerPacketWriter::WritePacketWithCallback(
return result;
}
void QuicServerPacketWriter::OnWriteComplete(int rv) {
void QuicSimpleServerPacketWriter::OnWriteComplete(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
write_blocked_ = false;
WriteResult result(rv < 0 ? WRITE_STATUS_ERROR : WRITE_STATUS_OK, rv);
......@@ -49,20 +50,20 @@ void QuicServerPacketWriter::OnWriteComplete(int rv) {
blocked_writer_->OnCanWrite();
}
bool QuicServerPacketWriter::IsWriteBlockedDataBuffered() const {
bool QuicSimpleServerPacketWriter::IsWriteBlockedDataBuffered() const {
// UDPServerSocket::SendTo buffers the data until the Write is permitted.
return true;
}
bool QuicServerPacketWriter::IsWriteBlocked() const {
bool QuicSimpleServerPacketWriter::IsWriteBlocked() const {
return write_blocked_;
}
void QuicServerPacketWriter::SetWritable() {
void QuicSimpleServerPacketWriter::SetWritable() {
write_blocked_ = false;
}
WriteResult QuicServerPacketWriter::WritePacket(
WriteResult QuicSimpleServerPacketWriter::WritePacket(
const char* buffer,
size_t buf_len,
const IPAddressNumber& self_address,
......@@ -73,11 +74,13 @@ WriteResult QuicServerPacketWriter::WritePacket(
DCHECK(!callback_.is_null());
int rv;
if (buf_len <= static_cast<size_t>(std::numeric_limits<int>::max())) {
rv = socket_->SendTo(buf.get(),
static_cast<int>(buf_len),
peer_address,
base::Bind(&QuicServerPacketWriter::OnWriteComplete,
weak_factory_.GetWeakPtr()));
rv = socket_->SendTo(
buf.get(),
static_cast<int>(buf_len),
peer_address,
base::Bind(
&QuicSimpleServerPacketWriter::OnWriteComplete,
weak_factory_.GetWeakPtr()));
} else {
rv = ERR_MSG_TOO_BIG;
}
......@@ -94,4 +97,5 @@ WriteResult QuicServerPacketWriter::WritePacket(
return WriteResult(status, rv);
}
} // namespace tools
} // namespace net
......@@ -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_QUIC_QUIC_SERVER_PACKET_WRITER_H_
#define NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_
#ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_
#define NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_
#include "base/basictypes.h"
#include "base/memory/weak_ptr.h"
......@@ -18,19 +18,21 @@ class QuicBlockedWriterInterface;
class UDPServerSocket;
struct WriteResult;
namespace tools {
// Chrome specific packet writer which uses a UDPServerSocket for writing
// data.
class QuicServerPacketWriter : public QuicPacketWriter {
class QuicSimpleServerPacketWriter : public QuicPacketWriter {
public:
typedef base::Callback<void(WriteResult)> WriteCallback;
QuicServerPacketWriter(UDPServerSocket* socket,
QuicSimpleServerPacketWriter(UDPServerSocket* socket,
QuicBlockedWriterInterface* blocked_writer);
~QuicServerPacketWriter() override;
~QuicSimpleServerPacketWriter() override;
// Use this method to write packets rather than WritePacket:
// QuicServerPacketWriter requires a callback to exist for every write, which
// will be called once the write completes.
// QuicSimpleServerPacketWriter requires a callback to exist for every
// write, which will be called once the write completes.
virtual WriteResult WritePacketWithCallback(
const char* buffer,
size_t buf_len,
......@@ -64,11 +66,12 @@ class QuicServerPacketWriter : public QuicPacketWriter {
// Whether a write is currently in flight.
bool write_blocked_;
base::WeakPtrFactory<QuicServerPacketWriter> weak_factory_;
base::WeakPtrFactory<QuicSimpleServerPacketWriter> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(QuicServerPacketWriter);
DISALLOW_COPY_AND_ASSIGN(QuicSimpleServerPacketWriter);
};
} // namespace tools
} // namespace net
#endif // NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_
#endif // NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_
// Copyright 2014 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.
#include "net/tools/quic/quic_simple_server.h"
#include "net/quic/crypto/quic_random.h"
#include "net/quic/quic_utils.h"
#include "net/quic/test_tools/mock_quic_dispatcher.h"
#include "net/quic/test_tools/quic_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
namespace net {
namespace tools {
namespace test {
// TODO(dmz) Remove "Chrome" part of name once net/tools/quic is deleted.
class QuicChromeServerDispatchPacketTest : public ::testing::Test {
public:
QuicChromeServerDispatchPacketTest()
: crypto_config_("blah", QuicRandom::GetInstance()),
dispatcher_(config_,
crypto_config_,
new tools::QuicDispatcher::DefaultPacketWriterFactory(),
new net::test::MockHelper) {
dispatcher_.InitializeWithWriter(nullptr);
}
void DispatchPacket(const QuicEncryptedPacket& packet) {
IPEndPoint client_addr, server_addr;
dispatcher_.ProcessPacket(server_addr, client_addr, packet);
}
protected:
QuicConfig config_;
QuicCryptoServerConfig crypto_config_;
net::test::MockQuicDispatcher dispatcher_;
};
TEST_F(QuicChromeServerDispatchPacketTest, DispatchPacket) {
unsigned char valid_packet[] = {
// public flags (8 byte connection_id)
0x3C,
// connection_id
0x10, 0x32, 0x54, 0x76,
0x98, 0xBA, 0xDC, 0xFE,
// packet sequence number
0xBC, 0x9A, 0x78, 0x56,
0x34, 0x12,
// private flags
0x00 };
QuicEncryptedPacket encrypted_valid_packet(QuicUtils::AsChars(valid_packet),
arraysize(valid_packet), false);
EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _)).Times(1);
DispatchPacket(encrypted_valid_packet);
}
} // namespace tools
} // namespace test
} // namespace net
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