]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_PEERPOOLMGR_H |
10 | #define SQUID_SRC_PEERPOOLMGR_H | |
e8dca475 CT |
11 | |
12 | #include "base/AsyncJob.h" | |
2b6b1bcb | 13 | #include "base/JobWait.h" |
e8dca475 | 14 | #include "comm/forward.h" |
fcfdf7f9 | 15 | #include "security/forward.h" |
e8dca475 CT |
16 | |
17 | class HttpRequest; | |
18 | class CachePeer; | |
19 | class CommConnectCbParams; | |
20 | ||
e8dca475 CT |
21 | /// Maintains an fixed-size "standby" PconnPool for a single CachePeer. |
22 | class PeerPoolMgr: public AsyncJob | |
23 | { | |
337b9aa4 | 24 | CBDATA_CHILD(PeerPoolMgr); |
5c2f68b7 | 25 | |
e8dca475 CT |
26 | public: |
27 | typedef CbcPointer<PeerPoolMgr> Pointer; | |
28 | ||
29 | // syncs mgr state whenever connection-related peer or pool state changes | |
30 | static void Checkpoint(const Pointer &mgr, const char *reason); | |
31 | ||
32 | explicit PeerPoolMgr(CachePeer *aPeer); | |
337b9aa4 | 33 | ~PeerPoolMgr() override; |
e8dca475 CT |
34 | |
35 | protected: | |
36 | /* AsyncJob API */ | |
337b9aa4 AR |
37 | void start() override; |
38 | void swanSong() override; | |
39 | bool doneAll() const override; | |
e8dca475 CT |
40 | |
41 | /// whether the peer is still out there and in a valid state we can safely use | |
42 | bool validPeer() const; | |
43 | ||
44 | /// Starts new connection, or closes the excess connections | |
45 | /// according pool configuration | |
46 | void checkpoint(const char *reason); | |
47 | /// starts the process of opening a new standby connection (if possible) | |
48 | void openNewConnection(); | |
49 | /// closes 'howMany' standby connections | |
50 | void closeOldConnections(const int howMany); | |
51 | ||
52 | /// Comm::ConnOpener calls this when done opening a connection for us | |
53 | void handleOpenedConnection(const CommConnectCbParams ¶ms); | |
fcfdf7f9 | 54 | |
a72b6e88 | 55 | /// Security::PeerConnector callback |
fcfdf7f9 AJ |
56 | void handleSecuredPeer(Security::EncryptorAnswer &answer); |
57 | ||
e8dca475 CT |
58 | /// the final step in connection opening (and, optionally, securing) sequence |
59 | void pushNewConnection(const Comm::ConnectionPointer &conn); | |
60 | ||
61 | private: | |
62 | CachePeer *peer; ///< the owner of the pool we manage | |
63 | RefCount<HttpRequest> request; ///< fake HTTP request for conn opening code | |
2b6b1bcb AR |
64 | |
65 | /// waits for a transport connection to the peer to be established/opened | |
66 | JobWait<Comm::ConnOpener> transportWait; | |
67 | ||
68 | /// waits for the established transport connection to be secured/encrypted | |
69 | JobWait<Security::BlindPeerConnector> encryptionWait; | |
70 | ||
e8dca475 | 71 | unsigned int addrUsed; ///< counter for cycling through peer addresses |
e8dca475 CT |
72 | }; |
73 | ||
ff9d9458 | 74 | #endif /* SQUID_SRC_PEERPOOLMGR_H */ |
f53969cc | 75 |