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

Unified Diff: net/quic/port_suggester.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months 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
« no previous file with comments | « net/quic/port_suggester.h ('k') | net/quic/port_suggester_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/port_suggester.cc
diff --git a/net/quic/port_suggester.cc b/net/quic/port_suggester.cc
deleted file mode 100644
index b1dfa484fd54258328fc5b462cf1aadb589f4f88..0000000000000000000000000000000000000000
--- a/net/quic/port_suggester.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-// 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.
-
-#include "net/quic/port_suggester.h"
-
-#include "base/logging.h"
-#include "net/base/host_port_pair.h"
-
-namespace net {
-
-PortSuggester::PortSuggester(const HostPortPair& server, uint64 seed)
- : call_count_(0),
- previous_suggestion_(-1) {
- unsigned char hash_bytes[base::kSHA1Length];
- base::SHA1HashBytes(
- reinterpret_cast<const unsigned char*>(server.host().data()),
- server.host().length(), hash_bytes);
- static_assert(sizeof(seed_) < sizeof(hash_bytes), "seed larger than hash");
- memcpy(&seed_, hash_bytes, sizeof(seed_));
- seed_ ^= seed ^ server.port();
-}
-
-int PortSuggester::SuggestPort(int min, int max) {
- // Sometimes our suggestion can't be used, so we ensure that if additional
- // calls are made, then each call (probably) provides a new suggestion.
- if (++call_count_ > 1) {
- // Evolve the seed.
- unsigned char hash_bytes[base::kSHA1Length];
- base::SHA1HashBytes(reinterpret_cast<const unsigned char *>(&seed_),
- sizeof(seed_), hash_bytes);
- memcpy(&seed_, hash_bytes, sizeof(seed_));
- }
- DCHECK_LE(min, max);
- DCHECK_GT(min, 0);
- int range = max - min + 1;
- // Ports (and hence the extent of the |range|) are generally under 2^16, so
- // the tiny non-uniformity in the pseudo-random distribution is not
- // significant.
- previous_suggestion_ = static_cast<int>(seed_ % range) + min;
- return previous_suggestion_;
-}
-
-int PortSuggester::previous_suggestion() const {
- DCHECK_LT(0u, call_count_);
- return previous_suggestion_;
-}
-
-} // namespace net
« no previous file with comments | « net/quic/port_suggester.h ('k') | net/quic/port_suggester_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698