netwerk/protocol/http/SpdyStream3.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef mozilla_net_SpdyStream3_h
michael@0 7 #define mozilla_net_SpdyStream3_h
michael@0 8
michael@0 9 #include "nsAHttpTransaction.h"
michael@0 10 #include "zlib.h"
michael@0 11
michael@0 12 class nsISocketTransport;
michael@0 13
michael@0 14 namespace mozilla { namespace net {
michael@0 15
michael@0 16 class SpdySession3;
michael@0 17 class SpdyPushedStream3;
michael@0 18
michael@0 19 class SpdyStream3 : public nsAHttpSegmentReader
michael@0 20 , public nsAHttpSegmentWriter
michael@0 21 {
michael@0 22 public:
michael@0 23 NS_DECL_NSAHTTPSEGMENTREADER
michael@0 24 NS_DECL_NSAHTTPSEGMENTWRITER
michael@0 25
michael@0 26 SpdyStream3(nsAHttpTransaction *, SpdySession3 *, int32_t);
michael@0 27
michael@0 28 uint32_t StreamID() { return mStreamID; }
michael@0 29 SpdyPushedStream3 *PushSource() { return mPushSource; }
michael@0 30
michael@0 31 virtual nsresult ReadSegments(nsAHttpSegmentReader *, uint32_t, uint32_t *);
michael@0 32 virtual nsresult WriteSegments(nsAHttpSegmentWriter *, uint32_t, uint32_t *);
michael@0 33 virtual bool DeferCleanupOnSuccess() { return false; }
michael@0 34
michael@0 35 const nsAFlatCString &Origin() const { return mOrigin; }
michael@0 36
michael@0 37 bool RequestBlockedOnRead()
michael@0 38 {
michael@0 39 return static_cast<bool>(mRequestBlockedOnRead);
michael@0 40 }
michael@0 41
michael@0 42 // returns false if called more than once
michael@0 43 bool GetFullyOpen() {return mFullyOpen;}
michael@0 44 void SetFullyOpen()
michael@0 45 {
michael@0 46 MOZ_ASSERT(!mFullyOpen);
michael@0 47 mFullyOpen = 1;
michael@0 48 }
michael@0 49
michael@0 50 bool HasRegisteredID() { return mStreamID != 0; }
michael@0 51
michael@0 52 nsAHttpTransaction *Transaction() { return mTransaction; }
michael@0 53 virtual nsILoadGroupConnectionInfo *LoadGroupConnectionInfo()
michael@0 54 {
michael@0 55 return mTransaction ? mTransaction->LoadGroupConnectionInfo() : nullptr;
michael@0 56 }
michael@0 57
michael@0 58 void Close(nsresult reason);
michael@0 59
michael@0 60 void SetRecvdFin(bool aStatus) { mRecvdFin = aStatus ? 1 : 0; }
michael@0 61 bool RecvdFin() { return mRecvdFin; }
michael@0 62
michael@0 63 void SetRecvdData(bool aStatus) { mReceivedData = aStatus ? 1 : 0; }
michael@0 64 bool RecvdData() { return mReceivedData; }
michael@0 65
michael@0 66 void UpdateTransportSendEvents(uint32_t count);
michael@0 67 void UpdateTransportReadEvents(uint32_t count);
michael@0 68
michael@0 69 // The zlib header compression dictionary defined by SPDY.
michael@0 70 static const unsigned char kDictionary[1423];
michael@0 71
michael@0 72 nsresult Uncompress(z_stream *, char *, uint32_t);
michael@0 73 nsresult ConvertHeaders(nsACString &);
michael@0 74
michael@0 75 void UpdateRemoteWindow(int32_t delta);
michael@0 76 int64_t RemoteWindow() { return mRemoteWindow; }
michael@0 77
michael@0 78 void DecrementLocalWindow(uint32_t delta) {
michael@0 79 mLocalWindow -= delta;
michael@0 80 mLocalUnacked += delta;
michael@0 81 }
michael@0 82
michael@0 83 void IncrementLocalWindow(uint32_t delta) {
michael@0 84 mLocalWindow += delta;
michael@0 85 mLocalUnacked -= delta;
michael@0 86 }
michael@0 87
michael@0 88 uint64_t LocalUnAcked() { return mLocalUnacked; }
michael@0 89 int64_t LocalWindow() { return mLocalWindow; }
michael@0 90
michael@0 91 bool BlockedOnRwin() { return mBlockedOnRwin; }
michael@0 92
michael@0 93 // A pull stream has an implicit sink, a pushed stream has a sink
michael@0 94 // once it is matched to a pull stream.
michael@0 95 virtual bool HasSink() { return true; }
michael@0 96
michael@0 97 virtual ~SpdyStream3();
michael@0 98
michael@0 99 protected:
michael@0 100 nsresult FindHeader(nsCString, nsDependentCSubstring &);
michael@0 101
michael@0 102 static void CreatePushHashKey(const nsCString &scheme,
michael@0 103 const nsCString &hostHeader,
michael@0 104 uint64_t serial,
michael@0 105 const nsCSubstring &pathInfo,
michael@0 106 nsCString &outOrigin,
michael@0 107 nsCString &outKey);
michael@0 108
michael@0 109 enum stateType {
michael@0 110 GENERATING_SYN_STREAM,
michael@0 111 GENERATING_REQUEST_BODY,
michael@0 112 SENDING_REQUEST_BODY,
michael@0 113 SENDING_FIN_STREAM,
michael@0 114 UPSTREAM_COMPLETE
michael@0 115 };
michael@0 116
michael@0 117 uint32_t mStreamID;
michael@0 118
michael@0 119 // The session that this stream is a subset of
michael@0 120 SpdySession3 *mSession;
michael@0 121
michael@0 122 nsCString mOrigin;
michael@0 123
michael@0 124 // Each stream goes from syn_stream to upstream_complete, perhaps
michael@0 125 // looping on multiple instances of generating_request_body and
michael@0 126 // sending_request_body for each SPDY chunk in the upload.
michael@0 127 enum stateType mUpstreamState;
michael@0 128
michael@0 129 // Flag is set when all http request headers have been read and ID is stable
michael@0 130 uint32_t mSynFrameComplete : 1;
michael@0 131
michael@0 132 // Flag is set when a FIN has been placed on a data or syn packet
michael@0 133 // (i.e after the client has closed)
michael@0 134 uint32_t mSentFinOnData : 1;
michael@0 135
michael@0 136 void ChangeState(enum stateType);
michael@0 137
michael@0 138 private:
michael@0 139 friend class nsAutoPtr<SpdyStream3>;
michael@0 140
michael@0 141 static PLDHashOperator hdrHashEnumerate(const nsACString &,
michael@0 142 nsAutoPtr<nsCString> &,
michael@0 143 void *);
michael@0 144
michael@0 145 nsresult ParseHttpRequestHeaders(const char *, uint32_t, uint32_t *);
michael@0 146 void AdjustInitialWindow();
michael@0 147 nsresult TransmitFrame(const char *, uint32_t *, bool forceCommitment);
michael@0 148 void GenerateDataFrameHeader(uint32_t, bool);
michael@0 149
michael@0 150 void CompressToFrame(const nsACString &);
michael@0 151 void CompressToFrame(const nsACString *);
michael@0 152 void CompressToFrame(const char *, uint32_t);
michael@0 153 void CompressToFrame(uint32_t);
michael@0 154 void CompressFlushFrame();
michael@0 155 void ExecuteCompress(uint32_t);
michael@0 156
michael@0 157 // The underlying HTTP transaction. This pointer is used as the key
michael@0 158 // in the SpdySession3 mStreamTransactionHash so it is important to
michael@0 159 // keep a reference to it as long as this stream is a member of that hash.
michael@0 160 // (i.e. don't change it or release it after it is set in the ctor).
michael@0 161 nsRefPtr<nsAHttpTransaction> mTransaction;
michael@0 162
michael@0 163 // The underlying socket transport object is needed to propogate some events
michael@0 164 nsISocketTransport *mSocketTransport;
michael@0 165
michael@0 166 // These are temporary state variables to hold the argument to
michael@0 167 // Read/WriteSegments so it can be accessed by On(read/write)segment
michael@0 168 // further up the stack.
michael@0 169 nsAHttpSegmentReader *mSegmentReader;
michael@0 170 nsAHttpSegmentWriter *mSegmentWriter;
michael@0 171
michael@0 172 // The quanta upstream data frames are chopped into
michael@0 173 uint32_t mChunkSize;
michael@0 174
michael@0 175 // Flag is set when the HTTP processor has more data to send
michael@0 176 // but has blocked in doing so.
michael@0 177 uint32_t mRequestBlockedOnRead : 1;
michael@0 178
michael@0 179 // Flag is set after the response frame bearing the fin bit has
michael@0 180 // been processed. (i.e. after the server has closed).
michael@0 181 uint32_t mRecvdFin : 1;
michael@0 182
michael@0 183 // Flag is set after syn reply received
michael@0 184 uint32_t mFullyOpen : 1;
michael@0 185
michael@0 186 // Flag is set after the WAITING_FOR Transport event has been generated
michael@0 187 uint32_t mSentWaitingFor : 1;
michael@0 188
michael@0 189 // Flag is set after 1st DATA frame has been passed to stream, after
michael@0 190 // which additional HEADERS data is invalid
michael@0 191 uint32_t mReceivedData : 1;
michael@0 192
michael@0 193 // Flag is set after TCP send autotuning has been disabled
michael@0 194 uint32_t mSetTCPSocketBuffer : 1;
michael@0 195
michael@0 196 // The InlineFrame and associated data is used for composing control
michael@0 197 // frames and data frame headers.
michael@0 198 nsAutoArrayPtr<uint8_t> mTxInlineFrame;
michael@0 199 uint32_t mTxInlineFrameSize;
michael@0 200 uint32_t mTxInlineFrameUsed;
michael@0 201
michael@0 202 // mTxStreamFrameSize tracks the progress of
michael@0 203 // transmitting a request body data frame. The data frame itself
michael@0 204 // is never copied into the spdy layer.
michael@0 205 uint32_t mTxStreamFrameSize;
michael@0 206
michael@0 207 // Compression context and buffer for request header compression.
michael@0 208 // This is a copy of SpdySession3::mUpstreamZlib because it needs
michael@0 209 // to remain the same in all streams of a session.
michael@0 210 z_stream *mZlib;
michael@0 211 nsCString mFlatHttpRequestHeaders;
michael@0 212
michael@0 213 // These are used for decompressing downstream spdy response headers
michael@0 214 uint32_t mDecompressBufferSize;
michael@0 215 uint32_t mDecompressBufferUsed;
michael@0 216 uint32_t mDecompressedBytes;
michael@0 217 nsAutoArrayPtr<char> mDecompressBuffer;
michael@0 218
michael@0 219 // Track the content-length of a request body so that we can
michael@0 220 // place the fin flag on the last data packet instead of waiting
michael@0 221 // for a stream closed indication. Relying on stream close results
michael@0 222 // in an extra 0-length runt packet and seems to have some interop
michael@0 223 // problems with the google servers.
michael@0 224 int64_t mRequestBodyLenRemaining;
michael@0 225
michael@0 226 // based on nsISupportsPriority definitions
michael@0 227 int32_t mPriority;
michael@0 228
michael@0 229 // mLocalWindow, mRemoteWindow, and mLocalUnacked are for flow control.
michael@0 230 // *window are signed because they race conditions in asynchronous SETTINGS
michael@0 231 // messages can force them temporarily negative.
michael@0 232
michael@0 233 // LocalWindow is how much data the server will send without getting a
michael@0 234 // window update
michael@0 235 int64_t mLocalWindow;
michael@0 236
michael@0 237 // RemoteWindow is how much data the client is allowed to send without
michael@0 238 // getting a window update
michael@0 239 int64_t mRemoteWindow;
michael@0 240
michael@0 241 // LocalUnacked is the number of bytes received by the client but not
michael@0 242 // yet reflected in a window update. Sending that update will increment
michael@0 243 // LocalWindow
michael@0 244 uint64_t mLocalUnacked;
michael@0 245
michael@0 246 // True when sending is suspended becuase the remote flow control window is
michael@0 247 // <= 0
michael@0 248 bool mBlockedOnRwin;
michael@0 249
michael@0 250 // For Progress Events
michael@0 251 uint64_t mTotalSent;
michael@0 252 uint64_t mTotalRead;
michael@0 253
michael@0 254 // For SpdyPush
michael@0 255 SpdyPushedStream3 *mPushSource;
michael@0 256 };
michael@0 257
michael@0 258 }} // namespace mozilla::net
michael@0 259
michael@0 260 #endif // mozilla_net_SpdyStream3_h

mercurial