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

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: 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..6e265bf63b00baca89961c7332d84462a0b06a3b
--- /dev/null
+++ b/net/quic/port_suggester.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
wtc 2013/12/06 23:36:44 Nit: this should say 2013. And "(c)" is now not ne
jar (doing other things) 2013/12/07 00:47:58 Done.
+// 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/host_port_pair.h"
wtc 2013/12/06 23:36:44 Nit: you may be able to get by with a forward decl
jar (doing other things) 2013/12/07 00:47:58 Done.
+
+namespace net {
+
+// 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> {
+ public:
+ // |per_profile_randomness| is used to prevent (reduce probability of) one
+ // profile's suggestions from matching that of another.
+ PortSuggester(const HostPortPair& hostport, uint64 per_profile_randomness);
wtc 2013/12/06 23:36:44 Nit: you should explain whose host and port |hostp
jar (doing other things) 2013/12/07 00:47:58 Done (switched to |server|)
+
+ // Generate a pseudo-random int in the given range. Will (probably) return
wtc 2013/12/06 23:36:44 Nit: please specify whether the range is inclusive
jar (doing other things) 2013/12/07 00:47:58 Done.
+ // different numbers when called repeatedly.
+ int SuggestPort(int min, int max);
+
+ private:
+ friend class base::RefCountedThreadSafe<PortSuggester>;
+
+ virtual ~PortSuggester();
+
+ unsigned char seed_[base::kSHA1Length];
+ 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