ResolvedPeers.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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#include <limits>
17#include <utility>
18
20{
21public:
23
25 bool available;
26};
27
29
33{
35
36public:
37 // ResolvedPeerPaths in addPath() call order
38 typedef std::vector<ResolvedPeerPath> Paths;
39 using size_type = Paths::size_type;
41
43
45 bool empty() const { return !availablePaths; }
46
48 void addPath(const Comm::ConnectionPointer &);
49
53
56
60
64
66 bool haveSpare(const Comm::Connection &currentPeer);
67
69 bool doneWithPrimes(const Comm::Connection &currentPeer);
70
72 bool doneWithSpares(const Comm::Connection &currentPeer);
73
75 bool doneWithPeer(const Comm::Connection &currentPeer);
76
78 size_type size() const { return availablePaths; }
79
82
84 bool notificationPending = false;
85
86private:
89 typedef std::pair<Paths::iterator, bool> Finding;
90
92 static int ConnectionFamily(const Comm::Connection &conn);
93
94 Paths::iterator start();
95 Finding findSpare(const Comm::Connection &currentPeer);
96 Finding findPrime(const Comm::Connection &currentPeer);
97 Finding findPeer(const Comm::Connection &currentPeer);
98 PeerConnectionPointer extractFound(const char *description, const Paths::iterator &found);
99 Finding makeFinding(const Paths::iterator &found, bool foundOther);
100
101 bool doneWith(const Finding &findings) const;
102
105
107
112
115};
116
121{
122public:
124
128
129 /* read-only pointer API; for Connection assignment, see finalize() */
130 explicit operator bool() const { return static_cast<bool>(connection_); }
133
135 operator const Comm::ConnectionPointer&() const { return connection_; }
136
139
141 void print(std::ostream &) const;
142
143private:
145 static constexpr auto npos = std::numeric_limits<size_type>::max();
146
149
152 friend class ResolvedPeers;
153};
154
156std::ostream &operator <<(std::ostream &, const ResolvedPeers &);
157
158inline std::ostream &
159operator <<(std::ostream &os, const PeerConnectionPointer &dest)
160{
161 dest.print(os);
162 return os;
163}
164
165#endif /* SQUID_RESOLVEDPEERS_H */
166
#define true
Definition: GnuRegex.c:241
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition: Lock.h:66
std::ostream & operator<<(std::ostream &, const ResolvedPeers &)
summarized ResolvedPeers (for debugging)
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:19
PeerConnectionPointer(std::nullptr_t)
implicit nullptr conversion
Comm::ConnectionPointer connection_
half-baked, open, failed, or closed Comm::Connection (or nil)
void finalize(const Comm::ConnectionPointer &conn)
upgrade stored peer selection details with a matching actual connection
Comm::Connection * operator->() const
void print(std::ostream &) const
debugging dump
PeerConnectionPointer(const Comm::ConnectionPointer &conn, const size_type pos)
PeerConnectionPointer()=default
static constexpr auto npos
non-existent position for nil connection
size_type position_
ResolvedPeers-maintained membership index (or npos)
ResolvedPeers::size_type size_type
Comm::Connection & operator*() const
C * getRaw() const
Definition: RefCount.h:80
Comm::ConnectionPointer connection
(the address of) a path
Definition: ResolvedPeers.h:24
ResolvedPeerPath(const Comm::ConnectionPointer &conn)
Definition: ResolvedPeers.h:22
bool available
whether this path may be used (i.e., has not been tried already)
Definition: ResolvedPeers.h:25
Finding makeFinding(const Paths::iterator &found, bool foundOther)
finalizes the iterator part of the given preliminary find*() result
Paths paths_
resolved addresses in (peer, family) order
PeerConnectionPointer extractFront()
extracts and returns the first queued address
bool doneWith(const Finding &findings) const
size_type pathsToSkip
MEMPROXY_CLASS(ResolvedPeers)
std::vector< ResolvedPeerPath > Paths
Definition: ResolvedPeers.h:38
bool haveSpare(const Comm::Connection &currentPeer)
whether extractSpare() would return a non-nil path right now
Finding findPrime(const Comm::Connection &currentPeer)
void increaseAvailability()
increments the number of available paths
Finding findSpare(const Comm::Connection &currentPeer)
Paths::iterator start()
size_type availablePaths
the total number of currently available elements in paths_
static int ConnectionFamily(const Comm::Connection &conn)
The protocol family of the given path, AF_INET or AF_INET6.
bool doneWithPrimes(const Comm::Connection &currentPeer)
whether extractPrime() returns and will continue to return nil
std::pair< Paths::iterator, bool > Finding
Definition: ResolvedPeers.h:89
bool doneWithPeer(const Comm::Connection &currentPeer)
whether doneWithPrimes() and doneWithSpares() are true for currentPeer
void reinstatePath(const PeerConnectionPointer &)
size_type size() const
the current number of candidate paths
Definition: ResolvedPeers.h:78
PeerConnectionPointer extractFound(const char *description, const Paths::iterator &found)
convenience method to finish a successful extract*() call
Paths::size_type size_type
Definition: ResolvedPeers.h:39
PeerConnectionPointer extractSpare(const Comm::Connection &currentPeer)
RefCount< ResolvedPeers > Pointer
Definition: ResolvedPeers.h:40
bool notificationPending
whether HappyConnOpener::noteCandidatesChange() is scheduled to fire
Definition: ResolvedPeers.h:84
void decreaseAvailability()
decrements the number of available paths
bool empty() const
whether we lack any known candidate paths
Definition: ResolvedPeers.h:45
bool destinationsFinalized
whether all of the available candidate paths received from DNS
Definition: ResolvedPeers.h:81
void addPath(const Comm::ConnectionPointer &)
add a candidate path to try after all the existing paths
Finding findPeer(const Comm::Connection &currentPeer)
PeerConnectionPointer extractPrime(const Comm::Connection &currentPeer)
bool doneWithSpares(const Comm::Connection &currentPeer)
whether extractSpare() returns and will continue to return nil
A const & max(A const &lhs, A const &rhs)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors