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 @@ ...@@ -288,7 +288,7 @@
'../base/base.gyp:base', '../base/base.gyp:base',
'../net/net.gyp:net', '../net/net.gyp:net',
'../net/net.gyp:net_test_support', '../net/net.gyp:net_test_support',
'../net/net.gyp:quic_tools', '../net/net.gyp:simple_quic_tools',
'../url/url.gyp:url_lib', '../url/url.gyp:url_lib',
'../base/base.gyp:base_i18n', '../base/base.gyp:base_i18n',
'../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icui18n',
......
...@@ -1139,7 +1139,7 @@ if (is_linux) { ...@@ -1139,7 +1139,7 @@ if (is_linux) {
] ]
} }
source_set("quic_base") { source_set("epoll_quic_tools") {
sources = [ sources = [
"tools/quic/quic_client.cc", "tools/quic/quic_client.cc",
"tools/quic/quic_client.h", "tools/quic/quic_client.h",
...@@ -1170,14 +1170,29 @@ if (is_linux) { ...@@ -1170,14 +1170,29 @@ if (is_linux) {
] ]
} }
executable("quic_client") { executable("epoll_quic_client") {
sources = [ sources = [
"tools/quic/quic_client_bin.cc", "tools/quic/quic_client_bin.cc",
] ]
deps = [ deps = [
":balsa", ":balsa",
":epoll_server", ":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", ":net",
":simple_quic_tools", ":simple_quic_tools",
"//base", "//base",
...@@ -1221,25 +1236,6 @@ if (is_android || is_linux) { ...@@ -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") { source_set("simple_quic_tools") {
sources = [ sources = [
"tools/quic/quic_client_session.cc", "tools/quic/quic_client_session.cc",
...@@ -1254,6 +1250,12 @@ source_set("simple_quic_tools") { ...@@ -1254,6 +1250,12 @@ source_set("simple_quic_tools") {
"tools/quic/quic_server_session.h", "tools/quic/quic_server_session.h",
"tools/quic/quic_simple_client.cc", "tools/quic/quic_simple_client.cc",
"tools/quic/quic_simple_client.h", "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.cc",
"tools/quic/quic_spdy_client_stream.h", "tools/quic/quic_spdy_client_stream.h",
"tools/quic/quic_spdy_server_stream.cc", "tools/quic/quic_spdy_server_stream.cc",
...@@ -1271,8 +1273,7 @@ source_set("simple_quic_tools") { ...@@ -1271,8 +1273,7 @@ source_set("simple_quic_tools") {
] ]
} }
executable("simple_quic_client") { executable("quic_client") {
testonly = true
sources = [ sources = [
"tools/quic/quic_simple_client_bin.cc", "tools/quic/quic_simple_client_bin.cc",
] ]
...@@ -1284,6 +1285,18 @@ executable("simple_quic_client") { ...@@ -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) 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 Windows; dependency on boringssl is wrong.
# TODO(GYP) Also doesn't work on Mac, need to figure out why not. # 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) { ...@@ -1299,7 +1312,7 @@ if (!is_android && !is_win && !is_mac) {
":extras", ":extras",
":http_server", ":http_server",
":net", ":net",
":quic_tools", ":epoll_quic_tools",
":simple_quic_tools", ":simple_quic_tools",
":test_support", ":test_support",
"//base", "//base",
...@@ -1325,7 +1338,7 @@ if (!is_android && !is_win && !is_mac) { ...@@ -1325,7 +1338,7 @@ if (!is_android && !is_win && !is_mac) {
":balsa", ":balsa",
":epoll_server", ":epoll_server",
":flip_in_mem_edsm_server_base", ":flip_in_mem_edsm_server_base",
":quic_base", ":epoll_quic_tools",
] ]
} }
...@@ -1585,21 +1598,6 @@ if (!is_android && !is_win && !is_mac) { ...@@ -1585,21 +1598,6 @@ if (!is_android && !is_win && !is_mac) {
} }
} # !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") { executable("net_perftests") {
testonly = true testonly = true
sources = [ sources = [
......
...@@ -114,7 +114,6 @@ ...@@ -114,7 +114,6 @@
'net_derived_sources', 'net_derived_sources',
'net_extras', 'net_extras',
'net_test_support', 'net_test_support',
'quic_tools',
'simple_quic_tools', 'simple_quic_tools',
], ],
'sources': [ 'sources': [
...@@ -123,9 +122,9 @@ ...@@ -123,9 +122,9 @@
'conditions': [ 'conditions': [
['os_posix == 1 and OS != "mac" and OS != "ios" and OS != "android"', { ['os_posix == 1 and OS != "mac" and OS != "ios" and OS != "android"', {
'dependencies': [ 'dependencies': [
'epoll_quic_tools',
'epoll_server', 'epoll_server',
'flip_in_mem_edsm_server_base', 'flip_in_mem_edsm_server_base',
'quic_base',
], ],
'sources': [ 'sources': [
'<@(net_linux_test_sources)', '<@(net_linux_test_sources)',
...@@ -772,27 +771,6 @@ ...@@ -772,27 +771,6 @@
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations. # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [4267, ], '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', 'target_name': 'simple_quic_tools',
'type': 'static_library', 'type': 'static_library',
...@@ -815,6 +793,12 @@ ...@@ -815,6 +793,12 @@
'tools/quic/quic_server_session.h', 'tools/quic/quic_server_session.h',
'tools/quic/quic_simple_client.cc', 'tools/quic/quic_simple_client.cc',
'tools/quic/quic_simple_client.h', '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.cc',
'tools/quic/quic_spdy_client_stream.h', 'tools/quic/quic_spdy_client_stream.h',
'tools/quic/quic_spdy_server_stream.cc', 'tools/quic/quic_spdy_server_stream.cc',
...@@ -1087,7 +1071,7 @@ ...@@ -1087,7 +1071,7 @@
], ],
}, },
{ {
'target_name': 'simple_quic_client', 'target_name': 'quic_client',
'type': 'executable', 'type': 'executable',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base', '../base/base.gyp:base',
...@@ -1099,6 +1083,18 @@ ...@@ -1099,6 +1083,18 @@
'tools/quic/quic_simple_client_bin.cc', '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', 'target_name': 'stress_cache',
'type': 'executable', 'type': 'executable',
...@@ -1227,7 +1223,7 @@ ...@@ -1227,7 +1223,7 @@
], ],
}, },
{ {
'target_name': 'quic_base', 'target_name': 'epoll_quic_tools',
'type': 'static_library', 'type': 'static_library',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base', '../base/base.gyp:base',
...@@ -1257,33 +1253,29 @@ ...@@ -1257,33 +1253,29 @@
], ],
}, },
{ {
'target_name': 'quic_client', 'target_name': 'epoll_quic_client',
'type': 'executable', 'type': 'executable',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base', '../base/base.gyp:base',
'net', 'net',
'quic_base', 'epoll_quic_tools',
'simple_quic_tools', 'simple_quic_tools',
], ],
'sources': [ 'sources': [
'tools/quic/quic_client_bin.cc', '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', 'type': 'executable',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base', '../base/base.gyp:base',
'net', 'net',
'quic_tools', 'epoll_quic_tools',
'simple_quic_tools', 'simple_quic_tools',
], ],
'sources': [ 'sources': [
'quic/quic_server_bin.cc', 'tools/quic/quic_server_bin.cc',
], ],
}, },
] ]
......
...@@ -1522,7 +1522,6 @@ ...@@ -1522,7 +1522,6 @@
'quic/quic_sent_entropy_manager_test.cc', 'quic/quic_sent_entropy_manager_test.cc',
'quic/quic_sent_packet_manager_test.cc', 'quic/quic_sent_packet_manager_test.cc',
'quic/quic_server_id_test.cc', 'quic/quic_server_id_test.cc',
'quic/quic_server_test.cc',
'quic/quic_session_test.cc', 'quic/quic_session_test.cc',
'quic/quic_socket_address_coder_test.cc', 'quic/quic_socket_address_coder_test.cc',
'quic/quic_stream_factory_test.cc', 'quic/quic_stream_factory_test.cc',
...@@ -1744,6 +1743,7 @@ ...@@ -1744,6 +1743,7 @@
'tools/quic/quic_in_memory_cache_test.cc', 'tools/quic/quic_in_memory_cache_test.cc',
'tools/quic/quic_server_session_test.cc', 'tools/quic/quic_server_session_test.cc',
'tools/quic/quic_server_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_client_stream_test.cc',
'tools/quic/quic_spdy_server_stream_test.cc', 'tools/quic/quic_spdy_server_stream_test.cc',
'tools/quic/quic_time_wait_list_manager_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 @@ ...@@ -2,28 +2,29 @@
// 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/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 net {
namespace tools {
QuicPerConnectionPacketWriter::QuicPerConnectionPacketWriter( QuicSimplePerConnectionPacketWriter::QuicSimplePerConnectionPacketWriter(
QuicServerPacketWriter* shared_writer, QuicSimpleServerPacketWriter* shared_writer,
QuicConnection* connection) QuicConnection* connection)
: shared_writer_(shared_writer), : shared_writer_(shared_writer),
connection_(connection), connection_(connection),
weak_factory_(this){ weak_factory_(this){
} }
QuicPerConnectionPacketWriter::~QuicPerConnectionPacketWriter() { QuicSimplePerConnectionPacketWriter::~QuicSimplePerConnectionPacketWriter() {
} }
QuicPacketWriter* QuicPerConnectionPacketWriter::shared_writer() const { QuicPacketWriter* QuicSimplePerConnectionPacketWriter::shared_writer() const {
return shared_writer_; return shared_writer_;
} }
WriteResult QuicPerConnectionPacketWriter::WritePacket( WriteResult QuicSimplePerConnectionPacketWriter::WritePacket(
const char* buffer, const char* buffer,
size_t buf_len, size_t buf_len,
const IPAddressNumber& self_address, const IPAddressNumber& self_address,
...@@ -33,26 +34,27 @@ WriteResult QuicPerConnectionPacketWriter::WritePacket( ...@@ -33,26 +34,27 @@ WriteResult QuicPerConnectionPacketWriter::WritePacket(
buf_len, buf_len,
self_address, self_address,
peer_address, peer_address,
base::Bind(&QuicPerConnectionPacketWriter::OnWriteComplete, base::Bind(&QuicSimplePerConnectionPacketWriter::OnWriteComplete,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
bool QuicPerConnectionPacketWriter::IsWriteBlockedDataBuffered() const { bool QuicSimplePerConnectionPacketWriter::IsWriteBlockedDataBuffered() const {
return shared_writer_->IsWriteBlockedDataBuffered(); return shared_writer_->IsWriteBlockedDataBuffered();
} }
bool QuicPerConnectionPacketWriter::IsWriteBlocked() const { bool QuicSimplePerConnectionPacketWriter::IsWriteBlocked() const {
return shared_writer_->IsWriteBlocked(); return shared_writer_->IsWriteBlocked();
} }
void QuicPerConnectionPacketWriter::SetWritable() { void QuicSimplePerConnectionPacketWriter::SetWritable() {
shared_writer_->SetWritable(); shared_writer_->SetWritable();
} }
void QuicPerConnectionPacketWriter::OnWriteComplete(WriteResult result) { void QuicSimplePerConnectionPacketWriter::OnWriteComplete(WriteResult result) {
if (result.status == WRITE_STATUS_ERROR) { if (result.status == WRITE_STATUS_ERROR) {
connection_->OnWriteError(result.error_code); connection_->OnWriteError(result.error_code);
} }
} }
} // namespace tools
} // namespace net } // namespace net
...@@ -2,27 +2,29 @@ ...@@ -2,27 +2,29 @@
// 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_QUIC_QUIC_PER_CONNECTION_PACKET_WRITER_H_ #ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
#define NET_QUIC_QUIC_PER_CONNECTION_PACKET_WRITER_H_ #define NET_QUIC_TOOLS_QUIC_SIMPLE_PER_CONNECTION_PACKET_WRITER_H_
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "net/quic/quic_connection.h" #include "net/quic/quic_connection.h"
#include "net/quic/quic_packet_writer.h" #include "net/quic/quic_packet_writer.h"
namespace net { namespace net {
namespace tools {
class QuicServerPacketWriter; class QuicSimpleServerPacketWriter;
// A connection-specific packet writer that notifies its connection when its // A connection-specific packet writer that notifies its connection when its
// writes to the shared QuicServerPacketWriter complete. // writes to the shared QuicServerPacketWriter complete.
// This class is necessary because multiple connections can share the same // This class is necessary because multiple connections can share the same
// QuicServerPacketWriter, so it has no way to know which connection to notify. // QuicServerPacketWriter, so it has no way to know which connection to notify.
class QuicPerConnectionPacketWriter : public QuicPacketWriter { class QuicSimplePerConnectionPacketWriter : public QuicPacketWriter {
public: public:
// Does not take ownership of |shared_writer| or |connection|. // Does not take ownership of |shared_writer| or |connection|.
QuicPerConnectionPacketWriter(QuicServerPacketWriter* shared_writer, QuicSimplePerConnectionPacketWriter(
QuicConnection* connection); QuicSimpleServerPacketWriter* shared_writer,
~QuicPerConnectionPacketWriter() override; QuicConnection* connection);
~QuicSimplePerConnectionPacketWriter() override;
QuicPacketWriter* shared_writer() const; QuicPacketWriter* shared_writer() const;
QuicConnection* connection() const { return connection_; } QuicConnection* connection() const { return connection_; }
...@@ -40,14 +42,15 @@ class QuicPerConnectionPacketWriter : public QuicPacketWriter { ...@@ -40,14 +42,15 @@ class QuicPerConnectionPacketWriter : public QuicPacketWriter {
private: private:
void OnWriteComplete(WriteResult result); void OnWriteComplete(WriteResult result);
QuicServerPacketWriter* shared_writer_; // Not owned. QuicSimpleServerPacketWriter* shared_writer_; // Not owned.
QuicConnection* connection_; // 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 } // 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 @@ ...@@ -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/quic/quic_server.h" #include "net/tools/quic/quic_simple_server.h"
#include <string.h> #include <string.h>
...@@ -12,15 +12,14 @@ ...@@ -12,15 +12,14 @@
#include "net/quic/crypto/quic_random.h" #include "net/quic/crypto/quic_random.h"
#include "net/quic/quic_crypto_stream.h" #include "net/quic/quic_crypto_stream.h"
#include "net/quic/quic_data_reader.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_protocol.h"
#include "net/quic/quic_server_packet_writer.h"
#include "net/tools/quic/quic_dispatcher.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" #include "net/udp/udp_server_socket.h"
namespace net { namespace net {
namespace tools {
using tools::QuicDispatcher;
namespace { namespace {
...@@ -30,10 +29,10 @@ const char kSourceAddressTokenSecret[] = "secret"; ...@@ -30,10 +29,10 @@ const char kSourceAddressTokenSecret[] = "secret";
// the limit. // the limit.
const int kReadBufferSize = 2 * kMaxPacketSize; 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 // inside of a QuicPerConnectionPacketWriter. Instead of checking that
// the shared_writer is the expected writer, this could instead cast // the shared_writer is the expected writer, this could instead cast
// from QuicPacketWriter to QuicServerPacketWriter. // from QuicPacketWriter to QuicSimpleServerPacketWriter.
class CustomPacketWriterFactory : public QuicDispatcher::PacketWriterFactory { class CustomPacketWriterFactory : public QuicDispatcher::PacketWriterFactory {
public: public:
~CustomPacketWriterFactory() override {} ~CustomPacketWriterFactory() override {}
...@@ -48,21 +47,21 @@ class CustomPacketWriterFactory : public QuicDispatcher::PacketWriterFactory { ...@@ -48,21 +47,21 @@ class CustomPacketWriterFactory : public QuicDispatcher::PacketWriterFactory {
LOG(DFATAL) << "writer mismatch"; LOG(DFATAL) << "writer mismatch";
return nullptr; 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; shared_writer_ = shared_writer;
} }
private: private:
QuicServerPacketWriter* shared_writer_; // Not owned. QuicSimpleServerPacketWriter* shared_writer_; // Not owned.
}; };
} // namespace } // namespace
QuicServer::QuicServer(const QuicConfig& config, QuicSimpleServer::QuicSimpleServer(const QuicConfig& config,
const QuicVersionVector& supported_versions) const QuicVersionVector& supported_versions)
: helper_(base::MessageLoop::current()->message_loop_proxy().get(), : helper_(base::MessageLoop::current()->message_loop_proxy().get(),
&clock_, &clock_,
QuicRandom::GetInstance()), QuicRandom::GetInstance()),
...@@ -76,7 +75,7 @@ QuicServer::QuicServer(const QuicConfig& config, ...@@ -76,7 +75,7 @@ QuicServer::QuicServer(const QuicConfig& config,
Initialize(); Initialize();
} }
void QuicServer::Initialize() { void QuicSimpleServer::Initialize() {
#if MMSG_MORE #if MMSG_MORE
use_recvmmsg_ = true; use_recvmmsg_ = true;
#endif #endif
...@@ -102,10 +101,10 @@ void QuicServer::Initialize() { ...@@ -102,10 +101,10 @@ void QuicServer::Initialize() {
QuicCryptoServerConfig::ConfigOptions())); QuicCryptoServerConfig::ConfigOptions()));
} }
QuicServer::~QuicServer() { QuicSimpleServer::~QuicSimpleServer() {
} }
int QuicServer::Listen(const IPEndPoint& address) { int QuicSimpleServer::Listen(const IPEndPoint& address) {
scoped_ptr<UDPServerSocket> socket( scoped_ptr<UDPServerSocket> socket(
new UDPServerSocket(&net_log_, NetLog::Source())); new UDPServerSocket(&net_log_, NetLog::Source()));
...@@ -118,8 +117,8 @@ int QuicServer::Listen(const IPEndPoint& address) { ...@@ -118,8 +117,8 @@ int QuicServer::Listen(const IPEndPoint& address) {
} }
// These send and receive buffer sizes are sized for a single connection, // 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 // because the default usage of QuicSimpleServer is as a test server with
// two clients. Adjust higher for use with many clients. // one or two clients. Adjust higher for use with many clients.
rc = socket->SetReceiveBufferSize( rc = socket->SetReceiveBufferSize(
static_cast<int32>(kDefaultSocketReceiveBuffer)); static_cast<int32>(kDefaultSocketReceiveBuffer));
if (rc < 0) { if (rc < 0) {
...@@ -150,7 +149,7 @@ int QuicServer::Listen(const IPEndPoint& address) { ...@@ -150,7 +149,7 @@ int QuicServer::Listen(const IPEndPoint& address) {
supported_versions_, supported_versions_,
factory, factory,
&helper_)); &helper_));
QuicServerPacketWriter* writer = new QuicServerPacketWriter( QuicSimpleServerPacketWriter* writer = new QuicSimpleServerPacketWriter(
socket_.get(), socket_.get(),
dispatcher_.get()); dispatcher_.get());
factory->set_shared_writer(writer); factory->set_shared_writer(writer);
...@@ -161,7 +160,7 @@ int QuicServer::Listen(const IPEndPoint& address) { ...@@ -161,7 +160,7 @@ int QuicServer::Listen(const IPEndPoint& address) {
return OK; return OK;
} }
void QuicServer::Shutdown() { void QuicSimpleServer::Shutdown() {
// Before we shut down the epoll server, give all active sessions a chance to // Before we shut down the epoll server, give all active sessions a chance to
// notify clients that they're closing. // notify clients that they're closing.
dispatcher_->Shutdown(); dispatcher_->Shutdown();
...@@ -170,7 +169,7 @@ void QuicServer::Shutdown() { ...@@ -170,7 +169,7 @@ void QuicServer::Shutdown() {
socket_.reset(); socket_.reset();
} }
void QuicServer::StartReading() { void QuicSimpleServer::StartReading() {
if (read_pending_) { if (read_pending_) {
return; return;
} }
...@@ -180,7 +179,7 @@ void QuicServer::StartReading() { ...@@ -180,7 +179,7 @@ void QuicServer::StartReading() {
read_buffer_.get(), read_buffer_.get(),
read_buffer_->size(), read_buffer_->size(),
&client_address_, &client_address_,
base::Bind(&QuicServer::OnReadComplete, base::Unretained(this))); base::Bind(&QuicSimpleServer::OnReadComplete, base::Unretained(this)));
if (result == ERR_IO_PENDING) { if (result == ERR_IO_PENDING) {
synchronous_read_count_ = 0; synchronous_read_count_ = 0;
...@@ -193,7 +192,7 @@ void QuicServer::StartReading() { ...@@ -193,7 +192,7 @@ void QuicServer::StartReading() {
// recursion and 2) avoid blocking the thread for too long. // recursion and 2) avoid blocking the thread for too long.
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&QuicServer::OnReadComplete, base::Bind(&QuicSimpleServer::OnReadComplete,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
result)); result));
} else { } else {
...@@ -201,13 +200,13 @@ void QuicServer::StartReading() { ...@@ -201,13 +200,13 @@ void QuicServer::StartReading() {
} }
} }
void QuicServer::OnReadComplete(int result) { void QuicSimpleServer::OnReadComplete(int result) {
read_pending_ = false; read_pending_ = false;
if (result == 0) if (result == 0)
result = ERR_CONNECTION_CLOSED; result = ERR_CONNECTION_CLOSED;
if (result < 0) { if (result < 0) {
LOG(ERROR) << "QuicServer read failed: " << ErrorToString(result); LOG(ERROR) << "QuicSimpleServer read failed: " << ErrorToString(result);
Shutdown(); Shutdown();
return; return;
} }
...@@ -218,4 +217,5 @@ void QuicServer::OnReadComplete(int result) { ...@@ -218,4 +217,5 @@ void QuicServer::OnReadComplete(int result) {
StartReading(); StartReading();
} }
} // namespace tools
} // namespace net } // namespace net
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
// A toy server, which listens on a specified address for QUIC traffic and // A toy server, which listens on a specified address for QUIC traffic and
// handles incoming responses. // handles incoming responses.
#ifndef NET_QUIC_QUIC_SERVER_H_ #ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
#define NET_QUIC_QUIC_SERVER_H_ #define NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -20,23 +20,22 @@ ...@@ -20,23 +20,22 @@
namespace net { namespace net {
class UDPServerSocket;
namespace test {
class QuicServerPeer;
} // namespace test
namespace tools { namespace tools {
class QuicDispatcher; class QuicDispatcher;
} // namespace tools
class UDPServerSocket; namespace test {
class QuicSimpleServerPeer;
} // namespace test
class QuicServer { class QuicSimpleServer {
public: public:
QuicServer(const QuicConfig& config, QuicSimpleServer(const QuicConfig& config,
const QuicVersionVector& supported_versions); const QuicVersionVector& supported_versions);
virtual ~QuicServer(); virtual ~QuicSimpleServer();
// Start listening on the specified address. Returns an error code. // Start listening on the specified address. Returns an error code.
int Listen(const IPEndPoint& address); int Listen(const IPEndPoint& address);
...@@ -62,16 +61,16 @@ class QuicServer { ...@@ -62,16 +61,16 @@ class QuicServer {
crypto_config_.SetProofSource(source); crypto_config_.SetProofSource(source);
} }
tools::QuicDispatcher* dispatcher() { return dispatcher_.get(); } QuicDispatcher* dispatcher() { return dispatcher_.get(); }
private: private:
friend class net::test::QuicServerPeer; friend class test::QuicSimpleServerPeer;
// Initialize the internal state of the server. // Initialize the internal state of the server.
void Initialize(); void Initialize();
// Accepts data from the framer and demuxes clients to sessions. // 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. // Used by the helper_ to time alarms.
QuicClock clock_; QuicClock clock_;
...@@ -114,11 +113,12 @@ class QuicServer { ...@@ -114,11 +113,12 @@ class QuicServer {
// The log to use for the socket. // The log to use for the socket.
NetLog net_log_; 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 } // namespace net
#endif // NET_QUIC_QUIC_SERVER_H_ #endif // NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "net/base/ip_endpoint.h" #include "net/base/ip_endpoint.h"
#include "net/quic/quic_protocol.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_in_memory_cache.h"
#include "net/tools/quic/quic_simple_server.h"
// The port the quic server will listen on. // The port the quic server will listen on.
int32 FLAGS_port = 6121; int32 FLAGS_port = 6121;
...@@ -47,7 +47,7 @@ int main(int argc, char *argv[]) { ...@@ -47,7 +47,7 @@ int main(int argc, char *argv[]) {
if (line->HasSwitch("quic_in_memory_cache_dir")) { if (line->HasSwitch("quic_in_memory_cache_dir")) {
net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory(
line->GetSwitchValueNative("quic_in_memory_cache_dir")); line->GetSwitchValueASCII("quic_in_memory_cache_dir"));
} }
if (line->HasSwitch("port")) { if (line->HasSwitch("port")) {
...@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { ...@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
CHECK(net::ParseIPLiteralToNumber("::", &ip)); CHECK(net::ParseIPLiteralToNumber("::", &ip));
net::QuicConfig config; 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)); int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port));
if (rc < 0) { if (rc < 0) {
......
...@@ -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/quic/quic_server_packet_writer.h" #include "net/tools/quic/quic_simple_server_packet_writer.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/location.h" #include "base/location.h"
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
#include "net/udp/udp_server_socket.h" #include "net/udp/udp_server_socket.h"
namespace net { namespace net {
namespace tools {
QuicServerPacketWriter::QuicServerPacketWriter( QuicSimpleServerPacketWriter::QuicSimpleServerPacketWriter(
UDPServerSocket* socket, UDPServerSocket* socket,
QuicBlockedWriterInterface* blocked_writer) QuicBlockedWriterInterface* blocked_writer)
: socket_(socket), : socket_(socket),
...@@ -23,10 +24,10 @@ QuicServerPacketWriter::QuicServerPacketWriter( ...@@ -23,10 +24,10 @@ QuicServerPacketWriter::QuicServerPacketWriter(
weak_factory_(this) { weak_factory_(this) {
} }
QuicServerPacketWriter::~QuicServerPacketWriter() { QuicSimpleServerPacketWriter::~QuicSimpleServerPacketWriter() {
} }
WriteResult QuicServerPacketWriter::WritePacketWithCallback( WriteResult QuicSimpleServerPacketWriter::WritePacketWithCallback(
const char* buffer, const char* buffer,
size_t buf_len, size_t buf_len,
const IPAddressNumber& self_address, const IPAddressNumber& self_address,
...@@ -41,7 +42,7 @@ WriteResult QuicServerPacketWriter::WritePacketWithCallback( ...@@ -41,7 +42,7 @@ WriteResult QuicServerPacketWriter::WritePacketWithCallback(
return result; return result;
} }
void QuicServerPacketWriter::OnWriteComplete(int rv) { void QuicSimpleServerPacketWriter::OnWriteComplete(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING); DCHECK_NE(rv, ERR_IO_PENDING);
write_blocked_ = false; write_blocked_ = false;
WriteResult result(rv < 0 ? WRITE_STATUS_ERROR : WRITE_STATUS_OK, rv); WriteResult result(rv < 0 ? WRITE_STATUS_ERROR : WRITE_STATUS_OK, rv);
...@@ -49,20 +50,20 @@ void QuicServerPacketWriter::OnWriteComplete(int rv) { ...@@ -49,20 +50,20 @@ void QuicServerPacketWriter::OnWriteComplete(int rv) {
blocked_writer_->OnCanWrite(); blocked_writer_->OnCanWrite();
} }
bool QuicServerPacketWriter::IsWriteBlockedDataBuffered() const { bool QuicSimpleServerPacketWriter::IsWriteBlockedDataBuffered() const {
// UDPServerSocket::SendTo buffers the data until the Write is permitted. // UDPServerSocket::SendTo buffers the data until the Write is permitted.
return true; return true;
} }
bool QuicServerPacketWriter::IsWriteBlocked() const { bool QuicSimpleServerPacketWriter::IsWriteBlocked() const {
return write_blocked_; return write_blocked_;
} }
void QuicServerPacketWriter::SetWritable() { void QuicSimpleServerPacketWriter::SetWritable() {
write_blocked_ = false; write_blocked_ = false;
} }
WriteResult QuicServerPacketWriter::WritePacket( WriteResult QuicSimpleServerPacketWriter::WritePacket(
const char* buffer, const char* buffer,
size_t buf_len, size_t buf_len,
const IPAddressNumber& self_address, const IPAddressNumber& self_address,
...@@ -73,11 +74,13 @@ WriteResult QuicServerPacketWriter::WritePacket( ...@@ -73,11 +74,13 @@ WriteResult QuicServerPacketWriter::WritePacket(
DCHECK(!callback_.is_null()); DCHECK(!callback_.is_null());
int rv; int rv;
if (buf_len <= static_cast<size_t>(std::numeric_limits<int>::max())) { if (buf_len <= static_cast<size_t>(std::numeric_limits<int>::max())) {
rv = socket_->SendTo(buf.get(), rv = socket_->SendTo(
static_cast<int>(buf_len), buf.get(),
peer_address, static_cast<int>(buf_len),
base::Bind(&QuicServerPacketWriter::OnWriteComplete, peer_address,
weak_factory_.GetWeakPtr())); base::Bind(
&QuicSimpleServerPacketWriter::OnWriteComplete,
weak_factory_.GetWeakPtr()));
} else { } else {
rv = ERR_MSG_TOO_BIG; rv = ERR_MSG_TOO_BIG;
} }
...@@ -94,4 +97,5 @@ WriteResult QuicServerPacketWriter::WritePacket( ...@@ -94,4 +97,5 @@ WriteResult QuicServerPacketWriter::WritePacket(
return WriteResult(status, rv); return WriteResult(status, rv);
} }
} // namespace tools
} // namespace net } // namespace net
...@@ -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_QUIC_QUIC_SERVER_PACKET_WRITER_H_ #ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_
#define NET_QUIC_QUIC_SERVER_PACKET_WRITER_H_ #define NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_PACKET_WRITER_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -18,19 +18,21 @@ class QuicBlockedWriterInterface; ...@@ -18,19 +18,21 @@ class QuicBlockedWriterInterface;
class UDPServerSocket; class UDPServerSocket;
struct WriteResult; struct WriteResult;
namespace tools {
// Chrome specific packet writer which uses a UDPServerSocket for writing // Chrome specific packet writer which uses a UDPServerSocket for writing
// data. // data.
class QuicServerPacketWriter : public QuicPacketWriter { class QuicSimpleServerPacketWriter : public QuicPacketWriter {
public: public:
typedef base::Callback<void(WriteResult)> WriteCallback; typedef base::Callback<void(WriteResult)> WriteCallback;
QuicServerPacketWriter(UDPServerSocket* socket, QuicSimpleServerPacketWriter(UDPServerSocket* socket,
QuicBlockedWriterInterface* blocked_writer); QuicBlockedWriterInterface* blocked_writer);
~QuicServerPacketWriter() override; ~QuicSimpleServerPacketWriter() override;
// Use this method to write packets rather than WritePacket: // Use this method to write packets rather than WritePacket:
// QuicServerPacketWriter requires a callback to exist for every write, which // QuicSimpleServerPacketWriter requires a callback to exist for every
// will be called once the write completes. // write, which will be called once the write completes.
virtual WriteResult WritePacketWithCallback( virtual WriteResult WritePacketWithCallback(
const char* buffer, const char* buffer,
size_t buf_len, size_t buf_len,
...@@ -64,11 +66,12 @@ class QuicServerPacketWriter : public QuicPacketWriter { ...@@ -64,11 +66,12 @@ class QuicServerPacketWriter : public QuicPacketWriter {
// Whether a write is currently in flight. // Whether a write is currently in flight.
bool write_blocked_; 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 } // 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