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 "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
| 15 #include "net/quic/crypto/crypto_handshake.h" |
| 16 #include "net/quic/crypto/quic_random.h" |
| 17 #include "net/quic/quic_clock.h" |
| 18 #include "net/quic/quic_crypto_stream.h" |
15 #include "net/quic/quic_data_reader.h" | 19 #include "net/quic/quic_data_reader.h" |
16 #include "net/quic/quic_protocol.h" | 20 #include "net/quic/quic_protocol.h" |
17 #include "net/tools/quic/quic_in_memory_cache.h" | 21 #include "net/tools/quic/quic_in_memory_cache.h" |
18 #include "net/tools/quic/quic_socket_utils.h" | 22 #include "net/tools/quic/quic_socket_utils.h" |
19 | 23 |
20 #define MMSG_MORE 0 | 24 #define MMSG_MORE 0 |
21 | 25 |
22 #ifndef SO_RXQ_OVFL | 26 #ifndef SO_RXQ_OVFL |
23 #define SO_RXQ_OVFL 40 | 27 #define SO_RXQ_OVFL 40 |
24 #endif | 28 #endif |
25 | 29 |
26 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; | 30 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; |
27 const int kNumPacketsPerReadCall = 5; // Arbitrary | 31 const int kNumPacketsPerReadCall = 5; // Arbitrary |
| 32 static const char kSourceAddressTokenSecret[] = "secret"; |
28 | 33 |
29 namespace net { | 34 namespace net { |
30 namespace tools { | 35 namespace tools { |
31 | 36 |
32 QuicServer::QuicServer() | 37 QuicServer::QuicServer() |
33 : port_(0), | 38 : port_(0), |
34 packets_dropped_(0), | 39 packets_dropped_(0), |
35 overflow_supported_(false), | 40 overflow_supported_(false), |
36 use_recvmmsg_(false) { | 41 use_recvmmsg_(false), |
| 42 crypto_config_(kSourceAddressTokenSecret) { |
37 epoll_server_.set_timeout_in_us(50 * 1000); | 43 epoll_server_.set_timeout_in_us(50 * 1000); |
38 // Initialize the in memory cache now. | 44 // Initialize the in memory cache now. |
39 QuicInMemoryCache::GetInstance(); | 45 QuicInMemoryCache::GetInstance(); |
| 46 |
| 47 // Use hardcoded crypto parameters for now. |
| 48 config_.SetDefaults(); |
| 49 CryptoHandshakeMessage extra_tags; |
| 50 config_.ToHandshakeMessage(&extra_tags); |
| 51 QuicEpollClock clock(&epoll_server_); |
| 52 |
| 53 scoped_ptr<CryptoHandshakeMessage> scfg( |
| 54 crypto_config_.AddDefaultConfig(QuicRandom::GetInstance(), &clock, |
| 55 extra_tags)); |
| 56 // If we were using the same config in many servers then we would have to |
| 57 // parse a QuicConfig from config_tags here. |
| 58 if (!config_.SetFromHandshakeMessage(*scfg)) { |
| 59 CHECK(false) << "Crypto config could not be parsed by QuicConfig."; |
| 60 } |
40 } | 61 } |
41 | 62 |
42 QuicServer::~QuicServer() { | 63 QuicServer::~QuicServer() { |
43 } | 64 } |
44 | 65 |
45 bool QuicServer::Listen(const IPEndPoint& address) { | 66 bool QuicServer::Listen(const IPEndPoint& address) { |
46 port_ = address.port(); | 67 port_ = address.port(); |
47 int address_family = address.GetSockAddrFamily(); | 68 int address_family = address.GetSockAddrFamily(); |
48 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); | 69 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); |
49 if (fd_ < 0) { | 70 if (fd_ < 0) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 !server_address.FromSockAddr(storage.addr, storage.addr_len)) { | 123 !server_address.FromSockAddr(storage.addr, storage.addr_len)) { |
103 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); | 124 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); |
104 return false; | 125 return false; |
105 } | 126 } |
106 port_ = server_address.port(); | 127 port_ = server_address.port(); |
107 LOG(INFO) << "Kernel assigned port is " << port_; | 128 LOG(INFO) << "Kernel assigned port is " << port_; |
108 } | 129 } |
109 | 130 |
110 epoll_server_.RegisterFD(fd_, this, kEpollFlags); | 131 epoll_server_.RegisterFD(fd_, this, kEpollFlags); |
111 | 132 |
112 dispatcher_.reset(new QuicDispatcher(fd_, &epoll_server_)); | 133 dispatcher_.reset(new QuicDispatcher(config_, crypto_config_, fd_, |
| 134 &epoll_server_)); |
113 | 135 |
114 return true; | 136 return true; |
115 } | 137 } |
116 | 138 |
117 void QuicServer::WaitForEvents() { | 139 void QuicServer::WaitForEvents() { |
118 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 140 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
119 } | 141 } |
120 | 142 |
121 void QuicServer::Shutdown() { | 143 void QuicServer::Shutdown() { |
122 // Before we shut down the epoll server, give all active sessions a chance to | 144 // Before we shut down the epoll server, give all active sessions a chance to |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 198 } |
177 | 199 |
178 IPEndPoint server_address(server_ip, port); | 200 IPEndPoint server_address(server_ip, port); |
179 dispatcher->ProcessPacket(server_address, client_address, guid, packet); | 201 dispatcher->ProcessPacket(server_address, client_address, guid, packet); |
180 | 202 |
181 return true; | 203 return true; |
182 } | 204 } |
183 | 205 |
184 } // namespace tools | 206 } // namespace tools |
185 } // namespace net | 207 } // namespace net |
OLD | NEW |