Update V8 to version 4.7.42.
[chromium-blink-merge.git] / net / quic / quic_address_mismatch.cc
blob96aaef410309446dab6109961ace5e290014c705
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.
5 #include "net/quic/quic_address_mismatch.h"
7 #include "base/logging.h"
8 #include "net/base/ip_endpoint.h"
10 namespace net {
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;
17 IPAddressNumber first_ip_address = first_address.address();
18 if (IsIPv4Mapped(first_ip_address)) {
19 first_ip_address = ConvertIPv4MappedToIPv4(first_ip_address);
21 IPAddressNumber second_ip_address = second_address.address();
22 if (IsIPv4Mapped(second_ip_address)) {
23 second_ip_address = ConvertIPv4MappedToIPv4(second_ip_address);
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;
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.size() == kIPv4AddressSize);
41 bool second_ipv4 = (second_ip_address.size() == kIPv4AddressSize);
42 if (first_ipv4 != second_ipv4) {
43 CHECK_EQ(sample, QUIC_ADDRESS_MISMATCH_BASE);
44 sample += 2;
46 if (!first_ipv4) {
47 sample += 1;
49 return sample;
52 } // namespace net