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