Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: net/quic/crypto/source_address_token.h

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/crypto/scoped_evp_aead_ctx.cc ('k') | net/quic/crypto/source_address_token.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_
6 #define NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_
7
8 #include <string>
9 #include <vector>
10
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"
17
18 namespace net {
19
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();
27
28 std::string SerializeAsString() const;
29
30 bool ParseFromArray(const char* plaintext, size_t plaintext_length);
31
32 std::string ip() const {
33 return ip_;
34 }
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()));
39 }
40
41 int64 timestamp() const {
42 return timestamp_;
43 }
44 void set_timestamp(int64 timestamp) {
45 timestamp_ = timestamp;
46 }
47
48 const CachedNetworkParameters& cached_network_parameters() const {
49 return cached_network_parameters_;
50 }
51 CachedNetworkParameters* mutable_cached_network_parameters() {
52 return &cached_network_parameters_;
53 }
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;
58 }
59 bool has_cached_network_parameters() const {
60 return has_cached_network_parameters_;
61 }
62
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_;
70
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_;
77 };
78
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_;
103 };
104
105 } // namespace net
106
107 #endif // NET_QUIC_CRYPTO_SOURCE_ADDRESS_TOKEN_H_
OLDNEW
« no previous file with comments | « net/quic/crypto/scoped_evp_aead_ctx.cc ('k') | net/quic/crypto/source_address_token.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698