Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: net/quic/quic_client_session.cc

Issue 14083012: QUIC: retransmit packets with the correct encryption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge ToT and Reset the callback in case of errors Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_client_session_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quic/quic_client_session.h" 5 #include "net/quic/quic_client_session.h"
6 6
7 #include "base/callback_helpers.h"
7 #include "base/message_loop.h" 8 #include "base/message_loop.h"
8 #include "base/stl_util.h" 9 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
12 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
13 #include "net/quic/quic_connection_helper.h" 14 #include "net/quic/quic_connection_helper.h"
14 #include "net/quic/quic_crypto_client_stream_factory.h" 15 #include "net/quic/quic_crypto_client_stream_factory.h"
15 #include "net/quic/quic_stream_factory.h" 16 #include "net/quic/quic_stream_factory.h"
16 #include "net/udp/datagram_client_socket.h" 17 #include "net/udp/datagram_client_socket.h"
(...skipping 26 matching lines...) Expand all
43 server_hostname, config_, this, crypto_config)); 44 server_hostname, config_, this, crypto_config));
44 45
45 connection->set_debug_visitor(&logger_); 46 connection->set_debug_visitor(&logger_);
46 // TODO(rch): pass in full host port proxy pair 47 // TODO(rch): pass in full host port proxy pair
47 net_log_.BeginEvent( 48 net_log_.BeginEvent(
48 NetLog::TYPE_QUIC_SESSION, 49 NetLog::TYPE_QUIC_SESSION,
49 NetLog::StringCallback("host", &server_hostname)); 50 NetLog::StringCallback("host", &server_hostname));
50 } 51 }
51 52
52 QuicClientSession::~QuicClientSession() { 53 QuicClientSession::~QuicClientSession() {
54 callback_.Reset();
Ryan Hamilton 2013/04/26 19:52:17 I though we were going to run the callback here wi
ramant (doing other things) 2013/04/30 02:17:03 Ran the callback_ if it is not NULL with error. D
Ryan Hamilton 2013/04/30 02:56:14 I'm not sure I follow. Is the callback suposed to
ramant (doing other things) 2013/04/30 19:00:32 Changed the QuicClientSessionTest's GoAwayReceived
53 connection()->set_debug_visitor(NULL); 55 connection()->set_debug_visitor(NULL);
54 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION); 56 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION);
55 } 57 }
56 58
57 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { 59 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() {
58 if (!crypto_stream_->handshake_complete()) { 60 if (!crypto_stream_->encryption_established()) {
59 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created."; 61 DLOG(INFO) << "Encryption not active so no outgoing stream created.";
60 return NULL; 62 return NULL;
61 } 63 }
62 if (GetNumOpenStreams() >= get_max_open_streams()) { 64 if (GetNumOpenStreams() >= get_max_open_streams()) {
63 DLOG(INFO) << "Failed to create a new outgoing stream. " 65 DLOG(INFO) << "Failed to create a new outgoing stream. "
64 << "Already " << GetNumOpenStreams() << " open."; 66 << "Already " << GetNumOpenStreams() << " open.";
65 return NULL; 67 return NULL;
66 } 68 }
67 if (goaway_received()) { 69 if (goaway_received()) {
68 DLOG(INFO) << "Failed to create a new outgoing stream. " 70 DLOG(INFO) << "Failed to create a new outgoing stream. "
69 << "Already received goaway."; 71 << "Already received goaway.";
(...skipping 10 matching lines...) Expand all
80 return crypto_stream_.get(); 82 return crypto_stream_.get();
81 }; 83 };
82 84
83 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { 85 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) {
84 if (!crypto_stream_->CryptoConnect()) { 86 if (!crypto_stream_->CryptoConnect()) {
85 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a 87 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a
86 // QuicErrorCode and map it to a net error code. 88 // QuicErrorCode and map it to a net error code.
87 return ERR_CONNECTION_FAILED; 89 return ERR_CONNECTION_FAILED;
88 } 90 }
89 91
90 if (IsCryptoHandshakeComplete()) { 92 if (IsCryptoHandshakeConfirmed()) {
91 return OK; 93 return OK;
92 } 94 }
93 95
94 callback_ = callback; 96 callback_ = callback;
95 return ERR_IO_PENDING; 97 return ERR_IO_PENDING;
96 } 98 }
97 99
98 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream( 100 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream(
99 QuicStreamId id) { 101 QuicStreamId id) {
100 DLOG(ERROR) << "Server push not supported"; 102 DLOG(ERROR) << "Server push not supported";
101 return NULL; 103 return NULL;
102 } 104 }
103 105
104 void QuicClientSession::CloseStream(QuicStreamId stream_id) { 106 void QuicClientSession::CloseStream(QuicStreamId stream_id) {
105 QuicSession::CloseStream(stream_id); 107 QuicSession::CloseStream(stream_id);
106 108
107 if (GetNumOpenStreams() == 0) { 109 if (GetNumOpenStreams() == 0) {
108 stream_factory_->OnIdleSession(this); 110 stream_factory_->OnIdleSession(this);
109 } 111 }
110 } 112 }
111 113
112 void QuicClientSession::OnCryptoHandshakeComplete(QuicErrorCode error) { 114 void QuicClientSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) {
113 if (!callback_.is_null()) { 115 if (!callback_.is_null()) {
114 callback_.Run(error == QUIC_NO_ERROR ? OK : ERR_UNEXPECTED); 116 // TODO(rtenneti): Currently for all CryptoHandshakeEvent events, callback_
117 // could send the data. Change the following code if that changes.
118 base::ResetAndReturn(&callback_).Run(OK);
115 } 119 }
116 } 120 }
117 121
118 void QuicClientSession::StartReading() { 122 void QuicClientSession::StartReading() {
119 if (read_pending_) { 123 if (read_pending_) {
120 return; 124 return;
121 } 125 }
122 read_pending_ = true; 126 read_pending_ = true;
123 int rv = socket_->Read(read_buffer_, read_buffer_->size(), 127 int rv = socket_->Read(read_buffer_, read_buffer_->size(),
124 base::Bind(&QuicClientSession::OnReadComplete, 128 base::Bind(&QuicClientSession::OnReadComplete,
125 weak_factory_.GetWeakPtr())); 129 weak_factory_.GetWeakPtr()));
126 if (rv == ERR_IO_PENDING) { 130 if (rv == ERR_IO_PENDING) {
127 return; 131 return;
128 } 132 }
129 133
130 // Data was read, process it. 134 // Data was read, process it.
131 // Schedule the work through the message loop to avoid recursive 135 // Schedule the work through the message loop to avoid recursive
132 // callbacks. 136 // callbacks.
133 MessageLoop::current()->PostTask( 137 MessageLoop::current()->PostTask(
134 FROM_HERE, 138 FROM_HERE,
135 base::Bind(&QuicClientSession::OnReadComplete, 139 base::Bind(&QuicClientSession::OnReadComplete,
136 weak_factory_.GetWeakPtr(), rv)); 140 weak_factory_.GetWeakPtr(), rv));
137 } 141 }
138 142
139 void QuicClientSession::CloseSessionOnError(int error) { 143 void QuicClientSession::CloseSessionOnError(int error) {
Ryan Hamilton 2013/04/26 19:52:17 I think you also want to override QuicSession::Con
ramant (doing other things) 2013/04/30 02:17:03 Done.
144 if (!callback_.is_null()) {
145 base::ResetAndReturn(&callback_).Run(error);
146 }
140 while (!streams()->empty()) { 147 while (!streams()->empty()) {
141 ReliableQuicStream* stream = streams()->begin()->second; 148 ReliableQuicStream* stream = streams()->begin()->second;
142 QuicStreamId id = stream->id(); 149 QuicStreamId id = stream->id();
143 static_cast<QuicReliableClientStream*>(stream)->OnError(error); 150 static_cast<QuicReliableClientStream*>(stream)->OnError(error);
144 CloseStream(id); 151 CloseStream(id);
145 } 152 }
146 net_log_.BeginEvent( 153 net_log_.BeginEvent(
147 NetLog::TYPE_QUIC_SESSION, 154 NetLog::TYPE_QUIC_SESSION,
148 NetLog::IntegerCallback("net_error", error)); 155 NetLog::IntegerCallback("net_error", error));
149 // Will delete |this|. 156 // Will delete |this|.
(...skipping 26 matching lines...) Expand all
176 connection()->ProcessUdpPacket(local_address, peer_address, packet); 183 connection()->ProcessUdpPacket(local_address, peer_address, packet);
177 if (!connection()->connected()) { 184 if (!connection()->connected()) {
178 stream_factory_->OnSessionClose(this); 185 stream_factory_->OnSessionClose(this);
179 return; 186 return;
180 } 187 }
181 StartReading(); 188 StartReading();
182 } 189 }
183 } 190 }
184 191
185 } // namespace net 192 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_client_session_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698