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

mercurial