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 #ifndef NET_SPDY_SPDY_SESSION_H_ | 5 #ifndef NET_SPDY_SPDY_SESSION_H_ |
6 #define NET_SPDY_SPDY_SESSION_H_ | 6 #define NET_SPDY_SPDY_SESSION_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 // This is somewhat arbitrary and not really fixed, but it will always work | 54 // This is somewhat arbitrary and not really fixed, but it will always work |
55 // reasonably with ethernet. Chop the world into 2-packet chunks. This is | 55 // reasonably with ethernet. Chop the world into 2-packet chunks. This is |
56 // somewhat arbitrary, but is reasonably small and ensures that we elicit | 56 // somewhat arbitrary, but is reasonably small and ensures that we elicit |
57 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). | 57 // ACKs quickly from TCP (because TCP tries to only ACK every other packet). |
58 const int kMss = 1430; | 58 const int kMss = 1430; |
59 // The 8 is the size of the SPDY frame header. | 59 // The 8 is the size of the SPDY frame header. |
60 const int kMaxSpdyFrameChunkSize = (2 * kMss) - 8; | 60 const int kMaxSpdyFrameChunkSize = (2 * kMss) - 8; |
61 | 61 |
| 62 // Default value of SETTINGS_INITIAL_WINDOW_SIZE per protocol specification. |
| 63 // A session is always created with this initial window size. |
| 64 const int32_t kDefaultInitialWindowSize = 65535; |
| 65 |
62 // Maximum number of concurrent streams we will create, unless the server | 66 // Maximum number of concurrent streams we will create, unless the server |
63 // sends a SETTINGS frame with a different value. | 67 // sends a SETTINGS frame with a different value. |
64 const size_t kInitialMaxConcurrentStreams = 100; | 68 const size_t kInitialMaxConcurrentStreams = 100; |
65 | 69 |
66 // Specifies the maxiumum concurrent streams server could send (via push). | 70 // Specifies the maxiumum concurrent streams server could send (via push). |
67 const int kMaxConcurrentPushedStreams = 1000; | 71 const int kMaxConcurrentPushedStreams = 1000; |
68 | 72 |
69 // If more than this many bytes have been read or more than that many | 73 // If more than this many bytes have been read or more than that many |
70 // milliseconds have passed, return ERR_IO_PENDING from ReadLoop. | 74 // milliseconds have passed, return ERR_IO_PENDING from ReadLoop. |
71 const int kYieldAfterBytesRead = 32 * 1024; | 75 const int kYieldAfterBytesRead = 32 * 1024; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 MapRstStreamStatusToProtocolError(SpdyRstStreamStatus status); | 145 MapRstStreamStatusToProtocolError(SpdyRstStreamStatus status); |
142 SpdyGoAwayStatus NET_EXPORT_PRIVATE MapNetErrorToGoAwayStatus(Error err); | 146 SpdyGoAwayStatus NET_EXPORT_PRIVATE MapNetErrorToGoAwayStatus(Error err); |
143 | 147 |
144 // If these compile asserts fail then SpdyProtocolErrorDetails needs | 148 // If these compile asserts fail then SpdyProtocolErrorDetails needs |
145 // to be updated with new values, as do the mapping functions above. | 149 // to be updated with new values, as do the mapping functions above. |
146 static_assert(17 == SpdyFramer::LAST_ERROR, | 150 static_assert(17 == SpdyFramer::LAST_ERROR, |
147 "SpdyProtocolErrorDetails / Spdy Errors mismatch"); | 151 "SpdyProtocolErrorDetails / Spdy Errors mismatch"); |
148 static_assert(17 == RST_STREAM_NUM_STATUS_CODES, | 152 static_assert(17 == RST_STREAM_NUM_STATUS_CODES, |
149 "SpdyProtocolErrorDetails / RstStreamStatus mismatch"); | 153 "SpdyProtocolErrorDetails / RstStreamStatus mismatch"); |
150 | 154 |
151 // Splits pushed |headers| into request and response parts. Request headers are | |
152 // the headers specifying resource URL. | |
153 void NET_EXPORT_PRIVATE | |
154 SplitPushedHeadersToRequestAndResponse(const SpdyHeaderBlock& headers, | |
155 SpdyMajorVersion protocol_version, | |
156 SpdyHeaderBlock* request_headers, | |
157 SpdyHeaderBlock* response_headers); | |
158 | |
159 // A helper class used to manage a request to create a stream. | 155 // A helper class used to manage a request to create a stream. |
160 class NET_EXPORT_PRIVATE SpdyStreamRequest { | 156 class NET_EXPORT_PRIVATE SpdyStreamRequest { |
161 public: | 157 public: |
162 SpdyStreamRequest(); | 158 SpdyStreamRequest(); |
163 // Calls CancelRequest(). | 159 // Calls CancelRequest(). |
164 ~SpdyStreamRequest(); | 160 ~SpdyStreamRequest(); |
165 | 161 |
166 // Starts the request to create a stream. If OK is returned, then | 162 // Starts the request to create a stream. If OK is returned, then |
167 // ReleaseStream() may be called. If ERR_IO_PENDING is returned, | 163 // ReleaseStream() may be called. If ERR_IO_PENDING is returned, |
168 // then when the stream is created, |callback| will be called, at | 164 // then when the stream is created, |callback| will be called, at |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // and proxy configuration settings that it's using. | 288 // and proxy configuration settings that it's using. |
293 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log | 289 // |session| is the HttpNetworkSession. |net_log| is the NetLog that we log |
294 // network events to. | 290 // network events to. |
295 SpdySession(const SpdySessionKey& spdy_session_key, | 291 SpdySession(const SpdySessionKey& spdy_session_key, |
296 HttpServerProperties* http_server_properties, | 292 HttpServerProperties* http_server_properties, |
297 TransportSecurityState* transport_security_state, | 293 TransportSecurityState* transport_security_state, |
298 bool verify_domain_authentication, | 294 bool verify_domain_authentication, |
299 bool enable_sending_initial_data, | 295 bool enable_sending_initial_data, |
300 bool enable_ping_based_connection_checking, | 296 bool enable_ping_based_connection_checking, |
301 bool enable_priority_dependencies, | 297 bool enable_priority_dependencies, |
302 NextProto default_protocol, | |
303 size_t session_max_recv_window_size, | 298 size_t session_max_recv_window_size, |
304 size_t stream_max_recv_window_size, | 299 size_t stream_max_recv_window_size, |
305 TimeFunc time_func, | 300 TimeFunc time_func, |
306 ProxyDelegate* proxy_delegate, | 301 ProxyDelegate* proxy_delegate, |
307 NetLog* net_log); | 302 NetLog* net_log); |
308 | 303 |
309 ~SpdySession() override; | 304 ~SpdySession() override; |
310 | 305 |
311 const HostPortPair& host_port_pair() const { | 306 const HostPortPair& host_port_pair() const { |
312 return spdy_session_key_.host_port_proxy_pair().first; | 307 return spdy_session_key_.host_port_proxy_pair().first; |
(...skipping 29 matching lines...) Expand all Loading... |
342 // ERR_IO_PENDING. | 337 // ERR_IO_PENDING. |
343 // | 338 // |
344 // The session begins reading from |connection| on a subsequent event loop | 339 // The session begins reading from |connection| on a subsequent event loop |
345 // iteration, so the SpdySession may close immediately afterwards if the first | 340 // iteration, so the SpdySession may close immediately afterwards if the first |
346 // read of |connection| fails. | 341 // read of |connection| fails. |
347 void InitializeWithSocket(std::unique_ptr<ClientSocketHandle> connection, | 342 void InitializeWithSocket(std::unique_ptr<ClientSocketHandle> connection, |
348 SpdySessionPool* pool, | 343 SpdySessionPool* pool, |
349 bool is_secure, | 344 bool is_secure, |
350 int certificate_error_code); | 345 int certificate_error_code); |
351 | 346 |
352 // Returns the protocol used by this session. Always between | |
353 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion. | |
354 NextProto protocol() const { return protocol_; } | |
355 | |
356 // Check to see if this SPDY session can support an additional domain. | 347 // Check to see if this SPDY session can support an additional domain. |
357 // If the session is un-authenticated, then this call always returns true. | 348 // If the session is un-authenticated, then this call always returns true. |
358 // For SSL-based sessions, verifies that the server certificate in use by | 349 // For SSL-based sessions, verifies that the server certificate in use by |
359 // this session provides authentication for the domain and no client | 350 // this session provides authentication for the domain and no client |
360 // certificate or channel ID was sent to the original server during the SSL | 351 // certificate or channel ID was sent to the original server during the SSL |
361 // handshake. NOTE: This function can have false negatives on some | 352 // handshake. NOTE: This function can have false negatives on some |
362 // platforms. | 353 // platforms. |
363 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch | 354 // TODO(wtc): rename this function and the Net.SpdyIPPoolDomainMatch |
364 // histogram because this function does more than verifying domain | 355 // histogram because this function does more than verifying domain |
365 // authentication now. | 356 // authentication now. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 int GetLocalAddress(IPEndPoint* address) const; | 515 int GetLocalAddress(IPEndPoint* address) const; |
525 | 516 |
526 // Adds |alias| to set of aliases associated with this session. | 517 // Adds |alias| to set of aliases associated with this session. |
527 void AddPooledAlias(const SpdySessionKey& alias_key); | 518 void AddPooledAlias(const SpdySessionKey& alias_key); |
528 | 519 |
529 // Returns the set of aliases associated with this session. | 520 // Returns the set of aliases associated with this session. |
530 const std::set<SpdySessionKey>& pooled_aliases() const { | 521 const std::set<SpdySessionKey>& pooled_aliases() const { |
531 return pooled_aliases_; | 522 return pooled_aliases_; |
532 } | 523 } |
533 | 524 |
534 SpdyMajorVersion GetProtocolVersion() const; | |
535 | |
536 size_t GetDataFrameMinimumSize() const { | 525 size_t GetDataFrameMinimumSize() const { |
537 return buffered_spdy_framer_->GetDataFrameMinimumSize(); | 526 return buffered_spdy_framer_->GetDataFrameMinimumSize(); |
538 } | 527 } |
539 | 528 |
540 size_t GetControlFrameHeaderSize() const { | 529 size_t GetControlFrameHeaderSize() const { |
541 return buffered_spdy_framer_->GetControlFrameHeaderSize(); | 530 return buffered_spdy_framer_->GetControlFrameHeaderSize(); |
542 } | 531 } |
543 | 532 |
544 size_t GetFrameMinimumSize() const { | 533 size_t GetFrameMinimumSize() const { |
545 return buffered_spdy_framer_->GetFrameMinimumSize(); | 534 return buffered_spdy_framer_->GetFrameMinimumSize(); |
546 } | 535 } |
547 | 536 |
548 size_t GetFrameMaximumSize() const { | 537 size_t GetFrameMaximumSize() const { |
549 return buffered_spdy_framer_->GetFrameMaximumSize(); | 538 return buffered_spdy_framer_->GetFrameMaximumSize(); |
550 } | 539 } |
551 | 540 |
552 size_t GetDataFrameMaximumPayload() const { | 541 size_t GetDataFrameMaximumPayload() const { |
553 return buffered_spdy_framer_->GetDataFrameMaximumPayload(); | 542 return buffered_spdy_framer_->GetDataFrameMaximumPayload(); |
554 } | 543 } |
555 | 544 |
556 // Default value of SETTINGS_INITIAL_WINDOW_SIZE per protocol specification. | |
557 // A session is always created with this initial window size. | |
558 static int32_t GetDefaultInitialWindowSize(NextProto protocol) { | |
559 return protocol < kProtoHTTP2 ? 65536 : 65535; | |
560 } | |
561 | |
562 // https://http2.github.io/http2-spec/#TLSUsage mandates minimum security | 545 // https://http2.github.io/http2-spec/#TLSUsage mandates minimum security |
563 // standards for TLS. | 546 // standards for TLS. |
564 bool HasAcceptableTransportSecurity() const; | 547 bool HasAcceptableTransportSecurity() const; |
565 | 548 |
566 // Must be used only by |pool_|. | 549 // Must be used only by |pool_|. |
567 base::WeakPtr<SpdySession> GetWeakPtr(); | 550 base::WeakPtr<SpdySession> GetWeakPtr(); |
568 | 551 |
569 // HigherLayeredPool implementation: | 552 // HigherLayeredPool implementation: |
570 bool CloseOneIdleConnection() override; | 553 bool CloseOneIdleConnection() override; |
571 | 554 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 const char* data, | 869 const char* data, |
887 size_t len) override; | 870 size_t len) override; |
888 void OnStreamEnd(SpdyStreamId stream_id) override; | 871 void OnStreamEnd(SpdyStreamId stream_id) override; |
889 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override; | 872 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override; |
890 void OnSettings(bool clear_persisted) override; | 873 void OnSettings(bool clear_persisted) override; |
891 void OnSetting(SpdySettingsIds id, uint8_t flags, uint32_t value) override; | 874 void OnSetting(SpdySettingsIds id, uint8_t flags, uint32_t value) override; |
892 void OnWindowUpdate(SpdyStreamId stream_id, int delta_window_size) override; | 875 void OnWindowUpdate(SpdyStreamId stream_id, int delta_window_size) override; |
893 void OnPushPromise(SpdyStreamId stream_id, | 876 void OnPushPromise(SpdyStreamId stream_id, |
894 SpdyStreamId promised_stream_id, | 877 SpdyStreamId promised_stream_id, |
895 const SpdyHeaderBlock& headers) override; | 878 const SpdyHeaderBlock& headers) override; |
896 void OnSynStream(SpdyStreamId stream_id, | |
897 SpdyStreamId associated_stream_id, | |
898 SpdyPriority priority, | |
899 bool fin, | |
900 bool unidirectional, | |
901 const SpdyHeaderBlock& headers) override; | |
902 void OnSynReply(SpdyStreamId stream_id, | |
903 bool fin, | |
904 const SpdyHeaderBlock& headers) override; | |
905 void OnHeaders(SpdyStreamId stream_id, | 879 void OnHeaders(SpdyStreamId stream_id, |
906 bool has_priority, | 880 bool has_priority, |
907 int weight, | 881 int weight, |
908 SpdyStreamId parent_stream_id, | 882 SpdyStreamId parent_stream_id, |
909 bool exclusive, | 883 bool exclusive, |
910 bool fin, | 884 bool fin, |
911 const SpdyHeaderBlock& headers) override; | 885 const SpdyHeaderBlock& headers) override; |
912 void OnAltSvc(SpdyStreamId stream_id, | 886 void OnAltSvc(SpdyStreamId stream_id, |
913 base::StringPiece origin, | 887 base::StringPiece origin, |
914 const SpdyAltSvcWireFormat::AlternativeServiceVector& | 888 const SpdyAltSvcWireFormat::AlternativeServiceVector& |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 size_t last_compressed_frame_len_; | 1119 size_t last_compressed_frame_len_; |
1146 | 1120 |
1147 // This is the next time that unclaimed push streams should be checked for | 1121 // This is the next time that unclaimed push streams should be checked for |
1148 // expirations. | 1122 // expirations. |
1149 base::TimeTicks next_unclaimed_push_stream_sweep_time_; | 1123 base::TimeTicks next_unclaimed_push_stream_sweep_time_; |
1150 | 1124 |
1151 // Indicate if we have already scheduled a delayed task to check the ping | 1125 // Indicate if we have already scheduled a delayed task to check the ping |
1152 // status. | 1126 // status. |
1153 bool check_ping_status_pending_; | 1127 bool check_ping_status_pending_; |
1154 | 1128 |
1155 // Whether to send the (HTTP/2) connection header prefix. | |
1156 bool send_connection_header_prefix_; | |
1157 | |
1158 // Current send window size. Zero unless session flow control is turned on. | 1129 // Current send window size. Zero unless session flow control is turned on. |
1159 int32_t session_send_window_size_; | 1130 int32_t session_send_window_size_; |
1160 | 1131 |
1161 // Maximum receive window size. Each time a WINDOW_UPDATE is sent, it | 1132 // Maximum receive window size. Each time a WINDOW_UPDATE is sent, it |
1162 // restores the receive window size to this value. Zero unless session flow | 1133 // restores the receive window size to this value. Zero unless session flow |
1163 // control is turned on. | 1134 // control is turned on. |
1164 int32_t session_max_recv_window_size_; | 1135 int32_t session_max_recv_window_size_; |
1165 | 1136 |
1166 // Sum of |session_unacked_recv_window_bytes_| and current receive window | 1137 // Sum of |session_unacked_recv_window_bytes_| and current receive window |
1167 // size. Zero unless session flow control is turned on. | 1138 // size. Zero unless session flow control is turned on. |
(...skipping 22 matching lines...) Expand all Loading... |
1190 // in the past. | 1161 // in the past. |
1191 std::deque<SpdyStreamId> stream_send_unstall_queue_[NUM_PRIORITIES]; | 1162 std::deque<SpdyStreamId> stream_send_unstall_queue_[NUM_PRIORITIES]; |
1192 | 1163 |
1193 BoundNetLog net_log_; | 1164 BoundNetLog net_log_; |
1194 | 1165 |
1195 // Outside of tests, these should always be true. | 1166 // Outside of tests, these should always be true. |
1196 bool verify_domain_authentication_; | 1167 bool verify_domain_authentication_; |
1197 bool enable_sending_initial_data_; | 1168 bool enable_sending_initial_data_; |
1198 bool enable_ping_based_connection_checking_; | 1169 bool enable_ping_based_connection_checking_; |
1199 | 1170 |
1200 // The SPDY protocol used. Always between kProtoSPDYMinimumVersion and | |
1201 // kProtoSPDYMaximumVersion. | |
1202 NextProto protocol_; | |
1203 | |
1204 // |connection_at_risk_of_loss_time_| is an optimization to avoid sending | 1171 // |connection_at_risk_of_loss_time_| is an optimization to avoid sending |
1205 // wasteful preface pings (when we just got some data). | 1172 // wasteful preface pings (when we just got some data). |
1206 // | 1173 // |
1207 // If it is zero (the most conservative figure), then we always send the | 1174 // If it is zero (the most conservative figure), then we always send the |
1208 // preface ping (when none are in flight). | 1175 // preface ping (when none are in flight). |
1209 // | 1176 // |
1210 // It is common for TCP/IP sessions to time out in about 3-5 minutes. | 1177 // It is common for TCP/IP sessions to time out in about 3-5 minutes. |
1211 // Certainly if it has been more than 3 minutes, we do want to send a preface | 1178 // Certainly if it has been more than 3 minutes, we do want to send a preface |
1212 // ping. | 1179 // ping. |
1213 // | 1180 // |
(...skipping 22 matching lines...) Expand all Loading... |
1236 // Used for posting asynchronous IO tasks. We use this even though | 1203 // Used for posting asynchronous IO tasks. We use this even though |
1237 // SpdySession is refcounted because we don't need to keep the SpdySession | 1204 // SpdySession is refcounted because we don't need to keep the SpdySession |
1238 // alive if the last reference is within a RunnableMethod. Just revoke the | 1205 // alive if the last reference is within a RunnableMethod. Just revoke the |
1239 // method. | 1206 // method. |
1240 base::WeakPtrFactory<SpdySession> weak_factory_; | 1207 base::WeakPtrFactory<SpdySession> weak_factory_; |
1241 }; | 1208 }; |
1242 | 1209 |
1243 } // namespace net | 1210 } // namespace net |
1244 | 1211 |
1245 #endif // NET_SPDY_SPDY_SESSION_H_ | 1212 #endif // NET_SPDY_SPDY_SESSION_H_ |
OLD | NEW |