Chromium Code Reviews| Index: net/quic/port_suggester.h |
| diff --git a/net/quic/port_suggester.h b/net/quic/port_suggester.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3eab184a050e9c04b530032b4122925f9f01abf5 |
| --- /dev/null |
| +++ b/net/quic/port_suggester.h |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_QUIC_PORT_SUGGESTER_H_ |
| +#define NET_QUIC_PORT_SUGGESTER_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/sha1.h" |
| +#include "net/base/net_export.h" |
| + |
| +namespace net { |
| + |
| +class HostPortPair; |
| + |
| +// We provide a pseudo-random number generator that is always seeded the same |
| +// way for a given destination host-port pair. The generator is used to |
| +// consistently suggest (for that host-port pair) an ephemeral source port, |
| +// and hence increase the likelihood that a server's load balancer will direct |
| +// a repeated connection to the same server (with QUIC, further increasing the |
| +// chance of connection establishment with 0-RTT). |
| +class NET_EXPORT PortSuggester |
|
Ryan Hamilton
2013/12/07 23:21:55
Should this be NET_EXPORT or NET_EXPORT_PRIVATE?
jar (doing other things)
2013/12/08 01:38:36
Done.
|
| + : public base::RefCounted<PortSuggester> { |
|
Ryan Hamilton
2013/12/07 23:21:55
nit: I think this can all fit on a single line. (
jar (doing other things)
2013/12/08 01:38:36
Made private... doesn't fit.
|
| + public: |
| + // |per_profile_randomness| is used to seed the generator. |
| + PortSuggester(const HostPortPair& server, uint64 per_profile_randomness); |
| + |
| + // Generate a pseudo-random int in the inclusive range from |min| to |max|. |
| + // Will (probably) return different numbers when called repeatedly. |
| + int SuggestPort(int min, int max); |
| + |
| + uint32 call_count() const { return call_count_; } |
| + int previous_suggestion() const { return previous_suggestion_; } |
|
Ryan Hamilton
2013/12/07 23:21:55
if you decide to keep this method, should it DCHEC
jar (doing other things)
2013/12/08 01:38:36
I can add that. I gave it a init value of -1, so
|
| + |
| + private: |
| + friend class base::RefCounted<PortSuggester>; |
| + |
| + virtual ~PortSuggester() {} |
| + |
| + // We maintain the first 8 bytes of a hash as our seed_ state. |
| + uint64 seed_; |
|
Ryan Hamilton
2013/12/07 23:21:55
nit: extra space before seed_;
jar (doing other things)
2013/12/08 01:38:36
Done.
|
| + uint32 call_count_; // Number of suggestions made. |
| + int previous_suggestion_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PortSuggester); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_QUIC_PORT_SUGGESTER_H_ |