2012-05-25 14:37:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
2012-05-29 08:52:43 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-06-22 09:01:06 -07:00
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2014-02-07 13:15:24 -08:00
|
|
|
// Log on level :5, instead of default :4.
|
|
|
|
#undef LOG
|
|
|
|
#define LOG(args) LOG5(args)
|
|
|
|
#undef LOG_ENABLED
|
|
|
|
#define LOG_ENABLED() LOG5_ENABLED()
|
|
|
|
|
2013-05-03 15:51:35 -07:00
|
|
|
#include "mozilla/Endian.h"
|
2012-05-25 14:37:08 -07:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-05-28 21:07:03 -07:00
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsHttpHandler.h"
|
|
|
|
#include "nsILoadGroup.h"
|
2014-06-13 06:29:00 -07:00
|
|
|
#include "nsISupportsPriority.h"
|
2012-05-25 14:37:08 -07:00
|
|
|
#include "prprf.h"
|
2013-05-28 21:07:03 -07:00
|
|
|
#include "SpdyPush3.h"
|
|
|
|
#include "SpdySession3.h"
|
|
|
|
#include "SpdyStream3.h"
|
2013-07-26 14:22:46 -07:00
|
|
|
#include "PSpdyPush.h"
|
2014-03-20 11:22:17 -07:00
|
|
|
#include "SpdyZlibReporter.h"
|
2014-04-16 06:52:43 -07:00
|
|
|
#include "TunnelUtils.h"
|
2013-05-28 21:07:03 -07:00
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// defined by the socket transport service while active
|
|
|
|
extern PRThread *gSocketThread;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
// SpdySession3 has multiple inheritance of things that implement
|
|
|
|
// nsISupports, so this magic is taken from nsHttpPipeline that
|
|
|
|
// implements some of the same abstract classes.
|
2013-07-18 19:24:13 -07:00
|
|
|
NS_IMPL_ADDREF(SpdySession3)
|
|
|
|
NS_IMPL_RELEASE(SpdySession3)
|
2012-05-25 14:37:08 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(SpdySession3)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsAHttpConnection)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-05-16 08:46:11 -07:00
|
|
|
SpdySession3::SpdySession3(nsISocketTransport *aSocketTransport)
|
2014-04-17 16:55:04 -07:00
|
|
|
: mSocketTransport(aSocketTransport)
|
|
|
|
, mSegmentReader(nullptr)
|
|
|
|
, mSegmentWriter(nullptr)
|
|
|
|
, mNextStreamID(1)
|
|
|
|
, mConcurrentHighWater(0)
|
|
|
|
, mDownstreamState(BUFFERING_FRAME_HEADER)
|
|
|
|
, mInputFrameBufferSize(kDefaultBufferSize)
|
|
|
|
, mInputFrameBufferUsed(0)
|
|
|
|
, mInputFrameDataLast(false)
|
|
|
|
, mInputFrameDataStream(nullptr)
|
|
|
|
, mNeedsCleanup(nullptr)
|
|
|
|
, mShouldGoAway(false)
|
|
|
|
, mClosed(false)
|
|
|
|
, mCleanShutdown(false)
|
|
|
|
, mDataPending(false)
|
|
|
|
, mGoAwayID(0)
|
|
|
|
, mMaxConcurrent(kDefaultMaxConcurrent)
|
|
|
|
, mConcurrent(0)
|
|
|
|
, mServerPushedResources(0)
|
|
|
|
, mServerInitialWindow(kDefaultServerRwin)
|
|
|
|
, mOutputQueueSize(kDefaultQueueSize)
|
|
|
|
, mOutputQueueUsed(0)
|
|
|
|
, mOutputQueueSent(0)
|
|
|
|
, mLastReadEpoch(PR_IntervalNow())
|
|
|
|
, mPingSentEpoch(0)
|
|
|
|
, mNextPingID(1)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
static uint64_t sSerial;
|
|
|
|
mSerial = ++sSerial;
|
|
|
|
|
2014-05-16 08:46:11 -07:00
|
|
|
LOG3(("SpdySession3::SpdySession3 %p serial=0x%X\n", this, mSerial));
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mInputFrameBuffer = new char[mInputFrameBufferSize];
|
|
|
|
mOutputQueueBuffer = new char[mOutputQueueSize];
|
|
|
|
zlibInit();
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
mPushAllowance = gHttpHandler->SpdyPushAllowance();
|
2012-05-25 14:37:08 -07:00
|
|
|
mSendingChunkSize = gHttpHandler->SpdySendingChunkSize();
|
2012-05-25 14:43:10 -07:00
|
|
|
GenerateSettings();
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mLastDataReadEpoch = mLastReadEpoch;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mPingThreshold = gHttpHandler->SpdyPingThreshold();
|
|
|
|
}
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
SpdySession3::ShutdownEnumerator(nsAHttpTransaction *key,
|
2014-04-17 16:55:04 -07:00
|
|
|
nsAutoPtr<SpdyStream3> &stream,
|
|
|
|
void *closure)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
SpdySession3 *self = static_cast<SpdySession3 *>(closure);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// On a clean server hangup the server sets the GoAwayID to be the ID of
|
|
|
|
// the last transaction it processed. If the ID of stream in the
|
2012-12-20 10:27:15 -08:00
|
|
|
// local stream is greater than that it can safely be restarted because the
|
|
|
|
// server guarantees it was not partially processed. Streams that have not
|
|
|
|
// registered an ID haven't actually been sent yet so they can always be
|
|
|
|
// restarted.
|
|
|
|
if (self->mCleanShutdown &&
|
|
|
|
(stream->StreamID() > self->mGoAwayID || !stream->HasRegisteredID()))
|
2012-06-03 18:13:12 -07:00
|
|
|
self->CloseStream(stream, NS_ERROR_NET_RESET); // can be restarted
|
2012-05-25 14:37:08 -07:00
|
|
|
else
|
2012-06-03 18:13:12 -07:00
|
|
|
self->CloseStream(stream, NS_ERROR_ABORT);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-12-20 10:27:15 -08:00
|
|
|
PLDHashOperator
|
|
|
|
SpdySession3::GoAwayEnumerator(nsAHttpTransaction *key,
|
|
|
|
nsAutoPtr<SpdyStream3> &stream,
|
|
|
|
void *closure)
|
|
|
|
{
|
|
|
|
SpdySession3 *self = static_cast<SpdySession3 *>(closure);
|
|
|
|
|
|
|
|
// these streams were not processed by the server and can be restarted.
|
|
|
|
// Do that after the enumerator completes to avoid the risk of
|
2013-05-28 21:07:03 -07:00
|
|
|
// a restart event re-entrantly modifying this hash. Be sure not to restart
|
|
|
|
// a pushed (even numbered) stream
|
|
|
|
if ((stream->StreamID() > self->mGoAwayID && (stream->StreamID() & 1)) ||
|
|
|
|
!stream->HasRegisteredID()) {
|
2012-12-20 10:27:15 -08:00
|
|
|
self->mGoAwayStreamsToRestart.Push(stream);
|
2013-05-28 21:07:03 -07:00
|
|
|
}
|
2012-12-20 10:27:15 -08:00
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::~SpdySession3()
|
|
|
|
{
|
|
|
|
LOG3(("SpdySession3::~SpdySession3 %p mDownstreamState=%X",
|
|
|
|
this, mDownstreamState));
|
|
|
|
|
|
|
|
inflateEnd(&mDownstreamZlib);
|
|
|
|
deflateEnd(&mUpstreamZlib);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mStreamTransactionHash.Enumerate(ShutdownEnumerator, this);
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_PARALLEL_STREAMS, mConcurrentHighWater);
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_REQUEST_PER_CONN, (mNextStreamID - 1) / 2);
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SERVER_INITIATED_STREAMS,
|
|
|
|
mServerPushedResources);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::LogIO(SpdySession3 *self, SpdyStream3 *stream, const char *label,
|
2014-04-17 16:55:04 -07:00
|
|
|
const char *data, uint32_t datalen)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
if (!LOG4_ENABLED())
|
|
|
|
return;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG4(("SpdySession3::LogIO %p stream=%p id=0x%X [%s]",
|
|
|
|
self, stream, stream ? stream->StreamID() : 0, label));
|
|
|
|
|
|
|
|
// Max line is (16 * 3) + 10(prefix) + newline + null
|
|
|
|
char linebuf[128];
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index;
|
2012-05-25 14:37:08 -07:00
|
|
|
char *line = linebuf;
|
|
|
|
|
|
|
|
linebuf[127] = 0;
|
|
|
|
|
|
|
|
for (index = 0; index < datalen; ++index) {
|
|
|
|
if (!(index % 16)) {
|
|
|
|
if (index) {
|
|
|
|
*line = 0;
|
|
|
|
LOG4(("%s", linebuf));
|
|
|
|
}
|
|
|
|
line = linebuf;
|
|
|
|
PR_snprintf(line, 128, "%08X: ", index);
|
|
|
|
line += 10;
|
|
|
|
}
|
|
|
|
PR_snprintf(line, 128 - (line - linebuf), "%02X ",
|
|
|
|
((unsigned char *)data)[index]);
|
|
|
|
line += 3;
|
|
|
|
}
|
|
|
|
if (index) {
|
|
|
|
*line = 0;
|
|
|
|
LOG4(("%s", linebuf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdySession3::RoomForMoreConcurrent()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
return (mConcurrent < mMaxConcurrent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdySession3::RoomForMoreStreams()
|
|
|
|
{
|
|
|
|
if (mNextStreamID + mStreamTransactionHash.Count() * 2 > kMaxStreamID)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !mShouldGoAway;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntervalTime
|
|
|
|
SpdySession3::IdleTime()
|
|
|
|
{
|
|
|
|
return PR_IntervalNow() - mLastDataReadEpoch;
|
|
|
|
}
|
|
|
|
|
2014-01-29 23:29:20 -08:00
|
|
|
uint32_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::ReadTimeoutTick(PRIntervalTime now)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
|
|
|
MOZ_ASSERT(mNextPingID & 1, "Ping Counter Not Odd");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
LOG(("SpdySession3::ReadTimeoutTick %p delta since last read %ds\n",
|
|
|
|
this, PR_IntervalToSeconds(now - mLastReadEpoch)));
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
if (!mPingThreshold)
|
2014-01-29 23:29:20 -08:00
|
|
|
return UINT32_MAX;
|
2013-05-28 21:07:03 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if ((now - mLastReadEpoch) < mPingThreshold) {
|
|
|
|
// recent activity means ping is not an issue
|
|
|
|
if (mPingSentEpoch)
|
2012-10-25 11:20:08 -07:00
|
|
|
mPingSentEpoch = 0;
|
2014-01-29 23:29:20 -08:00
|
|
|
|
|
|
|
return PR_IntervalToSeconds(mPingThreshold) -
|
|
|
|
PR_IntervalToSeconds(now - mLastReadEpoch);
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mPingSentEpoch) {
|
|
|
|
LOG(("SpdySession3::ReadTimeoutTick %p handle outstanding ping\n"));
|
|
|
|
if ((now - mPingSentEpoch) >= gHttpHandler->SpdyPingTimeout()) {
|
|
|
|
LOG(("SpdySession3::ReadTimeoutTick %p Ping Timer Exhaustion\n",
|
|
|
|
this));
|
2012-10-25 11:20:08 -07:00
|
|
|
mPingSentEpoch = 0;
|
2012-05-25 14:37:08 -07:00
|
|
|
Close(NS_ERROR_NET_TIMEOUT);
|
2014-01-29 23:29:20 -08:00
|
|
|
return UINT32_MAX;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
2014-01-29 23:29:20 -08:00
|
|
|
return 1; // run the tick aggressively while ping is outstanding
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG(("SpdySession3::ReadTimeoutTick %p generating ping 0x%X\n",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, mNextPingID));
|
|
|
|
|
|
|
|
if (mNextPingID == 0xffffffff) {
|
|
|
|
LOG(("SpdySession3::ReadTimeoutTick %p cannot form ping - ids exhausted\n",
|
|
|
|
this));
|
2014-01-29 23:29:20 -08:00
|
|
|
return UINT32_MAX;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mPingSentEpoch = PR_IntervalNow();
|
|
|
|
if (!mPingSentEpoch)
|
|
|
|
mPingSentEpoch = 1; // avoid the 0 sentinel value
|
|
|
|
GeneratePing(mNextPingID);
|
|
|
|
mNextPingID += 2;
|
2012-10-05 12:03:14 -07:00
|
|
|
ResumeRecv(); // read the ping reply
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
// Check for orphaned push streams. This looks expensive, but generally the
|
|
|
|
// list is empty.
|
|
|
|
SpdyPushedStream3 *deleteMe;
|
|
|
|
TimeStamp timestampNow;
|
|
|
|
do {
|
|
|
|
deleteMe = nullptr;
|
|
|
|
|
|
|
|
for (uint32_t index = mPushedStreams.Length();
|
|
|
|
index > 0 ; --index) {
|
|
|
|
SpdyPushedStream3 *pushedStream = mPushedStreams[index - 1];
|
|
|
|
|
|
|
|
if (timestampNow.IsNull())
|
|
|
|
timestampNow = TimeStamp::Now(); // lazy initializer
|
|
|
|
|
|
|
|
// if spdy finished, but not connected, and its been like that for too long..
|
|
|
|
// cleanup the stream..
|
|
|
|
if (pushedStream->IsOrphaned(timestampNow))
|
|
|
|
{
|
|
|
|
LOG3(("SpdySession3 Timeout Pushed Stream %p 0x%X\n",
|
|
|
|
this, pushedStream->StreamID()));
|
|
|
|
deleteMe = pushedStream;
|
|
|
|
break; // don't CleanupStream() while iterating this vector
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (deleteMe)
|
|
|
|
CleanupStream(deleteMe, NS_ERROR_ABORT, RST_CANCEL);
|
|
|
|
|
|
|
|
} while (deleteMe);
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mNextPingID == 0xffffffff) {
|
|
|
|
LOG(("SpdySession3::ReadTimeoutTick %p "
|
|
|
|
"ping ids exhausted marking goaway\n", this));
|
|
|
|
mShouldGoAway = true;
|
|
|
|
}
|
2014-01-29 23:29:20 -08:00
|
|
|
return 1; // run the tick aggressively while ping is outstanding
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2013-05-28 21:07:03 -07:00
|
|
|
SpdySession3::RegisterStreamID(SpdyStream3 *stream, uint32_t aNewID)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(mNextStreamID < 0xfffffff0,
|
|
|
|
"should have stopped admitting streams");
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
MOZ_ASSERT(!(aNewID & 1),
|
|
|
|
"0 for autoassign pull, otherwise explicit even push assignment");
|
|
|
|
if (!aNewID) {
|
|
|
|
// auto generate a new pull stream ID
|
|
|
|
aNewID = mNextStreamID;
|
|
|
|
MOZ_ASSERT(aNewID & 1, "pull ID must be odd.");
|
|
|
|
mNextStreamID += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::RegisterStreamID session=%p stream=%p id=0x%X "
|
|
|
|
"concurrent=%d",this, stream, aNewID, mConcurrent));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// We've used up plenty of ID's on this session. Start
|
|
|
|
// moving to a new one before there is a crunch involving
|
|
|
|
// server push streams or concurrent non-registered submits
|
2013-05-28 21:07:03 -07:00
|
|
|
if (aNewID >= kMaxStreamID)
|
2012-05-25 14:37:08 -07:00
|
|
|
mShouldGoAway = true;
|
|
|
|
|
|
|
|
// integrity check
|
2013-05-28 21:07:03 -07:00
|
|
|
if (mStreamIDHash.Get(aNewID)) {
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3((" New ID already present\n"));
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "New ID already present in mStreamIDHash");
|
2012-05-25 14:37:08 -07:00
|
|
|
mShouldGoAway = true;
|
|
|
|
return kDeadStreamID;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
mStreamIDHash.Put(aNewID, stream);
|
|
|
|
return aNewID;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdySession3::AddStream(nsAHttpTransaction *aHttpTransaction,
|
2014-04-16 06:52:43 -07:00
|
|
|
int32_t aPriority,
|
|
|
|
bool aUseTunnel,
|
|
|
|
nsIInterfaceRequestor *aCallbacks)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// integrity check
|
|
|
|
if (mStreamTransactionHash.Get(aHttpTransaction)) {
|
|
|
|
LOG3((" New transaction already present\n"));
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "AddStream duplicate transaction pointer");
|
2012-05-25 14:37:08 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-16 08:46:11 -07:00
|
|
|
if (!mConnection) {
|
|
|
|
mConnection = aHttpTransaction->Connection();
|
|
|
|
}
|
2014-04-16 06:52:43 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
aHttpTransaction->SetConnection(this);
|
2014-04-16 06:52:43 -07:00
|
|
|
|
|
|
|
if (aUseTunnel) {
|
|
|
|
LOG3(("SpdySession3::AddStream session=%p trans=%p OnTunnel",
|
|
|
|
this, aHttpTransaction));
|
|
|
|
DispatchOnTunnel(aHttpTransaction, aCallbacks);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
SpdyStream3 *stream = new SpdyStream3(aHttpTransaction, this, aPriority);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2014-04-16 06:52:43 -07:00
|
|
|
LOG3(("SpdySession3::AddStream session=%p stream=%p serial=%u "
|
|
|
|
"NextID=0x%X (tentative)", this, stream, mSerial, mNextStreamID));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
mStreamTransactionHash.Put(aHttpTransaction, stream);
|
|
|
|
|
|
|
|
if (RoomForMoreConcurrent()) {
|
|
|
|
LOG3(("SpdySession3::AddStream %p stream %p activated immediately.",
|
|
|
|
this, stream));
|
|
|
|
ActivateStream(stream);
|
|
|
|
}
|
|
|
|
else {
|
2013-05-28 21:07:03 -07:00
|
|
|
LOG3(("SpdySession3::AddStream %p stream %p queued.", this, stream));
|
2012-05-25 14:37:08 -07:00
|
|
|
mQueuedStreams.Push(stream);
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-07-08 19:53:18 -07:00
|
|
|
if (!(aHttpTransaction->Caps() & NS_HTTP_ALLOW_KEEPALIVE)) {
|
|
|
|
LOG3(("SpdySession3::AddStream %p transaction %p forces keep-alive off.\n",
|
|
|
|
this, aHttpTransaction));
|
|
|
|
DontReuse();
|
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::ActivateStream(SpdyStream3 *stream)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2013-05-28 21:07:03 -07:00
|
|
|
MOZ_ASSERT(!stream->StreamID() || (stream->StreamID() & 1),
|
|
|
|
"Do not activate pushed streams");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
++mConcurrent;
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mConcurrent > mConcurrentHighWater)
|
|
|
|
mConcurrentHighWater = mConcurrent;
|
|
|
|
LOG3(("SpdySession3::AddStream %p activating stream %p Currently %d "
|
|
|
|
"streams in session, high water mark is %d",
|
|
|
|
this, stream, mConcurrent, mConcurrentHighWater));
|
|
|
|
|
|
|
|
mReadyForWrite.Push(stream);
|
|
|
|
SetWriteCallbacks();
|
|
|
|
|
|
|
|
// Kick off the SYN transmit without waiting for the poll loop
|
|
|
|
// This won't work for stream id=1 because there is no segment reader
|
|
|
|
// yet.
|
|
|
|
if (mSegmentReader) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t countRead;
|
2012-07-30 07:20:58 -07:00
|
|
|
ReadSegments(nullptr, kDefaultBufferSize, &countRead);
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::ProcessPending()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
while (RoomForMoreConcurrent()) {
|
|
|
|
SpdyStream3 *stream = static_cast<SpdyStream3 *>(mQueuedStreams.PopFront());
|
|
|
|
if (!stream)
|
|
|
|
return;
|
|
|
|
LOG3(("SpdySession3::ProcessPending %p stream %p activated from queue.",
|
|
|
|
this, stream));
|
|
|
|
ActivateStream(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::NetworkRead(nsAHttpSegmentWriter *writer, char *buf,
|
2014-04-17 16:55:04 -07:00
|
|
|
uint32_t count, uint32_t *countWritten)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-11-10 07:27:59 -08:00
|
|
|
if (!count) {
|
|
|
|
*countWritten = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult rv = writer->OnWriteSegment(buf, count, countWritten);
|
|
|
|
if (NS_SUCCEEDED(rv) && *countWritten > 0)
|
|
|
|
mLastReadEpoch = PR_IntervalNow();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::SetWriteCallbacks()
|
|
|
|
{
|
|
|
|
if (mConnection && (GetWriteQueueSize() || mOutputQueueUsed))
|
|
|
|
mConnection->ResumeSend();
|
|
|
|
}
|
|
|
|
|
2012-12-18 14:14:21 -08:00
|
|
|
void
|
|
|
|
SpdySession3::RealignOutputQueue()
|
|
|
|
{
|
|
|
|
mOutputQueueUsed -= mOutputQueueSent;
|
|
|
|
memmove(mOutputQueueBuffer.get(),
|
|
|
|
mOutputQueueBuffer.get() + mOutputQueueSent,
|
|
|
|
mOutputQueueUsed);
|
|
|
|
mOutputQueueSent = 0;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
void
|
|
|
|
SpdySession3::FlushOutputQueue()
|
|
|
|
{
|
|
|
|
if (!mSegmentReader || !mOutputQueueUsed)
|
|
|
|
return;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult rv;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t countRead;
|
|
|
|
uint32_t avail = mOutputQueueUsed - mOutputQueueSent;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
rv = mSegmentReader->
|
|
|
|
OnReadSegment(mOutputQueueBuffer.get() + mOutputQueueSent, avail,
|
|
|
|
&countRead);
|
|
|
|
LOG3(("SpdySession3::FlushOutputQueue %p sz=%d rv=%x actual=%d",
|
|
|
|
this, avail, rv, countRead));
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// Dont worry about errors on write, we will pick this up as a read error too
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (countRead == avail) {
|
|
|
|
mOutputQueueUsed = 0;
|
|
|
|
mOutputQueueSent = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOutputQueueSent += countRead;
|
|
|
|
|
|
|
|
// If the output queue is close to filling up and we have sent out a good
|
|
|
|
// chunk of data from the beginning then realign it.
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if ((mOutputQueueSent >= kQueueMinimumCleanup) &&
|
|
|
|
((mOutputQueueSize - mOutputQueueUsed) < kQueueTailRoom)) {
|
2012-12-18 14:14:21 -08:00
|
|
|
RealignOutputQueue();
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::DontReuse()
|
|
|
|
{
|
|
|
|
mShouldGoAway = true;
|
|
|
|
if (!mStreamTransactionHash.Count())
|
|
|
|
Close(NS_OK);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::GetWriteQueueSize()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
return mReadyForWrite.GetSize();
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::ChangeDownstreamState(enum stateType newState)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2014-04-17 16:55:04 -07:00
|
|
|
LOG3(("SpdySession3::ChangeDownstreamState() %p from %X to %X",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, mDownstreamState, newState));
|
|
|
|
mDownstreamState = newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::ResetDownstreamState()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2014-04-17 16:55:04 -07:00
|
|
|
LOG3(("SpdySession3::ResetDownstreamState() %p", this));
|
2012-05-25 14:37:08 -07:00
|
|
|
ChangeDownstreamState(BUFFERING_FRAME_HEADER);
|
|
|
|
|
|
|
|
if (mInputFrameDataLast && mInputFrameDataStream) {
|
|
|
|
mInputFrameDataLast = false;
|
|
|
|
if (!mInputFrameDataStream->RecvdFin()) {
|
2013-05-28 21:07:03 -07:00
|
|
|
LOG3((" SetRecvdFin id=0x%x\n", mInputFrameDataStream->StreamID()));
|
2012-05-25 14:37:08 -07:00
|
|
|
mInputFrameDataStream->SetRecvdFin(true);
|
2013-05-28 21:07:03 -07:00
|
|
|
DecrementConcurrent(mInputFrameDataStream);
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mInputFrameBufferUsed = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
mInputFrameDataStream = nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
void
|
|
|
|
SpdySession3::DecrementConcurrent(SpdyStream3 *aStream)
|
|
|
|
{
|
|
|
|
uint32_t id = aStream->StreamID();
|
|
|
|
|
|
|
|
if (id && !(id & 0x1))
|
|
|
|
return; // pushed streams aren't counted in concurrent limit
|
|
|
|
|
|
|
|
MOZ_ASSERT(mConcurrent);
|
|
|
|
--mConcurrent;
|
|
|
|
LOG3(("DecrementConcurrent %p id=0x%X concurrent=%d\n",
|
|
|
|
this, id, mConcurrent));
|
|
|
|
ProcessPending();
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
void
|
|
|
|
SpdySession3::zlibInit()
|
|
|
|
{
|
2014-03-20 11:22:17 -07:00
|
|
|
mDownstreamZlib.zalloc = SpdyZlibReporter::Alloc;
|
|
|
|
mDownstreamZlib.zfree = SpdyZlibReporter::Free;
|
2012-05-25 14:37:08 -07:00
|
|
|
mDownstreamZlib.opaque = Z_NULL;
|
|
|
|
|
|
|
|
inflateInit(&mDownstreamZlib);
|
|
|
|
|
2014-03-20 11:22:17 -07:00
|
|
|
mUpstreamZlib.zalloc = SpdyZlibReporter::Alloc;
|
|
|
|
mUpstreamZlib.zfree = SpdyZlibReporter::Free;
|
2012-05-25 14:37:08 -07:00
|
|
|
mUpstreamZlib.opaque = Z_NULL;
|
|
|
|
|
2012-08-07 07:44:51 -07:00
|
|
|
// mixing carte blanche compression with tls subjects us to traffic
|
|
|
|
// analysis attacks
|
|
|
|
deflateInit(&mUpstreamZlib, Z_NO_COMPRESSION);
|
2012-05-25 14:37:08 -07:00
|
|
|
deflateSetDictionary(&mUpstreamZlib,
|
2012-05-25 14:43:10 -07:00
|
|
|
SpdyStream3::kDictionary,
|
|
|
|
sizeof(SpdyStream3::kDictionary));
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// Need to decompress some data in order to keep the compression
|
|
|
|
// context correct, but we really don't care what the result is
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdySession3::UncompressAndDiscard(uint32_t offset,
|
|
|
|
uint32_t blockLen)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2012-05-25 14:43:10 -07:00
|
|
|
char *blockStart = mInputFrameBuffer + offset;
|
|
|
|
unsigned char trash[2048];
|
2012-05-25 14:37:08 -07:00
|
|
|
mDownstreamZlib.avail_in = blockLen;
|
|
|
|
mDownstreamZlib.next_in = reinterpret_cast<unsigned char *>(blockStart);
|
2012-08-07 18:49:53 -07:00
|
|
|
bool triedDictionary = false;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
do {
|
2012-05-25 14:43:10 -07:00
|
|
|
mDownstreamZlib.next_out = trash;
|
|
|
|
mDownstreamZlib.avail_out = sizeof(trash);
|
2012-05-25 14:37:08 -07:00
|
|
|
int zlib_rv = inflate(&mDownstreamZlib, Z_NO_FLUSH);
|
|
|
|
|
2012-08-07 18:49:53 -07:00
|
|
|
if (zlib_rv == Z_NEED_DICT) {
|
|
|
|
if (triedDictionary) {
|
|
|
|
LOG3(("SpdySession3::UncompressAndDiscard %p Dictionary Error\n", this));
|
2013-06-25 10:16:27 -07:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2012-08-07 18:49:53 -07:00
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-08-07 18:49:53 -07:00
|
|
|
triedDictionary = true;
|
2012-05-25 14:43:10 -07:00
|
|
|
inflateSetDictionary(&mDownstreamZlib, SpdyStream3::kDictionary,
|
|
|
|
sizeof(SpdyStream3::kDictionary));
|
2012-08-07 18:49:53 -07:00
|
|
|
}
|
2012-05-25 14:43:10 -07:00
|
|
|
|
2013-06-25 10:16:27 -07:00
|
|
|
if (zlib_rv == Z_DATA_ERROR)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if (zlib_rv == Z_MEM_ERROR)
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
while (mDownstreamZlib.avail_in);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdySession3::GeneratePing(uint32_t aID)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::GeneratePing %p 0x%X\n", this, aID));
|
|
|
|
|
|
|
|
EnsureBuffer(mOutputQueueBuffer, mOutputQueueUsed + 12,
|
|
|
|
mOutputQueueUsed, mOutputQueueSize);
|
|
|
|
char *packet = mOutputQueueBuffer.get() + mOutputQueueUsed;
|
|
|
|
mOutputQueueUsed += 12;
|
|
|
|
|
|
|
|
packet[0] = kFlag_Control;
|
2012-05-25 14:43:10 -07:00
|
|
|
packet[1] = kVersion;
|
2012-05-25 14:37:08 -07:00
|
|
|
packet[2] = 0;
|
|
|
|
packet[3] = CONTROL_TYPE_PING;
|
|
|
|
packet[4] = 0; /* flags */
|
|
|
|
packet[5] = 0;
|
|
|
|
packet[6] = 0;
|
|
|
|
packet[7] = 4; /* length */
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::writeUint32(packet + 8, aID);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
LogIO(this, nullptr, "Generate Ping", packet, 12);
|
2012-05-25 14:37:08 -07:00
|
|
|
FlushOutputQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdySession3::GenerateRstStream(uint32_t aStatusCode, uint32_t aID)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::GenerateRst %p 0x%X %d\n", this, aID, aStatusCode));
|
|
|
|
|
|
|
|
EnsureBuffer(mOutputQueueBuffer, mOutputQueueUsed + 16,
|
|
|
|
mOutputQueueUsed, mOutputQueueSize);
|
|
|
|
char *packet = mOutputQueueBuffer.get() + mOutputQueueUsed;
|
|
|
|
mOutputQueueUsed += 16;
|
|
|
|
|
|
|
|
packet[0] = kFlag_Control;
|
2012-05-25 14:43:10 -07:00
|
|
|
packet[1] = kVersion;
|
2012-05-25 14:37:08 -07:00
|
|
|
packet[2] = 0;
|
|
|
|
packet[3] = CONTROL_TYPE_RST_STREAM;
|
|
|
|
packet[4] = 0; /* flags */
|
|
|
|
packet[5] = 0;
|
|
|
|
packet[6] = 0;
|
|
|
|
packet[7] = 8; /* length */
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::writeUint32(packet + 8, aID);
|
|
|
|
NetworkEndian::writeUint32(packet + 12, aStatusCode);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
LogIO(this, nullptr, "Generate Reset", packet, 16);
|
2012-05-25 14:37:08 -07:00
|
|
|
FlushOutputQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-10 07:27:53 -08:00
|
|
|
SpdySession3::GenerateGoAway(uint32_t aStatusCode)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-11-10 07:27:53 -08:00
|
|
|
LOG3(("SpdySession3::GenerateGoAway %p code=%X\n", this, aStatusCode));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-11-10 07:27:53 -08:00
|
|
|
EnsureBuffer(mOutputQueueBuffer, mOutputQueueUsed + 16,
|
2012-05-25 14:37:08 -07:00
|
|
|
mOutputQueueUsed, mOutputQueueSize);
|
|
|
|
char *packet = mOutputQueueBuffer.get() + mOutputQueueUsed;
|
2012-11-10 07:27:53 -08:00
|
|
|
mOutputQueueUsed += 16;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-11-10 07:27:53 -08:00
|
|
|
memset(packet, 0, 16);
|
2012-05-25 14:37:08 -07:00
|
|
|
packet[0] = kFlag_Control;
|
2012-05-25 14:43:10 -07:00
|
|
|
packet[1] = kVersion;
|
2012-05-25 14:37:08 -07:00
|
|
|
packet[3] = CONTROL_TYPE_GOAWAY;
|
2012-11-10 07:27:53 -08:00
|
|
|
packet[7] = 8; /* data length */
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// last-good-stream-id are bytes 8-11, when we accept server push this will
|
|
|
|
// need to be set non zero
|
|
|
|
|
2012-11-10 07:27:53 -08:00
|
|
|
// bytes 12-15 are the status code.
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::writeUint32(packet + 12, aStatusCode);
|
2012-11-10 07:27:53 -08:00
|
|
|
|
|
|
|
LogIO(this, nullptr, "Generate GoAway", packet, 16);
|
2012-05-25 14:43:10 -07:00
|
|
|
FlushOutputQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::GenerateSettings()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3::GenerateSettings %p\n", this));
|
|
|
|
|
2013-02-12 12:07:50 -08:00
|
|
|
static const uint32_t maxDataLen = 4 + 3 * 8; // sized for 3 settings
|
2013-01-30 17:34:25 -08:00
|
|
|
EnsureBuffer(mOutputQueueBuffer, mOutputQueueUsed + 8 + maxDataLen,
|
2012-05-25 14:43:10 -07:00
|
|
|
mOutputQueueUsed, mOutputQueueSize);
|
|
|
|
char *packet = mOutputQueueBuffer.get() + mOutputQueueUsed;
|
|
|
|
|
2013-01-30 17:34:25 -08:00
|
|
|
memset(packet, 0, 8 + maxDataLen);
|
2012-05-25 14:43:10 -07:00
|
|
|
packet[0] = kFlag_Control;
|
|
|
|
packet[1] = kVersion;
|
|
|
|
packet[3] = CONTROL_TYPE_SETTINGS;
|
2013-01-30 17:34:25 -08:00
|
|
|
|
|
|
|
uint8_t numberOfEntries = 0;
|
|
|
|
|
|
|
|
// entries need to be listed in order by ID
|
|
|
|
// 1st entry is bytes 12 to 19
|
|
|
|
// 2nd entry is bytes 20 to 27
|
2013-02-12 12:07:50 -08:00
|
|
|
// 3rd entry is bytes 28 to 35
|
|
|
|
|
2013-10-09 17:21:49 -07:00
|
|
|
if (!gHttpHandler->AllowPush()) {
|
2013-02-12 12:07:50 -08:00
|
|
|
// announcing that we accept 0 incoming streams is done to
|
2013-05-28 21:07:03 -07:00
|
|
|
// disable server push
|
|
|
|
packet[15 + 8 * numberOfEntries] = SETTINGS_TYPE_MAX_CONCURRENT;
|
|
|
|
// The value portion of the setting pair is already initialized to 0
|
|
|
|
numberOfEntries++;
|
|
|
|
}
|
2013-01-30 17:34:25 -08:00
|
|
|
|
|
|
|
nsRefPtr<nsHttpConnectionInfo> ci;
|
|
|
|
uint32_t cwnd = 0;
|
|
|
|
GetConnectionInfo(getter_AddRefs(ci));
|
|
|
|
if (ci)
|
|
|
|
cwnd = gHttpHandler->ConnMgr()->GetSpdyCWNDSetting(ci);
|
|
|
|
if (cwnd) {
|
|
|
|
packet[12 + 8 * numberOfEntries] = PERSISTED_VALUE;
|
|
|
|
packet[15 + 8 * numberOfEntries] = SETTINGS_TYPE_CWND;
|
|
|
|
LOG(("SpdySession3::GenerateSettings %p sending CWND %u\n", this, cwnd));
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::writeUint32(packet + 16 + 8 * numberOfEntries, cwnd);
|
2013-01-30 17:34:25 -08:00
|
|
|
numberOfEntries++;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
// Advertise the Push RWIN and on each client SYN_STREAM pipeline
|
|
|
|
// a window update with it in order to use larger initial windows with pulled
|
|
|
|
// streams.
|
2013-01-30 17:34:25 -08:00
|
|
|
packet[15 + 8 * numberOfEntries] = SETTINGS_TYPE_INITIAL_WINDOW;
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::writeUint32(packet + 16 + 8 * numberOfEntries, mPushAllowance);
|
2013-01-30 17:34:25 -08:00
|
|
|
numberOfEntries++;
|
|
|
|
|
|
|
|
uint32_t dataLen = 4 + 8 * numberOfEntries;
|
|
|
|
mOutputQueueUsed += 8 + dataLen;
|
|
|
|
packet[7] = dataLen;
|
|
|
|
packet[11] = numberOfEntries;
|
2012-05-25 14:43:10 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
LogIO(this, nullptr, "Generate Settings", packet, 8 + dataLen);
|
2012-05-25 14:37:08 -07:00
|
|
|
FlushOutputQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
// perform a bunch of integrity checks on the stream.
|
|
|
|
// returns true if passed, false (plus LOG and ABORT) if failed.
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdySession3::VerifyStream(SpdyStream3 *aStream, uint32_t aOptionalID = 0)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
// This is annoying, but at least it is O(1)
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-07-20 05:44:21 -07:00
|
|
|
#ifndef DEBUG
|
|
|
|
// Only do the real verification in debug builds
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (!aStream)
|
|
|
|
return true;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t test = 0;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
do {
|
|
|
|
if (aStream->StreamID() == kDeadStreamID)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsAHttpTransaction *trans = aStream->Transaction();
|
|
|
|
|
2013-05-16 06:30:42 -07:00
|
|
|
test++;
|
2012-05-25 14:37:08 -07:00
|
|
|
if (!trans)
|
|
|
|
break;
|
|
|
|
|
|
|
|
test++;
|
|
|
|
if (mStreamTransactionHash.Get(trans) != aStream)
|
|
|
|
break;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (aStream->StreamID()) {
|
|
|
|
SpdyStream3 *idStream = mStreamIDHash.Get(aStream->StreamID());
|
|
|
|
|
|
|
|
test++;
|
|
|
|
if (idStream != aStream)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (aOptionalID) {
|
|
|
|
test++;
|
|
|
|
if (idStream->StreamID() != aOptionalID)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tests passed
|
|
|
|
return true;
|
|
|
|
} while (0);
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG(("SpdySession3 %p VerifyStream Failure %p stream->id=0x%X "
|
|
|
|
"optionalID=0x%X trans=%p test=%d\n",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, aStream, aStream->StreamID(),
|
|
|
|
aOptionalID, aStream->Transaction(), test));
|
2013-05-28 21:07:03 -07:00
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "VerifyStream");
|
2012-05-25 14:37:08 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::CleanupStream(SpdyStream3 *aStream, nsresult aResult,
|
2014-04-17 16:55:04 -07:00
|
|
|
rstReason aResetCode)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3::CleanupStream %p %p 0x%X %X\n",
|
2014-01-13 07:10:10 -08:00
|
|
|
this, aStream, aStream ? aStream->StreamID() : 0, aResult));
|
|
|
|
if (!aStream) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
SpdyPushedStream3 *pushSource = nullptr;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aResult) && aStream->DeferCleanupOnSuccess()) {
|
|
|
|
LOG(("SpdySession3::CleanupStream 0x%X deferred\n", aStream->StreamID()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (!VerifyStream(aStream)) {
|
|
|
|
LOG(("SpdySession3::CleanupStream failed to verify stream\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
pushSource = aStream->PushSource();
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (!aStream->RecvdFin() && aStream->StreamID()) {
|
|
|
|
LOG3(("Stream had not processed recv FIN, sending RST code %X\n",
|
|
|
|
aResetCode));
|
|
|
|
GenerateRstStream(aResetCode, aStream->StreamID());
|
2013-05-28 21:07:03 -07:00
|
|
|
DecrementConcurrent(aStream);
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-06-03 18:13:12 -07:00
|
|
|
CloseStream(aStream, aResult);
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
// Remove the stream from the ID hash table and, if an even id, the pushed
|
|
|
|
// table too.
|
|
|
|
uint32_t id = aStream->StreamID();
|
|
|
|
if (id > 0) {
|
|
|
|
mStreamIDHash.Remove(id);
|
|
|
|
if (!(id & 1))
|
|
|
|
mPushedStreams.RemoveElement(aStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveStreamFromQueues(aStream);
|
2012-06-03 18:13:12 -07:00
|
|
|
|
|
|
|
// removing from the stream transaction hash will
|
|
|
|
// delete the SpdyStream3 and drop the reference to
|
|
|
|
// its transaction
|
|
|
|
mStreamTransactionHash.Remove(aStream->Transaction());
|
|
|
|
|
|
|
|
if (mShouldGoAway && !mStreamTransactionHash.Count())
|
|
|
|
Close(NS_OK);
|
2013-05-28 21:07:03 -07:00
|
|
|
|
|
|
|
if (pushSource) {
|
|
|
|
pushSource->SetDeferCleanupOnSuccess(false);
|
|
|
|
CleanupStream(pushSource, aResult, aResetCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RemoveStreamFromQueue(SpdyStream3 *aStream, nsDeque &queue)
|
|
|
|
{
|
|
|
|
uint32_t size = queue.GetSize();
|
|
|
|
for (uint32_t count = 0; count < size; ++count) {
|
|
|
|
SpdyStream3 *stream = static_cast<SpdyStream3 *>(queue.PopFront());
|
|
|
|
if (stream != aStream)
|
|
|
|
queue.Push(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::RemoveStreamFromQueues(SpdyStream3 *aStream)
|
|
|
|
{
|
|
|
|
RemoveStreamFromQueue(aStream, mReadyForWrite);
|
|
|
|
RemoveStreamFromQueue(aStream, mQueuedStreams);
|
|
|
|
RemoveStreamFromQueue(aStream, mReadyForRead);
|
2012-06-03 18:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::CloseStream(SpdyStream3 *aStream, nsresult aResult)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-06-03 18:13:12 -07:00
|
|
|
LOG3(("SpdySession3::CloseStream %p %p 0x%x %X\n",
|
|
|
|
this, aStream, aStream->StreamID(), aResult));
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// Check if partial frame reader
|
|
|
|
if (aStream == mInputFrameDataStream) {
|
|
|
|
LOG3(("Stream had active partial read frame on close"));
|
|
|
|
ChangeDownstreamState(DISCARDING_DATA_FRAME);
|
2012-07-30 07:20:58 -07:00
|
|
|
mInputFrameDataStream = nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
RemoveStreamFromQueues(aStream);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2014-04-16 06:52:43 -07:00
|
|
|
if (aStream->IsTunnel()) {
|
|
|
|
UnRegisterTunnel(aStream);
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// Send the stream the close() indication
|
|
|
|
aStream->Close(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleSynStream(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_SYN_STREAM);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (self->mInputFrameDataSize < 18) {
|
|
|
|
LOG3(("SpdySession3::HandleSynStream %p SYN_STREAM too short data=%d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t streamID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t associatedID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 3 * sizeof(uint32_t));
|
2013-05-28 21:07:03 -07:00
|
|
|
uint8_t flags = reinterpret_cast<uint8_t *>(self->mInputFrameBuffer.get())[4];
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleSynStream %p recv SYN_STREAM (push) "
|
2013-05-28 21:07:03 -07:00
|
|
|
"for ID 0x%X associated with 0x%X.\n",
|
2012-05-25 14:37:08 -07:00
|
|
|
self, streamID, associatedID));
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (streamID & 0x01) { // test for odd stream ID
|
|
|
|
LOG3(("SpdySession3::HandleSynStream %p recvd SYN_STREAM id must be even.",
|
|
|
|
self));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
// confirm associated-to
|
|
|
|
nsresult rv = self->SetInputFrameDataStream(associatedID);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
SpdyStream3 *associatedStream = self->mInputFrameDataStream;
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
++(self->mServerPushedResources);
|
|
|
|
|
|
|
|
// Anytime we start using the high bit of stream ID (either client or server)
|
|
|
|
// begin to migrate to a new session.
|
|
|
|
if (streamID >= kMaxStreamID)
|
|
|
|
self->mShouldGoAway = true;
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
bool resetStream = true;
|
2013-07-26 14:22:46 -07:00
|
|
|
SpdyPushCache *cache = nullptr;
|
2013-05-28 21:07:03 -07:00
|
|
|
|
|
|
|
if (!(flags & kFlag_Data_UNI)) {
|
|
|
|
// pushed streams require UNIDIRECTIONAL flag
|
|
|
|
LOG3(("SpdySession3::HandleSynStream %p ID %0x%X associated ID 0x%X failed.\n",
|
|
|
|
self, streamID, associatedID));
|
|
|
|
self->GenerateRstStream(RST_PROTOCOL_ERROR, streamID);
|
|
|
|
|
|
|
|
} else if (!associatedID) {
|
|
|
|
// associated stream 0 will never find a match, but the spec requires a
|
|
|
|
// PROTOCOL_ERROR in this specific case
|
|
|
|
LOG3(("SpdySession3::HandleSynStream %p associated ID of 0 failed.\n", self));
|
|
|
|
self->GenerateRstStream(RST_PROTOCOL_ERROR, streamID);
|
|
|
|
|
2013-10-09 17:21:49 -07:00
|
|
|
} else if (!gHttpHandler->AllowPush()) {
|
2013-05-28 21:07:03 -07:00
|
|
|
// MAX_CONCURRENT_STREAMS of 0 in settings should have disabled push,
|
|
|
|
// but some servers are buggy about that.. or the config could have
|
|
|
|
// been updated after the settings frame was sent. In both cases just
|
|
|
|
// reject the pushed stream as refused
|
|
|
|
LOG3(("SpdySession3::HandleSynStream Push Recevied when Disabled\n"));
|
|
|
|
self->GenerateRstStream(RST_REFUSED_STREAM, streamID);
|
|
|
|
|
|
|
|
} else if (!associatedStream) {
|
|
|
|
LOG3(("SpdySession3::HandleSynStream %p lookup associated ID failed.\n", self));
|
|
|
|
self->GenerateRstStream(RST_INVALID_STREAM, streamID);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
nsILoadGroupConnectionInfo *loadGroupCI = associatedStream->LoadGroupConnectionInfo();
|
|
|
|
if (loadGroupCI) {
|
2013-07-26 14:22:46 -07:00
|
|
|
loadGroupCI->GetSpdyPushCache(&cache);
|
2013-05-28 21:07:03 -07:00
|
|
|
if (!cache) {
|
2013-07-26 14:22:46 -07:00
|
|
|
cache = new SpdyPushCache();
|
|
|
|
if (!cache || NS_FAILED(loadGroupCI->SetSpdyPushCache(cache))) {
|
2013-05-28 21:07:03 -07:00
|
|
|
delete cache;
|
|
|
|
cache = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!cache) {
|
|
|
|
// this is unexpected, but we can handle it just be refusing the push
|
|
|
|
LOG3(("SpdySession3::HandleSynStream Push Recevied without loadgroup cache\n"));
|
|
|
|
self->GenerateRstStream(RST_REFUSED_STREAM, streamID);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resetStream = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resetStream) {
|
|
|
|
// Need to decompress the headers even though we aren't using them yet in
|
|
|
|
// order to keep the compression context consistent for other syn_reply frames
|
|
|
|
rv = self->UncompressAndDiscard(18, self->mInputFrameDataSize - 10);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("SpdySession3::HandleSynStream uncompress failed\n"));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the buffering transaction and push stream
|
|
|
|
nsRefPtr<SpdyPush3TransactionBuffer> transactionBuffer =
|
|
|
|
new SpdyPush3TransactionBuffer();
|
|
|
|
transactionBuffer->SetConnection(self);
|
|
|
|
SpdyPushedStream3 *pushedStream =
|
|
|
|
new SpdyPushedStream3(transactionBuffer, self,
|
|
|
|
associatedStream, streamID);
|
|
|
|
|
|
|
|
// ownership of the pushed stream is by the transaction hash, just as it
|
|
|
|
// is for a client initiated stream. Errors that aren't fatal to the
|
|
|
|
// whole session must call cleanupStream() after this point in order
|
|
|
|
// to remove the stream from that hash.
|
|
|
|
self->mStreamTransactionHash.Put(transactionBuffer, pushedStream);
|
|
|
|
self->mPushedStreams.AppendElement(pushedStream);
|
|
|
|
|
|
|
|
// The pushed stream is unidirectional so it is fully open immediately
|
2014-04-16 06:52:43 -07:00
|
|
|
rv = pushedStream->SetFullyOpen();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("SpdySession3::HandleSynStream pushedstream fully open failed\n"));
|
|
|
|
self->CleanupStream(pushedStream, rv, RST_CANCEL);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-05-28 21:07:03 -07:00
|
|
|
|
|
|
|
// Uncompress the response headers into a stream specific buffer, leaving them
|
|
|
|
// in spdy format for the time being.
|
|
|
|
rv = pushedStream->Uncompress(&self->mDownstreamZlib,
|
|
|
|
self->mInputFrameBuffer + 18,
|
|
|
|
self->mInputFrameDataSize - 10);
|
2012-05-25 14:37:08 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("SpdySession3::HandleSynStream uncompress failed\n"));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
if (self->RegisterStreamID(pushedStream, streamID) == kDeadStreamID) {
|
|
|
|
LOG(("SpdySession3::HandleSynStream registerstreamid failed\n"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fake the request side of the pushed HTTP transaction. Sets up hash
|
|
|
|
// key and origin
|
|
|
|
uint32_t notUsed;
|
|
|
|
pushedStream->ReadSegments(nullptr, 1, ¬Used);
|
|
|
|
|
|
|
|
nsAutoCString key;
|
|
|
|
if (!pushedStream->GetHashKey(key)) {
|
|
|
|
LOG(("SpdySession3::HandleSynStream one of :host :scheme :path missing from push\n"));
|
|
|
|
self->CleanupStream(pushedStream, NS_ERROR_FAILURE, RST_INVALID_STREAM);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!associatedStream->Origin().Equals(pushedStream->Origin())) {
|
|
|
|
LOG(("SpdySession3::HandleSynStream pushed stream mismatched origin\n"));
|
|
|
|
self->CleanupStream(pushedStream, NS_ERROR_FAILURE, RST_INVALID_STREAM);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-26 14:22:46 -07:00
|
|
|
if (!cache->RegisterPushedStreamSpdy3(key, pushedStream)) {
|
2013-05-28 21:07:03 -07:00
|
|
|
LOG(("SpdySession3::HandleSynStream registerPushedStream Failed\n"));
|
|
|
|
self->CleanupStream(pushedStream, NS_ERROR_FAILURE, RST_INVALID_STREAM);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdySession3::SetInputFrameDataStream(uint32_t streamID)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
mInputFrameDataStream = mStreamIDHash.Get(streamID);
|
|
|
|
if (VerifyStream(mInputFrameDataStream, streamID))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
LOG(("SpdySession3::SetInputFrameDataStream failed to verify 0x%X\n",
|
|
|
|
streamID));
|
2012-07-30 07:20:58 -07:00
|
|
|
mInputFrameDataStream = nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleSynReply(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_SYN_REPLY);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
if (self->mInputFrameDataSize < 4) {
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::HandleSynReply %p SYN REPLY too short data=%d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
// A framing error is a session wide error that cannot be recovered
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t streamID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2014-04-16 06:52:43 -07:00
|
|
|
LOG3(("SpdySession3::HandleSynReply %p lookup via streamID 0x%X in syn_reply.\n",
|
|
|
|
self, streamID));
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult rv = self->SetInputFrameDataStream(streamID);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!self->mInputFrameDataStream) {
|
2012-05-25 14:43:10 -07:00
|
|
|
// Cannot find stream. We can continue the SPDY session, but we need to
|
|
|
|
// uncompress the header block to maintain the correct compression context
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::HandleSynReply %p lookup streamID in syn_reply "
|
2012-05-25 14:43:10 -07:00
|
|
|
"0x%X failed. NextStreamID = 0x%X\n",
|
|
|
|
self, streamID, self->mNextStreamID));
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (streamID >= self->mNextStreamID)
|
|
|
|
self->GenerateRstStream(RST_INVALID_STREAM, streamID);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-06-25 10:16:27 -07:00
|
|
|
rv = self->UncompressAndDiscard(12, self->mInputFrameDataSize - 4);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG(("SpdySession3::HandleSynReply uncompress failed\n"));
|
|
|
|
// this is fatal to the session
|
2013-06-25 10:16:27 -07:00
|
|
|
return rv;
|
2012-05-25 14:43:10 -07:00
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// Uncompress the headers into a stream specific buffer, leaving them in
|
|
|
|
// spdy format for the time being. Make certain to do this
|
|
|
|
// step before any error handling that might abort the stream but not
|
|
|
|
// the session becuase the session compression context will become
|
|
|
|
// inconsistent if all of the compressed data is not processed.
|
|
|
|
rv = self->mInputFrameDataStream->Uncompress(&self->mDownstreamZlib,
|
|
|
|
self->mInputFrameBuffer + 12,
|
|
|
|
self->mInputFrameDataSize - 4);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("SpdySession3::HandleSynReply uncompress failed\n"));
|
2013-06-25 10:16:27 -07:00
|
|
|
return rv;
|
2012-05-25 14:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (self->mInputFrameDataStream->GetFullyOpen()) {
|
|
|
|
// "If an endpoint receives multiple SYN_REPLY frames for the same active
|
|
|
|
// stream ID, it MUST issue a stream error (Section 2.4.2) with the error
|
|
|
|
// code STREAM_IN_USE."
|
|
|
|
//
|
|
|
|
// "STREAM_ALREADY_CLOSED. The endpoint received a data or SYN_REPLY
|
|
|
|
// frame for a stream which is half closed."
|
|
|
|
//
|
|
|
|
// If the stream is open then just RST_STREAM with STREAM_IN_USE
|
|
|
|
// If the stream is half closed then RST_STREAM with STREAM_ALREADY_CLOSED
|
|
|
|
// abort the session
|
|
|
|
//
|
|
|
|
LOG3(("SpdySession3::HandleSynReply %p dup SYN_REPLY for 0x%X"
|
|
|
|
" recvdfin=%d", self, self->mInputFrameDataStream->StreamID(),
|
|
|
|
self->mInputFrameDataStream->RecvdFin()));
|
|
|
|
|
|
|
|
self->CleanupStream(self->mInputFrameDataStream, NS_ERROR_ALREADY_OPENED,
|
2013-05-16 06:30:42 -07:00
|
|
|
self->mInputFrameDataStream->RecvdFin() ?
|
2012-05-25 14:43:10 -07:00
|
|
|
RST_STREAM_ALREADY_CLOSED : RST_STREAM_IN_USE);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-04-16 06:52:43 -07:00
|
|
|
|
|
|
|
rv = self->mInputFrameDataStream->SetFullyOpen();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("SpdySession3::HandleSynReply SetFullyOpen failed\n"));
|
|
|
|
if (self->mInputFrameDataStream->IsTunnel()) {
|
|
|
|
gHttpHandler->ConnMgr()->CancelTransactions(
|
|
|
|
self->mInputFrameDataStream->Transaction()->ConnectionInfo(),
|
|
|
|
NS_ERROR_CONNECTION_REFUSED);
|
|
|
|
}
|
|
|
|
self->CleanupStream(self->mInputFrameDataStream, rv, RST_CANCEL);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
self->mInputFrameDataLast = self->mInputFrameBuffer[4] & kFlag_Data_FIN;
|
|
|
|
self->mInputFrameDataStream->UpdateTransportReadEvents(self->mInputFrameDataSize);
|
|
|
|
self->mLastDataReadEpoch = self->mLastReadEpoch;
|
|
|
|
|
|
|
|
if (self->mInputFrameBuffer[4] & ~kFlag_Data_FIN) {
|
|
|
|
LOG3(("SynReply %p had undefined flag set 0x%X\n", self, streamID));
|
|
|
|
self->CleanupStream(self->mInputFrameDataStream, NS_ERROR_ILLEGAL_VALUE,
|
|
|
|
RST_PROTOCOL_ERROR);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self->mInputFrameDataLast) {
|
|
|
|
// don't process the headers yet as there could be more coming from HEADERS
|
|
|
|
// frames
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = self->ResponseHeadersComplete();
|
2012-05-25 14:37:08 -07:00
|
|
|
if (rv == NS_ERROR_ILLEGAL_VALUE) {
|
|
|
|
LOG3(("SpdySession3::HandleSynReply %p PROTOCOL_ERROR detected 0x%X\n",
|
|
|
|
self, streamID));
|
|
|
|
self->CleanupStream(self->mInputFrameDataStream, rv, RST_PROTOCOL_ERROR);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// ResponseHeadersComplete() returns NS_ERROR_ILLEGAL_VALUE when the stream
|
2012-05-25 14:37:08 -07:00
|
|
|
// should be reset with a PROTOCOL_ERROR, NS_OK when the SYN_REPLY was
|
|
|
|
// fine, and any other error is fatal to the session.
|
|
|
|
nsresult
|
2012-05-25 14:43:10 -07:00
|
|
|
SpdySession3::ResponseHeadersComplete()
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3::ResponseHeadersComplete %p for 0x%X fin=%d",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, mInputFrameDataStream->StreamID(), mInputFrameDataLast));
|
|
|
|
|
|
|
|
// The spdystream needs to see flattened http headers
|
|
|
|
// Uncompressed spdy format headers currently live in
|
2012-05-25 14:43:10 -07:00
|
|
|
// SpdyStream3::mDecompressBuffer - convert that to HTTP format in
|
|
|
|
// mFlatHTTPResponseHeaders via ConvertHeaders()
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
mFlatHTTPResponseHeadersOut = 0;
|
|
|
|
nsresult rv = mInputFrameDataStream->ConvertHeaders(mFlatHTTPResponseHeaders);
|
2012-05-25 14:37:08 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
ChangeDownstreamState(PROCESSING_COMPLETE_HEADERS);
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleRstStream(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_RST_STREAM);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
if (self->mInputFrameDataSize != 8) {
|
|
|
|
LOG3(("SpdySession3::HandleRstStream %p RST_STREAM wrong length data=%d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t flags = reinterpret_cast<uint8_t *>(self->mInputFrameBuffer.get())[4];
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t streamID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
self->mDownstreamRstReason =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 3 * sizeof(uint32_t));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleRstStream %p RST_STREAM Reason Code %u ID %x "
|
|
|
|
"flags %x", self, self->mDownstreamRstReason, streamID, flags));
|
|
|
|
|
|
|
|
if (flags != 0) {
|
|
|
|
LOG3(("SpdySession3::HandleRstStream %p RST_STREAM with flags is illegal",
|
|
|
|
self));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (self->mDownstreamRstReason == RST_INVALID_STREAM ||
|
2012-05-25 14:43:10 -07:00
|
|
|
self->mDownstreamRstReason == RST_STREAM_IN_USE ||
|
2012-05-25 14:37:08 -07:00
|
|
|
self->mDownstreamRstReason == RST_FLOW_CONTROL_ERROR) {
|
|
|
|
// basically just ignore this
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3::HandleRstStream %p No Reset Processing Needed.\n"));
|
2012-05-25 14:37:08 -07:00
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = self->SetInputFrameDataStream(streamID);
|
|
|
|
|
|
|
|
if (!self->mInputFrameDataStream) {
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
LOG(("SpdySession3::HandleRstStream %p lookup streamID for RST Frame "
|
|
|
|
"0x%X failed reason = %d :: VerifyStream Failed\n", self, streamID,
|
|
|
|
self->mDownstreamRstReason));
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleRstStream %p lookup streamID for RST Frame "
|
|
|
|
"0x%X failed reason = %d", self, streamID,
|
|
|
|
self->mDownstreamRstReason));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->ChangeDownstreamState(PROCESSING_CONTROL_RST_STREAM);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
PLDHashOperator
|
|
|
|
SpdySession3::UpdateServerRwinEnumerator(nsAHttpTransaction *key,
|
|
|
|
nsAutoPtr<SpdyStream3> &stream,
|
|
|
|
void *closure)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t delta = *(static_cast<int32_t *>(closure));
|
2012-05-25 14:43:10 -07:00
|
|
|
stream->UpdateRemoteWindow(delta);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleSettings(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_SETTINGS);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
if (self->mInputFrameDataSize < 4) {
|
|
|
|
LOG3(("SpdySession3::HandleSettings %p SETTINGS wrong length data=%d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t numEntries =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// Ensure frame is large enough for supplied number of entries
|
|
|
|
// Each entry is 8 bytes, frame data is reduced by 4 to account for
|
|
|
|
// the NumEntries value.
|
|
|
|
if ((self->mInputFrameDataSize - 4) < (numEntries * 8)) {
|
|
|
|
LOG3(("SpdySession3::HandleSettings %p SETTINGS wrong length data=%d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleSettings %p SETTINGS Control Frame with %d entries",
|
|
|
|
self, numEntries));
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t index = 0; index < numEntries; ++index) {
|
2012-05-25 14:37:08 -07:00
|
|
|
unsigned char *setting = reinterpret_cast<unsigned char *>
|
|
|
|
(self->mInputFrameBuffer.get()) + 12 + index * 8;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = setting[0];
|
2013-05-03 15:51:35 -07:00
|
|
|
uint32_t id = NetworkEndian::readUint32(setting) & 0xffffff;
|
|
|
|
uint32_t value = NetworkEndian::readUint32(setting + 1 * sizeof(uint32_t));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
LOG3(("Settings ID %d, Flags %X, Value %d", id, flags, value));
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case SETTINGS_TYPE_UPLOAD_BW:
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_UL_BW, value);
|
|
|
|
break;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
case SETTINGS_TYPE_DOWNLOAD_BW:
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_DL_BW, value);
|
|
|
|
break;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
case SETTINGS_TYPE_RTT:
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_RTT, value);
|
|
|
|
break;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
case SETTINGS_TYPE_MAX_CONCURRENT:
|
|
|
|
self->mMaxConcurrent = value;
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_MAX_STREAMS, value);
|
|
|
|
break;
|
2013-01-30 17:34:25 -08:00
|
|
|
|
2013-05-16 06:30:42 -07:00
|
|
|
case SETTINGS_TYPE_CWND:
|
2013-01-30 17:34:25 -08:00
|
|
|
if (flags & PERSIST_VALUE)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsHttpConnectionInfo> ci;
|
|
|
|
self->GetConnectionInfo(getter_AddRefs(ci));
|
|
|
|
if (ci)
|
|
|
|
gHttpHandler->ConnMgr()->ReportSpdyCWNDSetting(ci, value);
|
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_CWND, value);
|
|
|
|
break;
|
2013-01-30 17:34:25 -08:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
case SETTINGS_TYPE_DOWNLOAD_RETRANS_RATE:
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_RETRANS, value);
|
|
|
|
break;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
case SETTINGS_TYPE_INITIAL_WINDOW:
|
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_SETTINGS_IW, value >> 10);
|
2012-05-25 14:43:10 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t delta = value - self->mServerInitialWindow;
|
2012-05-25 14:43:10 -07:00
|
|
|
self->mServerInitialWindow = value;
|
|
|
|
|
|
|
|
// we need to add the delta to all open streams (delta can be negative)
|
|
|
|
self->mStreamTransactionHash.Enumerate(UpdateServerRwinEnumerator,
|
|
|
|
&delta);
|
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
break;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleNoop(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_NOOP);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// Should not be receiving noop frames in spdy/3, so we'll just
|
|
|
|
// make a log and ignore it
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleNoop %p NOP.", self));
|
|
|
|
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandlePing(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_PING);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
if (self->mInputFrameDataSize != 4) {
|
|
|
|
LOG3(("SpdySession3::HandlePing %p PING had wrong amount of data %d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t pingID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandlePing %p PING ID 0x%X.", self, pingID));
|
|
|
|
|
|
|
|
if (pingID & 0x01) {
|
|
|
|
// presumably a reply to our timeout ping
|
2012-10-25 11:20:08 -07:00
|
|
|
self->mPingSentEpoch = 0;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Servers initiate even numbered pings, go ahead and echo it back
|
|
|
|
self->GeneratePing(pingID);
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleGoAway(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_GOAWAY);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-10-05 12:03:24 -07:00
|
|
|
if (self->mInputFrameDataSize != 8) {
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::HandleGoAway %p GOAWAY had wrong amount of data %d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->mShouldGoAway = true;
|
|
|
|
self->mGoAwayID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2012-05-25 14:37:08 -07:00
|
|
|
self->mCleanShutdown = true;
|
2012-12-20 10:27:15 -08:00
|
|
|
|
2013-05-16 06:30:42 -07:00
|
|
|
// Find streams greater than the last-good ID and mark them for deletion
|
2013-05-28 21:07:03 -07:00
|
|
|
// in the mGoAwayStreamsToRestart queue with the GoAwayEnumerator. The
|
|
|
|
// underlying transaction can be restarted.
|
2012-12-20 10:27:15 -08:00
|
|
|
self->mStreamTransactionHash.Enumerate(GoAwayEnumerator, self);
|
|
|
|
|
|
|
|
// Process the streams marked for deletion and restart.
|
|
|
|
uint32_t size = self->mGoAwayStreamsToRestart.GetSize();
|
|
|
|
for (uint32_t count = 0; count < size; ++count) {
|
|
|
|
SpdyStream3 *stream =
|
|
|
|
static_cast<SpdyStream3 *>(self->mGoAwayStreamsToRestart.PopFront());
|
|
|
|
|
|
|
|
self->CloseStream(stream, NS_ERROR_NET_RESET);
|
|
|
|
if (stream->HasRegisteredID())
|
|
|
|
self->mStreamIDHash.Remove(stream->StreamID());
|
|
|
|
self->mStreamTransactionHash.Remove(stream->Transaction());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Queued streams can also be deleted from this session and restarted
|
|
|
|
// in another one. (they were never sent on the network so they implicitly
|
|
|
|
// are not covered by the last-good id.
|
|
|
|
size = self->mQueuedStreams.GetSize();
|
|
|
|
for (uint32_t count = 0; count < size; ++count) {
|
|
|
|
SpdyStream3 *stream =
|
|
|
|
static_cast<SpdyStream3 *>(self->mQueuedStreams.PopFront());
|
|
|
|
self->CloseStream(stream, NS_ERROR_NET_RESET);
|
|
|
|
self->mStreamTransactionHash.Remove(stream->Transaction());
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleGoAway %p GOAWAY Last-Good-ID 0x%X status 0x%X "
|
2013-05-16 06:30:42 -07:00
|
|
|
"live streams=%d\n", self, self->mGoAwayID,
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer +
|
|
|
|
3 * sizeof(uint32_t)),
|
2012-12-20 10:27:15 -08:00
|
|
|
self->mStreamTransactionHash.Count()));
|
2012-10-05 12:03:24 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleHeaders(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_HEADERS);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
if (self->mInputFrameDataSize < 4) {
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::HandleHeaders %p HEADERS had wrong amount of data %d",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t streamID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3::HandleHeaders %p HEADERS for Stream 0x%X.\n",
|
|
|
|
self, streamID));
|
|
|
|
nsresult rv = self->SetInputFrameDataStream(streamID);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!self->mInputFrameDataStream) {
|
|
|
|
LOG3(("SpdySession3::HandleHeaders %p lookup streamID 0x%X failed.\n",
|
|
|
|
self, streamID));
|
|
|
|
if (streamID >= self->mNextStreamID)
|
|
|
|
self->GenerateRstStream(RST_INVALID_STREAM, streamID);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-06-25 10:16:27 -07:00
|
|
|
rv = self->UncompressAndDiscard(12, self->mInputFrameDataSize - 4);
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-05-28 21:07:03 -07:00
|
|
|
LOG(("SpdySession3::HandleHeaders uncompress failed\n"));
|
2012-05-25 14:43:10 -07:00
|
|
|
// this is fatal to the session
|
2013-06-25 10:16:27 -07:00
|
|
|
return rv;
|
2012-05-25 14:43:10 -07:00
|
|
|
}
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// Uncompress the headers into local buffers in the SpdyStream, leaving
|
|
|
|
// them in spdy format for the time being. Make certain to do this
|
|
|
|
// step before any error handling that might abort the stream but not
|
|
|
|
// the session becuase the session compression context will become
|
|
|
|
// inconsistent if all of the compressed data is not processed.
|
|
|
|
rv = self->mInputFrameDataStream->Uncompress(&self->mDownstreamZlib,
|
|
|
|
self->mInputFrameBuffer + 12,
|
|
|
|
self->mInputFrameDataSize - 4);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("SpdySession3::HandleHeaders uncompress failed\n"));
|
2013-06-25 10:16:27 -07:00
|
|
|
return rv;
|
2012-05-25 14:43:10 -07:00
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
self->mInputFrameDataLast = self->mInputFrameBuffer[4] & kFlag_Data_FIN;
|
|
|
|
self->mInputFrameDataStream->
|
|
|
|
UpdateTransportReadEvents(self->mInputFrameDataSize);
|
2012-05-25 14:37:08 -07:00
|
|
|
self->mLastDataReadEpoch = self->mLastReadEpoch;
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
if (self->mInputFrameBuffer[4] & ~kFlag_Data_FIN) {
|
|
|
|
LOG3(("Headers %p had undefined flag set 0x%X\n", self, streamID));
|
|
|
|
self->CleanupStream(self->mInputFrameDataStream, NS_ERROR_ILLEGAL_VALUE,
|
|
|
|
RST_PROTOCOL_ERROR);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self->mInputFrameDataLast) {
|
|
|
|
// don't process the headers yet as there could be more HEADERS frames
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = self->ResponseHeadersComplete();
|
|
|
|
if (rv == NS_ERROR_ILLEGAL_VALUE) {
|
|
|
|
LOG3(("SpdySession3::HanndleHeaders %p PROTOCOL_ERROR detected 0x%X\n",
|
|
|
|
self, streamID));
|
|
|
|
self->CleanupStream(self->mInputFrameDataStream, rv, RST_PROTOCOL_ERROR);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleWindowUpdate(SpdySession3 *self)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_WINDOW_UPDATE);
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
if (self->mInputFrameDataSize < 8) {
|
|
|
|
LOG3(("SpdySession3::HandleWindowUpdate %p Window Update wrong length %d\n",
|
|
|
|
self, self->mInputFrameDataSize));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t delta =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 3 * sizeof(uint32_t));
|
2012-05-25 14:43:10 -07:00
|
|
|
delta &= 0x7fffffff;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t streamID =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(self->mInputFrameBuffer + 2 * sizeof(uint32_t));
|
2012-05-25 14:43:10 -07:00
|
|
|
streamID &= 0x7fffffff;
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleWindowUpdate %p len=%d for Stream 0x%X.\n",
|
|
|
|
self, delta, streamID));
|
|
|
|
nsresult rv = self->SetInputFrameDataStream(streamID);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!self->mInputFrameDataStream) {
|
|
|
|
LOG3(("SpdySession3::HandleWindowUpdate %p lookup streamID 0x%X failed.\n",
|
|
|
|
self, streamID));
|
|
|
|
if (streamID >= self->mNextStreamID)
|
|
|
|
self->GenerateRstStream(RST_INVALID_STREAM, streamID);
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->mInputFrameDataStream->UpdateRemoteWindow(delta);
|
2012-05-25 14:37:08 -07:00
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
2013-05-28 17:04:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::HandleCredential(SpdySession3 *self)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(self->mFrameControlType == CONTROL_TYPE_CREDENTIAL);
|
|
|
|
|
|
|
|
// These aren't used yet. Just ignore the frame.
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::HandleCredential %p NOP.", self));
|
|
|
|
|
|
|
|
self->ResetDownstreamState();
|
|
|
|
return NS_OK;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsAHttpTransaction. It is expected that nsHttpConnection is the caller
|
|
|
|
// of these methods
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::OnTransportStatus(nsITransport* aTransport,
|
2014-04-17 16:55:04 -07:00
|
|
|
nsresult aStatus,
|
|
|
|
uint64_t aProgress)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
switch (aStatus) {
|
|
|
|
// These should appear only once, deliver to the first
|
|
|
|
// transaction on the session.
|
|
|
|
case NS_NET_STATUS_RESOLVING_HOST:
|
|
|
|
case NS_NET_STATUS_RESOLVED_HOST:
|
|
|
|
case NS_NET_STATUS_CONNECTING_TO:
|
|
|
|
case NS_NET_STATUS_CONNECTED_TO:
|
|
|
|
{
|
|
|
|
SpdyStream3 *target = mStreamIDHash.Get(1);
|
2013-05-28 21:07:03 -07:00
|
|
|
nsAHttpTransaction *transaction = target ? target->Transaction() : nullptr;
|
|
|
|
if (transaction)
|
|
|
|
transaction->OnTransportStatus(aTransport, aStatus, aProgress);
|
2012-05-25 14:37:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
// The other transport events are ignored here because there is no good
|
|
|
|
// way to map them to the right transaction in spdy. Instead, the events
|
|
|
|
// are generated again from the spdy code and passed directly to the
|
|
|
|
// correct transaction.
|
|
|
|
|
|
|
|
// NS_NET_STATUS_SENDING_TO:
|
|
|
|
// This is generated by the socket transport when (part) of
|
|
|
|
// a transaction is written out
|
|
|
|
//
|
|
|
|
// There is no good way to map it to the right transaction in spdy,
|
|
|
|
// so it is ignored here and generated separately when the SYN_STREAM
|
|
|
|
// is sent from SpdyStream3::TransmitFrame
|
|
|
|
|
|
|
|
// NS_NET_STATUS_WAITING_FOR:
|
|
|
|
// Created by nsHttpConnection when the request has been totally sent.
|
|
|
|
// There is no good way to map it to the right transaction in spdy,
|
|
|
|
// so it is ignored here and generated separately when the same
|
|
|
|
// condition is complete in SpdyStream3 when there is no more
|
|
|
|
// request body left to be transmitted.
|
|
|
|
|
|
|
|
// NS_NET_STATUS_RECEIVING_FROM
|
|
|
|
// Generated in spdysession whenever we read a data frame or a syn_reply
|
|
|
|
// that can be attributed to a particular stream/transaction
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSegments() is used to write data to the network. Generally, HTTP
|
|
|
|
// request data is pulled from the approriate transaction and
|
|
|
|
// converted to SPDY data. Sometimes control data like window-update are
|
|
|
|
// generated instead.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::ReadSegments(nsAHttpSegmentReader *reader,
|
2014-04-17 16:55:04 -07:00
|
|
|
uint32_t count,
|
|
|
|
uint32_t *countRead)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(!mSegmentReader || !reader || (mSegmentReader == reader),
|
|
|
|
"Inconsistent Write Function Callback");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
if (reader)
|
|
|
|
mSegmentReader = reader;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
*countRead = 0;
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::ReadSegments %p", this));
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
SpdyStream3 *stream = static_cast<SpdyStream3 *>(mReadyForWrite.PopFront());
|
2012-05-25 14:37:08 -07:00
|
|
|
if (!stream) {
|
|
|
|
LOG3(("SpdySession3 %p could not identify a stream to write; suspending.",
|
|
|
|
this));
|
|
|
|
FlushOutputQueue();
|
|
|
|
SetWriteCallbacks();
|
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3 %p will write from SpdyStream3 %p 0x%X "
|
|
|
|
"block-input=%d block-output=%d\n", this, stream, stream->StreamID(),
|
|
|
|
stream->RequestBlockedOnRead(), stream->BlockedOnRwin()));
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
rv = stream->ReadSegments(this, count, countRead);
|
|
|
|
|
|
|
|
// Not every permutation of stream->ReadSegents produces data (and therefore
|
|
|
|
// tries to flush the output queue) - SENDING_FIN_STREAM can be an example
|
|
|
|
// of that. But we might still have old data buffered that would be good
|
|
|
|
// to flush.
|
|
|
|
FlushOutputQueue();
|
|
|
|
|
2012-11-10 07:27:59 -08:00
|
|
|
// Allow new server reads - that might be data or control information
|
|
|
|
// (e.g. window updates or http replies) that are responses to these writes
|
|
|
|
ResumeRecv();
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (stream->RequestBlockedOnRead()) {
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// We are blocked waiting for input - either more http headers or
|
|
|
|
// any request body data. When more data from the request stream
|
|
|
|
// becomes available the httptransaction will call conn->ResumeSend().
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::ReadSegments %p dealing with block on read", this));
|
|
|
|
|
|
|
|
// call readsegments again if there are other streams ready
|
|
|
|
// to run in this session
|
|
|
|
if (GetWriteQueueSize())
|
|
|
|
rv = NS_OK;
|
|
|
|
else
|
|
|
|
rv = NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
SetWriteCallbacks();
|
|
|
|
return rv;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG3(("SpdySession3::ReadSegments %p returning FAIL code %X",
|
|
|
|
this, rv));
|
|
|
|
if (rv != NS_BASE_STREAM_WOULD_BLOCK)
|
|
|
|
CleanupStream(stream, rv, RST_CANCEL);
|
|
|
|
return rv;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (*countRead > 0) {
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3::ReadSegments %p stream=%p countread=%d",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, stream, *countRead));
|
|
|
|
mReadyForWrite.Push(stream);
|
|
|
|
SetWriteCallbacks();
|
|
|
|
return rv;
|
|
|
|
}
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
if (stream->BlockedOnRwin()) {
|
|
|
|
LOG3(("SpdySession3 %p will stream %p 0x%X suspended for flow control\n",
|
|
|
|
this, stream, stream->StreamID()));
|
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::ReadSegments %p stream=%p stream send complete",
|
|
|
|
this, stream));
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// call readsegments again if there are other streams ready
|
|
|
|
// to go in this session
|
|
|
|
SetWriteCallbacks();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteSegments() is used to read data off the socket. Generally this is
|
|
|
|
// just the SPDY frame header and from there the appropriate SPDYStream
|
|
|
|
// is identified from the Stream-ID. The http transaction associated with
|
|
|
|
// that read then pulls in the data directly, which it will feed to
|
|
|
|
// OnWriteSegment(). That function will gateway it into http and feed
|
|
|
|
// it to the appropriate transaction.
|
|
|
|
|
2013-05-16 06:30:42 -07:00
|
|
|
// we call writer->OnWriteSegment via NetworkRead() to get a spdy header..
|
2012-05-25 14:37:08 -07:00
|
|
|
// and decide if it is data or control.. if it is control, just deal with it.
|
|
|
|
// if it is data, identify the spdy stream
|
2013-05-28 21:07:02 -07:00
|
|
|
// call stream->WriteSegments which can call this::OnWriteSegment to get the
|
2012-05-25 14:37:08 -07:00
|
|
|
// data. It always gets full frames if they are part of the stream
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::WriteSegments(nsAHttpSegmentWriter *writer,
|
2014-04-17 16:55:04 -07:00
|
|
|
uint32_t count,
|
|
|
|
uint32_t *countWritten)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-11-16 21:19:51 -08:00
|
|
|
typedef nsresult (*Control_FX) (SpdySession3 *self);
|
|
|
|
static const Control_FX sControlFunctions[] =
|
|
|
|
{
|
|
|
|
nullptr,
|
|
|
|
SpdySession3::HandleSynStream,
|
|
|
|
SpdySession3::HandleSynReply,
|
|
|
|
SpdySession3::HandleRstStream,
|
|
|
|
SpdySession3::HandleSettings,
|
|
|
|
SpdySession3::HandleNoop,
|
|
|
|
SpdySession3::HandlePing,
|
|
|
|
SpdySession3::HandleGoAway,
|
|
|
|
SpdySession3::HandleHeaders,
|
|
|
|
SpdySession3::HandleWindowUpdate,
|
|
|
|
SpdySession3::HandleCredential
|
|
|
|
};
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult rv;
|
|
|
|
*countWritten = 0;
|
|
|
|
|
|
|
|
if (mClosed)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
SetWriteCallbacks();
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
// If there are http transactions attached to a push stream with filled buffers
|
|
|
|
// trigger that data pump here. This only reads from buffers (not the network)
|
|
|
|
// so mDownstreamState doesn't matter.
|
|
|
|
SpdyStream3 *pushConnectedStream =
|
|
|
|
static_cast<SpdyStream3 *>(mReadyForRead.PopFront());
|
|
|
|
if (pushConnectedStream) {
|
|
|
|
LOG3(("SpdySession3::WriteSegments %p processing pushed stream 0x%X\n",
|
|
|
|
this, pushConnectedStream->StreamID()));
|
|
|
|
mSegmentWriter = writer;
|
|
|
|
rv = pushConnectedStream->WriteSegments(this, count, countWritten);
|
|
|
|
mSegmentWriter = nullptr;
|
|
|
|
|
|
|
|
// The pipe in nsHttpTransaction rewrites CLOSED error codes into OK
|
|
|
|
// so we need this check to determine the truth.
|
|
|
|
if (NS_SUCCEEDED(rv) && !*countWritten &&
|
|
|
|
pushConnectedStream->PushSource() &&
|
|
|
|
pushConnectedStream->PushSource()->GetPushComplete()) {
|
|
|
|
rv = NS_BASE_STREAM_CLOSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rv == NS_BASE_STREAM_CLOSED) {
|
|
|
|
CleanupStream(pushConnectedStream, NS_OK, RST_CANCEL);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we return OK to nsHttpConnection it will use mSocketInCondition
|
|
|
|
// to determine whether to schedule more reads, incorrectly
|
|
|
|
// assuming that nsHttpConnection::OnSocketWrite() was called.
|
|
|
|
if (NS_SUCCEEDED(rv) || rv == NS_BASE_STREAM_WOULD_BLOCK) {
|
|
|
|
rv = NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
ResumeRecv();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// We buffer all control frames and act on them in this layer.
|
|
|
|
// We buffer the first 8 bytes of data frames (the header) but
|
|
|
|
// the actual data is passed through unprocessed.
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mDownstreamState == BUFFERING_FRAME_HEADER) {
|
|
|
|
// The first 8 bytes of every frame is header information that
|
|
|
|
// we are going to want to strip before passing to http. That is
|
|
|
|
// true of both control and data packets.
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(mInputFrameBufferUsed < 8,
|
|
|
|
"Frame Buffer Used Too Large for State");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
rv = NetworkRead(writer, mInputFrameBuffer + mInputFrameBufferUsed,
|
|
|
|
8 - mInputFrameBufferUsed, countWritten);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG3(("SpdySession3 %p buffering frame header read failure %x\n",
|
|
|
|
this, rv));
|
|
|
|
// maybe just blocked reading from network
|
|
|
|
if (rv == NS_BASE_STREAM_WOULD_BLOCK)
|
2013-05-28 21:07:02 -07:00
|
|
|
rv = NS_OK;
|
2012-05-25 14:37:08 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
LogIO(this, nullptr, "Reading Frame Header",
|
2012-05-25 14:37:08 -07:00
|
|
|
mInputFrameBuffer + mInputFrameBufferUsed, *countWritten);
|
|
|
|
|
|
|
|
mInputFrameBufferUsed += *countWritten;
|
|
|
|
|
|
|
|
if (mInputFrameBufferUsed < 8)
|
|
|
|
{
|
|
|
|
LOG3(("SpdySession3::WriteSegments %p "
|
|
|
|
"BUFFERING FRAME HEADER incomplete size=%d",
|
|
|
|
this, mInputFrameBufferUsed));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For both control and data frames the second 32 bit word of the header
|
|
|
|
// is 8-flags, 24-length. (network byte order)
|
|
|
|
mInputFrameDataSize =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint32(mInputFrameBuffer + 1 * sizeof(uint32_t));
|
2012-05-25 14:37:08 -07:00
|
|
|
mInputFrameDataSize &= 0x00ffffff;
|
|
|
|
mInputFrameDataRead = 0;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mInputFrameBuffer[0] & kFlag_Control) {
|
|
|
|
EnsureBuffer(mInputFrameBuffer, mInputFrameDataSize + 8, 8,
|
|
|
|
mInputFrameBufferSize);
|
|
|
|
ChangeDownstreamState(BUFFERING_CONTROL_FRAME);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// The first 32 bit word of the header is
|
|
|
|
// 1 ctrl - 15 version - 16 type
|
2013-05-03 15:51:35 -07:00
|
|
|
uint16_t version = NetworkEndian::readUint16(mInputFrameBuffer);
|
2012-05-25 14:37:08 -07:00
|
|
|
version &= 0x7fff;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mFrameControlType =
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::readUint16(mInputFrameBuffer + sizeof(uint16_t));
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::WriteSegments %p - Control Frame Identified "
|
|
|
|
"type %d version %d data len %d",
|
|
|
|
this, mFrameControlType, version, mInputFrameDataSize));
|
|
|
|
|
|
|
|
if (mFrameControlType >= CONTROL_TYPE_LAST ||
|
|
|
|
mFrameControlType <= CONTROL_TYPE_FIRST)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
if (version != kVersion)
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ChangeDownstreamState(PROCESSING_DATA_FRAME);
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_CHUNK_RECVD,
|
|
|
|
mInputFrameDataSize >> 10);
|
|
|
|
mLastDataReadEpoch = mLastReadEpoch;
|
|
|
|
|
2013-05-03 15:51:35 -07:00
|
|
|
uint32_t streamID = NetworkEndian::readUint32(mInputFrameBuffer);
|
2012-05-25 14:37:08 -07:00
|
|
|
rv = SetInputFrameDataStream(streamID);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("SpdySession3::WriteSegments %p lookup streamID 0x%X failed. "
|
|
|
|
"probably due to verification.\n", this, streamID));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (!mInputFrameDataStream) {
|
|
|
|
LOG3(("SpdySession3::WriteSegments %p lookup streamID 0x%X failed. "
|
2012-05-25 14:43:10 -07:00
|
|
|
"Next = 0x%X", this, streamID, mNextStreamID));
|
2012-05-25 14:37:08 -07:00
|
|
|
if (streamID >= mNextStreamID)
|
|
|
|
GenerateRstStream(RST_INVALID_STREAM, streamID);
|
|
|
|
ChangeDownstreamState(DISCARDING_DATA_FRAME);
|
|
|
|
}
|
2012-05-25 14:43:10 -07:00
|
|
|
else if (mInputFrameDataStream->RecvdFin()) {
|
|
|
|
LOG3(("SpdySession3::WriteSegments %p streamID 0x%X "
|
|
|
|
"Data arrived for already server closed stream.\n",
|
|
|
|
this, streamID));
|
|
|
|
GenerateRstStream(RST_STREAM_ALREADY_CLOSED, streamID);
|
|
|
|
ChangeDownstreamState(DISCARDING_DATA_FRAME);
|
|
|
|
}
|
|
|
|
else if (!mInputFrameDataStream->RecvdData()) {
|
|
|
|
LOG3(("SpdySession3 %p First Data Frame Flushes Headers stream 0x%X\n",
|
|
|
|
this, streamID));
|
|
|
|
|
|
|
|
mInputFrameDataStream->SetRecvdData(true);
|
|
|
|
rv = ResponseHeadersComplete();
|
|
|
|
if (rv == NS_ERROR_ILLEGAL_VALUE) {
|
|
|
|
LOG3(("SpdySession3 %p PROTOCOL_ERROR detected 0x%X\n",
|
|
|
|
this, streamID));
|
|
|
|
CleanupStream(mInputFrameDataStream, rv, RST_PROTOCOL_ERROR);
|
|
|
|
ChangeDownstreamState(DISCARDING_DATA_FRAME);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mDataPending = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mInputFrameDataLast = (mInputFrameBuffer[4] & kFlag_Data_FIN);
|
|
|
|
LOG3(("Start Processing Data Frame. "
|
2012-05-25 14:43:10 -07:00
|
|
|
"Session=%p Stream ID 0x%X Stream Ptr %p Fin=%d Len=%d",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, streamID, mInputFrameDataStream, mInputFrameDataLast,
|
|
|
|
mInputFrameDataSize));
|
2012-05-25 14:43:10 -07:00
|
|
|
UpdateLocalRwin(mInputFrameDataStream, mInputFrameDataSize);
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDownstreamState == PROCESSING_CONTROL_RST_STREAM) {
|
|
|
|
if (mDownstreamRstReason == RST_REFUSED_STREAM)
|
|
|
|
rv = NS_ERROR_NET_RESET; //we can retry this 100% safely
|
2014-06-08 15:15:00 -07:00
|
|
|
else if (mDownstreamRstReason == RST_CANCEL) {
|
|
|
|
rv = mInputFrameDataStream->RecvdData() ?
|
|
|
|
NS_ERROR_NET_PARTIAL_TRANSFER :
|
|
|
|
NS_ERROR_NET_INTERRUPT;
|
|
|
|
}
|
|
|
|
else if (mDownstreamRstReason == RST_PROTOCOL_ERROR ||
|
2012-05-25 14:37:08 -07:00
|
|
|
mDownstreamRstReason == RST_INTERNAL_ERROR ||
|
2014-06-08 15:15:00 -07:00
|
|
|
mDownstreamRstReason == RST_UNSUPPORTED_VERSION) {
|
2012-05-25 14:37:08 -07:00
|
|
|
rv = NS_ERROR_NET_INTERRUPT;
|
2014-06-08 15:15:00 -07:00
|
|
|
}
|
2012-05-25 14:43:10 -07:00
|
|
|
else if (mDownstreamRstReason == RST_FRAME_TOO_LARGE)
|
|
|
|
rv = NS_ERROR_FILE_TOO_BIG;
|
2012-05-25 14:37:08 -07:00
|
|
|
else
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if (mDownstreamRstReason != RST_REFUSED_STREAM &&
|
|
|
|
mDownstreamRstReason != RST_CANCEL)
|
|
|
|
mShouldGoAway = true;
|
|
|
|
|
|
|
|
// mInputFrameDataStream is reset by ChangeDownstreamState
|
|
|
|
SpdyStream3 *stream = mInputFrameDataStream;
|
|
|
|
ResetDownstreamState();
|
|
|
|
LOG3(("SpdySession3::WriteSegments cleanup stream on recv of rst "
|
|
|
|
"session=%p stream=%p 0x%X\n", this, stream,
|
|
|
|
stream ? stream->StreamID() : 0));
|
|
|
|
CleanupStream(stream, rv, RST_CANCEL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDownstreamState == PROCESSING_DATA_FRAME ||
|
2012-05-25 14:43:10 -07:00
|
|
|
mDownstreamState == PROCESSING_COMPLETE_HEADERS) {
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// The cleanup stream should only be set while stream->WriteSegments is
|
|
|
|
// on the stack and then cleaned up in this code block afterwards.
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(!mNeedsCleanup, "cleanup stream set unexpectedly");
|
2012-07-30 07:20:58 -07:00
|
|
|
mNeedsCleanup = nullptr; /* just in case */
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2014-04-16 06:52:43 -07:00
|
|
|
SpdyStream3 *stream = mInputFrameDataStream;
|
2012-05-25 14:37:08 -07:00
|
|
|
mSegmentWriter = writer;
|
|
|
|
rv = mInputFrameDataStream->WriteSegments(this, count, countWritten);
|
2012-07-30 07:20:58 -07:00
|
|
|
mSegmentWriter = nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
mLastDataReadEpoch = mLastReadEpoch;
|
|
|
|
|
2014-01-07 04:29:11 -08:00
|
|
|
if (SoftStreamError(rv)) {
|
2012-05-25 14:37:08 -07:00
|
|
|
// This will happen when the transaction figures out it is EOF, generally
|
2014-01-07 04:29:11 -08:00
|
|
|
// due to a content-length match being made. Return OK from this function
|
|
|
|
// otherwise the whole session would be torn down.
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
// if we were doing PROCESSING_COMPLETE_HEADERS need to pop the state
|
|
|
|
// back to PROCESSING_DATA_FRAME where we came from
|
|
|
|
mDownstreamState = PROCESSING_DATA_FRAME;
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mInputFrameDataRead == mInputFrameDataSize)
|
|
|
|
ResetDownstreamState();
|
|
|
|
LOG3(("SpdySession3::WriteSegments session=%p stream=%p 0x%X "
|
|
|
|
"needscleanup=%p. cleanup stream based on "
|
2014-01-07 04:29:11 -08:00
|
|
|
"stream->writeSegments returning code %X\n",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, stream, stream ? stream->StreamID() : 0,
|
2014-01-07 04:29:11 -08:00
|
|
|
mNeedsCleanup, rv));
|
2012-05-25 14:37:08 -07:00
|
|
|
CleanupStream(stream, NS_OK, RST_CANCEL);
|
2014-04-16 06:52:43 -07:00
|
|
|
MOZ_ASSERT(!mNeedsCleanup || mNeedsCleanup == stream);
|
|
|
|
mNeedsCleanup = nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mNeedsCleanup) {
|
|
|
|
LOG3(("SpdySession3::WriteSegments session=%p stream=%p 0x%X "
|
|
|
|
"cleanup stream based on mNeedsCleanup.\n",
|
|
|
|
this, mNeedsCleanup, mNeedsCleanup ? mNeedsCleanup->StreamID() : 0));
|
|
|
|
CleanupStream(mNeedsCleanup, NS_OK, RST_CANCEL);
|
2012-07-30 07:20:58 -07:00
|
|
|
mNeedsCleanup = nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:02 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG3(("SpdySession3 %p data frame read failure %x\n", this, rv));
|
|
|
|
// maybe just blocked reading from network
|
|
|
|
if (rv == NS_BASE_STREAM_WOULD_BLOCK)
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDownstreamState == DISCARDING_DATA_FRAME) {
|
|
|
|
char trash[4096];
|
2013-01-15 04:22:03 -08:00
|
|
|
uint32_t count = std::min(4096U, mInputFrameDataSize - mInputFrameDataRead);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
if (!count) {
|
|
|
|
ResetDownstreamState();
|
|
|
|
ResumeRecv();
|
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = NetworkRead(writer, trash, count, countWritten);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG3(("SpdySession3 %p discard frame read failure %x\n", this, rv));
|
|
|
|
// maybe just blocked reading from network
|
|
|
|
if (rv == NS_BASE_STREAM_WOULD_BLOCK)
|
2013-05-28 21:07:02 -07:00
|
|
|
rv = NS_OK;
|
2012-05-25 14:37:08 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
LogIO(this, nullptr, "Discarding Frame", trash, *countWritten);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
mInputFrameDataRead += *countWritten;
|
|
|
|
|
|
|
|
if (mInputFrameDataRead == mInputFrameDataSize)
|
|
|
|
ResetDownstreamState();
|
|
|
|
return rv;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
MOZ_ASSERT(mDownstreamState == BUFFERING_CONTROL_FRAME);
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mDownstreamState != BUFFERING_CONTROL_FRAME) {
|
|
|
|
// this cannot happen
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(mInputFrameBufferUsed == 8,
|
|
|
|
"Frame Buffer Header Not Present");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
rv = NetworkRead(writer, mInputFrameBuffer + 8 + mInputFrameDataRead,
|
|
|
|
mInputFrameDataSize - mInputFrameDataRead, countWritten);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG3(("SpdySession3 %p buffering control frame read failure %x\n",
|
|
|
|
this, rv));
|
|
|
|
// maybe just blocked reading from network
|
|
|
|
if (rv == NS_BASE_STREAM_WOULD_BLOCK)
|
2013-05-28 21:07:02 -07:00
|
|
|
rv = NS_OK;
|
2012-05-25 14:37:08 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
LogIO(this, nullptr, "Reading Control Frame",
|
2012-05-25 14:37:08 -07:00
|
|
|
mInputFrameBuffer + 8 + mInputFrameDataRead, *countWritten);
|
|
|
|
|
|
|
|
mInputFrameDataRead += *countWritten;
|
|
|
|
|
|
|
|
if (mInputFrameDataRead != mInputFrameDataSize)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// This check is actually redundant, the control type was previously
|
|
|
|
// checked to make sure it was in range, but we will check it again
|
|
|
|
// at time of use to make sure a regression doesn't creep in.
|
|
|
|
if (mFrameControlType >= CONTROL_TYPE_LAST ||
|
2013-05-16 06:30:42 -07:00
|
|
|
mFrameControlType <= CONTROL_TYPE_FIRST)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "control type out of range");
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
rv = sControlFunctions[mFrameControlType](this);
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(NS_FAILED(rv) ||
|
|
|
|
mDownstreamState != BUFFERING_CONTROL_FRAME,
|
|
|
|
"Control Handler returned OK but did not change state");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
if (mShouldGoAway && !mStreamTransactionHash.Count())
|
|
|
|
Close(NS_OK);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
void
|
|
|
|
SpdySession3::UpdateLocalRwin(SpdyStream3 *stream,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t bytes)
|
2012-05-25 14:43:10 -07:00
|
|
|
{
|
|
|
|
// If this data packet was not for a valid or live stream then there
|
|
|
|
// is no reason to mess with the flow control
|
|
|
|
if (!stream || stream->RecvdFin())
|
|
|
|
return;
|
|
|
|
|
|
|
|
stream->DecrementLocalWindow(bytes);
|
|
|
|
|
|
|
|
// Don't necessarily ack every data packet. Only do it
|
|
|
|
// after a significant amount of data.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t unacked = stream->LocalUnAcked();
|
2013-05-28 21:07:03 -07:00
|
|
|
int64_t localWindow = stream->LocalWindow();
|
2012-05-25 14:43:10 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
LOG3(("SpdySession3::UpdateLocalRwin this=%p id=0x%X newbytes=%u "
|
|
|
|
"unacked=%llu localWindow=%lld\n",
|
|
|
|
this, stream->StreamID(), bytes, unacked, localWindow));
|
2012-05-25 14:43:10 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
if (!unacked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((unacked < kMinimumToAck) && (localWindow > kEmergencyWindowThreshold))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!stream->HasSink()) {
|
|
|
|
LOG3(("SpdySession3::UpdateLocalRwin %p 0x%X Pushed Stream Has No Sink\n",
|
|
|
|
this, stream->StreamID()));
|
2012-05-25 14:43:10 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate window updates directly out of spdysession instead of the stream
|
2013-05-28 21:07:03 -07:00
|
|
|
// in order to avoid queue delays in getting the 'ACK' out.
|
2013-05-28 17:05:53 -07:00
|
|
|
uint32_t toack = (unacked <= 0x7fffffffU) ? unacked : 0x7fffffffU;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
LOG3(("SpdySession3::UpdateLocalRwin Ack this=%p id=0x%X acksize=%d\n",
|
2012-05-25 14:43:10 -07:00
|
|
|
this, stream->StreamID(), toack));
|
|
|
|
stream->IncrementLocalWindow(toack);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint32_t dataLen = 8;
|
2012-05-25 14:43:10 -07:00
|
|
|
EnsureBuffer(mOutputQueueBuffer, mOutputQueueUsed + 8 + dataLen,
|
|
|
|
mOutputQueueUsed, mOutputQueueSize);
|
|
|
|
char *packet = mOutputQueueBuffer.get() + mOutputQueueUsed;
|
|
|
|
mOutputQueueUsed += 8 + dataLen;
|
|
|
|
|
|
|
|
memset(packet, 0, 8 + dataLen);
|
|
|
|
packet[0] = kFlag_Control;
|
|
|
|
packet[1] = kVersion;
|
|
|
|
packet[3] = CONTROL_TYPE_WINDOW_UPDATE;
|
|
|
|
packet[7] = dataLen;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-05-03 15:51:35 -07:00
|
|
|
NetworkEndian::writeUint32(packet + 8, stream->StreamID());
|
|
|
|
NetworkEndian::writeUint32(packet + 12, toack);
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
LogIO(this, stream, "Window Update", packet, 8 + dataLen);
|
|
|
|
FlushOutputQueue();
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
void
|
|
|
|
SpdySession3::Close(nsresult aReason)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
if (mClosed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::Close %p %X", this, aReason));
|
|
|
|
|
|
|
|
mClosed = true;
|
2012-06-03 18:13:12 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mStreamTransactionHash.Enumerate(ShutdownEnumerator, this);
|
2012-06-03 18:13:12 -07:00
|
|
|
mStreamIDHash.Clear();
|
|
|
|
mStreamTransactionHash.Clear();
|
|
|
|
|
2013-06-25 10:16:27 -07:00
|
|
|
uint32_t goAwayReason;
|
|
|
|
if (NS_SUCCEEDED(aReason)) {
|
|
|
|
goAwayReason = OK;
|
|
|
|
} else if (aReason == NS_ERROR_ILLEGAL_VALUE) {
|
|
|
|
goAwayReason = PROTOCOL_ERROR;
|
|
|
|
} else {
|
|
|
|
goAwayReason = INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
GenerateGoAway(goAwayReason);
|
2012-07-30 07:20:58 -07:00
|
|
|
mConnection = nullptr;
|
|
|
|
mSegmentReader = nullptr;
|
|
|
|
mSegmentWriter = nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2014-04-20 09:01:35 -07:00
|
|
|
nsHttpConnectionInfo *
|
|
|
|
SpdySession3::ConnectionInfo()
|
|
|
|
{
|
|
|
|
nsRefPtr<nsHttpConnectionInfo> ci;
|
|
|
|
GetConnectionInfo(getter_AddRefs(ci));
|
|
|
|
return ci.get();
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
void
|
|
|
|
SpdySession3::CloseTransaction(nsAHttpTransaction *aTransaction,
|
2014-04-17 16:55:04 -07:00
|
|
|
nsresult aResult)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::CloseTransaction %p %p %x", this, aTransaction, aResult));
|
|
|
|
|
|
|
|
// Generally this arrives as a cancel event from the connection manager.
|
|
|
|
|
|
|
|
// need to find the stream and call CleanupStream() on it.
|
|
|
|
SpdyStream3 *stream = mStreamTransactionHash.Get(aTransaction);
|
|
|
|
if (!stream) {
|
|
|
|
LOG3(("SpdySession3::CloseTransaction %p %p %x - not found.",
|
|
|
|
this, aTransaction, aResult));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG3(("SpdySession3::CloseTranscation probably a cancel. "
|
|
|
|
"this=%p, trans=%p, result=%x, streamID=0x%X stream=%p",
|
|
|
|
this, aTransaction, aResult, stream->StreamID(), stream));
|
|
|
|
CleanupStream(stream, aResult, RST_CANCEL);
|
|
|
|
ResumeRecv();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsAHttpSegmentReader
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::OnReadSegment(const char *buf,
|
2014-04-17 16:55:04 -07:00
|
|
|
uint32_t count,
|
|
|
|
uint32_t *countRead)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult rv;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// If we can release old queued data then we can try and write the new
|
|
|
|
// data directly to the network without using the output queue at all
|
|
|
|
if (mOutputQueueUsed)
|
|
|
|
FlushOutputQueue();
|
|
|
|
|
|
|
|
if (!mOutputQueueUsed && mSegmentReader) {
|
|
|
|
// try and write directly without output queue
|
|
|
|
rv = mSegmentReader->OnReadSegment(buf, count, countRead);
|
|
|
|
|
|
|
|
if (rv == NS_BASE_STREAM_WOULD_BLOCK)
|
|
|
|
*countRead = 0;
|
|
|
|
else if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (*countRead < count) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t required = count - *countRead;
|
2012-05-25 14:37:08 -07:00
|
|
|
// assuming a commitment() happened, this ensurebuffer is a nop
|
|
|
|
// but just in case the queuesize is too small for the required data
|
|
|
|
// call ensurebuffer().
|
|
|
|
EnsureBuffer(mOutputQueueBuffer, required, 0, mOutputQueueSize);
|
|
|
|
memcpy(mOutputQueueBuffer.get(), buf + *countRead, required);
|
|
|
|
mOutputQueueUsed = required;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
*countRead = count;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point we are going to buffer the new data in the output
|
|
|
|
// queue if it fits. By coalescing multiple small submissions into one larger
|
|
|
|
// buffer we can get larger writes out to the network later on.
|
|
|
|
|
|
|
|
// This routine should not be allowed to fill up the output queue
|
|
|
|
// all on its own - at least kQueueReserved bytes are always left
|
|
|
|
// for other routines to use - but this is an all-or-nothing function,
|
|
|
|
// so if it will not all fit just return WOULD_BLOCK
|
|
|
|
|
|
|
|
if ((mOutputQueueUsed + count) > (mOutputQueueSize - kQueueReserved))
|
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
memcpy(mOutputQueueBuffer.get() + mOutputQueueUsed, buf, count);
|
|
|
|
mOutputQueueUsed += count;
|
|
|
|
*countRead = count;
|
|
|
|
|
|
|
|
FlushOutputQueue();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-18 14:14:21 -08:00
|
|
|
SpdySession3::CommitToSegmentSize(uint32_t count, bool forceCommitment)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
if (mOutputQueueUsed)
|
|
|
|
FlushOutputQueue();
|
|
|
|
|
|
|
|
// would there be enough room to buffer this if needed?
|
|
|
|
if ((mOutputQueueUsed + count) <= (mOutputQueueSize - kQueueReserved))
|
|
|
|
return NS_OK;
|
2012-12-18 14:14:21 -08:00
|
|
|
|
|
|
|
// if we are using part of our buffers already, try again later unless
|
|
|
|
// forceCommitment is set.
|
|
|
|
if (mOutputQueueUsed && !forceCommitment)
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
|
2012-12-18 14:14:21 -08:00
|
|
|
if (mOutputQueueUsed) {
|
|
|
|
// normally we avoid the memmove of RealignOutputQueue, but we'll try
|
|
|
|
// it if forceCommitment is set before growing the buffer.
|
|
|
|
RealignOutputQueue();
|
|
|
|
|
|
|
|
// is there enough room now?
|
|
|
|
if ((mOutputQueueUsed + count) <= (mOutputQueueSize - kQueueReserved))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-12-18 14:14:21 -08:00
|
|
|
// resize the buffers as needed
|
|
|
|
EnsureBuffer(mOutputQueueBuffer, mOutputQueueUsed + count + kQueueReserved,
|
|
|
|
mOutputQueueUsed, mOutputQueueSize);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT((mOutputQueueUsed + count) <= (mOutputQueueSize - kQueueReserved),
|
|
|
|
"buffer not as large as expected");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsAHttpSegmentWriter
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::OnWriteSegment(char *buf,
|
2014-04-17 16:55:04 -07:00
|
|
|
uint32_t count,
|
|
|
|
uint32_t *countWritten)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!mSegmentWriter) {
|
|
|
|
// the only way this could happen would be if Close() were called on the
|
|
|
|
// stack with WriteSegments()
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mDownstreamState == PROCESSING_DATA_FRAME) {
|
|
|
|
|
|
|
|
if (mInputFrameDataLast &&
|
|
|
|
mInputFrameDataRead == mInputFrameDataSize) {
|
|
|
|
*countWritten = 0;
|
|
|
|
SetNeedsCleanup();
|
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
count = std::min(count, mInputFrameDataSize - mInputFrameDataRead);
|
2012-05-25 14:37:08 -07:00
|
|
|
rv = NetworkRead(mSegmentWriter, buf, count, countWritten);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
LogIO(this, mInputFrameDataStream, "Reading Data Frame",
|
|
|
|
buf, *countWritten);
|
|
|
|
|
|
|
|
mInputFrameDataRead += *countWritten;
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
mInputFrameDataStream->UpdateTransportReadEvents(*countWritten);
|
|
|
|
if ((mInputFrameDataRead == mInputFrameDataSize) && !mInputFrameDataLast)
|
|
|
|
ResetDownstreamState();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
if (mDownstreamState == PROCESSING_COMPLETE_HEADERS) {
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
if (mFlatHTTPResponseHeaders.Length() == mFlatHTTPResponseHeadersOut &&
|
|
|
|
mInputFrameDataLast) {
|
|
|
|
*countWritten = 0;
|
|
|
|
SetNeedsCleanup();
|
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
count = std::min(count,
|
2012-05-25 14:37:08 -07:00
|
|
|
mFlatHTTPResponseHeaders.Length() -
|
|
|
|
mFlatHTTPResponseHeadersOut);
|
|
|
|
memcpy(buf,
|
|
|
|
mFlatHTTPResponseHeaders.get() + mFlatHTTPResponseHeadersOut,
|
|
|
|
count);
|
|
|
|
mFlatHTTPResponseHeadersOut += count;
|
|
|
|
*countWritten = count;
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
if (mFlatHTTPResponseHeaders.Length() == mFlatHTTPResponseHeadersOut) {
|
|
|
|
if (mDataPending) {
|
2012-06-20 10:07:01 -07:00
|
|
|
// Now ready to process data frames - pop PROCESING_DATA_FRAME back onto
|
|
|
|
// the stack because receipt of that first data frame triggered the
|
|
|
|
// response header processing
|
2012-05-25 14:43:10 -07:00
|
|
|
mDataPending = false;
|
|
|
|
ChangeDownstreamState(PROCESSING_DATA_FRAME);
|
|
|
|
}
|
2012-06-20 10:07:01 -07:00
|
|
|
else if (!mInputFrameDataLast) {
|
|
|
|
// If more frames are expected in this stream, then reset the state so they can be
|
|
|
|
// handled. Otherwise (e.g. a 0 length response with the fin on the SYN_REPLY)
|
|
|
|
// stay in PROCESSING_COMPLETE_HEADERS state so the SetNeedsCleanup() code above can
|
|
|
|
// cleanup the stream.
|
2012-05-25 14:43:10 -07:00
|
|
|
ResetDownstreamState();
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::SetNeedsCleanup()
|
|
|
|
{
|
|
|
|
LOG3(("SpdySession3::SetNeedsCleanup %p - recorded downstream fin of "
|
|
|
|
"stream %p 0x%X", this, mInputFrameDataStream,
|
|
|
|
mInputFrameDataStream->StreamID()));
|
|
|
|
|
|
|
|
// This will result in Close() being called
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(!mNeedsCleanup, "mNeedsCleanup unexpectedly set");
|
2012-05-25 14:37:08 -07:00
|
|
|
mNeedsCleanup = mInputFrameDataStream;
|
|
|
|
ResetDownstreamState();
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
void
|
|
|
|
SpdySession3::ConnectPushedStream(SpdyStream3 *stream)
|
|
|
|
{
|
|
|
|
mReadyForRead.Push(stream);
|
|
|
|
ForceRecv();
|
|
|
|
}
|
|
|
|
|
2014-04-16 06:52:43 -07:00
|
|
|
uint32_t
|
|
|
|
SpdySession3::FindTunnelCount(nsHttpConnectionInfo *aConnInfo)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
|
|
|
uint32_t rv = 0;
|
|
|
|
mTunnelHash.Get(aConnInfo->HashKey(), &rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::RegisterTunnel(SpdyStream3 *aTunnel)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
|
|
|
nsHttpConnectionInfo *ci = aTunnel->Transaction()->ConnectionInfo();
|
|
|
|
uint32_t newcount = FindTunnelCount(ci) + 1;
|
|
|
|
mTunnelHash.Remove(ci->HashKey());
|
|
|
|
mTunnelHash.Put(ci->HashKey(), newcount);
|
|
|
|
LOG3(("SpdySession3::RegisterTunnel %p stream=%p tunnels=%d [%s]",
|
|
|
|
this, aTunnel, newcount, ci->HashKey().get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::UnRegisterTunnel(SpdyStream3 *aTunnel)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
|
|
|
nsHttpConnectionInfo *ci = aTunnel->Transaction()->ConnectionInfo();
|
|
|
|
MOZ_ASSERT(FindTunnelCount(ci));
|
|
|
|
uint32_t newcount = FindTunnelCount(ci) - 1;
|
|
|
|
mTunnelHash.Remove(ci->HashKey());
|
|
|
|
if (newcount) {
|
|
|
|
mTunnelHash.Put(ci->HashKey(), newcount);
|
|
|
|
}
|
|
|
|
LOG3(("SpdySession3::UnRegisterTunnel %p stream=%p tunnels=%d [%s]",
|
|
|
|
this, aTunnel, newcount, ci->HashKey().get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::DispatchOnTunnel(nsAHttpTransaction *aHttpTransaction,
|
|
|
|
nsIInterfaceRequestor *aCallbacks)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
|
|
|
nsHttpTransaction *trans = aHttpTransaction->QueryHttpTransaction();
|
|
|
|
nsHttpConnectionInfo *ci = aHttpTransaction->ConnectionInfo();
|
|
|
|
MOZ_ASSERT(trans);
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::DispatchOnTunnel %p trans=%p", this, trans));
|
|
|
|
|
|
|
|
aHttpTransaction->SetConnection(nullptr);
|
|
|
|
|
|
|
|
// this transaction has done its work of setting up a tunnel, let
|
|
|
|
// the connection manager queue it if necessary
|
|
|
|
trans->SetDontRouteViaWildCard(true);
|
|
|
|
|
|
|
|
if (FindTunnelCount(ci) < gHttpHandler->MaxConnectionsPerOrigin()) {
|
|
|
|
LOG3(("SpdySession3::DispatchOnTunnel %p create on new tunnel %s",
|
|
|
|
this, ci->HashKey().get()));
|
|
|
|
nsRefPtr<SpdyConnectTransaction> connectTrans =
|
|
|
|
new SpdyConnectTransaction(ci, aCallbacks,
|
|
|
|
trans->Caps(), trans, this);
|
2014-06-13 06:29:00 -07:00
|
|
|
AddStream(connectTrans, nsISupportsPriority::PRIORITY_NORMAL,
|
2014-04-16 06:52:43 -07:00
|
|
|
false, nullptr);
|
|
|
|
SpdyStream3 *tunnel = mStreamTransactionHash.Get(connectTrans);
|
|
|
|
MOZ_ASSERT(tunnel);
|
|
|
|
RegisterTunnel(tunnel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// requeue it. The connection manager is responsible for actually putting
|
|
|
|
// this on the tunnel connection with the specific ci now that it
|
|
|
|
// has DontRouteViaWildCard set.
|
2014-05-16 08:46:12 -07:00
|
|
|
trans->EnableKeepAlive();
|
2014-04-16 06:52:43 -07:00
|
|
|
gHttpHandler->InitiateTransaction(trans, trans->Priority());
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Modified methods of nsAHttpConnection
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::TransactionHasDataToWrite(nsAHttpTransaction *caller)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::TransactionHasDataToWrite %p trans=%p", this, caller));
|
|
|
|
|
|
|
|
// a trapped signal from the http transaction to the connection that
|
|
|
|
// it is no longer blocked on read.
|
|
|
|
|
|
|
|
SpdyStream3 *stream = mStreamTransactionHash.Get(caller);
|
|
|
|
if (!stream || !VerifyStream(stream)) {
|
|
|
|
LOG3(("SpdySession3::TransactionHasDataToWrite %p caller %p not found",
|
|
|
|
this, caller));
|
|
|
|
return;
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
LOG3(("SpdySession3::TransactionHasDataToWrite %p ID is 0x%X\n",
|
2012-05-25 14:37:08 -07:00
|
|
|
this, stream->StreamID()));
|
|
|
|
|
|
|
|
mReadyForWrite.Push(stream);
|
2014-04-16 06:52:43 -07:00
|
|
|
SetWriteCallbacks();
|
|
|
|
|
|
|
|
// NSPR poll will not poll the network if there are non system PR_FileDesc's
|
|
|
|
// that are ready - so we can get into a deadlock waiting for the system IO
|
|
|
|
// to come back here if we don't force the send loop manually.
|
|
|
|
ForceSend();
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::TransactionHasDataToWrite(SpdyStream3 *stream)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
LOG3(("SpdySession3::TransactionHasDataToWrite %p stream=%p ID=%x",
|
|
|
|
this, stream, stream->StreamID()));
|
|
|
|
|
|
|
|
mReadyForWrite.Push(stream);
|
|
|
|
SetWriteCallbacks();
|
2014-04-16 06:52:43 -07:00
|
|
|
ForceSend();
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdySession3::IsPersistent()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::TakeTransport(nsISocketTransport **,
|
2014-04-17 16:55:04 -07:00
|
|
|
nsIAsyncInputStream **,
|
|
|
|
nsIAsyncOutputStream **)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "TakeTransport of SpdySession3");
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpConnection *
|
|
|
|
SpdySession3::TakeHttpConnection()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "TakeHttpConnection of SpdySession3");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::CancelPipeline(nsresult reason)
|
|
|
|
{
|
|
|
|
// we don't pipeline inside spdy, so this isn't an issue
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAHttpTransaction::Classifier
|
|
|
|
SpdySession3::Classification()
|
|
|
|
{
|
|
|
|
if (!mConnection)
|
|
|
|
return nsAHttpTransaction::CLASS_GENERAL;
|
|
|
|
return mConnection->Classification();
|
|
|
|
}
|
|
|
|
|
2014-04-16 06:52:43 -07:00
|
|
|
void
|
|
|
|
SpdySession3::GetSecurityCallbacks(nsIInterfaceRequestor **aOut)
|
|
|
|
{
|
|
|
|
*aOut = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// unused methods of nsAHttpTransaction
|
|
|
|
// We can be sure of this because SpdySession3 is only constructed in
|
2014-04-16 06:52:43 -07:00
|
|
|
// nsHttpConnection and is never passed out of that object or a TLSFilterTransaction
|
|
|
|
// TLS tunnel
|
2012-05-25 14:37:08 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
SpdySession3::SetConnection(nsAHttpConnection *)
|
|
|
|
{
|
|
|
|
// This is unexpected
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "SpdySession3::SetConnection()");
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-22 12:06:00 -07:00
|
|
|
SpdySession3::SetProxyConnectFailed()
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "SpdySession3::SetProxyConnectFailed()");
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdySession3::IsDone()
|
|
|
|
{
|
|
|
|
return !mStreamTransactionHash.Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::Status()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "SpdySession3::Status()");
|
2012-05-25 14:37:08 -07:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-11-29 17:34:35 -08:00
|
|
|
uint32_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::Caps()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "SpdySession3::Caps()");
|
2012-05-25 14:37:08 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-27 10:19:14 -08:00
|
|
|
void
|
|
|
|
SpdySession3::SetDNSWasRefreshed()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::Available()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "SpdySession3::Available()");
|
2012-05-25 14:37:08 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpRequestHead *
|
|
|
|
SpdySession3::RequestHead()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"SpdySession3::RequestHead() "
|
|
|
|
"should not be called after SPDY is setup");
|
2013-09-19 12:29:27 -07:00
|
|
|
return nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::Http1xTransactionCount()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// used as an enumerator by TakeSubTransactions()
|
|
|
|
static PLDHashOperator
|
|
|
|
TakeStream(nsAHttpTransaction *key,
|
|
|
|
nsAutoPtr<SpdyStream3> &stream,
|
|
|
|
void *closure)
|
|
|
|
{
|
|
|
|
nsTArray<nsRefPtr<nsAHttpTransaction> > *list =
|
|
|
|
static_cast<nsTArray<nsRefPtr<nsAHttpTransaction> > *>(closure);
|
|
|
|
|
|
|
|
list->AppendElement(key);
|
|
|
|
|
|
|
|
// removing the stream from the hash will delete the stream
|
|
|
|
// and drop the transaction reference the hash held
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::TakeSubTransactions(
|
|
|
|
nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions)
|
|
|
|
{
|
|
|
|
// Generally this cannot be done with spdy as transactions are
|
|
|
|
// started right away.
|
|
|
|
|
|
|
|
LOG3(("SpdySession3::TakeSubTransactions %p\n", this));
|
|
|
|
|
|
|
|
if (mConcurrentHighWater > 0)
|
|
|
|
return NS_ERROR_ALREADY_OPENED;
|
|
|
|
|
|
|
|
LOG3((" taking %d\n", mStreamTransactionHash.Count()));
|
|
|
|
|
|
|
|
mStreamTransactionHash.Enumerate(TakeStream, &outTransactions);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::AddTransaction(nsAHttpTransaction *)
|
|
|
|
{
|
|
|
|
// This API is meant for pipelining, SpdySession3's should be
|
|
|
|
// extended with AddStream()
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"SpdySession3::AddTransaction() should not be called");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::PipelineDepth()
|
|
|
|
{
|
|
|
|
return IsDone() ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdySession3::SetPipelinePosition(int32_t position)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
// This API is meant for pipelining, SpdySession3's should be
|
|
|
|
// extended with AddStream()
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"SpdySession3::SetPipelinePosition() should not be called");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-05-25 14:37:08 -07:00
|
|
|
SpdySession3::PipelinePosition()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Pass through methods of nsAHttpConnection
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsAHttpConnection *
|
|
|
|
SpdySession3::Connection()
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-05-25 14:37:08 -07:00
|
|
|
return mConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdySession3::OnHeadersAvailable(nsAHttpTransaction *transaction,
|
2014-04-17 16:55:04 -07:00
|
|
|
nsHttpRequestHead *requestHead,
|
|
|
|
nsHttpResponseHead *responseHead,
|
|
|
|
bool *reset)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
return mConnection->OnHeadersAvailable(transaction,
|
|
|
|
requestHead,
|
|
|
|
responseHead,
|
|
|
|
reset);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdySession3::IsReused()
|
|
|
|
{
|
|
|
|
return mConnection->IsReused();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdySession3::PushBack(const char *buf, uint32_t len)
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
return mConnection->PushBack(buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla::net
|
|
|
|
} // namespace mozilla
|