]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ResolvedPeers.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ResolvedPeers.h
CommitLineData
55622953 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
55622953
CT
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
19class ResolvedPeers: public RefCountable
20{
21 MEMPROXY_CLASS(ResolvedPeers);
22
23public:
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 &currentPeer);
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 &currentPeer);
47
48 /// whether extractSpare() would return a non-nil path right now
49 bool haveSpare(const Comm::Connection &currentPeer);
50
51 /// whether extractPrime() returns and will continue to return nil
52 bool doneWithPrimes(const Comm::Connection &currentPeer) const;
53
54 /// whether extractSpare() returns and will continue to return nil
55 bool doneWithSpares(const Comm::Connection &currentPeer);
56
57 /// whether doneWithPrimes() and doneWithSpares() are true for currentPeer
58 bool doneWithPeer(const Comm::Connection &currentPeer) 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
69private:
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 &currentPeer);
74 Comm::ConnectionPointer extractFound(const char *description, const Comm::ConnectionList::iterator &found);
75
76 Comm::ConnectionList paths_;
77};
78
79/// summarized ResolvedPeers (for debugging)
80std::ostream &operator <<(std::ostream &, const ResolvedPeers &);
81
82#endif /* SQUID_RESOLVEDPEERS_H */
83