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

Side by Side Diff: net/quic/quic_address_mismatch.cc

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « net/quic/quic_address_mismatch.h ('k') | net/quic/quic_address_mismatch_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "net/quic/quic_address_mismatch.h"
6
7 #include "base/logging.h"
8 #include "net/base/ip_address.h"
9
10 namespace net {
11
12 int GetAddressMismatch(const IPEndPoint& first_address,
13 const IPEndPoint& second_address) {
14 if (first_address.address().empty() || second_address.address().empty()) {
15 return -1;
16 }
17 IPAddress first_ip_address = first_address.address();
18 if (first_ip_address.IsIPv4MappedIPv6()) {
19 first_ip_address = ConvertIPv4MappedIPv6ToIPv4(first_ip_address);
20 }
21 IPAddress second_ip_address = second_address.address();
22 if (second_ip_address.IsIPv4MappedIPv6()) {
23 second_ip_address = ConvertIPv4MappedIPv6ToIPv4(second_ip_address);
24 }
25
26 int sample;
27 if (first_ip_address != second_ip_address) {
28 sample = QUIC_ADDRESS_MISMATCH_BASE;
29 } else if (first_address.port() != second_address.port()) {
30 sample = QUIC_PORT_MISMATCH_BASE;
31 } else {
32 sample = QUIC_ADDRESS_AND_PORT_MATCH_BASE;
33 }
34
35 // Add an offset to |sample|:
36 // V4_V4: add 0
37 // V6_V6: add 1
38 // V4_V6: add 2
39 // V6_V4: add 3
40 bool first_ipv4 = first_ip_address.IsIPv4();
41 if (first_ipv4 != second_ip_address.IsIPv4()) {
42 CHECK_EQ(sample, QUIC_ADDRESS_MISMATCH_BASE);
43 sample += 2;
44 }
45 if (!first_ipv4) {
46 sample += 1;
47 }
48 return sample;
49 }
50
51 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_address_mismatch.h ('k') | net/quic/quic_address_mismatch_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698