| 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 24 matching lines...) Expand all Loading... |
| 35 namespace net { | 35 namespace net { |
| 36 namespace tools { | 36 namespace tools { |
| 37 | 37 |
| 38 QuicServer::QuicServer() | 38 QuicServer::QuicServer() |
| 39 : port_(0), | 39 : port_(0), |
| 40 fd_(-1), | 40 fd_(-1), |
| 41 packets_dropped_(0), | 41 packets_dropped_(0), |
| 42 overflow_supported_(false), | 42 overflow_supported_(false), |
| 43 use_recvmmsg_(false), | 43 use_recvmmsg_(false), |
| 44 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), | 44 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), |
| 45 supported_versions_(QuicSupportedVersions()), | 45 supported_versions_(QuicSupportedVersions()) { |
| 46 server_initial_flow_control_receive_window_( | |
| 47 kServerInitialFlowControlWindow) { | |
| 48 // Use hardcoded crypto parameters for now. | 46 // Use hardcoded crypto parameters for now. |
| 49 config_.SetDefaults(); | 47 config_.SetDefaults(); |
| 50 Initialize(); | 48 Initialize(); |
| 51 } | 49 } |
| 52 | 50 |
| 53 QuicServer::QuicServer(const QuicConfig& config, | 51 QuicServer::QuicServer(const QuicConfig& config, |
| 54 const QuicVersionVector& supported_versions, | 52 const QuicVersionVector& supported_versions) |
| 55 uint32 server_initial_flow_control_receive_window) | |
| 56 : port_(0), | 53 : port_(0), |
| 57 fd_(-1), | 54 fd_(-1), |
| 58 packets_dropped_(0), | 55 packets_dropped_(0), |
| 59 overflow_supported_(false), | 56 overflow_supported_(false), |
| 60 use_recvmmsg_(false), | 57 use_recvmmsg_(false), |
| 61 config_(config), | 58 config_(config), |
| 62 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), | 59 crypto_config_(kSourceAddressTokenSecret, QuicRandom::GetInstance()), |
| 63 supported_versions_(supported_versions), | 60 supported_versions_(supported_versions) { |
| 64 server_initial_flow_control_receive_window_( | |
| 65 server_initial_flow_control_receive_window) { | |
| 66 Initialize(); | 61 Initialize(); |
| 67 } | 62 } |
| 68 | 63 |
| 69 void QuicServer::Initialize() { | 64 void QuicServer::Initialize() { |
| 70 #if MMSG_MORE | 65 #if MMSG_MORE |
| 71 use_recvmmsg_ = true; | 66 use_recvmmsg_ = true; |
| 72 #endif | 67 #endif |
| 73 epoll_server_.set_timeout_in_us(50 * 1000); | 68 epoll_server_.set_timeout_in_us(50 * 1000); |
| 74 // Initialize the in memory cache now. | 69 // Initialize the in memory cache now. |
| 75 QuicInMemoryCache::GetInstance(); | 70 QuicInMemoryCache::GetInstance(); |
| 76 | 71 |
| 77 QuicEpollClock clock(&epoll_server_); | 72 QuicEpollClock clock(&epoll_server_); |
| 78 | 73 |
| 79 scoped_ptr<CryptoHandshakeMessage> scfg( | 74 scoped_ptr<CryptoHandshakeMessage> scfg( |
| 80 crypto_config_.AddDefaultConfig( | 75 crypto_config_.AddDefaultConfig( |
| 81 QuicRandom::GetInstance(), &clock, | 76 QuicRandom::GetInstance(), &clock, |
| 82 QuicCryptoServerConfig::ConfigOptions())); | 77 QuicCryptoServerConfig::ConfigOptions())); |
| 78 |
| 79 // Set flow control options in the config. |
| 80 config_.SetInitialCongestionWindowToSend(kServerInitialFlowControlWindow); |
| 83 } | 81 } |
| 84 | 82 |
| 85 QuicServer::~QuicServer() { | 83 QuicServer::~QuicServer() { |
| 86 } | 84 } |
| 87 | 85 |
| 88 bool QuicServer::Listen(const IPEndPoint& address) { | 86 bool QuicServer::Listen(const IPEndPoint& address) { |
| 89 port_ = address.port(); | 87 port_ = address.port(); |
| 90 int address_family = address.GetSockAddrFamily(); | 88 int address_family = address.GetSockAddrFamily(); |
| 91 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); | 89 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); |
| 92 if (fd_ < 0) { | 90 if (fd_ < 0) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (getsockname(fd_, storage.addr, &storage.addr_len) != 0 || | 155 if (getsockname(fd_, storage.addr, &storage.addr_len) != 0 || |
| 158 !server_address.FromSockAddr(storage.addr, storage.addr_len)) { | 156 !server_address.FromSockAddr(storage.addr, storage.addr_len)) { |
| 159 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); | 157 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); |
| 160 return false; | 158 return false; |
| 161 } | 159 } |
| 162 port_ = server_address.port(); | 160 port_ = server_address.port(); |
| 163 DVLOG(1) << "Kernel assigned port is " << port_; | 161 DVLOG(1) << "Kernel assigned port is " << port_; |
| 164 } | 162 } |
| 165 | 163 |
| 166 epoll_server_.RegisterFD(fd_, this, kEpollFlags); | 164 epoll_server_.RegisterFD(fd_, this, kEpollFlags); |
| 167 dispatcher_.reset(new QuicDispatcher( | 165 dispatcher_.reset(CreateQuicDispatcher()); |
| 168 config_, | |
| 169 crypto_config_, | |
| 170 supported_versions_, | |
| 171 &epoll_server_, | |
| 172 server_initial_flow_control_receive_window_)); | |
| 173 dispatcher_->Initialize(fd_); | 166 dispatcher_->Initialize(fd_); |
| 174 | 167 |
| 175 return true; | 168 return true; |
| 176 } | 169 } |
| 177 | 170 |
| 171 QuicDispatcher* QuicServer::CreateQuicDispatcher() { |
| 172 return new QuicDispatcher( |
| 173 config_, |
| 174 crypto_config_, |
| 175 supported_versions_, |
| 176 &epoll_server_); |
| 177 } |
| 178 |
| 178 void QuicServer::WaitForEvents() { | 179 void QuicServer::WaitForEvents() { |
| 179 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 180 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void QuicServer::Shutdown() { | 183 void QuicServer::Shutdown() { |
| 183 // Before we shut down the epoll server, give all active sessions a chance to | 184 // Before we shut down the epoll server, give all active sessions a chance to |
| 184 // notify clients that they're closing. | 185 // notify clients that they're closing. |
| 185 dispatcher_->Shutdown(); | 186 dispatcher_->Shutdown(); |
| 186 | 187 |
| 187 close(fd_); | 188 close(fd_); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 QuicEncryptedPacket packet(buf, bytes_read, false); | 235 QuicEncryptedPacket packet(buf, bytes_read, false); |
| 235 | 236 |
| 236 IPEndPoint server_address(server_ip, port); | 237 IPEndPoint server_address(server_ip, port); |
| 237 dispatcher->ProcessPacket(server_address, client_address, packet); | 238 dispatcher->ProcessPacket(server_address, client_address, packet); |
| 238 | 239 |
| 239 return true; | 240 return true; |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace tools | 243 } // namespace tools |
| 243 } // namespace net | 244 } // namespace net |
| OLD | NEW |