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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(new QuicDispatcher( |
168 config_, | 166 config_, |
169 crypto_config_, | 167 crypto_config_, |
170 supported_versions_, | 168 supported_versions_, |
171 &epoll_server_, | 169 &epoll_server_)); |
172 server_initial_flow_control_receive_window_)); | |
173 dispatcher_->Initialize(fd_); | 170 dispatcher_->Initialize(fd_); |
174 | 171 |
175 return true; | 172 return true; |
176 } | 173 } |
177 | 174 |
178 void QuicServer::WaitForEvents() { | 175 void QuicServer::WaitForEvents() { |
179 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 176 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
180 } | 177 } |
181 | 178 |
182 void QuicServer::Shutdown() { | 179 void QuicServer::Shutdown() { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 QuicEncryptedPacket packet(buf, bytes_read, false); | 231 QuicEncryptedPacket packet(buf, bytes_read, false); |
235 | 232 |
236 IPEndPoint server_address(server_ip, port); | 233 IPEndPoint server_address(server_ip, port); |
237 dispatcher->ProcessPacket(server_address, client_address, packet); | 234 dispatcher->ProcessPacket(server_address, client_address, packet); |
238 | 235 |
239 return true; | 236 return true; |
240 } | 237 } |
241 | 238 |
242 } // namespace tools | 239 } // namespace tools |
243 } // namespace net | 240 } // namespace net |
OLD | NEW |