ResolvedPeers.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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 {
21 public:
23 
25  bool available;
26 };
27 
29 
33 {
35 
36 public:
37  // ResolvedPeerPaths in addPath() call order
38  typedef std::vector<ResolvedPeerPath> Paths;
39  using size_type = Paths::size_type;
41 
42  ResolvedPeers();
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 
81  bool destinationsFinalized = false;
82 
84  bool notificationPending = false;
85 
86 private:
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 
103  void increaseAvailability();
104  void decreaseAvailability();
105 
107 
112 
115 };
116 
121 {
122 public:
124 
125  PeerConnectionPointer() = default;
126  PeerConnectionPointer(std::nullptr_t): PeerConnectionPointer() {}
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 
143 private:
145  static constexpr auto npos = std::numeric_limits<size_type>::max();
146 
149 
152  friend class ResolvedPeers;
153 };
154 
156 std::ostream &operator <<(std::ostream &, const ResolvedPeers &);
157 
158 inline std::ostream &
159 operator <<(std::ostream &os, const PeerConnectionPointer &dest)
160 {
161  dest.print(os);
162  return os;
163 }
164 
165 #endif /* SQUID_RESOLVEDPEERS_H */
166 
PeerConnectionPointer extractFront()
extracts and returns the first queued address
std::vector< ResolvedPeerPath > Paths
Definition: ResolvedPeers.h:38
Finding findPrime(const Comm::Connection &currentPeer)
bool doneWithPrimes(const Comm::Connection &currentPeer)
whether extractPrime() returns and will continue to return nil
std::ostream & operator<<(std::ostream &, const ResolvedPeers &)
summarized ResolvedPeers (for debugging)
size_type position_
ResolvedPeers-maintained membership index (or npos)
bool destinationsFinalized
whether all of the available candidate paths received from DNS
Definition: ResolvedPeers.h:81
void print(std::ostream &) const
debugging dump
Comm::ConnectionPointer connection_
half-baked, open, failed, or closed Comm::Connection (or nil)
void addPath(const Comm::ConnectionPointer &)
add a candidate path to try after all the existing paths
size_type availablePaths
the total number of currently available elements in paths_
const A & max(A const &lhs, A const &rhs)
C * getRaw() const
Definition: RefCount.h:80
static int ConnectionFamily(const Comm::Connection &conn)
The protocol family of the given path, AF_INET or AF_INET6.
Finding findSpare(const Comm::Connection &currentPeer)
PeerConnectionPointer(const Comm::ConnectionPointer &conn, const size_type pos)
Finding findPeer(const Comm::Connection &currentPeer)
Paths::size_type size_type
Definition: ResolvedPeers.h:39
bool doneWithSpares(const Comm::Connection &currentPeer)
whether extractSpare() returns and will continue to return nil
bool empty() const
whether we lack any known candidate paths
Definition: ResolvedPeers.h:45
static constexpr auto npos
non-existent position for nil connection
std::pair< Paths::iterator, bool > Finding
Definition: ResolvedPeers.h:89
bool haveSpare(const Comm::Connection &currentPeer)
whether extractSpare() would return a non-nil path right now
PeerConnectionPointer extractPrime(const Comm::Connection &currentPeer)
void decreaseAvailability()
decrements the number of available paths
MEMPROXY_CLASS(ResolvedPeers)
#define true
Definition: GnuRegex.c:234
PeerConnectionPointer extractFound(const char *description, const Paths::iterator &found)
convenience method to finish a successful extract*() call
Paths::iterator start()
Paths paths_
resolved addresses in (peer, family) order
size_type pathsToSkip
int conn
the current server connection FD
Definition: Transport.cc:26
#define assert(EX)
Definition: assert.h:19
Comm::Connection & operator*() const
PeerConnectionPointer extractSpare(const Comm::Connection &currentPeer)
ResolvedPeers::size_type size_type
bool notificationPending
whether HappyConnOpener::noteCandidatesChange() is scheduled to fire
Definition: ResolvedPeers.h:84
size_type size() const
the current number of candidate paths
Definition: ResolvedPeers.h:78
bool doneWithPeer(const Comm::Connection &currentPeer)
whether doneWithPrimes() and doneWithSpares() are true for currentPeer
bool available
whether this path may be used (i.e., has not been tried already)
Definition: ResolvedPeers.h:25
void reinstatePath(const PeerConnectionPointer &)
Comm::ConnectionPointer connection
(the address of) a path
Definition: ResolvedPeers.h:24
RefCount< ResolvedPeers > Pointer
Definition: ResolvedPeers.h:40
PeerConnectionPointer()=default
ResolvedPeerPath(const Comm::ConnectionPointer &conn)
Definition: ResolvedPeers.h:22
void finalize(const Comm::ConnectionPointer &conn)
upgrade stored peer selection details with a matching actual connection
void increaseAvailability()
increments the number of available paths
Comm::Connection * operator->() const
Finding makeFinding(const Paths::iterator &found, bool foundOther)
finalizes the iterator part of the given preliminary find*() result
bool doneWith(const Finding &findings) const

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors