Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef NET_QUIC_PORT_SUGGESTER_H_ | |
| 6 #define NET_QUIC_PORT_SUGGESTER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/sha1.h" | |
| 11 #include "net/base/net_export.h" | |
| 12 | |
| 13 namespace net { | |
| 14 | |
| 15 class HostPortPair; | |
| 16 | |
| 17 // We provide a pseudo-random number generator that is always seeded the same | |
| 18 // way for a given destination host-port pair. The generator is used to | |
| 19 // consistently suggest (for that host-port pair) an ephemeral source port, | |
| 20 // and hence increase the likelihood that a server's load balancer will direct | |
| 21 // a repeated connection to the same server (with QUIC, further increasing the | |
| 22 // chance of connection establishment with 0-RTT). | |
| 23 class NET_EXPORT PortSuggester | |
| 24 : public base::RefCountedThreadSafe<PortSuggester> { | |
|
Ryan Hamilton
2013/12/07 01:46:14
Does this really need to be thread safe? Almost n
jar (doing other things)
2013/12/07 03:12:18
Done.
| |
| 25 public: | |
| 26 // |per_profile_randomness| is used to prevent (reduce probability of) one | |
| 27 // profile's suggestions from matching that of another. | |
| 28 PortSuggester(const HostPortPair& server, uint64 per_profile_randomness); | |
|
Ryan Hamilton
2013/12/07 01:46:14
nit: can per_profile_randomness simply be renamed
jar (doing other things)
2013/12/07 03:12:18
Done.
Ryan Hamilton
2013/12/07 23:21:54
Looks like it's still called per_profile_randomnes
jar (doing other things)
2013/12/08 01:38:36
My mistake. I thought I did it. DONE now.
| |
| 29 | |
| 30 // Generate a pseudo-random int in the inclusive range from |min| to |max|. | |
| 31 // Will (probably) return different numbers when called repeatedly. | |
| 32 int SuggestPort(int min, int max); | |
| 33 | |
| 34 private: | |
| 35 friend class base::RefCountedThreadSafe<PortSuggester>; | |
| 36 | |
| 37 virtual ~PortSuggester(); | |
| 38 | |
| 39 union { | |
| 40 unsigned char hash_bytes[base::kSHA1Length]; | |
| 41 uint64 first_uint64; | |
| 42 int first_int; | |
|
wtc
2013/12/07 01:03:38
The indentation of these four lines seem off by on
jar (doing other things)
2013/12/07 03:12:18
Done.
| |
| 43 } seed_; | |
|
Ryan Hamilton
2013/12/07 01:46:14
This union seems really subtle and not terribly re
jar (doing other things)
2013/12/07 03:12:18
I originally used reinterpret casts, but wtc noted
Ryan Hamilton
2013/12/07 04:52:22
Hm. I don't think there are alignment issues with
jar (doing other things)
2013/12/07 21:09:28
The alignment issue (see wtc comments in patch 6)
Ryan Hamilton
2013/12/07 23:21:54
Ah, yes, using reinterpret_cast to go from bytes t
| |
| 44 int count_; // Number of suggestions made. | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(PortSuggester); | |
| 47 }; | |
| 48 | |
| 49 } // namespace net | |
| 50 | |
| 51 #endif // NET_QUIC_PORT_SUGGESTER_H_ | |
| OLD | NEW |