Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set sw=2 ts=8 et tw=80 : */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | // HttpLog.h should generally be included first |
michael@0 | 8 | #include "HttpLog.h" |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | Currently supported are HTTP-draft-[see nshttp.h]/2.0 spdy/3.1 and spdy/3 |
michael@0 | 12 | */ |
michael@0 | 13 | |
michael@0 | 14 | #include "nsHttp.h" |
michael@0 | 15 | #include "nsHttpHandler.h" |
michael@0 | 16 | |
michael@0 | 17 | #include "ASpdySession.h" |
michael@0 | 18 | #include "PSpdyPush.h" |
michael@0 | 19 | #include "SpdyPush3.h" |
michael@0 | 20 | #include "SpdyPush31.h" |
michael@0 | 21 | #include "Http2Push.h" |
michael@0 | 22 | #include "SpdySession3.h" |
michael@0 | 23 | #include "SpdySession31.h" |
michael@0 | 24 | #include "Http2Session.h" |
michael@0 | 25 | |
michael@0 | 26 | #include "mozilla/Telemetry.h" |
michael@0 | 27 | |
michael@0 | 28 | namespace mozilla { |
michael@0 | 29 | namespace net { |
michael@0 | 30 | |
michael@0 | 31 | ASpdySession * |
michael@0 | 32 | ASpdySession::NewSpdySession(uint32_t version, |
michael@0 | 33 | nsAHttpTransaction *aTransaction, |
michael@0 | 34 | nsISocketTransport *aTransport, |
michael@0 | 35 | int32_t aPriority) |
michael@0 | 36 | { |
michael@0 | 37 | // This is a necko only interface, so we can enforce version |
michael@0 | 38 | // requests as a precondition |
michael@0 | 39 | MOZ_ASSERT(version == SPDY_VERSION_3 || |
michael@0 | 40 | version == SPDY_VERSION_31 || |
michael@0 | 41 | version == NS_HTTP2_DRAFT_VERSION, |
michael@0 | 42 | "Unsupported spdy version"); |
michael@0 | 43 | |
michael@0 | 44 | // Don't do a runtime check of IsSpdyV?Enabled() here because pref value |
michael@0 | 45 | // may have changed since starting negotiation. The selected protocol comes |
michael@0 | 46 | // from a list provided in the SERVER HELLO filtered by our acceptable |
michael@0 | 47 | // versions, so there is no risk of the server ignoring our prefs. |
michael@0 | 48 | |
michael@0 | 49 | Telemetry::Accumulate(Telemetry::SPDY_VERSION2, version); |
michael@0 | 50 | |
michael@0 | 51 | if (version == SPDY_VERSION_3) |
michael@0 | 52 | return new SpdySession3(aTransaction, aTransport, aPriority); |
michael@0 | 53 | |
michael@0 | 54 | if (version == SPDY_VERSION_31) |
michael@0 | 55 | return new SpdySession31(aTransaction, aTransport, aPriority); |
michael@0 | 56 | |
michael@0 | 57 | if (version == NS_HTTP2_DRAFT_VERSION) |
michael@0 | 58 | return new Http2Session(aTransaction, aTransport, aPriority); |
michael@0 | 59 | |
michael@0 | 60 | return nullptr; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | SpdyInformation::SpdyInformation() |
michael@0 | 64 | { |
michael@0 | 65 | Version[0] = SPDY_VERSION_3; |
michael@0 | 66 | VersionString[0] = NS_LITERAL_CSTRING("spdy/3"); |
michael@0 | 67 | |
michael@0 | 68 | Version[1] = SPDY_VERSION_31; |
michael@0 | 69 | VersionString[1] = NS_LITERAL_CSTRING("spdy/3.1"); |
michael@0 | 70 | |
michael@0 | 71 | Version[2] = NS_HTTP2_DRAFT_VERSION; |
michael@0 | 72 | VersionString[2] = NS_LITERAL_CSTRING(NS_HTTP2_DRAFT_TOKEN); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | bool |
michael@0 | 76 | SpdyInformation::ProtocolEnabled(uint32_t index) |
michael@0 | 77 | { |
michael@0 | 78 | MOZ_ASSERT(index < kCount, "index out of range"); |
michael@0 | 79 | |
michael@0 | 80 | switch (index) { |
michael@0 | 81 | case 0: |
michael@0 | 82 | return gHttpHandler->IsSpdyV3Enabled(); |
michael@0 | 83 | case 1: |
michael@0 | 84 | return gHttpHandler->IsSpdyV31Enabled(); |
michael@0 | 85 | case 2: |
michael@0 | 86 | return gHttpHandler->IsHttp2DraftEnabled(); |
michael@0 | 87 | } |
michael@0 | 88 | return false; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | nsresult |
michael@0 | 92 | SpdyInformation::GetNPNVersionIndex(const nsACString &npnString, |
michael@0 | 93 | uint8_t *result) |
michael@0 | 94 | { |
michael@0 | 95 | if (npnString.IsEmpty()) |
michael@0 | 96 | return NS_ERROR_FAILURE; |
michael@0 | 97 | |
michael@0 | 98 | for (uint32_t index = 0; index < kCount; ++index) { |
michael@0 | 99 | if (npnString.Equals(VersionString[index])) { |
michael@0 | 100 | *result = Version[index]; |
michael@0 | 101 | return NS_OK; |
michael@0 | 102 | } |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | return NS_ERROR_FAILURE; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | ////////////////////////////////////////// |
michael@0 | 109 | // SpdyPushCache |
michael@0 | 110 | ////////////////////////////////////////// |
michael@0 | 111 | |
michael@0 | 112 | SpdyPushCache::SpdyPushCache() |
michael@0 | 113 | { |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | SpdyPushCache::~SpdyPushCache() |
michael@0 | 117 | { |
michael@0 | 118 | mHashSpdy3.Clear(); |
michael@0 | 119 | mHashSpdy31.Clear(); |
michael@0 | 120 | mHashHttp2.Clear(); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | bool |
michael@0 | 124 | SpdyPushCache::RegisterPushedStreamSpdy3(nsCString key, |
michael@0 | 125 | SpdyPushedStream3 *stream) |
michael@0 | 126 | { |
michael@0 | 127 | LOG3(("SpdyPushCache::RegisterPushedStreamSpdy3 %s 0x%X\n", |
michael@0 | 128 | key.get(), stream->StreamID())); |
michael@0 | 129 | if(mHashSpdy3.Get(key)) |
michael@0 | 130 | return false; |
michael@0 | 131 | mHashSpdy3.Put(key, stream); |
michael@0 | 132 | return true; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | SpdyPushedStream3 * |
michael@0 | 136 | SpdyPushCache::RemovePushedStreamSpdy3(nsCString key) |
michael@0 | 137 | { |
michael@0 | 138 | SpdyPushedStream3 *rv = mHashSpdy3.Get(key); |
michael@0 | 139 | LOG3(("SpdyPushCache::RemovePushedStream %s 0x%X\n", |
michael@0 | 140 | key.get(), rv ? rv->StreamID() : 0)); |
michael@0 | 141 | if (rv) |
michael@0 | 142 | mHashSpdy3.Remove(key); |
michael@0 | 143 | return rv; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | bool |
michael@0 | 147 | SpdyPushCache::RegisterPushedStreamSpdy31(nsCString key, |
michael@0 | 148 | SpdyPushedStream31 *stream) |
michael@0 | 149 | { |
michael@0 | 150 | LOG3(("SpdyPushCache::RegisterPushedStreamSpdy31 %s 0x%X\n", |
michael@0 | 151 | key.get(), stream->StreamID())); |
michael@0 | 152 | if(mHashSpdy31.Get(key)) |
michael@0 | 153 | return false; |
michael@0 | 154 | mHashSpdy31.Put(key, stream); |
michael@0 | 155 | return true; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | SpdyPushedStream31 * |
michael@0 | 159 | SpdyPushCache::RemovePushedStreamSpdy31(nsCString key) |
michael@0 | 160 | { |
michael@0 | 161 | SpdyPushedStream31 *rv = mHashSpdy31.Get(key); |
michael@0 | 162 | LOG3(("SpdyPushCache::RemovePushedStream %s 0x%X\n", |
michael@0 | 163 | key.get(), rv ? rv->StreamID() : 0)); |
michael@0 | 164 | if (rv) |
michael@0 | 165 | mHashSpdy31.Remove(key); |
michael@0 | 166 | return rv; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | bool |
michael@0 | 170 | SpdyPushCache::RegisterPushedStreamHttp2(nsCString key, |
michael@0 | 171 | Http2PushedStream *stream) |
michael@0 | 172 | { |
michael@0 | 173 | LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X\n", |
michael@0 | 174 | key.get(), stream->StreamID())); |
michael@0 | 175 | if(mHashHttp2.Get(key)) |
michael@0 | 176 | return false; |
michael@0 | 177 | mHashHttp2.Put(key, stream); |
michael@0 | 178 | return true; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | Http2PushedStream * |
michael@0 | 182 | SpdyPushCache::RemovePushedStreamHttp2(nsCString key) |
michael@0 | 183 | { |
michael@0 | 184 | Http2PushedStream *rv = mHashHttp2.Get(key); |
michael@0 | 185 | LOG3(("SpdyPushCache::RemovePushedStreamHttp2 %s 0x%X\n", |
michael@0 | 186 | key.get(), rv ? rv->StreamID() : 0)); |
michael@0 | 187 | if (rv) |
michael@0 | 188 | mHashHttp2.Remove(key); |
michael@0 | 189 | return rv; |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | } // namespace mozilla::net |
michael@0 | 193 | } // namespace mozilla |
michael@0 | 194 |