Prathmesh Prabhu | ba99b59 | 2013-04-17 15:13:14 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS 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 | #ifndef SHILL_IP_ADDRESS_STORE_H_ |
| 6 | #define SHILL_IP_ADDRESS_STORE_H_ |
| 7 | |
| 8 | #include <set> |
| 9 | |
| 10 | #include "shill/ip_address.h" |
| 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | struct IPAddressLTIgnorePrefix { |
| 15 | bool operator () (const IPAddress &lhs, const IPAddress &rhs) const; |
| 16 | }; |
| 17 | |
| 18 | // Stores a set of IP addresses used by ConnectionHealthChecker to check |
| 19 | // connectivity when there is a chance that the service has run out-of-credits. |
| 20 | // The IP addresses are populated (using DNS queries) opportunistically and |
| 21 | // must be persistent so that they can be used in an out-of-credit scenario |
| 22 | // (when DNS queries would also fail). |
| 23 | // To make the store persistent across Device resets (e.g. suspend-resume), it |
| 24 | // is owned by the Manager. |
| 25 | // Currently, this is a thin wrapper around an STL container. |
| 26 | class IPAddressStore { |
| 27 | public: |
| 28 | typedef std::set<IPAddress, IPAddressLTIgnorePrefix> IPAddresses; |
| 29 | |
| 30 | IPAddressStore(); |
| 31 | virtual ~IPAddressStore(); |
| 32 | |
| 33 | // Add a new IP address if it does not already exist. |
| 34 | virtual void AddUnique(const IPAddress &ip); |
| 35 | virtual void Clear(); |
| 36 | virtual size_t Count() const; |
| 37 | virtual bool Empty() const; |
| 38 | |
| 39 | virtual IPAddress GetRandomIP(); |
| 40 | |
| 41 | protected: |
| 42 | friend class IPAddressStoreTest; |
| 43 | |
| 44 | private: |
| 45 | IPAddresses ip_addresses_; |
| 46 | |
| 47 | DISALLOW_COPY_AND_ASSIGN(IPAddressStore); |
| 48 | }; |
| 49 | |
| 50 | } // namespace shill |
| 51 | |
| 52 | #endif // SHILL_IP_ADDRESS_STORE_H_ |