| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 latest_response_code_(-1), | 82 latest_response_code_(-1), |
| 83 packet_reader_(new QuicPacketReader()) {} | 83 packet_reader_(new QuicPacketReader()) {} |
| 84 | 84 |
| 85 QuicClient::~QuicClient() { | 85 QuicClient::~QuicClient() { |
| 86 if (connected()) { | 86 if (connected()) { |
| 87 session()->connection()->CloseConnection( | 87 session()->connection()->CloseConnection( |
| 88 QUIC_PEER_GOING_AWAY, "Client being torn down", | 88 QUIC_PEER_GOING_AWAY, "Client being torn down", |
| 89 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 89 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 90 } | 90 } |
| 91 | 91 |
| 92 STLDeleteElements(&data_to_resend_on_connect_); | 92 base::STLDeleteElements(&data_to_resend_on_connect_); |
| 93 STLDeleteElements(&data_sent_before_handshake_); | 93 base::STLDeleteElements(&data_sent_before_handshake_); |
| 94 | 94 |
| 95 CleanUpAllUDPSockets(); | 95 CleanUpAllUDPSockets(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool QuicClient::Initialize() { | 98 bool QuicClient::Initialize() { |
| 99 QuicClientBase::Initialize(); | 99 QuicClientBase::Initialize(); |
| 100 | 100 |
| 101 set_num_sent_client_hellos(0); | 101 set_num_sent_client_hellos(0); |
| 102 set_num_stateless_rejects_received(0); | 102 set_num_stateless_rejects_received(0); |
| 103 set_connection_error(QUIC_NO_ERROR); | 103 set_connection_error(QUIC_NO_ERROR); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 while (EncryptionBeingEstablished()) { | 186 while (EncryptionBeingEstablished()) { |
| 187 WaitForEvents(); | 187 WaitForEvents(); |
| 188 } | 188 } |
| 189 if (FLAGS_enable_quic_stateless_reject_support && connected() && | 189 if (FLAGS_enable_quic_stateless_reject_support && connected() && |
| 190 !data_to_resend_on_connect_.empty()) { | 190 !data_to_resend_on_connect_.empty()) { |
| 191 // A connection has been established and there was previously queued data | 191 // A connection has been established and there was previously queued data |
| 192 // to resend. Resend it and empty the queue. | 192 // to resend. Resend it and empty the queue. |
| 193 for (QuicDataToResend* data : data_to_resend_on_connect_) { | 193 for (QuicDataToResend* data : data_to_resend_on_connect_) { |
| 194 data->Resend(); | 194 data->Resend(); |
| 195 } | 195 } |
| 196 STLDeleteElements(&data_to_resend_on_connect_); | 196 base::STLDeleteElements(&data_to_resend_on_connect_); |
| 197 } | 197 } |
| 198 if (session() != nullptr && | 198 if (session() != nullptr && |
| 199 session()->error() != QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { | 199 session()->error() != QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { |
| 200 // We've successfully created a session but we're not connected, and there | 200 // We've successfully created a session but we're not connected, and there |
| 201 // is no stateless reject to recover from. Give up trying. | 201 // is no stateless reject to recover from. Give up trying. |
| 202 break; | 202 break; |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 if (!connected() && | 205 if (!connected() && |
| 206 GetNumSentClientHellos() > QuicCryptoClientStream::kMaxClientHellos && | 206 GetNumSentClientHellos() > QuicCryptoClientStream::kMaxClientHellos && |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 245 } |
| 246 | 246 |
| 247 void QuicClient::Disconnect() { | 247 void QuicClient::Disconnect() { |
| 248 DCHECK(initialized_); | 248 DCHECK(initialized_); |
| 249 | 249 |
| 250 if (connected()) { | 250 if (connected()) { |
| 251 session()->connection()->CloseConnection( | 251 session()->connection()->CloseConnection( |
| 252 QUIC_PEER_GOING_AWAY, "Client disconnecting", | 252 QUIC_PEER_GOING_AWAY, "Client disconnecting", |
| 253 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 253 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 254 } | 254 } |
| 255 STLDeleteElements(&data_to_resend_on_connect_); | 255 base::STLDeleteElements(&data_to_resend_on_connect_); |
| 256 STLDeleteElements(&data_sent_before_handshake_); | 256 base::STLDeleteElements(&data_sent_before_handshake_); |
| 257 | 257 |
| 258 CleanUpAllUDPSockets(); | 258 CleanUpAllUDPSockets(); |
| 259 | 259 |
| 260 initialized_ = false; | 260 initialized_ = false; |
| 261 } | 261 } |
| 262 | 262 |
| 263 void QuicClient::CleanUpUDPSocket(int fd) { | 263 void QuicClient::CleanUpUDPSocket(int fd) { |
| 264 CleanUpUDPSocketImpl(fd); | 264 CleanUpUDPSocketImpl(fd); |
| 265 fd_address_map_.erase(fd); | 265 fd_address_map_.erase(fd); |
| 266 } | 266 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 new ClientQuicDataToResend(new_headers, body, fin, this); | 313 new ClientQuicDataToResend(new_headers, body, fin, this); |
| 314 MaybeAddQuicDataToResend(data_to_resend); | 314 MaybeAddQuicDataToResend(data_to_resend); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 void QuicClient::MaybeAddQuicDataToResend(QuicDataToResend* data_to_resend) { | 318 void QuicClient::MaybeAddQuicDataToResend(QuicDataToResend* data_to_resend) { |
| 319 DCHECK(FLAGS_enable_quic_stateless_reject_support); | 319 DCHECK(FLAGS_enable_quic_stateless_reject_support); |
| 320 if (session()->IsCryptoHandshakeConfirmed()) { | 320 if (session()->IsCryptoHandshakeConfirmed()) { |
| 321 // The handshake is confirmed. No need to continue saving requests to | 321 // The handshake is confirmed. No need to continue saving requests to |
| 322 // resend. | 322 // resend. |
| 323 STLDeleteElements(&data_sent_before_handshake_); | 323 base::STLDeleteElements(&data_sent_before_handshake_); |
| 324 delete data_to_resend; | 324 delete data_to_resend; |
| 325 return; | 325 return; |
| 326 } | 326 } |
| 327 | 327 |
| 328 // The handshake is not confirmed. Push the data onto the queue of data to | 328 // The handshake is not confirmed. Push the data onto the queue of data to |
| 329 // resend if statelessly rejected. | 329 // resend if statelessly rejected. |
| 330 data_sent_before_handshake_.push_back(data_to_resend); | 330 data_sent_before_handshake_.push_back(data_to_resend); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void QuicClient::SendRequestAndWaitForResponse(const BalsaHeaders& headers, | 333 void QuicClient::SendRequestAndWaitForResponse(const BalsaHeaders& headers, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 return fd_address_map_.back().first; | 498 return fd_address_map_.back().first; |
| 499 } | 499 } |
| 500 | 500 |
| 501 void QuicClient::ProcessPacket(const IPEndPoint& self_address, | 501 void QuicClient::ProcessPacket(const IPEndPoint& self_address, |
| 502 const IPEndPoint& peer_address, | 502 const IPEndPoint& peer_address, |
| 503 const QuicReceivedPacket& packet) { | 503 const QuicReceivedPacket& packet) { |
| 504 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet); | 504 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet); |
| 505 } | 505 } |
| 506 | 506 |
| 507 } // namespace net | 507 } // namespace net |
| OLD | NEW |