| 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_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_ | 5 #ifndef NET_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_ |
| 6 #define NET_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_ | 6 #define NET_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 public: | 28 public: |
| 29 SpdySM(SMConnection* connection, | 29 SpdySM(SMConnection* connection, |
| 30 SMInterface* sm_http_interface, | 30 SMInterface* sm_http_interface, |
| 31 EpollServer* epoll_server, | 31 EpollServer* epoll_server, |
| 32 MemoryCache* memory_cache, | 32 MemoryCache* memory_cache, |
| 33 FlipAcceptor* acceptor, | 33 FlipAcceptor* acceptor, |
| 34 SpdyMajorVersion spdy_version); | 34 SpdyMajorVersion spdy_version); |
| 35 virtual ~SpdySM(); | 35 virtual ~SpdySM(); |
| 36 | 36 |
| 37 virtual void InitSMInterface(SMInterface* sm_http_interface, | 37 virtual void InitSMInterface(SMInterface* sm_http_interface, |
| 38 int32 server_idx) OVERRIDE {} | 38 int32 server_idx) override {} |
| 39 | 39 |
| 40 virtual void InitSMConnection(SMConnectionPoolInterface* connection_pool, | 40 virtual void InitSMConnection(SMConnectionPoolInterface* connection_pool, |
| 41 SMInterface* sm_interface, | 41 SMInterface* sm_interface, |
| 42 EpollServer* epoll_server, | 42 EpollServer* epoll_server, |
| 43 int fd, | 43 int fd, |
| 44 std::string server_ip, | 44 std::string server_ip, |
| 45 std::string server_port, | 45 std::string server_port, |
| 46 std::string remote_ip, | 46 std::string remote_ip, |
| 47 bool use_ssl) OVERRIDE; | 47 bool use_ssl) override; |
| 48 | 48 |
| 49 // Create new SPDY framer after reusing SpdySM and negotiating new version | 49 // Create new SPDY framer after reusing SpdySM and negotiating new version |
| 50 void CreateFramer(SpdyMajorVersion spdy_version); | 50 void CreateFramer(SpdyMajorVersion spdy_version); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 virtual void set_is_request() OVERRIDE {} | 53 virtual void set_is_request() override {} |
| 54 SMInterface* NewConnectionInterface(); | 54 SMInterface* NewConnectionInterface(); |
| 55 // virtual for tests | 55 // virtual for tests |
| 56 virtual SMInterface* FindOrMakeNewSMConnectionInterface( | 56 virtual SMInterface* FindOrMakeNewSMConnectionInterface( |
| 57 const std::string& server_ip, | 57 const std::string& server_ip, |
| 58 const std::string& server_port); | 58 const std::string& server_port); |
| 59 int SpdyHandleNewStream(SpdyStreamId stream_id, | 59 int SpdyHandleNewStream(SpdyStreamId stream_id, |
| 60 SpdyPriority priority, | 60 SpdyPriority priority, |
| 61 const SpdyHeaderBlock& headers, | 61 const SpdyHeaderBlock& headers, |
| 62 std::string& http_data, | 62 std::string& http_data, |
| 63 bool* is_https_scheme); | 63 bool* is_https_scheme); |
| 64 | 64 |
| 65 // BufferedSpdyFramerVisitorInterface: | 65 // BufferedSpdyFramerVisitorInterface: |
| 66 virtual void OnError(SpdyFramer::SpdyError error_code) OVERRIDE {} | 66 virtual void OnError(SpdyFramer::SpdyError error_code) override {} |
| 67 virtual void OnStreamError(SpdyStreamId stream_id, | 67 virtual void OnStreamError(SpdyStreamId stream_id, |
| 68 const std::string& description) OVERRIDE {} | 68 const std::string& description) override {} |
| 69 // Called after all the header data for SYN_STREAM control frame is received. | 69 // Called after all the header data for SYN_STREAM control frame is received. |
| 70 virtual void OnSynStream(SpdyStreamId stream_id, | 70 virtual void OnSynStream(SpdyStreamId stream_id, |
| 71 SpdyStreamId associated_stream_id, | 71 SpdyStreamId associated_stream_id, |
| 72 SpdyPriority priority, | 72 SpdyPriority priority, |
| 73 bool fin, | 73 bool fin, |
| 74 bool unidirectional, | 74 bool unidirectional, |
| 75 const SpdyHeaderBlock& headers) OVERRIDE; | 75 const SpdyHeaderBlock& headers) override; |
| 76 | 76 |
| 77 // Called after all the header data for SYN_REPLY control frame is received. | 77 // Called after all the header data for SYN_REPLY control frame is received. |
| 78 virtual void OnSynReply(SpdyStreamId stream_id, | 78 virtual void OnSynReply(SpdyStreamId stream_id, |
| 79 bool fin, | 79 bool fin, |
| 80 const SpdyHeaderBlock& headers) OVERRIDE; | 80 const SpdyHeaderBlock& headers) override; |
| 81 | 81 |
| 82 // Called after all the header data for HEADERS control frame is received. | 82 // Called after all the header data for HEADERS control frame is received. |
| 83 virtual void OnHeaders(SpdyStreamId stream_id, | 83 virtual void OnHeaders(SpdyStreamId stream_id, |
| 84 bool fin, | 84 bool fin, |
| 85 const SpdyHeaderBlock& headers) OVERRIDE; | 85 const SpdyHeaderBlock& headers) override; |
| 86 | 86 |
| 87 // Called when data frame header is received. | 87 // Called when data frame header is received. |
| 88 virtual void OnDataFrameHeader(SpdyStreamId stream_id, | 88 virtual void OnDataFrameHeader(SpdyStreamId stream_id, |
| 89 size_t length, | 89 size_t length, |
| 90 bool fin) OVERRIDE {} | 90 bool fin) override {} |
| 91 | 91 |
| 92 // Called when data is received. | 92 // Called when data is received. |
| 93 // |stream_id| The stream receiving data. | 93 // |stream_id| The stream receiving data. |
| 94 // |data| A buffer containing the data received. | 94 // |data| A buffer containing the data received. |
| 95 // |len| The length of the data buffer. | 95 // |len| The length of the data buffer. |
| 96 // When the other side has finished sending data on this stream, | 96 // When the other side has finished sending data on this stream, |
| 97 // this method will be called with a zero-length buffer. | 97 // this method will be called with a zero-length buffer. |
| 98 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 98 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
| 99 const char* data, | 99 const char* data, |
| 100 size_t len, | 100 size_t len, |
| 101 bool fin) OVERRIDE; | 101 bool fin) override; |
| 102 | 102 |
| 103 // Called when a SETTINGS frame is received. | 103 // Called when a SETTINGS frame is received. |
| 104 // |clear_persisted| True if the respective flag is set on the SETTINGS frame. | 104 // |clear_persisted| True if the respective flag is set on the SETTINGS frame. |
| 105 virtual void OnSettings(bool clear_persisted) OVERRIDE {} | 105 virtual void OnSettings(bool clear_persisted) override {} |
| 106 | 106 |
| 107 // Called when an individual setting within a SETTINGS frame has been parsed | 107 // Called when an individual setting within a SETTINGS frame has been parsed |
| 108 // and validated. | 108 // and validated. |
| 109 virtual void OnSetting(SpdySettingsIds id, | 109 virtual void OnSetting(SpdySettingsIds id, |
| 110 uint8 flags, | 110 uint8 flags, |
| 111 uint32 value) OVERRIDE {} | 111 uint32 value) override {} |
| 112 | 112 |
| 113 // Called when a PING frame has been parsed. | 113 // Called when a PING frame has been parsed. |
| 114 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE {} | 114 virtual void OnPing(SpdyPingId unique_id, bool is_ack) override {} |
| 115 | 115 |
| 116 // Called when a RST_STREAM frame has been parsed. | 116 // Called when a RST_STREAM frame has been parsed. |
| 117 virtual void OnRstStream(SpdyStreamId stream_id, | 117 virtual void OnRstStream(SpdyStreamId stream_id, |
| 118 SpdyRstStreamStatus status) OVERRIDE; | 118 SpdyRstStreamStatus status) override; |
| 119 | 119 |
| 120 // Called when a GOAWAY frame has been parsed. | 120 // Called when a GOAWAY frame has been parsed. |
| 121 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, | 121 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, |
| 122 SpdyGoAwayStatus status) OVERRIDE {} | 122 SpdyGoAwayStatus status) override {} |
| 123 | 123 |
| 124 // Called when a WINDOW_UPDATE frame has been parsed. | 124 // Called when a WINDOW_UPDATE frame has been parsed. |
| 125 virtual void OnWindowUpdate(SpdyStreamId stream_id, | 125 virtual void OnWindowUpdate(SpdyStreamId stream_id, |
| 126 uint32 delta_window_size) OVERRIDE {} | 126 uint32 delta_window_size) override {} |
| 127 | 127 |
| 128 // Called when a PUSH_PROMISE frame has been parsed. | 128 // Called when a PUSH_PROMISE frame has been parsed. |
| 129 virtual void OnPushPromise(SpdyStreamId stream_id, | 129 virtual void OnPushPromise(SpdyStreamId stream_id, |
| 130 SpdyStreamId promised_stream_id, | 130 SpdyStreamId promised_stream_id, |
| 131 const SpdyHeaderBlock& headers) OVERRIDE {} | 131 const SpdyHeaderBlock& headers) override {} |
| 132 | 132 |
| 133 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) OVERRIDE; | 133 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) override; |
| 134 | 134 |
| 135 public: | 135 public: |
| 136 virtual size_t ProcessReadInput(const char* data, size_t len) OVERRIDE; | 136 virtual size_t ProcessReadInput(const char* data, size_t len) override; |
| 137 virtual size_t ProcessWriteInput(const char* data, size_t len) OVERRIDE; | 137 virtual size_t ProcessWriteInput(const char* data, size_t len) override; |
| 138 virtual bool MessageFullyRead() const OVERRIDE; | 138 virtual bool MessageFullyRead() const override; |
| 139 virtual void SetStreamID(uint32 stream_id) OVERRIDE {} | 139 virtual void SetStreamID(uint32 stream_id) override {} |
| 140 virtual bool Error() const OVERRIDE; | 140 virtual bool Error() const override; |
| 141 virtual const char* ErrorAsString() const OVERRIDE; | 141 virtual const char* ErrorAsString() const override; |
| 142 virtual void Reset() OVERRIDE {} | 142 virtual void Reset() override {} |
| 143 virtual void ResetForNewInterface(int32 server_idx) OVERRIDE; | 143 virtual void ResetForNewInterface(int32 server_idx) override; |
| 144 virtual void ResetForNewConnection() OVERRIDE; | 144 virtual void ResetForNewConnection() override; |
| 145 // SMInterface's Cleanup is currently only called by SMConnection after a | 145 // SMInterface's Cleanup is currently only called by SMConnection after a |
| 146 // protocol message as been fully read. Spdy's SMInterface does not need | 146 // protocol message as been fully read. Spdy's SMInterface does not need |
| 147 // to do any cleanup at this time. | 147 // to do any cleanup at this time. |
| 148 // TODO(klindsay) This method is probably not being used properly and | 148 // TODO(klindsay) This method is probably not being used properly and |
| 149 // some logic review and method renaming is probably in order. | 149 // some logic review and method renaming is probably in order. |
| 150 virtual void Cleanup() OVERRIDE {} | 150 virtual void Cleanup() override {} |
| 151 // Send a settings frame | 151 // Send a settings frame |
| 152 virtual int PostAcceptHook() OVERRIDE; | 152 virtual int PostAcceptHook() override; |
| 153 virtual void NewStream(uint32 stream_id, | 153 virtual void NewStream(uint32 stream_id, |
| 154 uint32 priority, | 154 uint32 priority, |
| 155 const std::string& filename) OVERRIDE; | 155 const std::string& filename) override; |
| 156 void AddToOutputOrder(const MemCacheIter& mci); | 156 void AddToOutputOrder(const MemCacheIter& mci); |
| 157 virtual void SendEOF(uint32 stream_id) OVERRIDE; | 157 virtual void SendEOF(uint32 stream_id) override; |
| 158 virtual void SendErrorNotFound(uint32 stream_id) OVERRIDE; | 158 virtual void SendErrorNotFound(uint32 stream_id) override; |
| 159 virtual size_t SendSynStream(uint32 stream_id, | 159 virtual size_t SendSynStream(uint32 stream_id, |
| 160 const BalsaHeaders& headers) OVERRIDE; | 160 const BalsaHeaders& headers) override; |
| 161 virtual size_t SendSynReply(uint32 stream_id, | 161 virtual size_t SendSynReply(uint32 stream_id, |
| 162 const BalsaHeaders& headers) OVERRIDE; | 162 const BalsaHeaders& headers) override; |
| 163 virtual void SendDataFrame(uint32 stream_id, | 163 virtual void SendDataFrame(uint32 stream_id, |
| 164 const char* data, | 164 const char* data, |
| 165 int64 len, | 165 int64 len, |
| 166 uint32 flags, | 166 uint32 flags, |
| 167 bool compress) OVERRIDE; | 167 bool compress) override; |
| 168 BufferedSpdyFramer* spdy_framer() { return buffered_spdy_framer_.get(); } | 168 BufferedSpdyFramer* spdy_framer() { return buffered_spdy_framer_.get(); } |
| 169 | 169 |
| 170 const OutputOrdering& output_ordering() const { | 170 const OutputOrdering& output_ordering() const { |
| 171 return client_output_ordering_; | 171 return client_output_ordering_; |
| 172 } | 172 } |
| 173 | 173 |
| 174 static std::string forward_ip_header() { return forward_ip_header_; } | 174 static std::string forward_ip_header() { return forward_ip_header_; } |
| 175 static void set_forward_ip_header(const std::string& value) { | 175 static void set_forward_ip_header(const std::string& value) { |
| 176 forward_ip_header_ = value; | 176 forward_ip_header_ = value; |
| 177 } | 177 } |
| 178 SpdyMajorVersion spdy_version() const { | 178 SpdyMajorVersion spdy_version() const { |
| 179 DCHECK(buffered_spdy_framer_); | 179 DCHECK(buffered_spdy_framer_); |
| 180 return buffered_spdy_framer_->protocol_version(); | 180 return buffered_spdy_framer_->protocol_version(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 void SendEOFImpl(uint32 stream_id); | 184 void SendEOFImpl(uint32 stream_id); |
| 185 void SendErrorNotFoundImpl(uint32 stream_id); | 185 void SendErrorNotFoundImpl(uint32 stream_id); |
| 186 void KillStream(uint32 stream_id); | 186 void KillStream(uint32 stream_id); |
| 187 void CopyHeaders(SpdyHeaderBlock& dest, const BalsaHeaders& headers); | 187 void CopyHeaders(SpdyHeaderBlock& dest, const BalsaHeaders& headers); |
| 188 size_t SendSynStreamImpl(uint32 stream_id, const BalsaHeaders& headers); | 188 size_t SendSynStreamImpl(uint32 stream_id, const BalsaHeaders& headers); |
| 189 size_t SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers); | 189 size_t SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers); |
| 190 void SendDataFrameImpl(uint32 stream_id, | 190 void SendDataFrameImpl(uint32 stream_id, |
| 191 const char* data, | 191 const char* data, |
| 192 int64 len, | 192 int64 len, |
| 193 SpdyDataFlags flags, | 193 SpdyDataFlags flags, |
| 194 bool compress); | 194 bool compress); |
| 195 void EnqueueDataFrame(DataFrame* df); | 195 void EnqueueDataFrame(DataFrame* df); |
| 196 virtual void GetOutput() OVERRIDE; | 196 virtual void GetOutput() override; |
| 197 | 197 |
| 198 private: | 198 private: |
| 199 scoped_ptr<BufferedSpdyFramer> buffered_spdy_framer_; | 199 scoped_ptr<BufferedSpdyFramer> buffered_spdy_framer_; |
| 200 bool valid_spdy_session_; // True if we have seen valid data on this session. | 200 bool valid_spdy_session_; // True if we have seen valid data on this session. |
| 201 // Use this to fail fast when junk is sent to our | 201 // Use this to fail fast when junk is sent to our |
| 202 // port. | 202 // port. |
| 203 | 203 |
| 204 SMConnection* connection_; | 204 SMConnection* connection_; |
| 205 OutputList* client_output_list_; | 205 OutputList* client_output_list_; |
| 206 OutputOrdering client_output_ordering_; | 206 OutputOrdering client_output_ordering_; |
| 207 uint32 next_outgoing_stream_id_; | 207 uint32 next_outgoing_stream_id_; |
| 208 EpollServer* epoll_server_; | 208 EpollServer* epoll_server_; |
| 209 FlipAcceptor* acceptor_; | 209 FlipAcceptor* acceptor_; |
| 210 MemoryCache* memory_cache_; | 210 MemoryCache* memory_cache_; |
| 211 std::vector<SMInterface*> server_interface_list; | 211 std::vector<SMInterface*> server_interface_list; |
| 212 std::vector<int32> unused_server_interface_list; | 212 std::vector<int32> unused_server_interface_list; |
| 213 typedef std::map<uint32, SMInterface*> StreamToSmif; | 213 typedef std::map<uint32, SMInterface*> StreamToSmif; |
| 214 StreamToSmif stream_to_smif_; | 214 StreamToSmif stream_to_smif_; |
| 215 bool close_on_error_; | 215 bool close_on_error_; |
| 216 | 216 |
| 217 static std::string forward_ip_header_; | 217 static std::string forward_ip_header_; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 } // namespace net | 220 } // namespace net |
| 221 | 221 |
| 222 #endif // NET_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_ | 222 #endif // NET_TOOLS_FLIP_SERVER_SPDY_INTERFACE_H_ |
| OLD | NEW |