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_
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 #include "base/stl_util.h"
14 #include "base/strings/string_piece.h"
15 #include "net/base/net_export.h"
16 #include "net/quic/crypto/cached_network_parameters.h"
20 // TODO(rtenneti): sync with server more rationally.
21 // A SourceAddressToken is serialised, encrypted and sent to clients so that
22 // they can prove ownership of an IP address.
23 class NET_EXPORT_PRIVATE SourceAddressToken
{
26 ~SourceAddressToken();
28 std::string
SerializeAsString() const;
30 bool ParseFromArray(const char* plaintext
, size_t plaintext_length
);
32 std::string
ip() const {
35 void set_ip(base::StringPiece ip
) {
38 static_cast<size_t>(std::numeric_limits
<char>::max()));
41 int64
timestamp() const {
44 void set_timestamp(int64 timestamp
) {
45 timestamp_
= timestamp
;
48 const CachedNetworkParameters
& cached_network_parameters() const {
49 return cached_network_parameters_
;
51 CachedNetworkParameters
* mutable_cached_network_parameters() {
52 return &cached_network_parameters_
;
54 void set_cached_network_parameters(
55 const CachedNetworkParameters
& cached_network_parameters
) {
56 cached_network_parameters_
= cached_network_parameters
;
57 has_cached_network_parameters_
= true;
59 bool has_cached_network_parameters() const {
60 return has_cached_network_parameters_
;
64 // ip_ contains either 4 (IPv4) or 16 (IPv6) bytes of IP address in network
67 // timestamp_ contains a UNIX timestamp value of the time when the token was
71 // The server can provide estimated network parameters to be used for
72 // initial parameter selection in future connections.
73 CachedNetworkParameters cached_network_parameters_
;
74 // TODO(rtenneti): Delete |has_cached_network_parameters_| after we convert
75 // SourceAddressToken to protobuf.
76 bool has_cached_network_parameters_
;
79 class NET_EXPORT_PRIVATE SourceAddressTokens
{
81 SourceAddressTokens();
82 ~SourceAddressTokens();
84 std::string
SerializeAsString() const;
86 bool ParseFromArray(const char* plaintext
, size_t plaintext_length
);
88 size_t tokens_size() const { return tokens_
.size(); }
90 const SourceAddressToken
& tokens(size_t i
) const {
91 DCHECK_GT(tokens_
.size(), i
);
95 SourceAddressToken
* add_tokens() {
96 tokens_
.push_back(new SourceAddressToken
);
97 return tokens_
.back();
100 void clear_tokens() { STLDeleteElements(&tokens_
); }
102 std::vector
<SourceAddressToken
*> tokens_
;
107 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_