Chromium Code Reviews| Index: net/dns/address_sorter_posix.h |
| diff --git a/net/dns/address_sorter_posix.h b/net/dns/address_sorter_posix.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0083a37dc7dd1915c3cbe1ed4f896b0a955ad893 |
| --- /dev/null |
| +++ b/net/dns/address_sorter_posix.h |
| @@ -0,0 +1,86 @@ |
| +// Copyright (c) 2012 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. |
| + |
| +#ifndef NET_DNS_ADDRESS_SORTER_POSIX_H_ |
| +#define NET_DNS_ADDRESS_SORTER_POSIX_H_ |
| + |
| +#include <map> |
| +#include <vector> |
| + |
| +#include "net/base/address_list.h" |
| +#include "net/base/net_errors.h" |
| +#include "net/base/net_export.h" |
| +#include "net/base/net_util.h" |
| +#include "net/base/network_change_notifier.h" |
| +#include "net/dns/address_sorter.h" |
| + |
| +namespace net { |
| + |
| +class ClientSocketFactory; |
| + |
| +// Generic policy entry. |
| +struct PolicyEntry { |
| + // IPv4 addresses must be mapped to IPv6. |
| + unsigned char prefix[kIPv6AddressSize]; |
| + unsigned prefix_length; |
| + unsigned value; |
| +}; |
| + |
| +typedef std::vector<PolicyEntry> PolicyTable; |
| + |
| +enum AddressScope { |
| + SCOPE_UNDEFINED = 0, |
| + SCOPE_NODELOCAL = 1, |
| + SCOPE_LINKLOCAL = 2, |
| + SCOPE_SITELOCAL = 5, |
| + SCOPE_ORGLOCAL = 8, |
| + SCOPE_GLOBAL = 14, |
| +}; |
| + |
| +struct SourceAddressInfo { |
| + // Values read from policy tables. |
| + AddressScope scope; |
| + unsigned label; |
|
mmenke
2012/08/07 18:30:27
nit: Suggest a blank line here, for legibility.
|
| + // Values from the OS, matter only if more than one source address is used. |
| + unsigned prefix_length; |
| + bool deprecated; // vs. preferred RFC4862 |
| + bool home; // vs. care-of RFC6275 |
| + bool native; |
| +}; |
| + |
| +typedef std::map<IPAddressNumber, SourceAddressInfo> SourceAddressMap; |
| + |
| +class NET_EXPORT_PRIVATE AddressSorterPosix |
|
mmenke
2012/08/07 18:30:27
Suggest a comment that this is non-threadsafe and
|
| + : public AddressSorter, |
| + public NetworkChangeNotifier::IPAddressObserver { |
| + public: |
| + explicit AddressSorterPosix(ClientSocketFactory* socket_factory); |
| + virtual ~AddressSorterPosix(); |
| + |
| + virtual void Sort(const AddressList& list, |
| + const CallbackType& callback) const OVERRIDE; |
| + |
| + private: |
| + friend class AddressSorterPosixTest; |
| + |
| + // NetworkChangeNotifier::IPAddressObserver: |
| + virtual void OnIPAddressChanged() OVERRIDE; |
| + |
| + // Fills |info| with values for |address| from policy tables. |
| + void FillPolicy(const IPAddressNumber& address, |
| + SourceAddressInfo* info) const; |
| + |
| + mutable SourceAddressMap source_map_; |
|
mmenke
2012/08/07 18:30:27
Suggest a comment that this is mutable so unrecogn
|
| + |
| + ClientSocketFactory* socket_factory_; |
| + PolicyTable precedence_table_; |
| + PolicyTable label_table_; |
| + PolicyTable ipv4_scope_table_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AddressSorterPosix); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_DNS_ADDRESS_SORTER_POSIX_H_ |