OLD | NEW |
---|---|
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 "base/bind.h" |
wtc
2014/02/07 00:54:11
I think this header can be removed.
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/strings/string_piece.h" | 9 |
10 using std::string; | |
wtc
2014/02/07 00:54:11
I think we should remove this "using std::string"
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
11 | |
12 namespace { | |
13 const size_t kQuicCryptoConfigVersion = 1; | |
14 } // namespace | |
wtc
2014/02/07 00:54:11
1. Nit: kQuicCryptoConfigVersion can be of a small
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
10 | 15 |
11 namespace net { | 16 namespace net { |
12 | 17 |
13 QuicServerInfo::State::State() {} | 18 QuicServerInfo::State::State() {} |
14 | 19 |
15 QuicServerInfo::State::~State() {} | 20 QuicServerInfo::State::~State() {} |
16 | 21 |
17 void QuicServerInfo::State::Clear() { | 22 void QuicServerInfo::State::Clear() { |
18 data.clear(); | 23 server_config_.clear(); |
24 source_address_token_.clear(); | |
25 server_config_sig_.clear(); | |
26 certs_.clear(); | |
19 } | 27 } |
20 | 28 |
21 // TODO(rtenneti): Flesh out the details. | 29 QuicServerInfo::QuicServerInfo(const std::string& hostname) |
22 QuicServerInfo::QuicServerInfo( | |
23 const std::string& hostname) | |
24 : hostname_(hostname), | 30 : hostname_(hostname), |
31 data_loaded_(false), | |
25 weak_factory_(this) { | 32 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 std::string& data) { |
40 State* state = mutable_state(); | 47 State* state = mutable_state(); |
41 | 48 |
42 state->Clear(); | 49 state->Clear(); |
50 data_loaded_ = false; | |
wtc
2014/02/07 00:54:11
I recommend moving this to the beginning of ParseI
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
43 | 51 |
44 bool r = ParseInner(data); | 52 bool r = ParseInner(data); |
45 if (!r) | 53 if (!r) |
46 state->Clear(); | 54 state->Clear(); |
47 return r; | 55 return r; |
48 } | 56 } |
49 | 57 |
50 bool QuicServerInfo::ParseInner(const std::string& data) { | 58 bool QuicServerInfo::ParseInner(const std::string& data) { |
51 // TODO(rtenneti): restore QuicCryptoClientConfig::CachedState. | 59 State* state = mutable_state(); |
52 // State* state = mutable_state(); | |
53 | 60 |
54 // Pickle p(data.data(), data.size()); | 61 // No data was read from the disk cache. |
55 // PickleIterator iter(p); | 62 if (data.empty()) { |
63 return false; | |
64 } | |
65 | |
66 Pickle p(data.data(), data.size()); | |
67 PickleIterator iter(p); | |
68 | |
69 int version = -1; | |
70 if (!p.ReadInt(&iter, &version) || version < 0) { | |
wtc
2014/02/07 00:54:11
You should check version != kQuicCryptoConfigVersi
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
71 DVLOG(1) << "Missing version"; | |
72 return false; | |
73 } | |
74 | |
75 if (!p.ReadString(&iter, &state->server_config_)) { | |
76 DVLOG(1) << "Malformed server_config"; | |
77 return false; | |
78 } | |
79 if (!p.ReadString(&iter, &state->source_address_token_)) { | |
80 DVLOG(1) << "Malformed source_address_token"; | |
81 return false; | |
82 } | |
83 if (!p.ReadString(&iter, &state->server_config_sig_)) { | |
84 DVLOG(1) << "Malformed server_config_sig"; | |
85 return false; | |
86 } | |
87 | |
88 // Read certs. | |
89 int num_certs; | |
90 if (!p.ReadInt(&iter, &num_certs) || num_certs < 0) { | |
91 DVLOG(1) << "Malformed num_certs"; | |
92 return false; | |
93 } | |
94 | |
95 for (int i = 0; i < num_certs; i++) { | |
96 string cert; | |
97 if (!p.ReadString(&iter, &cert)) { | |
98 DVLOG(1) << "Malformed cert"; | |
99 return false; | |
100 } | |
101 state->certs_.push_back(cert); | |
102 } | |
103 data_loaded_ = true; | |
56 | 104 |
57 return true; | 105 return true; |
58 } | 106 } |
59 | 107 |
60 std::string QuicServerInfo::Serialize() const { | 108 std::string QuicServerInfo::Serialize() const { |
61 Pickle p(sizeof(Pickle::Header)); | 109 Pickle p(sizeof(Pickle::Header)); |
62 | 110 |
63 // TODO(rtenneti): serialize QuicCryptoClientConfig::CachedState. | 111 if (!p.WriteInt(kQuicCryptoConfigVersion) || |
64 return std::string(reinterpret_cast<const char *>(p.data()), p.size()); | 112 !p.WriteString(state_.server_config_) || |
113 !p.WriteString(state_.source_address_token_) || | |
114 !p.WriteString(state_.server_config_sig_) || | |
115 !p.WriteInt(state_.certs_.size())) { | |
wtc
2014/02/07 00:54:11
This probably should be p.WriteUInt32 since state_
ramant (doing other things)
2014/02/07 20:30:51
Done.
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
116 return ""; | |
wtc
2014/02/07 00:54:11
Nit: it may be better to return std::string().
| |
117 } | |
118 | |
119 for (size_t i = 0; i < state_.certs_.size(); i++) { | |
120 if (!p.WriteString(state_.certs_[i])) { | |
121 return ""; | |
122 } | |
123 } | |
124 | |
125 return string(reinterpret_cast<const char *>(p.data()), p.size()); | |
65 } | 126 } |
66 | 127 |
67 QuicServerInfoFactory::~QuicServerInfoFactory() {} | 128 QuicServerInfoFactory::~QuicServerInfoFactory() {} |
68 | 129 |
69 } // namespace net | 130 } // namespace net |
OLD | NEW |