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

Side by Side Diff: net/quic/port_suggester.cc

Issue 107803002: Consistently suggest ephemeral port for QUIC client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Repond to wtc review Created 7 years 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/quic/port_suggester.h"
6
7 #include "base/metrics/histogram.h"
8 #include "net/base/host_port_pair.h"
9
10 namespace net {
11
12 PortSuggester::PortSuggester(const HostPortPair& server,
13 uint64 per_profile_randomness)
14 : count_(0) {
15 base::SHA1HashBytes(
16 reinterpret_cast<const unsigned char*>(server.host().data()),
17 server.host().length(), seed_.hash_bytes);
18
19 DCHECK_LE(sizeof(seed_.first_uint64), sizeof(seed_.hash_bytes));
Ryan Hamilton 2013/12/07 01:46:14 Can you use COMPILE_ASSERT here?
jar (doing other things) 2013/12/07 03:12:18 Done.
Ryan Hamilton 2013/12/07 23:21:54 It looks like this check has been removed. I'm to
jar (doing other things) 2013/12/08 01:38:36 Done.
20 seed_.first_uint64 ^= per_profile_randomness ^ server.port();
Ryan Hamilton 2013/12/07 01:46:14 Since you've already gone through the trouble of u
jar (doing other things) 2013/12/07 03:12:18 The only item that should not be (close to) unifor
Ryan Hamilton 2013/12/07 04:52:22 Ah, I see. Makes sense.
21 }
22
23 PortSuggester::~PortSuggester() {
24 UMA_HISTOGRAM_COUNTS("Net.Quic.EphemeralPortsSuggested", count_);
25 }
26
27 int PortSuggester::SuggestPort(int min, int max) {
28 // Sometimes our suggestion can't be used, so we ensure that if a additional
wtc 2013/12/07 01:03:38 Nit: remove "a"
jar (doing other things) 2013/12/07 03:12:18 Done.
29 // calls are made, that each call (probably) provides a new suggestion.
wtc 2013/12/07 01:03:38 Nit: I think "that" can be removed
jar (doing other things) 2013/12/07 03:12:18 Done.
30 if (++count_ > 1) {
31 // Evolve the seed.
32 base::SHA1HashBytes(seed_.hash_bytes, sizeof(seed_.hash_bytes),
33 seed_.hash_bytes);
34 }
35 int rand = std::abs(seed_.first_int);
Ryan Hamilton 2013/12/07 01:46:14 I notice that you're using first_int here, and fir
jar (doing other things) 2013/12/07 03:12:18 Seed_ is currently large enough to hold all the re
Ryan Hamilton 2013/12/07 04:52:22 Understood. However, in my opinion the extra comp
36 DCHECK_LE(min, max);
37 DCHECK_GT(min, 0);
38 int range = max - min + 1;
39 // Ports (and hence the extent of the |range|) are generally under 2^16, while
40 // ints are bigger than 2^31, so the tiny non-uniformity in the pseudo-random
41 // distribution is not significant.
42 return (rand % range) + min;
43 }
44
45 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698