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