2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_PEERPOOLMGR_H
10 #define SQUID_SRC_PEERPOOLMGR_H
12 #include "base/AsyncJob.h"
13 #include "base/forward.h"
14 #include "base/JobWait.h"
15 #include "comm/forward.h"
16 #include "security/forward.h"
20 class CommConnectCbParams
;
22 /// Maintains an fixed-size "standby" PconnPool for a single CachePeer.
23 class PeerPoolMgr
: public AsyncJob
25 CBDATA_CHILD(PeerPoolMgr
);
28 typedef CbcPointer
<PeerPoolMgr
> Pointer
;
30 // syncs mgr state whenever connection-related peer or pool state changes
31 static void Checkpoint(const Pointer
&mgr
, const char *reason
);
33 explicit PeerPoolMgr(CachePeer
*aPeer
);
34 ~PeerPoolMgr() override
;
36 PrecomputedCodeContextPointer codeContext
;
40 void start() override
;
41 void swanSong() override
;
42 bool doneAll() const override
;
44 /// whether the peer is still out there and in a valid state we can safely use
45 bool validPeer() const;
47 /// Starts new connection, or closes the excess connections
48 /// according pool configuration
49 void checkpoint(const char *reason
);
50 /// starts the process of opening a new standby connection (if possible)
51 void openNewConnection();
52 /// closes 'howMany' standby connections
53 void closeOldConnections(const int howMany
);
55 /// Comm::ConnOpener calls this when done opening a connection for us
56 void handleOpenedConnection(const CommConnectCbParams
¶ms
);
58 /// Security::PeerConnector callback
59 void handleSecuredPeer(Security::EncryptorAnswer
&answer
);
61 /// the final step in connection opening (and, optionally, securing) sequence
62 void pushNewConnection(const Comm::ConnectionPointer
&conn
);
65 CachePeer
*peer
; ///< the owner of the pool we manage
66 RefCount
<HttpRequest
> request
; ///< fake HTTP request for conn opening code
68 /// waits for a transport connection to the peer to be established/opened
69 JobWait
<Comm::ConnOpener
> transportWait
;
71 /// waits for the established transport connection to be secured/encrypted
72 JobWait
<Security::BlindPeerConnector
> encryptionWait
;
74 unsigned int addrUsed
; ///< counter for cycling through peer addresses
77 #endif /* SQUID_SRC_PEERPOOLMGR_H */