]>
Commit | Line | Data |
---|---|---|
55622953 CT |
1 | /* |
2 | * Copyright (C) 1996-2019 The Squid Software Foundation and contributors | |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | #ifndef SQUID_RESOLVEDPEERS_H | |
10 | #define SQUID_RESOLVEDPEERS_H | |
11 | ||
12 | #include "base/RefCount.h" | |
13 | #include "comm/forward.h" | |
14 | ||
15 | #include <iosfwd> | |
16 | ||
17 | /// cache_peer and origin server addresses (a.k.a. paths) | |
18 | /// selected and resolved by the peering code | |
19 | class ResolvedPeers: public RefCountable | |
20 | { | |
21 | MEMPROXY_CLASS(ResolvedPeers); | |
22 | ||
23 | public: | |
24 | typedef RefCount<ResolvedPeers> Pointer; | |
25 | ||
26 | ResolvedPeers(); | |
27 | ||
28 | /// whether we lack any known candidate paths | |
29 | bool empty() const { return paths_.empty(); } | |
30 | ||
31 | /// add a candidate path to try after all the existing paths | |
32 | void addPath(const Comm::ConnectionPointer &); | |
33 | ||
34 | /// add a candidate path to try before all the existing paths | |
35 | void retryPath(const Comm::ConnectionPointer &); | |
36 | ||
37 | /// extracts and returns the first queued address | |
38 | Comm::ConnectionPointer extractFront(); | |
39 | ||
40 | /// extracts and returns the first same-peer same-family address | |
41 | /// \returns nil if it cannot find the requested address | |
42 | Comm::ConnectionPointer extractPrime(const Comm::Connection ¤tPeer); | |
43 | ||
44 | /// extracts and returns the first same-peer different-family address | |
45 | /// \returns nil if it cannot find the requested address | |
46 | Comm::ConnectionPointer extractSpare(const Comm::Connection ¤tPeer); | |
47 | ||
48 | /// whether extractSpare() would return a non-nil path right now | |
49 | bool haveSpare(const Comm::Connection ¤tPeer); | |
50 | ||
51 | /// whether extractPrime() returns and will continue to return nil | |
52 | bool doneWithPrimes(const Comm::Connection ¤tPeer) const; | |
53 | ||
54 | /// whether extractSpare() returns and will continue to return nil | |
55 | bool doneWithSpares(const Comm::Connection ¤tPeer); | |
56 | ||
57 | /// whether doneWithPrimes() and doneWithSpares() are true for currentPeer | |
58 | bool doneWithPeer(const Comm::Connection ¤tPeer) const; | |
59 | ||
60 | /// the current number of candidate paths | |
61 | Comm::ConnectionList::size_type size() const { return paths_.size(); } | |
62 | ||
63 | /// whether all of the available candidate paths received from DNS | |
64 | bool destinationsFinalized = false; | |
65 | ||
66 | /// whether HappyConnOpener::noteCandidatesChange() is scheduled to fire | |
67 | bool notificationPending = false; | |
68 | ||
69 | private: | |
70 | /// The protocol family of the given path, AF_INET or AF_INET6 | |
71 | static int ConnectionFamily(const Comm::Connection &conn); | |
72 | ||
73 | Comm::ConnectionList::iterator findSpareOrNextPeer(const Comm::Connection ¤tPeer); | |
74 | Comm::ConnectionPointer extractFound(const char *description, const Comm::ConnectionList::iterator &found); | |
75 | ||
76 | Comm::ConnectionList paths_; | |
77 | }; | |
78 | ||
79 | /// summarized ResolvedPeers (for debugging) | |
80 | std::ostream &operator <<(std::ostream &, const ResolvedPeers &); | |
81 | ||
82 | #endif /* SQUID_RESOLVEDPEERS_H */ | |
83 |