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 // A server specific QuicSession subclass. | 5 // A server specific QuicSession subclass. |
6 | 6 |
7 #ifndef NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | 7 #ifndef NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ |
8 #define NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | 8 #define NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 virtual void OnConnectionClosed(QuicConnectionId connection_id, | 47 virtual void OnConnectionClosed(QuicConnectionId connection_id, |
48 QuicErrorCode error, | 48 QuicErrorCode error, |
49 const std::string& error_details) = 0; | 49 const std::string& error_details) = 0; |
50 | 50 |
51 // Called when the session has become write blocked. | 51 // Called when the session has become write blocked. |
52 virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0; | 52 virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0; |
53 | 53 |
54 // Called after the given connection is added to the time-wait std::list. | 54 // Called after the given connection is added to the time-wait std::list. |
55 virtual void OnConnectionAddedToTimeWaitList( | 55 virtual void OnConnectionAddedToTimeWaitList( |
56 QuicConnectionId connection_id) = 0; | 56 QuicConnectionId connection_id) = 0; |
57 }; | |
58 | 57 |
59 // Provides helper functions for the session. | 58 // Called before a packet is going to be processed by |session|. |
60 class Helper { | 59 virtual void OnPacketBeingDispatchedToSession( |
61 public: | 60 QuicServerSessionBase* session) = 0; |
62 virtual ~Helper() {} | |
63 | |
64 // Given the current connection_id, generates a new ConnectionId to | |
65 // be returned with a stateless reject. | |
66 virtual QuicConnectionId GenerateConnectionIdForReject( | |
67 QuicConnectionId connection_id) const = 0; | |
68 | |
69 // Returns true if |message|, which was received on |self_address| is | |
70 // acceptable according to the visitor's policy. Otherwise, returns false | |
71 // and populates |error_details|. | |
72 virtual bool CanAcceptClientHello(const CryptoHandshakeMessage& message, | |
73 const IPEndPoint& self_address, | |
74 std::string* error_details) const = 0; | |
75 }; | 61 }; |
76 | 62 |
77 // Does not take ownership of |connection|. |crypto_config| must outlive the | 63 // Does not take ownership of |connection|. |crypto_config| must outlive the |
78 // session. | 64 // session. |helper| must outlive any created crypto streams. |
79 QuicServerSessionBase(const QuicConfig& config, | 65 QuicServerSessionBase(const QuicConfig& config, |
80 QuicConnection* connection, | 66 QuicConnection* connection, |
81 Visitor* visitor, | 67 Visitor* visitor, |
82 Helper* helper, | 68 QuicCryptoServerStream::Helper* helper, |
83 const QuicCryptoServerConfig* crypto_config, | 69 const QuicCryptoServerConfig* crypto_config, |
84 QuicCompressedCertsCache* compressed_certs_cache); | 70 QuicCompressedCertsCache* compressed_certs_cache); |
85 | 71 |
86 // Override the base class to notify the owner of the connection close. | 72 // Override the base class to notify the owner of the connection close. |
87 void OnConnectionClosed(QuicErrorCode error, | 73 void OnConnectionClosed(QuicErrorCode error, |
88 const std::string& error_details, | 74 const std::string& error_details, |
89 ConnectionCloseSource source) override; | 75 ConnectionCloseSource source) override; |
90 void OnWriteBlocked() override; | 76 void OnWriteBlocked() override; |
91 | 77 |
92 // Sends a server config update to the client, containing new bandwidth | 78 // Sends a server config update to the client, containing new bandwidth |
(...skipping 11 matching lines...) Expand all Loading... |
104 // Override base class to process bandwidth related config received from | 90 // Override base class to process bandwidth related config received from |
105 // client. | 91 // client. |
106 void OnConfigNegotiated() override; | 92 void OnConfigNegotiated() override; |
107 | 93 |
108 void set_serving_region(const std::string& serving_region) { | 94 void set_serving_region(const std::string& serving_region) { |
109 serving_region_ = serving_region; | 95 serving_region_ = serving_region; |
110 } | 96 } |
111 | 97 |
112 bool server_push_enabled() const { return server_push_enabled_; } | 98 bool server_push_enabled() const { return server_push_enabled_; } |
113 | 99 |
114 // Delegates to the helper's GenerateConnectionIdForReject method. | |
115 QuicConnectionId GenerateConnectionIdForReject( | |
116 QuicConnectionId connection_id); | |
117 | |
118 // Delegates to the helper's CanAcceptClientHello method. | |
119 bool CanAcceptClientHello(const CryptoHandshakeMessage& message, | |
120 std::string* error_details); | |
121 | |
122 protected: | 100 protected: |
123 // QuicSession methods(override them with return type of QuicSpdyStream*): | 101 // QuicSession methods(override them with return type of QuicSpdyStream*): |
124 QuicCryptoServerStreamBase* GetCryptoStream() override; | 102 QuicCryptoServerStreamBase* GetCryptoStream() override; |
125 | 103 |
126 // If an outgoing stream can be created, return true. | 104 // If an outgoing stream can be created, return true. |
127 // Return false when connection is closed or forward secure encryption hasn't | 105 // Return false when connection is closed or forward secure encryption hasn't |
128 // established yet or number of server initiated streams already reaches the | 106 // established yet or number of server initiated streams already reaches the |
129 // upper limit. | 107 // upper limit. |
130 bool ShouldCreateOutgoingDynamicStream() override; | 108 bool ShouldCreateOutgoingDynamicStream() override; |
131 | 109 |
132 // If we should create an incoming stream, returns true. Otherwise | 110 // If we should create an incoming stream, returns true. Otherwise |
133 // does error handling, including communicating the error to the client and | 111 // does error handling, including communicating the error to the client and |
134 // possibly closing the connection, and returns false. | 112 // possibly closing the connection, and returns false. |
135 bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override; | 113 bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override; |
136 | 114 |
137 virtual QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( | 115 virtual QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
138 const QuicCryptoServerConfig* crypto_config, | 116 const QuicCryptoServerConfig* crypto_config, |
139 QuicCompressedCertsCache* compressed_certs_cache) = 0; | 117 QuicCompressedCertsCache* compressed_certs_cache) = 0; |
140 | 118 |
141 const QuicCryptoServerConfig* crypto_config() { return crypto_config_; } | 119 const QuicCryptoServerConfig* crypto_config() { return crypto_config_; } |
142 | 120 |
143 void set_server_push_enabled(bool enable) { server_push_enabled_ = enable; } | 121 void set_server_push_enabled(bool enable) { server_push_enabled_ = enable; } |
144 | 122 |
| 123 Visitor* visitor() { return visitor_; } |
| 124 |
| 125 QuicCryptoServerStream::Helper* stream_helper() { return helper_; } |
| 126 |
145 private: | 127 private: |
146 friend class test::QuicServerSessionBasePeer; | 128 friend class test::QuicServerSessionBasePeer; |
147 friend class test::QuicSimpleServerSessionPeer; | 129 friend class test::QuicSimpleServerSessionPeer; |
148 | 130 |
149 const QuicCryptoServerConfig* crypto_config_; | 131 const QuicCryptoServerConfig* crypto_config_; |
150 | 132 |
151 // The cache which contains most recently compressed certs. | 133 // The cache which contains most recently compressed certs. |
152 // Owned by QuicDispatcher. | 134 // Owned by QuicDispatcher. |
153 QuicCompressedCertsCache* compressed_certs_cache_; | 135 QuicCompressedCertsCache* compressed_certs_cache_; |
154 | 136 |
155 std::unique_ptr<QuicCryptoServerStreamBase> crypto_stream_; | 137 std::unique_ptr<QuicCryptoServerStreamBase> crypto_stream_; |
156 Visitor* visitor_; | 138 Visitor* visitor_; |
157 Helper* helper_; | 139 |
| 140 // Pointer to the helper used to create crypto server streams. Must outlive |
| 141 // streams created via CreateQuicCryptoServerStream. |
| 142 QuicCryptoServerStream::Helper* helper_; |
158 | 143 |
159 // Whether bandwidth resumption is enabled for this connection. | 144 // Whether bandwidth resumption is enabled for this connection. |
160 bool bandwidth_resumption_enabled_; | 145 bool bandwidth_resumption_enabled_; |
161 | 146 |
162 // The most recent bandwidth estimate sent to the client. | 147 // The most recent bandwidth estimate sent to the client. |
163 QuicBandwidth bandwidth_estimate_sent_to_client_; | 148 QuicBandwidth bandwidth_estimate_sent_to_client_; |
164 | 149 |
165 // Text describing server location. Sent to the client as part of the bandwith | 150 // Text describing server location. Sent to the client as part of the bandwith |
166 // estimate in the source-address token. Optional, can be left empty. | 151 // estimate in the source-address token. Optional, can be left empty. |
167 std::string serving_region_; | 152 std::string serving_region_; |
(...skipping 13 matching lines...) Expand all Loading... |
181 // Set during handshake. If true, resources in x-associated-content and link | 166 // Set during handshake. If true, resources in x-associated-content and link |
182 // headers will be pushed. see: go/gfe_server_push. | 167 // headers will be pushed. see: go/gfe_server_push. |
183 bool server_push_enabled_; | 168 bool server_push_enabled_; |
184 | 169 |
185 DISALLOW_COPY_AND_ASSIGN(QuicServerSessionBase); | 170 DISALLOW_COPY_AND_ASSIGN(QuicServerSessionBase); |
186 }; | 171 }; |
187 | 172 |
188 } // namespace net | 173 } // namespace net |
189 | 174 |
190 #endif // NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ | 175 #endif // NET_QUIC_QUIC_SERVER_SESSION_BASE_H_ |
OLD | NEW |