Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / net / quic / quic_address_mismatch.cc
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_endpoint.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
18   int sample;
19   if (first_address.address() != second_address.address()) {
20     sample = QUIC_ADDRESS_MISMATCH_BASE;
21   } else if (first_address.port() != second_address.port()) {
22     sample = QUIC_PORT_MISMATCH_BASE;
23   } else {
24     sample = QUIC_ADDRESS_AND_PORT_MATCH_BASE;
25   }
26
27   // Add an offset to |sample|:
28   //   V4_V4: add 0
29   //   V6_V6: add 1
30   //   V4_V6: add 2
31   //   V6_V4: add 3
32   bool first_ipv4 = (first_address.address().size() == kIPv4AddressSize);
33   bool second_ipv4 = (second_address.address().size() == kIPv4AddressSize);
34   if (first_ipv4 != second_ipv4) {
35     CHECK_EQ(sample, QUIC_ADDRESS_MISMATCH_BASE);
36     sample += 2;
37   }
38   if (!first_ipv4) {
39     sample += 1;
40   }
41   return sample;
42 }
43
44 }  // namespace net