OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/port_suggester.h" | 5 #include "net/quic/port_suggester.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/base/host_port_pair.h" | 8 #include "net/base/host_port_pair.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
11 | 11 |
12 PortSuggester::PortSuggester(const HostPortPair& server, uint64 seed) | 12 PortSuggester::PortSuggester(const HostPortPair& server, uint64_t seed) |
13 : call_count_(0), previous_suggestion_(-1) { | 13 : call_count_(0), previous_suggestion_(-1) { |
14 unsigned char hash_bytes[base::kSHA1Length]; | 14 unsigned char hash_bytes[base::kSHA1Length]; |
15 base::SHA1HashBytes( | 15 base::SHA1HashBytes( |
16 reinterpret_cast<const unsigned char*>(server.host().data()), | 16 reinterpret_cast<const unsigned char*>(server.host().data()), |
17 server.host().length(), hash_bytes); | 17 server.host().length(), hash_bytes); |
18 static_assert(sizeof(seed_) < sizeof(hash_bytes), "seed larger than hash"); | 18 static_assert(sizeof(seed_) < sizeof(hash_bytes), "seed larger than hash"); |
19 memcpy(&seed_, hash_bytes, sizeof(seed_)); | 19 memcpy(&seed_, hash_bytes, sizeof(seed_)); |
20 seed_ ^= seed ^ server.port(); | 20 seed_ ^= seed ^ server.port(); |
21 } | 21 } |
22 | 22 |
(...skipping 16 matching lines...) Expand all Loading... |
39 previous_suggestion_ = static_cast<int>(seed_ % range) + min; | 39 previous_suggestion_ = static_cast<int>(seed_ % range) + min; |
40 return previous_suggestion_; | 40 return previous_suggestion_; |
41 } | 41 } |
42 | 42 |
43 int PortSuggester::previous_suggestion() const { | 43 int PortSuggester::previous_suggestion() const { |
44 DCHECK_LT(0u, call_count_); | 44 DCHECK_LT(0u, call_count_); |
45 return previous_suggestion_; | 45 return previous_suggestion_; |
46 } | 46 } |
47 | 47 |
48 } // namespace net | 48 } // namespace net |
OLD | NEW |