]> git.ipfire.org Git - thirdparty/squid.git/blob - src/PeerDigest.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / PeerDigest.h
1 /*
2 * Copyright (C) 1996-2021 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_PEERDIGEST_H
10 #define SQUID_PEERDIGEST_H
11
12 #if USE_CACHE_DIGESTS
13
14 #include "cbdata.h"
15 #include "StatCounters.h"
16
17 class Version
18 {
19 public:
20 short int current; /* current version */
21 short int required; /* minimal version that can safely handle current version */
22 };
23
24 /* digest control block; used for transmission and storage */
25
26 class StoreDigestCBlock
27 {
28 public:
29 Version ver;
30 int capacity;
31 int count;
32 int del_count;
33 int mask_size;
34 unsigned char bits_per_entry;
35 unsigned char hash_func_count;
36 short int reserved_short;
37 int reserved[32 - 6];
38 };
39
40 class HttpRequest;
41 class PeerDigest;
42 class store_client;
43
44 class DigestFetchState
45 {
46 CBDATA_CLASS(DigestFetchState);
47
48 public:
49 DigestFetchState(PeerDigest *,HttpRequest *);
50 ~DigestFetchState();
51
52 PeerDigest *pd;
53 StoreEntry *entry;
54 StoreEntry *old_entry;
55 store_client *sc;
56 store_client *old_sc;
57 HttpRequest *request;
58 int offset;
59 uint32_t mask_offset;
60 time_t start_time;
61 time_t resp_time;
62 time_t expires;
63
64 struct {
65 int msg;
66 int bytes;
67 } sent, recv;
68
69 char buf[SM_PAGE_SIZE];
70 ssize_t bufofs;
71 digest_read_state_t state;
72 };
73
74 class PeerDigest
75 {
76 CBDATA_CLASS(PeerDigest);
77
78 public:
79 PeerDigest(CachePeer *);
80 ~PeerDigest();
81
82 CachePeer *peer = nullptr; /**< pointer back to peer structure, argh */
83 CacheDigest *cd = nullptr; /**< actual digest structure */
84 SBuf host; ///< copy of peer->host
85 const char *req_result = nullptr; /**< text status of the last request */
86
87 struct {
88 bool needed = false; /**< there were requests for this digest */
89 bool usable = false; /**< can be used for lookups */
90 bool requested = false; /**< in process of receiving [fresh] digest */
91 } flags;
92
93 struct {
94 /* all times are absolute unless augmented with _delay */
95 time_t initialized = 0; /* creation */
96 time_t needed = 0; /* first lookup/use by a peer */
97 time_t next_check = 0; /* next scheduled check/refresh event */
98 time_t retry_delay = 0; /* delay before re-checking _invalid_ digest */
99 time_t requested = 0; /* requested a fresh copy of a digest */
100 time_t req_delay = 0; /* last request response time */
101 time_t received = 0; /* received the current copy of a digest */
102 time_t disabled = 0; /* disabled for good */
103 } times;
104
105 struct {
106 CacheDigestGuessStats guess;
107 int used_count = 0;
108
109 struct {
110 int msgs = 0;
111 ByteCounter kbytes;
112 } sent, recv;
113 } stats;
114 };
115
116 extern const Version CacheDigestVer;
117
118 void peerDigestCreate(CachePeer * p);
119 void peerDigestNeeded(PeerDigest * pd);
120 void peerDigestNotePeerGone(PeerDigest * pd);
121 void peerDigestStatsReport(const PeerDigest * pd, StoreEntry * e);
122
123 #endif /* USE_CACHE_DIGESTS */
124
125 #endif /* SQUID_PEERDIGEST_H */
126