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

Side by Side Diff: net/quic/quic_session.h

Issue 1190823003: Remove dependency on headers stream from QuicSession. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0616
Patch Set: deleted an include Created 5 years, 6 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
« no previous file with comments | « net/quic/quic_reliable_client_stream_test.cc ('k') | net/quic/quic_session.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 // A QuicSession, which demuxes a single connection to individual streams. 5 // A QuicSession, which demuxes a single connection to individual streams.
6 6
7 #ifndef NET_QUIC_QUIC_SESSION_H_ 7 #ifndef NET_QUIC_QUIC_SESSION_H_
8 #define NET_QUIC_QUIC_SESSION_H_ 8 #define NET_QUIC_QUIC_SESSION_H_
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/containers/hash_tables.h" 15 #include "base/containers/hash_tables.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "net/base/ip_endpoint.h" 18 #include "net/base/ip_endpoint.h"
19 #include "net/quic/quic_connection.h" 19 #include "net/quic/quic_connection.h"
20 #include "net/quic/quic_crypto_stream.h" 20 #include "net/quic/quic_crypto_stream.h"
21 #include "net/quic/quic_data_stream.h"
22 #include "net/quic/quic_headers_stream.h"
23 #include "net/quic/quic_packet_creator.h" 21 #include "net/quic/quic_packet_creator.h"
24 #include "net/quic/quic_protocol.h" 22 #include "net/quic/quic_protocol.h"
25 #include "net/quic/quic_write_blocked_list.h" 23 #include "net/quic/quic_write_blocked_list.h"
26 #include "net/quic/reliable_quic_stream.h" 24 #include "net/quic/reliable_quic_stream.h"
27 25
28 namespace net { 26 namespace net {
29 27
30 class QuicCryptoStream; 28 class QuicCryptoStream;
31 class QuicFlowController; 29 class QuicFlowController;
32 class ReliableQuicStream; 30 class ReliableQuicStream;
(...skipping 16 matching lines...) Expand all
49 // connection should resend any packets that were sent under 47 // connection should resend any packets that were sent under
50 // ENCRYPTION_INITIAL. (Client only.) 48 // ENCRYPTION_INITIAL. (Client only.)
51 ENCRYPTION_REESTABLISHED, 49 ENCRYPTION_REESTABLISHED,
52 // HANDSHAKE_CONFIRMED, in a client, indicates the the server has accepted 50 // HANDSHAKE_CONFIRMED, in a client, indicates the the server has accepted
53 // our handshake. In a server it indicates that a full, valid client hello 51 // our handshake. In a server it indicates that a full, valid client hello
54 // has been received. (Client and server.) 52 // has been received. (Client and server.)
55 HANDSHAKE_CONFIRMED, 53 HANDSHAKE_CONFIRMED,
56 }; 54 };
57 55
58 QuicSession(QuicConnection* connection, const QuicConfig& config); 56 QuicSession(QuicConnection* connection, const QuicConfig& config);
59 virtual void Initialize();
60 57
61 ~QuicSession() override; 58 ~QuicSession() override;
62 59
60 virtual void Initialize();
61
63 // QuicConnectionVisitorInterface methods: 62 // QuicConnectionVisitorInterface methods:
64 void OnStreamFrames(const std::vector<QuicStreamFrame>& frames) override; 63 void OnStreamFrames(const std::vector<QuicStreamFrame>& frames) override;
65 void OnRstStream(const QuicRstStreamFrame& frame) override; 64 void OnRstStream(const QuicRstStreamFrame& frame) override;
66 void OnGoAway(const QuicGoAwayFrame& frame) override; 65 void OnGoAway(const QuicGoAwayFrame& frame) override;
67 void OnWindowUpdateFrames( 66 void OnWindowUpdateFrames(
68 const std::vector<QuicWindowUpdateFrame>& frames) override; 67 const std::vector<QuicWindowUpdateFrame>& frames) override;
69 void OnBlockedFrames(const std::vector<QuicBlockedFrame>& frames) override; 68 void OnBlockedFrames(const std::vector<QuicBlockedFrame>& frames) override;
70 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override; 69 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override;
71 void OnWriteBlocked() override {} 70 void OnWriteBlocked() override {}
72 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override; 71 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override;
73 void OnCanWrite() override; 72 void OnCanWrite() override;
74 void OnCongestionWindowChange(QuicTime now) override {} 73 void OnCongestionWindowChange(QuicTime now) override {}
75 bool WillingAndAbleToWrite() const override; 74 bool WillingAndAbleToWrite() const override;
76 bool HasPendingHandshake() const override; 75 bool HasPendingHandshake() const override;
77 bool HasOpenDataStreams() const override; 76 bool HasOpenDynamicStreams() const override;
78
79 // Called by the headers stream when headers have been received for a stream.
80 virtual void OnStreamHeaders(QuicStreamId stream_id,
81 base::StringPiece headers_data);
82 // Called by the headers stream when headers with a priority have been
83 // received for this stream. This method will only be called for server
84 // streams.
85 virtual void OnStreamHeadersPriority(QuicStreamId stream_id,
86 QuicPriority priority);
87 // Called by the headers stream when headers have been completely received
88 // for a stream. |fin| will be true if the fin flag was set in the headers
89 // frame.
90 virtual void OnStreamHeadersComplete(QuicStreamId stream_id,
91 bool fin,
92 size_t frame_len);
93 77
94 // Called by streams when they want to write data to the peer. 78 // Called by streams when they want to write data to the peer.
95 // Returns a pair with the number of bytes consumed from data, and a boolean 79 // Returns a pair with the number of bytes consumed from data, and a boolean
96 // indicating if the fin bit was consumed. This does not indicate the data 80 // indicating if the fin bit was consumed. This does not indicate the data
97 // has been sent on the wire: it may have been turned into a packet and queued 81 // has been sent on the wire: it may have been turned into a packet and queued
98 // if the socket was unexpectedly blocked. |fec_protection| indicates if 82 // if the socket was unexpectedly blocked. |fec_protection| indicates if
99 // data is to be FEC protected. Note that data that is sent immediately 83 // data is to be FEC protected. Note that data that is sent immediately
100 // following MUST_FEC_PROTECT data may get protected by falling within the 84 // following MUST_FEC_PROTECT data may get protected by falling within the
101 // same FEC group. 85 // same FEC group.
102 // If provided, |ack_notifier_delegate| will be registered to be notified when 86 // If provided, |ack_notifier_delegate| will be registered to be notified when
103 // we have seen ACKs for all packets resulting from this call. 87 // we have seen ACKs for all packets resulting from this call.
104 virtual QuicConsumedData WritevData( 88 virtual QuicConsumedData WritevData(
105 QuicStreamId id, 89 QuicStreamId id,
106 const IOVector& data, 90 const IOVector& data,
107 QuicStreamOffset offset, 91 QuicStreamOffset offset,
108 bool fin, 92 bool fin,
109 FecProtection fec_protection, 93 FecProtection fec_protection,
110 QuicAckNotifier::DelegateInterface* ack_notifier_delegate); 94 QuicAckNotifier::DelegateInterface* ack_notifier_delegate);
111 95
112 // Writes |headers| for the stream |id| to the dedicated headers stream.
113 // If |fin| is true, then no more data will be sent for the stream |id|.
114 // If provided, |ack_notifier_delegate| will be registered to be notified when
115 // we have seen ACKs for all packets resulting from this call.
116 size_t WriteHeaders(
117 QuicStreamId id,
118 const SpdyHeaderBlock& headers,
119 bool fin,
120 QuicPriority priority,
121 QuicAckNotifier::DelegateInterface* ack_notifier_delegate);
122
123 // Called by streams when they want to close the stream in both directions. 96 // Called by streams when they want to close the stream in both directions.
124 virtual void SendRstStream(QuicStreamId id, 97 virtual void SendRstStream(QuicStreamId id,
125 QuicRstStreamErrorCode error, 98 QuicRstStreamErrorCode error,
126 QuicStreamOffset bytes_written); 99 QuicStreamOffset bytes_written);
127 100
128 // Called when the session wants to go away and not accept any new streams. 101 // Called when the session wants to go away and not accept any new streams.
129 void SendGoAway(QuicErrorCode error_code, const std::string& reason); 102 void SendGoAway(QuicErrorCode error_code, const std::string& reason);
130 103
131 // Removes the stream associated with 'stream_id' from the active stream map. 104 // Removes the stream associated with 'stream_id' from the active stream map.
132 virtual void CloseStream(QuicStreamId stream_id); 105 virtual void CloseStream(QuicStreamId stream_id);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // by QuicSession. 137 // by QuicSession.
165 QuicConfig* config(); 138 QuicConfig* config();
166 139
167 // Returns true if the stream existed previously and has been closed. 140 // Returns true if the stream existed previously and has been closed.
168 // Returns false if the stream is still active or if the stream has 141 // Returns false if the stream is still active or if the stream has
169 // not yet been created. 142 // not yet been created.
170 bool IsClosedStream(QuicStreamId id); 143 bool IsClosedStream(QuicStreamId id);
171 144
172 QuicConnection* connection() { return connection_.get(); } 145 QuicConnection* connection() { return connection_.get(); }
173 const QuicConnection* connection() const { return connection_.get(); } 146 const QuicConnection* connection() const { return connection_.get(); }
174 size_t num_active_requests() const { return stream_map_.size(); } 147 size_t num_active_requests() const { return dynamic_stream_map_.size(); }
175 const IPEndPoint& peer_address() const { 148 const IPEndPoint& peer_address() const {
176 return connection_->peer_address(); 149 return connection_->peer_address();
177 } 150 }
178 QuicConnectionId connection_id() const { 151 QuicConnectionId connection_id() const {
179 return connection_->connection_id(); 152 return connection_->connection_id();
180 } 153 }
181 154
182 // Returns the number of currently open streams, including those which have 155 // Returns the number of currently open streams, including those which have
183 // been implicitly created, but excluding the reserved headers and crypto 156 // been implicitly created, but excluding the reserved headers and crypto
184 // streams. 157 // streams.
(...skipping 19 matching lines...) Expand all
204 bool IsConnectionFlowControlBlocked() const; 177 bool IsConnectionFlowControlBlocked() const;
205 178
206 // Returns true if any stream is flow controller blocked. 179 // Returns true if any stream is flow controller blocked.
207 bool IsStreamFlowControlBlocked(); 180 bool IsStreamFlowControlBlocked();
208 181
209 // Returns true if this is a secure QUIC session. 182 // Returns true if this is a secure QUIC session.
210 bool IsSecure() const { return connection()->is_secure(); } 183 bool IsSecure() const { return connection()->is_secure(); }
211 184
212 size_t get_max_open_streams() const { return max_open_streams_; } 185 size_t get_max_open_streams() const { return max_open_streams_; }
213 186
214 // Used in Chrome.
215 const QuicHeadersStream* headers_stream() { return headers_stream_.get(); }
216
217 ReliableQuicStream* GetStream(const QuicStreamId stream_id); 187 ReliableQuicStream* GetStream(const QuicStreamId stream_id);
218 188
219 protected: 189 protected:
220 typedef base::hash_map<QuicStreamId, QuicDataStream*> DataStreamMap; 190 typedef base::hash_map<QuicStreamId, ReliableQuicStream*> StreamMap;
221 191
222 // Creates a new stream, owned by the caller, to handle a peer-initiated 192 // Creates a new stream, owned by the caller, to handle a peer-initiated
223 // stream. Returns nullptr and does error handling if the stream can not be 193 // stream. Returns nullptr and does error handling if the stream can not be
224 // created. 194 // created.
225 virtual QuicDataStream* CreateIncomingDataStream(QuicStreamId id) = 0; 195 virtual ReliableQuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0;
226 196
227 // Create a new stream, owned by the caller, to handle a locally-initiated 197 // Create a new stream, owned by the caller, to handle a locally-initiated
228 // stream. Returns nullptr if max streams have already been opened. 198 // stream. Returns nullptr if max streams have already been opened.
229 virtual QuicDataStream* CreateOutgoingDataStream() = 0; 199 virtual ReliableQuicStream* CreateOutgoingDynamicStream() = 0;
230 200
231 // Return the reserved crypto stream. 201 // Return the reserved crypto stream.
232 virtual QuicCryptoStream* GetCryptoStream() = 0; 202 virtual QuicCryptoStream* GetCryptoStream() = 0;
233 203
234 // Adds 'stream' to the active stream map. 204 // Adds 'stream' to the active stream map.
235 virtual void ActivateStream(QuicDataStream* stream); 205 virtual void ActivateStream(ReliableQuicStream* stream);
236 206
237 // Returns the stream id for a new stream. 207 // Returns the stream id for a new stream.
238 QuicStreamId GetNextStreamId(); 208 QuicStreamId GetNextStreamId();
239 209
240 QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id); 210 ReliableQuicStream* GetIncomingDynamicStream(QuicStreamId stream_id);
241 211
242 QuicDataStream* GetDataStream(const QuicStreamId stream_id); 212 ReliableQuicStream* GetDynamicStream(const QuicStreamId stream_id);
243 213
244 // This is called after every call other than OnConnectionClose from the 214 // This is called after every call other than OnConnectionClose from the
245 // QuicConnectionVisitor to allow post-processing once the work has been done. 215 // QuicConnectionVisitor to allow post-processing once the work has been done.
246 // In this case, it deletes streams given that it's safe to do so (no other 216 // In this case, it deletes streams given that it's safe to do so (no other
247 // operations are being done on the streams at this time) 217 // operations are being done on the streams at this time)
248 virtual void PostProcessAfterData(); 218 virtual void PostProcessAfterData();
249 219
250 base::hash_map<QuicStreamId, QuicDataStream*>* streams() { 220 StreamMap& static_streams() { return static_stream_map_; }
251 return &stream_map_; 221 const StreamMap& static_streams() const { return static_stream_map_; }
222
223 StreamMap& dynamic_streams() { return dynamic_stream_map_; }
224 const StreamMap& dynamic_streams() const { return dynamic_stream_map_; }
225
226 std::vector<ReliableQuicStream*>* closed_streams() {
227 return &closed_streams_;
252 } 228 }
253 229
254 const base::hash_map<QuicStreamId, QuicDataStream*>* streams() const {
255 return &stream_map_;
256 }
257
258 std::vector<QuicDataStream*>* closed_streams() { return &closed_streams_; }
259
260 void set_max_open_streams(size_t max_open_streams); 230 void set_max_open_streams(size_t max_open_streams);
261 231
262 scoped_ptr<QuicHeadersStream> headers_stream_; 232 void set_largest_peer_created_stream_id(
233 QuicStreamId largest_peer_created_stream_id) {
234 largest_peer_created_stream_id_ = largest_peer_created_stream_id;
235 }
263 236
264 private: 237 private:
265 friend class test::QuicSessionPeer; 238 friend class test::QuicSessionPeer;
266 friend class VisitorShim; 239 friend class VisitorShim;
267 240
268 // Performs the work required to close |stream_id|. If |locally_reset| 241 // Performs the work required to close |stream_id|. If |locally_reset|
269 // then the stream has been reset by this endpoint, not by the peer. 242 // then the stream has been reset by this endpoint, not by the peer.
270 void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); 243 void CloseStreamInner(QuicStreamId stream_id, bool locally_reset);
271 244
272 // When a stream is closed locally, it may not yet know how many bytes the 245 // When a stream is closed locally, it may not yet know how many bytes the
(...skipping 19 matching lines...) Expand all
292 // waiting for a definitive final highest offset from the peer. 265 // waiting for a definitive final highest offset from the peer.
293 std::map<QuicStreamId, QuicStreamOffset> 266 std::map<QuicStreamId, QuicStreamOffset>
294 locally_closed_streams_highest_offset_; 267 locally_closed_streams_highest_offset_;
295 268
296 scoped_ptr<QuicConnection> connection_; 269 scoped_ptr<QuicConnection> connection_;
297 270
298 // A shim to stand between the connection and the session, to handle stream 271 // A shim to stand between the connection and the session, to handle stream
299 // deletions. 272 // deletions.
300 scoped_ptr<VisitorShim> visitor_shim_; 273 scoped_ptr<VisitorShim> visitor_shim_;
301 274
302 std::vector<QuicDataStream*> closed_streams_; 275 std::vector<ReliableQuicStream*> closed_streams_;
303 276
304 QuicConfig config_; 277 QuicConfig config_;
305 278
306 // Returns the maximum number of streams this connection can open. 279 // Returns the maximum number of streams this connection can open.
307 size_t max_open_streams_; 280 size_t max_open_streams_;
308 281
282 // Static streams, such as crypto and header streams. Owned by child classes
283 // that create these streams.
284 StreamMap static_stream_map_;
285
309 // Map from StreamId to pointers to streams that are owned by the caller. 286 // Map from StreamId to pointers to streams that are owned by the caller.
310 DataStreamMap stream_map_; 287 StreamMap dynamic_stream_map_;
311 QuicStreamId next_stream_id_; 288 QuicStreamId next_stream_id_;
312 289
313 // Set of stream ids that have been "implicitly created" by receipt 290 // Set of stream ids that have been "implicitly created" by receipt
314 // of a stream id larger than the next expected stream id. 291 // of a stream id larger than the next expected stream id.
315 base::hash_set<QuicStreamId> implicitly_created_streams_; 292 base::hash_set<QuicStreamId> implicitly_created_streams_;
316 293
317 // A list of streams which need to write more data. 294 // A list of streams which need to write more data.
318 QuicWriteBlockedList write_blocked_streams_; 295 QuicWriteBlockedList write_blocked_streams_;
319 296
320 QuicStreamId largest_peer_created_stream_id_; 297 QuicStreamId largest_peer_created_stream_id_;
(...skipping 11 matching lines...) Expand all
332 309
333 // Indicate if there is pending data for the crypto stream. 310 // Indicate if there is pending data for the crypto stream.
334 bool has_pending_handshake_; 311 bool has_pending_handshake_;
335 312
336 DISALLOW_COPY_AND_ASSIGN(QuicSession); 313 DISALLOW_COPY_AND_ASSIGN(QuicSession);
337 }; 314 };
338 315
339 } // namespace net 316 } // namespace net
340 317
341 #endif // NET_QUIC_QUIC_SESSION_H_ 318 #endif // NET_QUIC_QUIC_SESSION_H_
OLDNEW
« no previous file with comments | « net/quic/quic_reliable_client_stream_test.cc ('k') | net/quic/quic_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698