| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/quic_server.h" | 5 #include "net/tools/quic/quic_server.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <features.h> | 8 #include <features.h> |
| 9 #include <netinet/in.h> | 9 #include <netinet/in.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <sys/epoll.h> | 11 #include <sys/epoll.h> |
| 12 #include <sys/socket.h> | 12 #include <sys/socket.h> |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
| 17 #include "net/base/sockaddr_storage.h" | 17 #include "net/base/sockaddr_storage.h" |
| 18 #include "net/quic/core/crypto/crypto_handshake.h" | 18 #include "net/quic/core/crypto/crypto_handshake.h" |
| 19 #include "net/quic/core/crypto/quic_random.h" | 19 #include "net/quic/core/crypto/quic_random.h" |
| 20 #include "net/quic/core/quic_clock.h" | 20 #include "net/quic/core/quic_clock.h" |
| 21 #include "net/quic/core/quic_crypto_stream.h" | 21 #include "net/quic/core/quic_crypto_stream.h" |
| 22 #include "net/quic/core/quic_data_reader.h" | 22 #include "net/quic/core/quic_data_reader.h" |
| 23 #include "net/quic/core/quic_packets.h" | 23 #include "net/quic/core/quic_packets.h" |
| 24 #include "net/tools/quic/quic_dispatcher.h" | 24 #include "net/tools/quic/quic_dispatcher.h" |
| 25 #include "net/tools/quic/quic_epoll_alarm_factory.h" | 25 #include "net/tools/quic/quic_epoll_alarm_factory.h" |
| 26 #include "net/tools/quic/quic_epoll_clock.h" | 26 #include "net/tools/quic/quic_epoll_clock.h" |
| 27 #include "net/tools/quic/quic_epoll_connection_helper.h" | 27 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 28 #include "net/tools/quic/quic_in_memory_cache.h" | 28 #include "net/tools/quic/quic_http_response_cache.h" |
| 29 #include "net/tools/quic/quic_packet_reader.h" | 29 #include "net/tools/quic/quic_packet_reader.h" |
| 30 #include "net/tools/quic/quic_simple_crypto_server_stream_helper.h" | 30 #include "net/tools/quic/quic_simple_crypto_server_stream_helper.h" |
| 31 #include "net/tools/quic/quic_simple_dispatcher.h" | 31 #include "net/tools/quic/quic_simple_dispatcher.h" |
| 32 #include "net/tools/quic/quic_socket_utils.h" | 32 #include "net/tools/quic/quic_socket_utils.h" |
| 33 | 33 |
| 34 #ifndef SO_RXQ_OVFL | 34 #ifndef SO_RXQ_OVFL |
| 35 #define SO_RXQ_OVFL 40 | 35 #define SO_RXQ_OVFL 40 |
| 36 #endif | 36 #endif |
| 37 namespace net { | 37 namespace net { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Specifies the directory used during QuicInMemoryCache | 40 // Specifies the directory used during QuicHttpResponseCache |
| 41 // construction to seed the cache. Cache directory can be | 41 // construction to seed the cache. Cache directory can be |
| 42 // generated using `wget -p --save-headers <url>` | 42 // generated using `wget -p --save-headers <url>` |
| 43 std::string FLAGS_quic_in_memory_cache_dir = ""; | 43 std::string FLAGS_quic_response_cache_dir = ""; |
| 44 | 44 |
| 45 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; | 45 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; |
| 46 const char kSourceAddressTokenSecret[] = "secret"; | 46 const char kSourceAddressTokenSecret[] = "secret"; |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 const size_t kNumSessionsToCreatePerSocketEvent = 16; | 50 const size_t kNumSessionsToCreatePerSocketEvent = 16; |
| 51 | 51 |
| 52 QuicServer::QuicServer(std::unique_ptr<ProofSource> proof_source, | 52 QuicServer::QuicServer(std::unique_ptr<ProofSource> proof_source, |
| 53 QuicInMemoryCache* in_memory_cache) | 53 QuicHttpResponseCache* response_cache) |
| 54 : QuicServer(std::move(proof_source), | 54 : QuicServer(std::move(proof_source), |
| 55 QuicConfig(), | 55 QuicConfig(), |
| 56 QuicCryptoServerConfig::ConfigOptions(), | 56 QuicCryptoServerConfig::ConfigOptions(), |
| 57 AllSupportedVersions(), | 57 AllSupportedVersions(), |
| 58 in_memory_cache) {} | 58 response_cache) {} |
| 59 | 59 |
| 60 QuicServer::QuicServer( | 60 QuicServer::QuicServer( |
| 61 std::unique_ptr<ProofSource> proof_source, | 61 std::unique_ptr<ProofSource> proof_source, |
| 62 const QuicConfig& config, | 62 const QuicConfig& config, |
| 63 const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, | 63 const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, |
| 64 const QuicVersionVector& supported_versions, | 64 const QuicVersionVector& supported_versions, |
| 65 QuicInMemoryCache* in_memory_cache) | 65 QuicHttpResponseCache* response_cache) |
| 66 : port_(0), | 66 : port_(0), |
| 67 fd_(-1), | 67 fd_(-1), |
| 68 packets_dropped_(0), | 68 packets_dropped_(0), |
| 69 overflow_supported_(false), | 69 overflow_supported_(false), |
| 70 config_(config), | 70 config_(config), |
| 71 crypto_config_(kSourceAddressTokenSecret, | 71 crypto_config_(kSourceAddressTokenSecret, |
| 72 QuicRandom::GetInstance(), | 72 QuicRandom::GetInstance(), |
| 73 std::move(proof_source)), | 73 std::move(proof_source)), |
| 74 crypto_config_options_(crypto_config_options), | 74 crypto_config_options_(crypto_config_options), |
| 75 version_manager_(supported_versions), | 75 version_manager_(supported_versions), |
| 76 packet_reader_(new QuicPacketReader()), | 76 packet_reader_(new QuicPacketReader()), |
| 77 in_memory_cache_(in_memory_cache) { | 77 response_cache_(response_cache) { |
| 78 Initialize(); | 78 Initialize(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void QuicServer::Initialize() { | 81 void QuicServer::Initialize() { |
| 82 // If an initial flow control window has not explicitly been set, then use a | 82 // If an initial flow control window has not explicitly been set, then use a |
| 83 // sensible value for a server: 1 MB for session, 64 KB for each stream. | 83 // sensible value for a server: 1 MB for session, 64 KB for each stream. |
| 84 const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024; // 1 MB | 84 const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024; // 1 MB |
| 85 const uint32_t kInitialStreamFlowControlWindow = 64 * 1024; // 64 KB | 85 const uint32_t kInitialStreamFlowControlWindow = 64 * 1024; // 64 KB |
| 86 if (config_.GetInitialStreamFlowControlWindowToSend() == | 86 if (config_.GetInitialStreamFlowControlWindowToSend() == |
| 87 kMinimumFlowControlSendWindow) { | 87 kMinimumFlowControlSendWindow) { |
| 88 config_.SetInitialStreamFlowControlWindowToSend( | 88 config_.SetInitialStreamFlowControlWindowToSend( |
| 89 kInitialStreamFlowControlWindow); | 89 kInitialStreamFlowControlWindow); |
| 90 } | 90 } |
| 91 if (config_.GetInitialSessionFlowControlWindowToSend() == | 91 if (config_.GetInitialSessionFlowControlWindowToSend() == |
| 92 kMinimumFlowControlSendWindow) { | 92 kMinimumFlowControlSendWindow) { |
| 93 config_.SetInitialSessionFlowControlWindowToSend( | 93 config_.SetInitialSessionFlowControlWindowToSend( |
| 94 kInitialSessionFlowControlWindow); | 94 kInitialSessionFlowControlWindow); |
| 95 } | 95 } |
| 96 | 96 |
| 97 epoll_server_.set_timeout_in_us(50 * 1000); | 97 epoll_server_.set_timeout_in_us(50 * 1000); |
| 98 | 98 |
| 99 if (!FLAGS_quic_in_memory_cache_dir.empty()) { | 99 if (!FLAGS_quic_response_cache_dir.empty()) { |
| 100 in_memory_cache_->InitializeFromDirectory(FLAGS_quic_in_memory_cache_dir); | 100 response_cache_->InitializeFromDirectory(FLAGS_quic_response_cache_dir); |
| 101 } | 101 } |
| 102 | 102 |
| 103 QuicEpollClock clock(&epoll_server_); | 103 QuicEpollClock clock(&epoll_server_); |
| 104 | 104 |
| 105 std::unique_ptr<CryptoHandshakeMessage> scfg(crypto_config_.AddDefaultConfig( | 105 std::unique_ptr<CryptoHandshakeMessage> scfg(crypto_config_.AddDefaultConfig( |
| 106 QuicRandom::GetInstance(), &clock, crypto_config_options_)); | 106 QuicRandom::GetInstance(), &clock, crypto_config_options_)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 QuicServer::~QuicServer() {} | 109 QuicServer::~QuicServer() {} |
| 110 | 110 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 QuicDispatcher* QuicServer::CreateQuicDispatcher() { | 145 QuicDispatcher* QuicServer::CreateQuicDispatcher() { |
| 146 QuicEpollAlarmFactory alarm_factory(&epoll_server_); | 146 QuicEpollAlarmFactory alarm_factory(&epoll_server_); |
| 147 return new QuicSimpleDispatcher( | 147 return new QuicSimpleDispatcher( |
| 148 config_, &crypto_config_, &version_manager_, | 148 config_, &crypto_config_, &version_manager_, |
| 149 std::unique_ptr<QuicEpollConnectionHelper>(new QuicEpollConnectionHelper( | 149 std::unique_ptr<QuicEpollConnectionHelper>(new QuicEpollConnectionHelper( |
| 150 &epoll_server_, QuicAllocator::BUFFER_POOL)), | 150 &epoll_server_, QuicAllocator::BUFFER_POOL)), |
| 151 std::unique_ptr<QuicCryptoServerStream::Helper>( | 151 std::unique_ptr<QuicCryptoServerStream::Helper>( |
| 152 new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())), | 152 new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())), |
| 153 std::unique_ptr<QuicEpollAlarmFactory>( | 153 std::unique_ptr<QuicEpollAlarmFactory>( |
| 154 new QuicEpollAlarmFactory(&epoll_server_)), | 154 new QuicEpollAlarmFactory(&epoll_server_)), |
| 155 in_memory_cache_); | 155 response_cache_); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void QuicServer::WaitForEvents() { | 158 void QuicServer::WaitForEvents() { |
| 159 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 159 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void QuicServer::Shutdown() { | 162 void QuicServer::Shutdown() { |
| 163 // Before we shut down the epoll server, give all active sessions a chance to | 163 // Before we shut down the epoll server, give all active sessions a chance to |
| 164 // notify clients that they're closing. | 164 // notify clients that they're closing. |
| 165 dispatcher_->Shutdown(); | 165 dispatcher_->Shutdown(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 196 dispatcher_->OnCanWrite(); | 196 dispatcher_->OnCanWrite(); |
| 197 if (dispatcher_->HasPendingWrites()) { | 197 if (dispatcher_->HasPendingWrites()) { |
| 198 event->out_ready_mask |= EPOLLOUT; | 198 event->out_ready_mask |= EPOLLOUT; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 if (event->in_events & EPOLLERR) { | 201 if (event->in_events & EPOLLERR) { |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace net | 205 } // namespace net |
| OLD | NEW |