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 #include "net/quic/crypto/source_address_token.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_split.h"
14 CachedNetworkParameters::CachedNetworkParameters()
15 : bandwidth_estimate_bytes_per_second_(0),
16 max_bandwidth_estimate_bytes_per_second_(0),
17 max_bandwidth_timestamp_seconds_(0),
19 previous_connection_state_(0),
23 CachedNetworkParameters::~CachedNetworkParameters() {
26 bool CachedNetworkParameters::operator==(
27 const CachedNetworkParameters& other) const {
28 return serving_region_ == other.serving_region_ &&
29 bandwidth_estimate_bytes_per_second_ ==
30 other.bandwidth_estimate_bytes_per_second_ &&
31 max_bandwidth_estimate_bytes_per_second_ ==
32 other.max_bandwidth_estimate_bytes_per_second_ &&
33 max_bandwidth_timestamp_seconds_ ==
34 other.max_bandwidth_timestamp_seconds_ &&
35 min_rtt_ms_ == other.min_rtt_ms_ &&
36 previous_connection_state_ == other.previous_connection_state_ &&
37 timestamp_ == other.timestamp_;
40 bool CachedNetworkParameters::operator!=(
41 const CachedNetworkParameters& other) const {
42 return !(*this == other);
45 SourceAddressToken::SourceAddressToken()
46 : has_cached_network_parameters_(false) {
49 SourceAddressToken::~SourceAddressToken() {
52 string SourceAddressToken::SerializeAsString() const {
54 out.push_back(ip_.size());
56 string time_str = base::Int64ToString(timestamp_);
57 out.push_back(time_str.size());
59 // TODO(rtenneti): Implement serialization of optional CachedNetworkParameters
60 // when they are used.
64 bool SourceAddressToken::ParseFromArray(const char* plaintext,
65 size_t plaintext_length) {
66 if (plaintext_length == 0) {
69 size_t ip_len = plaintext[0];
70 if (plaintext_length <= 1 + ip_len) {
73 size_t time_len = plaintext[1 + ip_len];
74 if (plaintext_length != 1 + ip_len + 1 + time_len) {
78 string time_str(&plaintext[1 + ip_len + 1], time_len);
80 if (!base::StringToInt64(time_str, ×tamp)) {
84 ip_.assign(&plaintext[1], ip_len);
85 timestamp_ = timestamp;
87 // TODO(rtenneti): Implement parsing of optional CachedNetworkParameters when