ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / net / quic / crypto / source_address_token.h
blob71ba54ede73e832b253c1b991fdc6d195669a2c5
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_
8 #include <string>
9 #include <vector>
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"
18 namespace net {
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 {
24 public:
25 SourceAddressToken();
26 ~SourceAddressToken();
28 std::string SerializeAsString() const;
30 bool ParseFromArray(const char* plaintext, size_t plaintext_length);
32 std::string ip() const {
33 return ip_;
35 void set_ip(base::StringPiece ip) {
36 ip_ = ip.as_string();
37 DCHECK_LE(ip_.size(),
38 static_cast<size_t>(std::numeric_limits<char>::max()));
41 int64 timestamp() const {
42 return timestamp_;
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_;
63 private:
64 // ip_ contains either 4 (IPv4) or 16 (IPv6) bytes of IP address in network
65 // byte order.
66 std::string ip_;
67 // timestamp_ contains a UNIX timestamp value of the time when the token was
68 // created.
69 int64 timestamp_;
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 {
80 public:
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);
92 return *tokens_[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_;
105 } // namespace net
107 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_