1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_
6 #define NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string_piece.h"
12 #include "net/base/net_export.h"
16 // TODO(rtenneti): sync with server more rationally.
17 // CachedNetworkParameters contains data that can be used to choose appropriate
18 // connection parameters (initial RTT, initial CWND, etc.) in new connections.
19 class NET_EXPORT_PRIVATE CachedNetworkParameters
{
21 // Describes the state of the connection during which the supplied network
22 // parameters were calculated.
23 enum PreviousConnectionState
{
25 CONGESTION_AVOIDANCE
= 1,
28 CachedNetworkParameters();
29 ~CachedNetworkParameters();
31 std::string
serving_region() const {
32 return serving_region_
;
34 void set_serving_region(base::StringPiece serving_region
) {
35 serving_region_
= serving_region
.as_string();
38 int32
bandwidth_estimate_bytes_per_second() const {
39 return bandwidth_estimate_bytes_per_second_
;
41 void set_bandwidth_estimate_bytes_per_second(
42 int32 bandwidth_estimate_bytes_per_second
) {
43 bandwidth_estimate_bytes_per_second_
= bandwidth_estimate_bytes_per_second
;
46 int32
max_bandwidth_estimate_bytes_per_second() const {
47 return max_bandwidth_estimate_bytes_per_second_
;
49 void set_max_bandwidth_estimate_bytes_per_second(
50 int32 max_bandwidth_estimate_bytes_per_second
) {
51 max_bandwidth_estimate_bytes_per_second_
=
52 max_bandwidth_estimate_bytes_per_second
;
55 int64
max_bandwidth_timestamp_seconds() const {
56 return max_bandwidth_timestamp_seconds_
;
58 void set_max_bandwidth_timestamp_seconds(
59 int64 max_bandwidth_timestamp_seconds
) {
60 max_bandwidth_timestamp_seconds_
= max_bandwidth_timestamp_seconds
;
63 int32
min_rtt_ms() const {
66 void set_min_rtt_ms(int32 min_rtt_ms
) {
67 min_rtt_ms_
= min_rtt_ms
;
70 int32
previous_connection_state() const {
71 return previous_connection_state_
;
73 void set_previous_connection_state(int32 previous_connection_state
) {
74 previous_connection_state_
= previous_connection_state
;
78 // serving_region_ is used to decide whether or not the bandwidth estimate and
79 // min RTT are reasonable and if they should be used.
80 // For example a group of geographically close servers may share the same
81 // serving_region_ string if they are expected to have similar network
83 std::string serving_region_
;
84 // The server can supply a bandwidth estimate (in bytes/s) which it may re-use
85 // on receipt of a source-address token with this field set.
86 int32 bandwidth_estimate_bytes_per_second_
;
87 // The maximum bandwidth seen by the client, not necessarily the latest.
88 int32 max_bandwidth_estimate_bytes_per_second_
;
89 // Timestamp (seconds since UNIX epoch) that indicates when the max bandwidth
90 // was seen by the server.
91 int64 max_bandwidth_timestamp_seconds_
;
92 // The min RTT seen on a previous connection can be used by the server to
93 // inform initial connection parameters for new connections.
95 // Encodes the PreviousConnectionState enum.
96 int32 previous_connection_state_
;
99 // TODO(rtenneti): sync with server more rationally.
100 // A SourceAddressToken is serialised, encrypted and sent to clients so that
101 // they can prove ownership of an IP address.
102 class NET_EXPORT_PRIVATE SourceAddressToken
{
104 SourceAddressToken();
105 ~SourceAddressToken();
107 std::string
SerializeAsString() const;
109 bool ParseFromArray(const char* plaintext
, size_t plaintext_length
);
111 std::string
ip() const {
114 void set_ip(base::StringPiece ip
) {
115 ip_
= ip
.as_string();
118 int64
timestamp() const {
121 void set_timestamp(int64 timestamp
) {
122 timestamp_
= timestamp
;
125 const CachedNetworkParameters
& cached_network_parameters() const {
126 return cached_network_parameters_
;
128 void set_cached_network_parameters(
129 const CachedNetworkParameters
& cached_network_parameters
) {
130 cached_network_parameters_
= cached_network_parameters
;
134 // ip_ contains either 4 (IPv4) or 16 (IPv6) bytes of IP address in network
137 // timestamp_ contains a UNIX timestamp value of the time when the token was
141 // The server can provide estimated network parameters to be used for
142 // initial parameter selection in future connections.
143 CachedNetworkParameters cached_network_parameters_
;
145 DISALLOW_COPY_AND_ASSIGN(SourceAddressToken
);
150 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_