]> git.ipfire.org Git - thirdparty/squid.git/blob - src/PeerDigest.h
Merge from trunk rev.13939
[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 CBDATA_CLASS(DigestFetchState);
48
49 public:
50 DigestFetchState(PeerDigest *,HttpRequest *);
51 ~DigestFetchState();
52
53 PeerDigest *pd;
54 StoreEntry *entry;
55 StoreEntry *old_entry;
56 store_client *sc;
57 store_client *old_sc;
58 HttpRequest *request;
59 int offset;
60 int mask_offset;
61 time_t start_time;
62 time_t resp_time;
63 time_t expires;
64
65 struct {
66 int msg;
67 int bytes;
68 } sent, recv;
69
70 char buf[SM_PAGE_SIZE];
71 ssize_t bufofs;
72 digest_read_state_t state;
73 };
74
75 class PeerDigest
76 {
77 CBDATA_CLASS(PeerDigest);
78
79 public:
80 CachePeer *peer; /**< pointer back to peer structure, argh */
81 CacheDigest *cd; /**< actual digest structure */
82 String host; /**< copy of peer->host */
83 const char *req_result; /**< text status of the last request */
84
85 struct {
86 bool needed; /**< there were requests for this digest */
87 bool usable; /**< can be used for lookups */
88 bool requested; /**< in process of receiving [fresh] digest */
89 } flags;
90
91 struct {
92 /* all times are absolute unless augmented with _delay */
93 time_t initialized; /* creation */
94 time_t needed; /* first lookup/use by a peer */
95 time_t next_check; /* next scheduled check/refresh event */
96 time_t retry_delay; /* delay before re-checking _invalid_ digest */
97 time_t requested; /* requested a fresh copy of a digest */
98 time_t req_delay; /* last request response time */
99 time_t received; /* received the current copy of a digest */
100 time_t disabled; /* disabled for good */
101 } times;
102
103 struct {
104 CacheDigestGuessStats guess;
105 int used_count;
106
107 struct {
108 int msgs;
109 kb_t kbytes;
110 } sent, recv;
111 } stats;
112 };
113
114 extern const Version CacheDigestVer;
115
116 PeerDigest *peerDigestCreate(CachePeer * p);
117 void peerDigestNeeded(PeerDigest * pd);
118 void peerDigestNotePeerGone(PeerDigest * pd);
119 void peerDigestStatsReport(const PeerDigest * pd, StoreEntry * e);
120
121 #endif /* USE_CACHE_DIGESTS */
122
123 #endif /* SQUID_PEERDIGEST_H */
124