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 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" |
12 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
13 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
14 #include "net/quic/crypto/cached_network_parameters.h" | 16 #include "net/quic/crypto/cached_network_parameters.h" |
15 | 17 |
16 namespace net { | 18 namespace net { |
17 | 19 |
18 // TODO(rtenneti): sync with server more rationally. | 20 // TODO(rtenneti): sync with server more rationally. |
19 // A SourceAddressToken is serialised, encrypted and sent to clients so that | 21 // A SourceAddressToken is serialised, encrypted and sent to clients so that |
20 // they can prove ownership of an IP address. | 22 // they can prove ownership of an IP address. |
21 class NET_EXPORT_PRIVATE SourceAddressToken { | 23 class NET_EXPORT_PRIVATE SourceAddressToken { |
(...skipping 17 matching lines...) Expand all Loading... |
39 int64 timestamp() const { | 41 int64 timestamp() const { |
40 return timestamp_; | 42 return timestamp_; |
41 } | 43 } |
42 void set_timestamp(int64 timestamp) { | 44 void set_timestamp(int64 timestamp) { |
43 timestamp_ = timestamp; | 45 timestamp_ = timestamp; |
44 } | 46 } |
45 | 47 |
46 const CachedNetworkParameters& cached_network_parameters() const { | 48 const CachedNetworkParameters& cached_network_parameters() const { |
47 return cached_network_parameters_; | 49 return cached_network_parameters_; |
48 } | 50 } |
| 51 CachedNetworkParameters* mutable_cached_network_parameters() { |
| 52 return &cached_network_parameters_; |
| 53 } |
49 void set_cached_network_parameters( | 54 void set_cached_network_parameters( |
50 const CachedNetworkParameters& cached_network_parameters) { | 55 const CachedNetworkParameters& cached_network_parameters) { |
51 cached_network_parameters_ = cached_network_parameters; | 56 cached_network_parameters_ = cached_network_parameters; |
52 has_cached_network_parameters_ = true; | 57 has_cached_network_parameters_ = true; |
53 } | 58 } |
54 bool has_cached_network_parameters() const { | 59 bool has_cached_network_parameters() const { |
55 return has_cached_network_parameters_; | 60 return has_cached_network_parameters_; |
56 } | 61 } |
57 | 62 |
58 private: | 63 private: |
59 // ip_ contains either 4 (IPv4) or 16 (IPv6) bytes of IP address in network | 64 // ip_ contains either 4 (IPv4) or 16 (IPv6) bytes of IP address in network |
60 // byte order. | 65 // byte order. |
61 std::string ip_; | 66 std::string ip_; |
62 // timestamp_ contains a UNIX timestamp value of the time when the token was | 67 // timestamp_ contains a UNIX timestamp value of the time when the token was |
63 // created. | 68 // created. |
64 int64 timestamp_; | 69 int64 timestamp_; |
65 | 70 |
66 // The server can provide estimated network parameters to be used for | 71 // The server can provide estimated network parameters to be used for |
67 // initial parameter selection in future connections. | 72 // initial parameter selection in future connections. |
68 CachedNetworkParameters cached_network_parameters_; | 73 CachedNetworkParameters cached_network_parameters_; |
69 // TODO(rtenneti): Delete |has_cached_network_parameters_| after we convert | 74 // TODO(rtenneti): Delete |has_cached_network_parameters_| after we convert |
70 // SourceAddressToken to protobuf. | 75 // SourceAddressToken to protobuf. |
71 bool has_cached_network_parameters_; | 76 bool has_cached_network_parameters_; |
| 77 }; |
72 | 78 |
73 DISALLOW_COPY_AND_ASSIGN(SourceAddressToken); | 79 class NET_EXPORT_PRIVATE SourceAddressTokens { |
| 80 public: |
| 81 SourceAddressTokens(); |
| 82 ~SourceAddressTokens(); |
| 83 |
| 84 std::string SerializeAsString() const; |
| 85 |
| 86 bool ParseFromArray(const char* plaintext, size_t plaintext_length); |
| 87 |
| 88 size_t tokens_size() const { return tokens_.size(); } |
| 89 |
| 90 const SourceAddressToken& tokens(size_t i) const { |
| 91 DCHECK_GT(tokens_.size(), i); |
| 92 return *tokens_[i]; |
| 93 } |
| 94 |
| 95 SourceAddressToken* add_tokens() { |
| 96 tokens_.push_back(new SourceAddressToken); |
| 97 return tokens_.back(); |
| 98 } |
| 99 |
| 100 void clear_tokens() { STLDeleteElements(&tokens_); } |
| 101 |
| 102 std::vector<SourceAddressToken*> tokens_; |
74 }; | 103 }; |
75 | 104 |
76 } // namespace net | 105 } // namespace net |
77 | 106 |
78 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ | 107 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_ |
OLD | NEW |