OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_QUIC_QUIC_CLIENT_SESSION_BASE_H_ | |
6 #define NET_QUIC_QUIC_CLIENT_SESSION_BASE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/macros.h" | |
11 #include "net/quic/quic_crypto_client_stream.h" | |
12 #include "net/quic/quic_spdy_session.h" | |
13 | |
14 namespace net { | |
15 | |
16 class QuicClientPromisedInfo; | |
17 class QuicClientPushPromiseIndex; | |
18 class QuicSpdyClientStream; | |
19 | |
20 // For client/http layer code. Lookup promised streams based on | |
21 // matching promised request url. The same map can be shared across | |
22 // multiple sessions, since cross-origin pushes are allowed (subject | |
23 // to authority constraints). Clients should use this map to enforce | |
24 // session affinity for requests corresponding to cross-origin push | |
25 // promised streams. | |
26 using QuicPromisedByUrlMap = | |
27 std::unordered_map<std::string, QuicClientPromisedInfo*>; | |
28 | |
29 // The maximum time a promises stream can be reserved without being | |
30 // claimed by a client request. | |
31 const int64_t kPushPromiseTimeoutSecs = 60; | |
32 | |
33 // Base class for all client-specific QuicSession subclasses. | |
34 class NET_EXPORT_PRIVATE QuicClientSessionBase | |
35 : public QuicSpdySession, | |
36 public QuicCryptoClientStream::ProofHandler { | |
37 public: | |
38 // Caller retains ownership of |promised_by_url|. | |
39 QuicClientSessionBase(QuicConnection* connection, | |
40 QuicClientPushPromiseIndex* push_promise_index, | |
41 const QuicConfig& config); | |
42 | |
43 ~QuicClientSessionBase() override; | |
44 | |
45 void OnConfigNegotiated() override; | |
46 | |
47 // Override base class to set FEC policy before any data is sent by client. | |
48 void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override; | |
49 | |
50 // Called by |headers_stream_| when push promise headers have been | |
51 // received for a stream. | |
52 void OnPromiseHeaders(QuicStreamId stream_id, | |
53 base::StringPiece headers_data) override; | |
54 | |
55 // Called by |headers_stream_| when push promise headers have been | |
56 // completely received. | |
57 void OnPromiseHeadersComplete(QuicStreamId stream_id, | |
58 QuicStreamId promised_stream_id, | |
59 size_t frame_len) override; | |
60 | |
61 // Called by |headers_stream_| when push promise headers have been | |
62 // completely received. | |
63 void OnPromiseHeaderList(QuicStreamId stream_id, | |
64 QuicStreamId promised_stream_id, | |
65 size_t frame_len, | |
66 const QuicHeaderList& header_list) override; | |
67 | |
68 // Called by |QuicSpdyClientStream| on receipt of response headers, | |
69 // needed to detect promised server push streams, as part of | |
70 // client-request to push-stream rendezvous. | |
71 void OnInitialHeadersComplete(QuicStreamId stream_id, | |
72 const SpdyHeaderBlock& response_headers); | |
73 | |
74 // Called by |QuicSpdyClientStream| on receipt of PUSH_PROMISE, does | |
75 // some session level validation and creates the | |
76 // |QuicClientPromisedInfo| inserting into maps by (promised) id and | |
77 // url. | |
78 virtual void HandlePromised(QuicStreamId associated_id, | |
79 QuicStreamId promised_id, | |
80 const SpdyHeaderBlock& headers); | |
81 | |
82 // For cross-origin server push, this should verify the server is | |
83 // authoritative per [RFC2818], Section 3. Roughly, subjectAltName | |
84 // std::list in the certificate should contain a matching DNS name, or IP | |
85 // address. |hostname| is derived from the ":authority" header field of | |
86 // the PUSH_PROMISE frame, port if present there will be dropped. | |
87 virtual bool IsAuthorized(const std::string& hostname) = 0; | |
88 | |
89 // Session retains ownership. | |
90 QuicClientPromisedInfo* GetPromisedByUrl(const std::string& url); | |
91 // Session retains ownership. | |
92 QuicClientPromisedInfo* GetPromisedById(const QuicStreamId id); | |
93 | |
94 // | |
95 QuicSpdyStream* GetPromisedStream(const QuicStreamId id); | |
96 | |
97 // Removes |promised| from the maps by url. | |
98 void ErasePromisedByUrl(QuicClientPromisedInfo* promised); | |
99 | |
100 // Removes |promised| from the maps by url and id and destroys | |
101 // promised. | |
102 virtual void DeletePromised(QuicClientPromisedInfo* promised); | |
103 | |
104 // Sends Rst for the stream, and makes sure that future calls to | |
105 // IsClosedStream(id) return true, which ensures that any subsequent | |
106 // frames related to this stream will be ignored (modulo flow | |
107 // control accounting). | |
108 void ResetPromised(QuicStreamId id, QuicRstStreamErrorCode error_code); | |
109 | |
110 size_t get_max_promises() const { | |
111 return max_open_incoming_streams() * kMaxPromisedStreamsMultiplier; | |
112 } | |
113 | |
114 QuicClientPushPromiseIndex* push_promise_index() { | |
115 return push_promise_index_; | |
116 } | |
117 | |
118 private: | |
119 // For QuicSpdyClientStream to detect that a response corresponds to a | |
120 // promise. | |
121 using QuicPromisedByIdMap = | |
122 std::unordered_map<QuicStreamId, std::unique_ptr<QuicClientPromisedInfo>>; | |
123 | |
124 // As per rfc7540, section 10.5: track promise streams in "reserved | |
125 // (remote)". The primary key is URL from he promise request | |
126 // headers. The promised stream id is a secondary key used to get | |
127 // promise info when the response headers of the promised stream | |
128 // arrive. | |
129 QuicClientPushPromiseIndex* push_promise_index_; | |
130 QuicPromisedByIdMap promised_by_id_; | |
131 QuicStreamId largest_promised_stream_id_; | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(QuicClientSessionBase); | |
134 }; | |
135 | |
136 } // namespace net | |
137 | |
138 #endif // NET_QUIC_QUIC_CLIENT_SESSION_BASE_H_ | |
OLD | NEW |