| 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> | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   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_in_memory_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     : QuicServer(std::move(proof_source), |   54     : QuicServer(std::move(proof_source), | 
|   54                  QuicConfig(), |   55                  QuicConfig(), | 
|   55                  QuicCryptoServerConfig::ConfigOptions(), |   56                  QuicCryptoServerConfig::ConfigOptions(), | 
|   56                  AllSupportedVersions()) {} |   57                  AllSupportedVersions(), | 
 |   58                  in_memory_cache) {} | 
|   57  |   59  | 
|   58 QuicServer::QuicServer( |   60 QuicServer::QuicServer( | 
|   59     std::unique_ptr<ProofSource> proof_source, |   61     std::unique_ptr<ProofSource> proof_source, | 
|   60     const QuicConfig& config, |   62     const QuicConfig& config, | 
|   61     const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, |   63     const QuicCryptoServerConfig::ConfigOptions& crypto_config_options, | 
|   62     const QuicVersionVector& supported_versions) |   64     const QuicVersionVector& supported_versions, | 
 |   65     QuicInMemoryCache* in_memory_cache) | 
|   63     : port_(0), |   66     : port_(0), | 
|   64       fd_(-1), |   67       fd_(-1), | 
|   65       packets_dropped_(0), |   68       packets_dropped_(0), | 
|   66       overflow_supported_(false), |   69       overflow_supported_(false), | 
|   67       config_(config), |   70       config_(config), | 
|   68       crypto_config_(kSourceAddressTokenSecret, |   71       crypto_config_(kSourceAddressTokenSecret, | 
|   69                      QuicRandom::GetInstance(), |   72                      QuicRandom::GetInstance(), | 
|   70                      std::move(proof_source)), |   73                      std::move(proof_source)), | 
|   71       crypto_config_options_(crypto_config_options), |   74       crypto_config_options_(crypto_config_options), | 
|   72       version_manager_(supported_versions), |   75       version_manager_(supported_versions), | 
|   73       packet_reader_(new QuicPacketReader()) { |   76       packet_reader_(new QuicPacketReader()), | 
 |   77       in_memory_cache_(in_memory_cache) { | 
|   74   Initialize(); |   78   Initialize(); | 
|   75 } |   79 } | 
|   76  |   80  | 
|   77 void QuicServer::Initialize() { |   81 void QuicServer::Initialize() { | 
|   78   // 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 | 
|   79   // 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. | 
|   80   const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024;  // 1 MB |   84   const uint32_t kInitialSessionFlowControlWindow = 1 * 1024 * 1024;  // 1 MB | 
|   81   const uint32_t kInitialStreamFlowControlWindow = 64 * 1024;         // 64 KB |   85   const uint32_t kInitialStreamFlowControlWindow = 64 * 1024;         // 64 KB | 
|   82   if (config_.GetInitialStreamFlowControlWindowToSend() == |   86   if (config_.GetInitialStreamFlowControlWindowToSend() == | 
|   83       kMinimumFlowControlSendWindow) { |   87       kMinimumFlowControlSendWindow) { | 
|   84     config_.SetInitialStreamFlowControlWindowToSend( |   88     config_.SetInitialStreamFlowControlWindowToSend( | 
|   85         kInitialStreamFlowControlWindow); |   89         kInitialStreamFlowControlWindow); | 
|   86   } |   90   } | 
|   87   if (config_.GetInitialSessionFlowControlWindowToSend() == |   91   if (config_.GetInitialSessionFlowControlWindowToSend() == | 
|   88       kMinimumFlowControlSendWindow) { |   92       kMinimumFlowControlSendWindow) { | 
|   89     config_.SetInitialSessionFlowControlWindowToSend( |   93     config_.SetInitialSessionFlowControlWindowToSend( | 
|   90         kInitialSessionFlowControlWindow); |   94         kInitialSessionFlowControlWindow); | 
|   91   } |   95   } | 
|   92  |   96  | 
|   93   epoll_server_.set_timeout_in_us(50 * 1000); |   97   epoll_server_.set_timeout_in_us(50 * 1000); | 
|   94  |   98  | 
|   95   if (!FLAGS_quic_in_memory_cache_dir.empty()) { |   99   if (!FLAGS_quic_in_memory_cache_dir.empty()) { | 
|   96     QuicInMemoryCache::GetInstance()->InitializeFromDirectory( |  100     in_memory_cache_->InitializeFromDirectory(FLAGS_quic_in_memory_cache_dir); | 
|   97         FLAGS_quic_in_memory_cache_dir); |  | 
|   98   } |  101   } | 
|   99  |  102  | 
|  100   QuicEpollClock clock(&epoll_server_); |  103   QuicEpollClock clock(&epoll_server_); | 
|  101  |  104  | 
|  102   std::unique_ptr<CryptoHandshakeMessage> scfg(crypto_config_.AddDefaultConfig( |  105   std::unique_ptr<CryptoHandshakeMessage> scfg(crypto_config_.AddDefaultConfig( | 
|  103       QuicRandom::GetInstance(), &clock, crypto_config_options_)); |  106       QuicRandom::GetInstance(), &clock, crypto_config_options_)); | 
|  104 } |  107 } | 
|  105  |  108  | 
|  106 QuicServer::~QuicServer() {} |  109 QuicServer::~QuicServer() {} | 
|  107  |  110  | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  141  |  144  | 
|  142 QuicDispatcher* QuicServer::CreateQuicDispatcher() { |  145 QuicDispatcher* QuicServer::CreateQuicDispatcher() { | 
|  143   QuicEpollAlarmFactory alarm_factory(&epoll_server_); |  146   QuicEpollAlarmFactory alarm_factory(&epoll_server_); | 
|  144   return new QuicSimpleDispatcher( |  147   return new QuicSimpleDispatcher( | 
|  145       config_, &crypto_config_, &version_manager_, |  148       config_, &crypto_config_, &version_manager_, | 
|  146       std::unique_ptr<QuicEpollConnectionHelper>(new QuicEpollConnectionHelper( |  149       std::unique_ptr<QuicEpollConnectionHelper>(new QuicEpollConnectionHelper( | 
|  147           &epoll_server_, QuicAllocator::BUFFER_POOL)), |  150           &epoll_server_, QuicAllocator::BUFFER_POOL)), | 
|  148       std::unique_ptr<QuicCryptoServerStream::Helper>( |  151       std::unique_ptr<QuicCryptoServerStream::Helper>( | 
|  149           new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())), |  152           new QuicSimpleCryptoServerStreamHelper(QuicRandom::GetInstance())), | 
|  150       std::unique_ptr<QuicEpollAlarmFactory>( |  153       std::unique_ptr<QuicEpollAlarmFactory>( | 
|  151           new QuicEpollAlarmFactory(&epoll_server_))); |  154           new QuicEpollAlarmFactory(&epoll_server_)), | 
 |  155       in_memory_cache_); | 
|  152 } |  156 } | 
|  153  |  157  | 
|  154 void QuicServer::WaitForEvents() { |  158 void QuicServer::WaitForEvents() { | 
|  155   epoll_server_.WaitForEventsAndExecuteCallbacks(); |  159   epoll_server_.WaitForEventsAndExecuteCallbacks(); | 
|  156 } |  160 } | 
|  157  |  161  | 
|  158 void QuicServer::Shutdown() { |  162 void QuicServer::Shutdown() { | 
|  159   // 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 | 
|  160   // notify clients that they're closing. |  164   // notify clients that they're closing. | 
|  161   dispatcher_->Shutdown(); |  165   dispatcher_->Shutdown(); | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
|  192     dispatcher_->OnCanWrite(); |  196     dispatcher_->OnCanWrite(); | 
|  193     if (dispatcher_->HasPendingWrites()) { |  197     if (dispatcher_->HasPendingWrites()) { | 
|  194       event->out_ready_mask |= EPOLLOUT; |  198       event->out_ready_mask |= EPOLLOUT; | 
|  195     } |  199     } | 
|  196   } |  200   } | 
|  197   if (event->in_events & EPOLLERR) { |  201   if (event->in_events & EPOLLERR) { | 
|  198   } |  202   } | 
|  199 } |  203 } | 
|  200  |  204  | 
|  201 }  // namespace net |  205 }  // namespace net | 
| OLD | NEW |