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

Side by Side Diff: net/quic/crypto/quic_server_info.cc

Issue 154933003: Persist server's crypto config data to disk cache for 0-RTT (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Deleted unused data_loaded_ member Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "net/quic/crypto/quic_server_info.h" 5 #include "net/quic/crypto/quic_server_info.h"
6 6
7 #include "base/bind.h" 7 #include <limits>
8
8 #include "base/pickle.h" 9 #include "base/pickle.h"
9 #include "base/strings/string_piece.h" 10
11 using std::string;
12
13 namespace {
14
15 const int kQuicCryptoConfigVersion = 1;
16
17 } // namespace
10 18
11 namespace net { 19 namespace net {
12 20
13 QuicServerInfo::State::State() {} 21 QuicServerInfo::State::State() {}
14 22
15 QuicServerInfo::State::~State() {} 23 QuicServerInfo::State::~State() {}
16 24
17 void QuicServerInfo::State::Clear() { 25 void QuicServerInfo::State::Clear() {
18 data.clear(); 26 server_config_.clear();
27 source_address_token_.clear();
28 server_config_sig_.clear();
29 certs_.clear();
19 } 30 }
20 31
21 // TODO(rtenneti): Flesh out the details. 32 QuicServerInfo::QuicServerInfo(const string& hostname) : hostname_(hostname) {
22 QuicServerInfo::QuicServerInfo(
23 const std::string& hostname)
24 : hostname_(hostname),
25 weak_factory_(this) {
26 } 33 }
27 34
28 QuicServerInfo::~QuicServerInfo() { 35 QuicServerInfo::~QuicServerInfo() {
29 } 36 }
30 37
31 const QuicServerInfo::State& QuicServerInfo::state() const { 38 const QuicServerInfo::State& QuicServerInfo::state() const {
32 return state_; 39 return state_;
33 } 40 }
34 41
35 QuicServerInfo::State* QuicServerInfo::mutable_state() { 42 QuicServerInfo::State* QuicServerInfo::mutable_state() {
36 return &state_; 43 return &state_;
37 } 44 }
38 45
39 bool QuicServerInfo::Parse(const std::string& data) { 46 bool QuicServerInfo::Parse(const string& data) {
40 State* state = mutable_state(); 47 State* state = mutable_state();
41 48
42 state->Clear(); 49 state->Clear();
43 50
44 bool r = ParseInner(data); 51 bool r = ParseInner(data);
45 if (!r) 52 if (!r)
46 state->Clear(); 53 state->Clear();
47 return r; 54 return r;
48 } 55 }
49 56
50 bool QuicServerInfo::ParseInner(const std::string& data) { 57 bool QuicServerInfo::ParseInner(const string& data) {
51 // TODO(rtenneti): restore QuicCryptoClientConfig::CachedState. 58 State* state = mutable_state();
52 // State* state = mutable_state();
53 59
54 // Pickle p(data.data(), data.size()); 60 // No data was read from the disk cache.
55 // PickleIterator iter(p); 61 if (data.empty()) {
62 return false;
63 }
64
65 Pickle p(data.data(), data.size());
66 PickleIterator iter(p);
67
68 int version = -1;
69 if (!p.ReadInt(&iter, &version) || version < 0) {
wtc 2014/02/11 01:01:45 I think we don't need to test if version < 0. We c
ramant (doing other things) 2014/02/11 07:57:55 Done.
70 DVLOG(1) << "Missing version";
71 return false;
72 }
73
74 if (version != kQuicCryptoConfigVersion) {
75 DVLOG(1) << "Unsupported version";
76 return false;
77 }
78
79 if (!p.ReadString(&iter, &state->server_config_)) {
80 DVLOG(1) << "Malformed server_config";
81 return false;
82 }
83 if (!p.ReadString(&iter, &state->source_address_token_)) {
84 DVLOG(1) << "Malformed source_address_token";
85 return false;
86 }
87 if (!p.ReadString(&iter, &state->server_config_sig_)) {
88 DVLOG(1) << "Malformed server_config_sig";
89 return false;
90 }
91
92 // Read certs.
93 int num_certs;
94 if (!p.ReadInt(&iter, &num_certs) || num_certs < 0) {
wtc 2014/02/11 01:01:45 num_certs should have the uint32 type to match the
ramant (doing other things) 2014/02/11 07:57:55 Done.
95 DVLOG(1) << "Malformed num_certs";
96 return false;
97 }
98
99 for (int i = 0; i < num_certs; i++) {
100 string cert;
101 if (!p.ReadString(&iter, &cert)) {
102 DVLOG(1) << "Malformed cert";
103 return false;
104 }
105 state->certs_.push_back(cert);
106 }
56 107
57 return true; 108 return true;
58 } 109 }
59 110
60 std::string QuicServerInfo::Serialize() const { 111 string QuicServerInfo::Serialize() const {
61 Pickle p(sizeof(Pickle::Header)); 112 Pickle p(sizeof(Pickle::Header));
62 113
63 // TODO(rtenneti): serialize QuicCryptoClientConfig::CachedState. 114 if (!p.WriteInt(kQuicCryptoConfigVersion) ||
64 return std::string(reinterpret_cast<const char *>(p.data()), p.size()); 115 !p.WriteString(state_.server_config_) ||
116 !p.WriteString(state_.source_address_token_) ||
117 !p.WriteString(state_.server_config_sig_) ||
118 state_.certs_.size() > std::numeric_limits<uint32>::max() ||
119 !p.WriteUInt32(state_.certs_.size())) {
120 return string();
121 }
122
123 for (size_t i = 0; i < state_.certs_.size(); i++) {
124 if (!p.WriteString(state_.certs_[i])) {
125 return string();
126 }
127 }
128
129 return string(reinterpret_cast<const char *>(p.data()), p.size());
65 } 130 }
66 131
67 QuicServerInfoFactory::~QuicServerInfoFactory() {} 132 QuicServerInfoFactory::~QuicServerInfoFactory() {}
68 133
69 } // namespace net 134 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698