ResolvedPeers.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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/Connection.h"
14#include "mem/AllocatorProxy.h"
15
16#include <iosfwd>
17#include <limits>
18#include <utility>
19
21{
22public:
24
26 bool available;
27};
28
30
34{
36
37public:
38 // ResolvedPeerPaths in addPath() call order
39 typedef std::vector<ResolvedPeerPath> Paths;
40 using size_type = Paths::size_type;
42
44
46 bool empty() const { return !availablePaths; }
47
49 void addPath(const Comm::ConnectionPointer &);
50
54
57
61
65
67 bool haveSpare(const Comm::Connection &currentPeer);
68
70 bool doneWithPrimes(const Comm::Connection &currentPeer);
71
73 bool doneWithSpares(const Comm::Connection &currentPeer);
74
76 bool doneWithPeer(const Comm::Connection &currentPeer);
77
79 size_type size() const { return availablePaths; }
80
83
85 bool notificationPending = false;
86
87private:
90 typedef std::pair<Paths::iterator, bool> Finding;
91
93 static int ConnectionFamily(const Comm::Connection &conn);
94
95 Paths::iterator start();
96 Finding findSpare(const Comm::Connection &currentPeer);
97 Finding findPrime(const Comm::Connection &currentPeer);
98 Finding findPeer(const Comm::Connection &currentPeer);
99 PeerConnectionPointer extractFound(const char *description, const Paths::iterator &found);
100 Finding makeFinding(const Paths::iterator &found, bool foundOther);
101
102 bool doneWith(const Finding &findings) const;
103
106
108
113
116};
117
122{
123public:
125
129
130 /* read-only pointer API; for Connection assignment, see finalize() */
131 explicit operator bool() const { return static_cast<bool>(connection_); }
134
136 operator const Comm::ConnectionPointer&() const { return connection_; }
137
140
142 void print(std::ostream &) const;
143
144private:
146 static constexpr auto npos = std::numeric_limits<size_type>::max();
147
150
153 friend class ResolvedPeers;
154};
155
157std::ostream &operator <<(std::ostream &, const ResolvedPeers &);
158
159inline std::ostream &
160operator <<(std::ostream &os, const PeerConnectionPointer &dest)
161{
162 dest.print(os);
163 return os;
164}
165
166#endif /* SQUID_RESOLVEDPEERS_H */
167
#define MEMPROXY_CLASS(CLASS)
#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:17
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:89
Comm::ConnectionPointer connection
(the address of) a path
Definition: ResolvedPeers.h:25
ResolvedPeerPath(const Comm::ConnectionPointer &conn)
Definition: ResolvedPeers.h:23
bool available
whether this path may be used (i.e., has not been tried already)
Definition: ResolvedPeers.h:26
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
std::vector< ResolvedPeerPath > Paths
Definition: ResolvedPeers.h:39
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:90
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:79
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:40
PeerConnectionPointer extractSpare(const Comm::Connection &currentPeer)
RefCount< ResolvedPeers > Pointer
Definition: ResolvedPeers.h:41
bool notificationPending
whether HappyConnOpener::noteCandidatesChange() is scheduled to fire
Definition: ResolvedPeers.h:85
void decreaseAvailability()
decrements the number of available paths
bool empty() const
whether we lack any known candidate paths
Definition: ResolvedPeers.h:46
bool destinationsFinalized
whether all of the available candidate paths received from DNS
Definition: ResolvedPeers.h:82
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