]> git.ipfire.org Git - thirdparty/squid.git/blob - src/PeerPoolMgr.h
3ebdaea7a6b96b12513b8b87b4745aba695b4d0f
[thirdparty/squid.git] / src / PeerPoolMgr.h
1 /*
2 * Copyright (C) 1996-2025 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_SRC_PEERPOOLMGR_H
10 #define SQUID_SRC_PEERPOOLMGR_H
11
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"
17
18 class HttpRequest;
19 class CachePeer;
20 class CommConnectCbParams;
21
22 /// Maintains an fixed-size "standby" PconnPool for a single CachePeer.
23 class PeerPoolMgr: public AsyncJob
24 {
25 CBDATA_CHILD(PeerPoolMgr);
26
27 public:
28 typedef CbcPointer<PeerPoolMgr> Pointer;
29
30 // syncs mgr state whenever connection-related peer or pool state changes
31 static void Checkpoint(const Pointer &mgr, const char *reason);
32
33 explicit PeerPoolMgr(CachePeer *aPeer);
34 ~PeerPoolMgr() override;
35
36 PrecomputedCodeContextPointer codeContext;
37
38 protected:
39 /* AsyncJob API */
40 void start() override;
41 void swanSong() override;
42 bool doneAll() const override;
43
44 /// whether the peer is still out there and in a valid state we can safely use
45 bool validPeer() const;
46
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);
54
55 /// Comm::ConnOpener calls this when done opening a connection for us
56 void handleOpenedConnection(const CommConnectCbParams &params);
57
58 /// Security::PeerConnector callback
59 void handleSecuredPeer(Security::EncryptorAnswer &answer);
60
61 /// the final step in connection opening (and, optionally, securing) sequence
62 void pushNewConnection(const Comm::ConnectionPointer &conn);
63
64 private:
65 CachePeer *peer; ///< the owner of the pool we manage
66 RefCount<HttpRequest> request; ///< fake HTTP request for conn opening code
67
68 /// waits for a transport connection to the peer to be established/opened
69 JobWait<Comm::ConnOpener> transportWait;
70
71 /// waits for the established transport connection to be secured/encrypted
72 JobWait<Security::BlindPeerConnector> encryptionWait;
73
74 unsigned int addrUsed; ///< counter for cycling through peer addresses
75 };
76
77 #endif /* SQUID_SRC_PEERPOOLMGR_H */
78