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