| 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_FRAMER_H_ | 5 #ifndef NET_SPDY_SPDY_FRAMER_H_ |
| 6 #define NET_SPDY_SPDY_FRAMER_H_ | 6 #define NET_SPDY_SPDY_FRAMER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // resource exhaustion). If this occurs the framer will discontinue | 91 // resource exhaustion). If this occurs the framer will discontinue |
| 92 // delivering chunks to the visitor, set a SPDY_CONTROL_PAYLOAD_TOO_LARGE | 92 // delivering chunks to the visitor, set a SPDY_CONTROL_PAYLOAD_TOO_LARGE |
| 93 // error, and clean up appropriately. Note that this will cause the header | 93 // error, and clean up appropriately. Note that this will cause the header |
| 94 // decompressor to lose synchronization with the sender's header compressor, | 94 // decompressor to lose synchronization with the sender's header compressor, |
| 95 // making the SPDY session unusable for future work. The visitor's OnError | 95 // making the SPDY session unusable for future work. The visitor's OnError |
| 96 // function should deal with this condition by closing the SPDY connection. | 96 // function should deal with this condition by closing the SPDY connection. |
| 97 class NET_EXPORT_PRIVATE SpdyFramerVisitorInterface { | 97 class NET_EXPORT_PRIVATE SpdyFramerVisitorInterface { |
| 98 public: | 98 public: |
| 99 virtual ~SpdyFramerVisitorInterface() {} | 99 virtual ~SpdyFramerVisitorInterface() {} |
| 100 | 100 |
| 101 // Called if an error is detected in the SpdyFrame protocol. | 101 // Called if an error is detected in the SpdySerializedFrame protocol. |
| 102 virtual void OnError(SpdyFramer* framer) = 0; | 102 virtual void OnError(SpdyFramer* framer) = 0; |
| 103 | 103 |
| 104 // Called when a data frame header is received. The frame's data | 104 // Called when a data frame header is received. The frame's data |
| 105 // payload will be provided via subsequent calls to | 105 // payload will be provided via subsequent calls to |
| 106 // OnStreamFrameData(). | 106 // OnStreamFrameData(). |
| 107 virtual void OnDataFrameHeader(SpdyStreamId stream_id, | 107 virtual void OnDataFrameHeader(SpdyStreamId stream_id, |
| 108 size_t length, | 108 size_t length, |
| 109 bool fin) = 0; | 109 bool fin) = 0; |
| 110 | 110 |
| 111 // Called when data is received. | 111 // Called when data is received. |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 406 |
| 407 // Given a buffer containing a decompressed header block in SPDY | 407 // Given a buffer containing a decompressed header block in SPDY |
| 408 // serialized format, parse out a SpdyHeaderBlock, putting the results | 408 // serialized format, parse out a SpdyHeaderBlock, putting the results |
| 409 // in the given header block. | 409 // in the given header block. |
| 410 // Returns true if successfully parsed, false otherwise. | 410 // Returns true if successfully parsed, false otherwise. |
| 411 bool ParseHeaderBlockInBuffer(const char* header_data, | 411 bool ParseHeaderBlockInBuffer(const char* header_data, |
| 412 size_t header_length, | 412 size_t header_length, |
| 413 SpdyHeaderBlock* block) const; | 413 SpdyHeaderBlock* block) const; |
| 414 | 414 |
| 415 // Serialize a data frame. | 415 // Serialize a data frame. |
| 416 SpdySerializedFrame* SerializeData(const SpdyDataIR& data) const; | 416 SpdySerializedFrame SerializeData(const SpdyDataIR& data) const; |
| 417 // Serializes the data frame header and optionally padding length fields, | 417 // Serializes the data frame header and optionally padding length fields, |
| 418 // excluding actual data payload and padding. | 418 // excluding actual data payload and padding. |
| 419 SpdySerializedFrame* SerializeDataFrameHeaderWithPaddingLengthField( | 419 SpdySerializedFrame SerializeDataFrameHeaderWithPaddingLengthField( |
| 420 const SpdyDataIR& data) const; | 420 const SpdyDataIR& data) const; |
| 421 | 421 |
| 422 // Serializes a SYN_STREAM frame. | 422 // Serializes a SYN_STREAM frame. |
| 423 SpdySerializedFrame* SerializeSynStream(const SpdySynStreamIR& syn_stream); | 423 SpdySerializedFrame SerializeSynStream(const SpdySynStreamIR& syn_stream); |
| 424 | 424 |
| 425 // Serialize a SYN_REPLY SpdyFrame. | 425 // Serialize a SYN_REPLY frame. |
| 426 SpdySerializedFrame* SerializeSynReply(const SpdySynReplyIR& syn_reply); | 426 SpdySerializedFrame SerializeSynReply(const SpdySynReplyIR& syn_reply); |
| 427 | 427 |
| 428 SpdySerializedFrame* SerializeRstStream( | 428 SpdySerializedFrame SerializeRstStream( |
| 429 const SpdyRstStreamIR& rst_stream) const; | 429 const SpdyRstStreamIR& rst_stream) const; |
| 430 | 430 |
| 431 // Serializes a SETTINGS frame. The SETTINGS frame is | 431 // Serializes a SETTINGS frame. The SETTINGS frame is |
| 432 // used to communicate name/value pairs relevant to the communication channel. | 432 // used to communicate name/value pairs relevant to the communication channel. |
| 433 SpdySerializedFrame* SerializeSettings(const SpdySettingsIR& settings) const; | 433 SpdySerializedFrame SerializeSettings(const SpdySettingsIR& settings) const; |
| 434 | 434 |
| 435 // Serializes a PING frame. The unique_id is used to | 435 // Serializes a PING frame. The unique_id is used to |
| 436 // identify the ping request/response. | 436 // identify the ping request/response. |
| 437 SpdySerializedFrame* SerializePing(const SpdyPingIR& ping) const; | 437 SpdySerializedFrame SerializePing(const SpdyPingIR& ping) const; |
| 438 | 438 |
| 439 // Serializes a GOAWAY frame. The GOAWAY frame is used | 439 // Serializes a GOAWAY frame. The GOAWAY frame is used |
| 440 // prior to the shutting down of the TCP connection, and includes the | 440 // prior to the shutting down of the TCP connection, and includes the |
| 441 // stream_id of the last stream the sender of the frame is willing to process | 441 // stream_id of the last stream the sender of the frame is willing to process |
| 442 // to completion. | 442 // to completion. |
| 443 SpdySerializedFrame* SerializeGoAway(const SpdyGoAwayIR& goaway) const; | 443 SpdySerializedFrame SerializeGoAway(const SpdyGoAwayIR& goaway) const; |
| 444 | 444 |
| 445 // Serializes a HEADERS frame. The HEADERS frame is used | 445 // Serializes a HEADERS frame. The HEADERS frame is used |
| 446 // for sending additional headers outside of a SYN_STREAM/SYN_REPLY. | 446 // for sending additional headers outside of a SYN_STREAM/SYN_REPLY. |
| 447 SpdySerializedFrame* SerializeHeaders(const SpdyHeadersIR& headers); | 447 SpdySerializedFrame SerializeHeaders(const SpdyHeadersIR& headers); |
| 448 | 448 |
| 449 // Serializes a WINDOW_UPDATE frame. The WINDOW_UPDATE | 449 // Serializes a WINDOW_UPDATE frame. The WINDOW_UPDATE |
| 450 // frame is used to implement per stream flow control in SPDY. | 450 // frame is used to implement per stream flow control in SPDY. |
| 451 SpdySerializedFrame* SerializeWindowUpdate( | 451 SpdySerializedFrame SerializeWindowUpdate( |
| 452 const SpdyWindowUpdateIR& window_update) const; | 452 const SpdyWindowUpdateIR& window_update) const; |
| 453 | 453 |
| 454 // Serializes a BLOCKED frame. The BLOCKED frame is used to | 454 // Serializes a BLOCKED frame. The BLOCKED frame is used to |
| 455 // indicate to the remote endpoint that this endpoint believes itself to be | 455 // indicate to the remote endpoint that this endpoint believes itself to be |
| 456 // flow-control blocked but otherwise ready to send data. The BLOCKED frame | 456 // flow-control blocked but otherwise ready to send data. The BLOCKED frame |
| 457 // is purely advisory and optional. | 457 // is purely advisory and optional. |
| 458 SpdySerializedFrame* SerializeBlocked(const SpdyBlockedIR& blocked) const; | 458 SpdySerializedFrame SerializeBlocked(const SpdyBlockedIR& blocked) const; |
| 459 | 459 |
| 460 // Serializes a PUSH_PROMISE frame. The PUSH_PROMISE frame is used | 460 // Serializes a PUSH_PROMISE frame. The PUSH_PROMISE frame is used |
| 461 // to inform the client that it will be receiving an additional stream | 461 // to inform the client that it will be receiving an additional stream |
| 462 // in response to the original request. The frame includes synthesized | 462 // in response to the original request. The frame includes synthesized |
| 463 // headers to explain the upcoming data. | 463 // headers to explain the upcoming data. |
| 464 SpdySerializedFrame* SerializePushPromise( | 464 SpdySerializedFrame SerializePushPromise( |
| 465 const SpdyPushPromiseIR& push_promise); | 465 const SpdyPushPromiseIR& push_promise); |
| 466 | 466 |
| 467 // Serializes a CONTINUATION frame. The CONTINUATION frame is used | 467 // Serializes a CONTINUATION frame. The CONTINUATION frame is used |
| 468 // to continue a sequence of header block fragments. | 468 // to continue a sequence of header block fragments. |
| 469 // TODO(jgraettinger): This implementation is incorrect. The continuation | 469 // TODO(jgraettinger): This implementation is incorrect. The continuation |
| 470 // frame continues a previously-begun HPACK encoding; it doesn't begin a | 470 // frame continues a previously-begun HPACK encoding; it doesn't begin a |
| 471 // new one. Figure out whether it makes sense to keep SerializeContinuation(). | 471 // new one. Figure out whether it makes sense to keep SerializeContinuation(). |
| 472 SpdySerializedFrame* SerializeContinuation( | 472 SpdySerializedFrame SerializeContinuation( |
| 473 const SpdyContinuationIR& continuation); | 473 const SpdyContinuationIR& continuation); |
| 474 | 474 |
| 475 // Serializes an ALTSVC frame. The ALTSVC frame advertises the | 475 // Serializes an ALTSVC frame. The ALTSVC frame advertises the |
| 476 // availability of an alternative service to the client. | 476 // availability of an alternative service to the client. |
| 477 SpdySerializedFrame* SerializeAltSvc(const SpdyAltSvcIR& altsvc); | 477 SpdySerializedFrame SerializeAltSvc(const SpdyAltSvcIR& altsvc); |
| 478 | 478 |
| 479 // Serializes a PRIORITY frame. The PRIORITY frame advises a change in | 479 // Serializes a PRIORITY frame. The PRIORITY frame advises a change in |
| 480 // the relative priority of the given stream. | 480 // the relative priority of the given stream. |
| 481 SpdySerializedFrame* SerializePriority(const SpdyPriorityIR& priority) const; | 481 SpdySerializedFrame SerializePriority(const SpdyPriorityIR& priority) const; |
| 482 | 482 |
| 483 // Serialize a frame of unknown type. | 483 // Serialize a frame of unknown type. |
| 484 SpdySerializedFrame* SerializeFrame(const SpdyFrameIR& frame); | 484 SpdySerializedFrame SerializeFrame(const SpdyFrameIR& frame); |
| 485 | 485 |
| 486 // NOTES about frame compression. | 486 // NOTES about frame compression. |
| 487 // We want spdy to compress headers across the entire session. As long as | 487 // We want spdy to compress headers across the entire session. As long as |
| 488 // the session is over TCP, frames are sent serially. The client & server | 488 // the session is over TCP, frames are sent serially. The client & server |
| 489 // can each compress frames in the same order and then compress them in that | 489 // can each compress frames in the same order and then compress them in that |
| 490 // order, and the remote can do the reverse. However, we ultimately want | 490 // order, and the remote can do the reverse. However, we ultimately want |
| 491 // the creation of frames to be less sensitive to order so that they can be | 491 // the creation of frames to be less sensitive to order so that they can be |
| 492 // placed over a UDP based protocol and yet still benefit from some | 492 // placed over a UDP based protocol and yet still benefit from some |
| 493 // compression. We don't know of any good compression protocol which does | 493 // compression. We don't know of any good compression protocol which does |
| 494 // not build its state in a serial (stream based) manner.... For now, we're | 494 // not build its state in a serial (stream based) manner.... For now, we're |
| 495 // using zlib anyway. | 495 // using zlib anyway. |
| 496 | 496 |
| 497 // Compresses a SpdyFrame. | |
| 498 // On success, returns a new SpdyFrame with the payload compressed. | |
| 499 // Compression state is maintained as part of the SpdyFramer. | |
| 500 // Returned frame must be freed with "delete". | |
| 501 // On failure, returns NULL. | |
| 502 SpdyFrame* CompressFrame(const SpdyFrame& frame); | |
| 503 | |
| 504 // For ease of testing and experimentation we can tweak compression on/off. | 497 // For ease of testing and experimentation we can tweak compression on/off. |
| 505 void set_enable_compression(bool value) { | 498 void set_enable_compression(bool value) { |
| 506 enable_compression_ = value; | 499 enable_compression_ = value; |
| 507 } | 500 } |
| 508 | 501 |
| 509 // Used only in log messages. | 502 // Used only in log messages. |
| 510 void set_display_protocol(const std::string& protocol) { | 503 void set_display_protocol(const std::string& protocol) { |
| 511 display_protocol_ = protocol; | 504 display_protocol_ = protocol; |
| 512 } | 505 } |
| 513 | 506 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 | 791 |
| 799 // Latched value of --FLAGS_spdy_on_stream_end. | 792 // Latched value of --FLAGS_spdy_on_stream_end. |
| 800 // If true, OnStreamEnd will be called instead of the sentinel call of | 793 // If true, OnStreamEnd will be called instead of the sentinel call of |
| 801 // OnStreamFrameData(stream_id, nullptr, 0, true) | 794 // OnStreamFrameData(stream_id, nullptr, 0, true) |
| 802 bool spdy_on_stream_end_; | 795 bool spdy_on_stream_end_; |
| 803 }; | 796 }; |
| 804 | 797 |
| 805 } // namespace net | 798 } // namespace net |
| 806 | 799 |
| 807 #endif // NET_SPDY_SPDY_FRAMER_H_ | 800 #endif // NET_SPDY_SPDY_FRAMER_H_ |
| OLD | NEW |