summaryrefslogtreecommitdiffstats
path: root/net/quic/crypto/cached_network_parameters.h
blob: 5f22070dc4f75f8156916dfdf1aedb11ac2d842f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_QUIC_CRYPTO_CACHED_NETWORK_PARAMETERS_H_
#define NET_QUIC_CRYPTO_CACHED_NETWORK_PARAMETERS_H_

#include <string>

#include "base/basictypes.h"
#include "base/strings/string_piece.h"
#include "net/base/net_export.h"

namespace net {

// TODO(rtenneti): sync with server more rationally.
// CachedNetworkParameters contains data that can be used to choose appropriate
// connection parameters (initial RTT, initial CWND, etc.) in new connections.
class NET_EXPORT_PRIVATE CachedNetworkParameters {
 public:
  // Describes the state of the connection during which the supplied network
  // parameters were calculated.
  enum PreviousConnectionState {
    SLOW_START = 0,
    CONGESTION_AVOIDANCE = 1,
  };

  CachedNetworkParameters();
  ~CachedNetworkParameters();

  bool operator==(const CachedNetworkParameters& other) const;
  bool operator!=(const CachedNetworkParameters& other) const;

  std::string serving_region() const {
    return serving_region_;
  }
  void set_serving_region(base::StringPiece serving_region) {
    serving_region_ = serving_region.as_string();
  }

  int32 bandwidth_estimate_bytes_per_second() const {
    return bandwidth_estimate_bytes_per_second_;
  }
  void set_bandwidth_estimate_bytes_per_second(
      int32 bandwidth_estimate_bytes_per_second) {
    bandwidth_estimate_bytes_per_second_ = bandwidth_estimate_bytes_per_second;
  }

  int32 max_bandwidth_estimate_bytes_per_second() const {
    return max_bandwidth_estimate_bytes_per_second_;
  }
  void set_max_bandwidth_estimate_bytes_per_second(
      int32 max_bandwidth_estimate_bytes_per_second) {
    max_bandwidth_estimate_bytes_per_second_ =
        max_bandwidth_estimate_bytes_per_second;
  }

  int64 max_bandwidth_timestamp_seconds() const {
    return max_bandwidth_timestamp_seconds_;
  }
  void set_max_bandwidth_timestamp_seconds(
      int64 max_bandwidth_timestamp_seconds) {
    max_bandwidth_timestamp_seconds_ = max_bandwidth_timestamp_seconds;
  }

  int32 min_rtt_ms() const {
    return min_rtt_ms_;
  }
  void set_min_rtt_ms(int32 min_rtt_ms) {
    min_rtt_ms_ = min_rtt_ms;
  }

  int32 previous_connection_state() const {
    return previous_connection_state_;
  }
  void set_previous_connection_state(int32 previous_connection_state) {
    previous_connection_state_ = previous_connection_state;
  }

  int64 timestamp() const { return timestamp_; }
  void set_timestamp(int64 timestamp) { timestamp_ = timestamp; }

 private:
  // serving_region_ is used to decide whether or not the bandwidth estimate and
  // min RTT are reasonable and if they should be used.
  // For example a group of geographically close servers may share the same
  // serving_region_ string if they are expected to have similar network
  // performance.
  std::string serving_region_;
  // The server can supply a bandwidth estimate (in bytes/s) which it may re-use
  // on receipt of a source-address token with this field set.
  int32 bandwidth_estimate_bytes_per_second_;
  // The maximum bandwidth seen by the client, not necessarily the latest.
  int32 max_bandwidth_estimate_bytes_per_second_;
  // Timestamp (seconds since UNIX epoch) that indicates when the max bandwidth
  // was seen by the server.
  int64 max_bandwidth_timestamp_seconds_;
  // The min RTT seen on a previous connection can be used by the server to
  // inform initial connection parameters for new connections.
  int32 min_rtt_ms_;
  // Encodes the PreviousConnectionState enum.
  int32 previous_connection_state_;
  // UNIX timestamp when this bandwidth estimate was created.
  int64 timestamp_;
};

}  // namespace net

#endif  // NET_QUIC_CRYPTO_CACHED_NETWORK_PARAMETERS_H_