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

Unified Diff: net/quic/port_suggester.h

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 side-by-side diff with in-line comments
Download patch
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..52655648c0f1cc204d9ea40a4c82f003f8234580
--- /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
+ : 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.
+ public:
+ // |per_profile_randomness| is used to prevent (reduce probability of) one
+ // profile's suggestions from matching that of another.
+ 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.
+
+ // 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);
+
+ private:
+ friend class base::RefCountedThreadSafe<PortSuggester>;
+
+ virtual ~PortSuggester();
+
+ union {
+ unsigned char hash_bytes[base::kSHA1Length];
+ uint64 first_uint64;
+ 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.
+ } 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
+ int count_; // Number of suggestions made.
+
+ DISALLOW_COPY_AND_ASSIGN(PortSuggester);
+};
+
+} // namespace net
+
+#endif // NET_QUIC_PORT_SUGGESTER_H_
« no previous file with comments | « net/net.gyp ('k') | net/quic/port_suggester.cc » ('j') | net/quic/port_suggester.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698