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_client.h" | 5 #include "net/tools/quic/quic_client.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <sys/epoll.h> | 10 #include <sys/epoll.h> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 QUIC_PEER_GOING_AWAY, ""); | 77 QUIC_PEER_GOING_AWAY, ""); |
78 } | 78 } |
79 if (fd_ > 0) { | 79 if (fd_ > 0) { |
80 epoll_server_->UnregisterFD(fd_); | 80 epoll_server_->UnregisterFD(fd_); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 bool QuicClient::Initialize() { | 84 bool QuicClient::Initialize() { |
85 DCHECK(!initialized_); | 85 DCHECK(!initialized_); |
86 | 86 |
| 87 // If an initial flow control window has not explicitly been set, then use the |
| 88 // same value that Chrome uses: 10 Mb. |
| 89 const uint32 kInitialFlowControlWindow = 10 * 1024 * 1024; // 10 Mb |
| 90 if (config_.GetInitialFlowControlWindowToSend() == |
| 91 kMinimumFlowControlSendWindow) { |
| 92 config_.SetInitialFlowControlWindowToSend(kInitialFlowControlWindow); |
| 93 } |
| 94 if (config_.GetInitialStreamFlowControlWindowToSend() == |
| 95 kMinimumFlowControlSendWindow) { |
| 96 config_.SetInitialStreamFlowControlWindowToSend(kInitialFlowControlWindow); |
| 97 } |
| 98 if (config_.GetInitialSessionFlowControlWindowToSend() == |
| 99 kMinimumFlowControlSendWindow) { |
| 100 config_.SetInitialSessionFlowControlWindowToSend(kInitialFlowControlWindow); |
| 101 } |
| 102 |
87 epoll_server_->set_timeout_in_us(50 * 1000); | 103 epoll_server_->set_timeout_in_us(50 * 1000); |
88 | 104 |
89 if (!CreateUDPSocket()) { | 105 if (!CreateUDPSocket()) { |
90 return false; | 106 return false; |
91 } | 107 } |
92 | 108 |
93 epoll_server_->RegisterFD(fd_, this, kEpollFlags); | 109 epoll_server_->RegisterFD(fd_, this, kEpollFlags); |
94 initialized_ = true; | 110 initialized_ = true; |
95 return true; | 111 return true; |
96 } | 112 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 SockaddrStorage storage; | 183 SockaddrStorage storage; |
168 if (getsockname(fd_, storage.addr, &storage.addr_len) != 0 || | 184 if (getsockname(fd_, storage.addr, &storage.addr_len) != 0 || |
169 !client_address_.FromSockAddr(storage.addr, storage.addr_len)) { | 185 !client_address_.FromSockAddr(storage.addr, storage.addr_len)) { |
170 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); | 186 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); |
171 } | 187 } |
172 | 188 |
173 return true; | 189 return true; |
174 } | 190 } |
175 | 191 |
176 bool QuicClient::Connect() { | 192 bool QuicClient::Connect() { |
177 if (!StartConnect()) { | 193 StartConnect(); |
178 return false; | |
179 } | |
180 while (EncryptionBeingEstablished()) { | 194 while (EncryptionBeingEstablished()) { |
181 WaitForEvents(); | 195 WaitForEvents(); |
182 } | 196 } |
183 return session_->connection()->connected(); | 197 return session_->connection()->connected(); |
184 } | 198 } |
185 | 199 |
186 bool QuicClient::StartConnect() { | 200 void QuicClient::StartConnect() { |
187 DCHECK(initialized_); | 201 DCHECK(initialized_); |
188 DCHECK(!connected()); | 202 DCHECK(!connected()); |
189 | 203 |
190 QuicPacketWriter* writer = CreateQuicPacketWriter(); | 204 QuicPacketWriter* writer = CreateQuicPacketWriter(); |
191 | 205 |
192 DummyPacketWriterFactory factory(writer); | 206 DummyPacketWriterFactory factory(writer); |
193 | 207 |
194 session_.reset(new QuicClientSession( | 208 session_.reset(new QuicClientSession( |
195 config_, | 209 config_, |
196 new QuicConnection(GenerateConnectionId(), | 210 new QuicConnection(GenerateConnectionId(), |
197 server_address_, | 211 server_address_, |
198 helper_.get(), | 212 helper_.get(), |
199 factory, | 213 factory, |
200 /* owns_writer= */ false, | 214 /* owns_writer= */ false, |
201 /* is_server= */ false, | 215 /* is_server= */ false, |
202 server_id_.is_https(), | 216 server_id_.is_https(), |
203 supported_versions_))); | 217 supported_versions_))); |
204 | 218 |
205 // Reset |writer_| after |session_| so that the old writer outlives the old | 219 // Reset |writer_| after |session_| so that the old writer outlives the old |
206 // session. | 220 // session. |
207 if (writer_.get() != writer) { | 221 if (writer_.get() != writer) { |
208 writer_.reset(writer); | 222 writer_.reset(writer); |
209 } | 223 } |
210 session_->InitializeSession(server_id_, &crypto_config_); | 224 session_->InitializeSession(server_id_, &crypto_config_); |
211 return session_->CryptoConnect(); | 225 session_->CryptoConnect(); |
212 } | 226 } |
213 | 227 |
214 bool QuicClient::EncryptionBeingEstablished() { | 228 bool QuicClient::EncryptionBeingEstablished() { |
215 return !session_->IsEncryptionEstablished() && | 229 return !session_->IsEncryptionEstablished() && |
216 session_->connection()->connected(); | 230 session_->connection()->connected(); |
217 } | 231 } |
218 | 232 |
219 void QuicClient::Disconnect() { | 233 void QuicClient::Disconnect() { |
220 DCHECK(initialized_); | 234 DCHECK(initialized_); |
221 | 235 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 QuicEncryptedPacket packet(buf, bytes_read, false); | 378 QuicEncryptedPacket packet(buf, bytes_read, false); |
365 | 379 |
366 IPEndPoint client_address(client_ip, client_address_.port()); | 380 IPEndPoint client_address(client_ip, client_address_.port()); |
367 session_->connection()->ProcessUdpPacket( | 381 session_->connection()->ProcessUdpPacket( |
368 client_address, server_address, packet); | 382 client_address, server_address, packet); |
369 return true; | 383 return true; |
370 } | 384 } |
371 | 385 |
372 } // namespace tools | 386 } // namespace tools |
373 } // namespace net | 387 } // namespace net |
OLD | NEW |