OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/core/quic_config.h" | 5 #include "net/quic/core/quic_config.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "net/quic/core/crypto/crypto_handshake_message.h" | 10 #include "net/quic/core/crypto/crypto_handshake_message.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 *error_details = | 107 *error_details = |
108 "Invalid value received for " + QuicUtils::TagToString(tag_); | 108 "Invalid value received for " + QuicUtils::TagToString(tag_); |
109 return QUIC_INVALID_NEGOTIATED_VALUE; | 109 return QUIC_INVALID_NEGOTIATED_VALUE; |
110 } | 110 } |
111 | 111 |
112 set_negotiated(true); | 112 set_negotiated(true); |
113 negotiated_value_ = min(value, max_value_); | 113 negotiated_value_ = min(value, max_value_); |
114 return QUIC_NO_ERROR; | 114 return QUIC_NO_ERROR; |
115 } | 115 } |
116 | 116 |
117 QuicNegotiableTag::QuicNegotiableTag(QuicTag tag, QuicConfigPresence presence) | |
118 : QuicNegotiableValue(tag, presence), | |
119 negotiated_tag_(0), | |
120 default_value_(0) {} | |
121 | |
122 QuicNegotiableTag::~QuicNegotiableTag() {} | |
123 | |
124 void QuicNegotiableTag::set(const QuicTagVector& possible, | |
125 QuicTag default_value) { | |
126 DCHECK(ContainsQuicTag(possible, default_value)); | |
127 possible_values_ = possible; | |
128 default_value_ = default_value; | |
129 } | |
130 | |
131 void QuicNegotiableTag::ToHandshakeMessage(CryptoHandshakeMessage* out) const { | |
132 if (negotiated()) { | |
133 // Because of the way we serialize and parse handshake messages we can | |
134 // serialize this as value and still parse it as a vector. | |
135 out->SetValue(tag_, negotiated_tag_); | |
136 } else { | |
137 out->SetVector(tag_, possible_values_); | |
138 } | |
139 } | |
140 | |
141 QuicErrorCode QuicNegotiableTag::ReadVector(const CryptoHandshakeMessage& msg, | |
142 const QuicTag** out, | |
143 size_t* out_length, | |
144 string* error_details) const { | |
145 DCHECK(error_details != nullptr); | |
146 QuicErrorCode error = msg.GetTaglist(tag_, out, out_length); | |
147 switch (error) { | |
148 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | |
149 if (presence_ == PRESENCE_REQUIRED) { | |
150 *error_details = "Missing " + QuicUtils::TagToString(tag_); | |
151 break; | |
152 } | |
153 error = QUIC_NO_ERROR; | |
154 *out_length = 1; | |
155 *out = &default_value_; | |
156 | |
157 case QUIC_NO_ERROR: | |
158 break; | |
159 default: | |
160 *error_details = "Bad " + QuicUtils::TagToString(tag_); | |
161 break; | |
162 } | |
163 return error; | |
164 } | |
165 | |
166 QuicErrorCode QuicNegotiableTag::ProcessPeerHello( | |
167 const CryptoHandshakeMessage& peer_hello, | |
168 HelloType hello_type, | |
169 string* error_details) { | |
170 DCHECK(!negotiated()); | |
171 DCHECK(error_details != nullptr); | |
172 const QuicTag* received_tags; | |
173 size_t received_tags_length; | |
174 QuicErrorCode error = ReadVector(peer_hello, &received_tags, | |
175 &received_tags_length, error_details); | |
176 if (error != QUIC_NO_ERROR) { | |
177 return error; | |
178 } | |
179 | |
180 if (hello_type == SERVER) { | |
181 if (received_tags_length != 1 || | |
182 !ContainsQuicTag(possible_values_, *received_tags)) { | |
183 *error_details = "Invalid " + QuicUtils::TagToString(tag_); | |
184 return QUIC_INVALID_NEGOTIATED_VALUE; | |
185 } | |
186 negotiated_tag_ = *received_tags; | |
187 } else { | |
188 QuicTag negotiated_tag; | |
189 if (!QuicUtils::FindMutualTag( | |
190 possible_values_, received_tags, received_tags_length, | |
191 QuicUtils::LOCAL_PRIORITY, &negotiated_tag, nullptr)) { | |
192 *error_details = "Unsupported " + QuicUtils::TagToString(tag_); | |
193 return QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP; | |
194 } | |
195 negotiated_tag_ = negotiated_tag; | |
196 } | |
197 | |
198 set_negotiated(true); | |
199 return QUIC_NO_ERROR; | |
200 } | |
201 | |
202 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) | 117 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) |
203 : QuicConfigValue(tag, presence), | 118 : QuicConfigValue(tag, presence), |
204 has_send_value_(false), | 119 has_send_value_(false), |
205 has_receive_value_(false) {} | 120 has_receive_value_(false) {} |
206 QuicFixedUint32::~QuicFixedUint32() {} | 121 QuicFixedUint32::~QuicFixedUint32() {} |
207 | 122 |
208 bool QuicFixedUint32::HasSendValue() const { | 123 bool QuicFixedUint32::HasSendValue() const { |
209 return has_send_value_; | 124 return has_send_value_; |
210 } | 125 } |
211 | 126 |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 error_details); | 673 error_details); |
759 } | 674 } |
760 if (error == QUIC_NO_ERROR) { | 675 if (error == QUIC_NO_ERROR) { |
761 error = force_hol_blocking_.ProcessPeerHello(peer_hello, hello_type, | 676 error = force_hol_blocking_.ProcessPeerHello(peer_hello, hello_type, |
762 error_details); | 677 error_details); |
763 } | 678 } |
764 return error; | 679 return error; |
765 } | 680 } |
766 | 681 |
767 } // namespace net | 682 } // namespace net |
OLD | NEW |