OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ | 5 #ifndef NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ |
6 #define NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ | 6 #define NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/quic/crypto/cached_network_parameters.h" |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 // TODO(rtenneti): sync with server more rationally. | 17 // 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 { | |
20 public: | |
21 // Describes the state of the connection during which the supplied network | |
22 // parameters were calculated. | |
23 enum PreviousConnectionState { | |
24 SLOW_START = 0, | |
25 CONGESTION_AVOIDANCE = 1, | |
26 }; | |
27 | |
28 CachedNetworkParameters(); | |
29 ~CachedNetworkParameters(); | |
30 | |
31 bool operator==(const CachedNetworkParameters& other) const; | |
32 bool operator!=(const CachedNetworkParameters& other) const; | |
33 | |
34 std::string serving_region() const { | |
35 return serving_region_; | |
36 } | |
37 void set_serving_region(base::StringPiece serving_region) { | |
38 serving_region_ = serving_region.as_string(); | |
39 } | |
40 | |
41 int32 bandwidth_estimate_bytes_per_second() const { | |
42 return bandwidth_estimate_bytes_per_second_; | |
43 } | |
44 void set_bandwidth_estimate_bytes_per_second( | |
45 int32 bandwidth_estimate_bytes_per_second) { | |
46 bandwidth_estimate_bytes_per_second_ = bandwidth_estimate_bytes_per_second; | |
47 } | |
48 | |
49 int32 max_bandwidth_estimate_bytes_per_second() const { | |
50 return max_bandwidth_estimate_bytes_per_second_; | |
51 } | |
52 void set_max_bandwidth_estimate_bytes_per_second( | |
53 int32 max_bandwidth_estimate_bytes_per_second) { | |
54 max_bandwidth_estimate_bytes_per_second_ = | |
55 max_bandwidth_estimate_bytes_per_second; | |
56 } | |
57 | |
58 int64 max_bandwidth_timestamp_seconds() const { | |
59 return max_bandwidth_timestamp_seconds_; | |
60 } | |
61 void set_max_bandwidth_timestamp_seconds( | |
62 int64 max_bandwidth_timestamp_seconds) { | |
63 max_bandwidth_timestamp_seconds_ = max_bandwidth_timestamp_seconds; | |
64 } | |
65 | |
66 int32 min_rtt_ms() const { | |
67 return min_rtt_ms_; | |
68 } | |
69 void set_min_rtt_ms(int32 min_rtt_ms) { | |
70 min_rtt_ms_ = min_rtt_ms; | |
71 } | |
72 | |
73 int32 previous_connection_state() const { | |
74 return previous_connection_state_; | |
75 } | |
76 void set_previous_connection_state(int32 previous_connection_state) { | |
77 previous_connection_state_ = previous_connection_state; | |
78 } | |
79 | |
80 int64 timestamp() const { return timestamp_; } | |
81 void set_timestamp(int64 timestamp) { timestamp_ = timestamp; } | |
82 | |
83 private: | |
84 // serving_region_ is used to decide whether or not the bandwidth estimate and | |
85 // min RTT are reasonable and if they should be used. | |
86 // For example a group of geographically close servers may share the same | |
87 // serving_region_ string if they are expected to have similar network | |
88 // performance. | |
89 std::string serving_region_; | |
90 // The server can supply a bandwidth estimate (in bytes/s) which it may re-use | |
91 // on receipt of a source-address token with this field set. | |
92 int32 bandwidth_estimate_bytes_per_second_; | |
93 // The maximum bandwidth seen by the client, not necessarily the latest. | |
94 int32 max_bandwidth_estimate_bytes_per_second_; | |
95 // Timestamp (seconds since UNIX epoch) that indicates when the max bandwidth | |
96 // was seen by the server. | |
97 int64 max_bandwidth_timestamp_seconds_; | |
98 // The min RTT seen on a previous connection can be used by the server to | |
99 // inform initial connection parameters for new connections. | |
100 int32 min_rtt_ms_; | |
101 // Encodes the PreviousConnectionState enum. | |
102 int32 previous_connection_state_; | |
103 // UNIX timestamp when this bandwidth estimate was created. | |
104 int64 timestamp_; | |
105 }; | |
106 | |
107 // TODO(rtenneti): sync with server more rationally. | |
108 // A SourceAddressToken is serialised, encrypted and sent to clients so that | 18 // A SourceAddressToken is serialised, encrypted and sent to clients so that |
109 // they can prove ownership of an IP address. | 19 // they can prove ownership of an IP address. |
110 class NET_EXPORT_PRIVATE SourceAddressToken { | 20 class NET_EXPORT_PRIVATE SourceAddressToken { |
111 public: | 21 public: |
112 SourceAddressToken(); | 22 SourceAddressToken(); |
113 ~SourceAddressToken(); | 23 ~SourceAddressToken(); |
114 | 24 |
115 std::string SerializeAsString() const; | 25 std::string SerializeAsString() const; |
116 | 26 |
117 bool ParseFromArray(const char* plaintext, size_t plaintext_length); | 27 bool ParseFromArray(const char* plaintext, size_t plaintext_length); |
(...skipping 38 matching lines...) Loading... |
156 // TODO(rtenneti): Delete |has_cached_network_parameters_| after we convert | 66 // TODO(rtenneti): Delete |has_cached_network_parameters_| after we convert |
157 // SourceAddressToken to protobuf. | 67 // SourceAddressToken to protobuf. |
158 bool has_cached_network_parameters_; | 68 bool has_cached_network_parameters_; |
159 | 69 |
160 DISALLOW_COPY_AND_ASSIGN(SourceAddressToken); | 70 DISALLOW_COPY_AND_ASSIGN(SourceAddressToken); |
161 }; | 71 }; |
162 | 72 |
163 } // namespace net | 73 } // namespace net |
164 | 74 |
165 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ | 75 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ |
OLD | NEW |