Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/http/ASpdySession.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
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/. */
6
7
#ifndef mozilla_net_ASpdySession_h
8
#define mozilla_net_ASpdySession_h
9
10
#include "nsAHttpTransaction.h"
11
#include "prinrval.h"
12
#include "nsString.h"
13
14
class nsISocketTransport;
15
16
namespace mozilla { namespace net {
17
18
class ASpdySession : public nsAHttpTransaction
19
{
20
public:
21
0
  ASpdySession() = default;
22
  virtual ~ASpdySession() = default;
23
24
  virtual MOZ_MUST_USE bool
25
  AddStream(nsAHttpTransaction *, int32_t, bool, nsIInterfaceRequestor *) = 0;
26
  virtual bool CanReuse() = 0;
27
  virtual bool RoomForMoreStreams() = 0;
28
  virtual PRIntervalTime IdleTime() = 0;
29
  virtual uint32_t ReadTimeoutTick(PRIntervalTime now) = 0;
30
  virtual void DontReuse() = 0;
31
  virtual enum SpdyVersion SpdyVersion() = 0;
32
33
  static ASpdySession *NewSpdySession(net::SpdyVersion version, nsISocketTransport *, bool);
34
35
  virtual bool TestJoinConnection(const nsACString &hostname, int32_t port) = 0;
36
  virtual bool JoinConnection(const nsACString &hostname, int32_t port) = 0;
37
38
  // MaybeReTunnel() is called by the connection manager when it cannot
39
  // dispatch a tunneled transaction. That might be because the tunnels it
40
  // expects to see are dead (and we may or may not be able to make more),
41
  // or it might just need to wait longer for one of them to become free.
42
  //
43
  // return true if the session takes back ownership of the transaction from
44
  // the connection manager.
45
  virtual bool MaybeReTunnel(nsAHttpTransaction *) = 0;
46
47
  virtual void PrintDiagnostics (nsCString &log) = 0;
48
49
0
  bool ResponseTimeoutEnabled() const final {
50
0
    return true;
51
0
  }
52
53
  virtual void SendPing() = 0;
54
55
  const static uint32_t kSendingChunkSize = 4095;
56
  const static uint32_t kTCPSendBufferSize = 131072;
57
58
  // This is roughly the amount of data a suspended channel will have to
59
  // buffer before h2 flow control kicks in.
60
  const static uint32_t kInitialRwin = 12 * 1024 * 1024; // 12MB
61
62
  const static uint32_t kDefaultMaxConcurrent = 100;
63
64
  // soft errors are errors that terminate a stream without terminating the
65
  // connection. In general non-network errors are stream errors as well
66
  // as network specific items like cancels.
67
  bool SoftStreamError(nsresult code)
68
0
  {
69
0
    if (NS_SUCCEEDED(code) || code == NS_BASE_STREAM_WOULD_BLOCK) {
70
0
      return false;
71
0
    }
72
0
73
0
    // this could go either way, but because there are network instances of
74
0
    // it being a hard error we should consider it hard.
75
0
    if (code == NS_ERROR_FAILURE || code == NS_ERROR_OUT_OF_MEMORY) {
76
0
      return false;
77
0
    }
78
0
79
0
    if (NS_ERROR_GET_MODULE(code) != NS_ERROR_MODULE_NETWORK) {
80
0
      return true;
81
0
    }
82
0
83
0
    // these are network specific soft errors
84
0
    return (code == NS_BASE_STREAM_CLOSED || code == NS_BINDING_FAILED ||
85
0
            code == NS_BINDING_ABORTED || code == NS_BINDING_REDIRECTED ||
86
0
            code == NS_ERROR_INVALID_CONTENT_ENCODING ||
87
0
            code == NS_BINDING_RETARGETED || code == NS_ERROR_CORRUPTED_CONTENT);
88
0
  }
89
};
90
91
typedef bool (*ALPNCallback) (nsISupports *); // nsISSLSocketControl is typical
92
93
// this is essentially a single instantiation as a member of nsHttpHandler.
94
// It could be all static except using static ctors of XPCOM objects is a
95
// bad idea.
96
class SpdyInformation
97
{
98
public:
99
  SpdyInformation();
100
0
  ~SpdyInformation() = default;
101
102
  static const uint32_t kCount = 1;
103
104
  // determine the index (0..kCount-1) of the spdy information that
105
  // correlates to the npn string. NS_FAILED() if no match is found.
106
  MOZ_MUST_USE nsresult GetNPNIndex(const nsACString &npnString, uint32_t *result) const;
107
108
  // determine if a version of the protocol is enabled for index < kCount
109
  bool ProtocolEnabled(uint32_t index) const;
110
111
  SpdyVersion Version[kCount]; // telemetry enum e.g. SPDY_VERSION_31
112
  nsCString VersionString[kCount]; // npn string e.g. "spdy/3.1"
113
114
  // the ALPNCallback function allows the protocol stack to decide whether or
115
  // not to offer a particular protocol based on the known TLS information
116
  // that we will offer in the client hello (such as version). There has
117
  // not been a Server Hello received yet, so not much else can be considered.
118
  ALPNCallback ALPNCallbacks[kCount];
119
};
120
121
} // namespace net
122
} // namespace mozilla
123
124
#endif // mozilla_net_ASpdySession_h