2 * stats.c - various routines to do stats on the key graph
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2000-2002 Project Purple
17 #include "onak-conf.h"
21 * initcolour - Clear the key graph ready for use.
22 * @parent: Do we want to clear the parent pointers too?
24 * Clears the parent and colour information on all elements in the key
27 void initcolour(bool parent)
33 * Init the colour/parent values. We get each entry list from the hash
34 * table and walk along it, zeroing the values.
36 for (loop = 0; loop < HASHSIZE; loop++) {
37 curkey = gethashtableentry(loop);
38 while (curkey != NULL) {
39 ((struct stats_key *)curkey->object)->colour = 0;
41 ((struct stats_key *)curkey->object)->parent =
44 curkey = curkey->next;
50 * findpath - Given 2 keys finds a path between them.
51 * @have: The key we have.
52 * @want: The key we want to get to.
54 * This does a breadth first search on the key tree, starting with the
55 * key we have. It returns as soon as a path is found or when we run out
56 * of keys; whichever comes sooner.
58 unsigned long findpath(struct stats_key *have, struct stats_key *want)
60 struct ll *keys = NULL;
61 struct ll *oldkeys = NULL;
62 struct ll *sigs = NULL;
63 struct ll *nextkeys = NULL;
65 unsigned long count = 0;
68 keys = lladd(NULL, want);
71 while ((!cleanup()) && keys != NULL && have->colour == 0) {
72 sigs = config.dbbackend->cached_getkeysigs(((struct stats_key *)
73 keys->object)->keyid);
74 while ((!cleanup()) && sigs != NULL && have->colour == 0) {
76 * Check if we've seen this key before and if not mark
77 * it and add its sigs to the list we want to look at.
79 if (!((struct stats_key *)sigs->object)->disabled &&
80 !((struct stats_key *)sigs->object)->revoked &&
81 ((struct stats_key *)sigs->object)->colour == 0) {
83 ((struct stats_key *)sigs->object)->colour =
85 ((struct stats_key *)sigs->object)->parent =
88 nextkeys = lladd(nextkeys, sigs->object);
95 llfree(oldkeys, NULL);
101 if (oldkeys != NULL) {
102 llfree(oldkeys, NULL);
105 if (nextkeys != NULL) {
106 llfree(nextkeys, NULL);
114 * dofindpath - Given 2 keys displays a path between them.
115 * @have: The key we have.
116 * @want: The key we want to get to.
117 * @html: Should we output in html.
118 * @count: How many paths we should look for.
120 * This does a breadth first search on the key tree, starting with the
121 * key we have. It returns as soon as a path is found or when we run out
122 * of keys; whichever comes sooner.
124 void dofindpath(uint64_t have, uint64_t want, bool html, int count)
126 struct stats_key *keyinfoa, *keyinfob, *curkey;
127 uint64_t fullhave, fullwant;
132 fullhave = config.dbbackend->getfullkeyid(have);
133 fullwant = config.dbbackend->getfullkeyid(want);
136 * Make sure the keys we have and want are in the cache.
138 (void) config.dbbackend->cached_getkeysigs(fullhave);
139 (void) config.dbbackend->cached_getkeysigs(fullwant);
141 if ((keyinfoa = findinhash(fullhave)) == NULL) {
142 printf("Couldn't find key 0x%" PRIx64 ".\n", have);
145 if ((keyinfob = findinhash(fullwant)) == NULL) {
146 printf("Couldn't find key 0x%" PRIx64 ".\n", want);
152 while ((!cleanup()) && (pathnum < count)) {
154 * Fill the tree info up.
157 rec = findpath(keyinfoa, keyinfob);
158 keyinfob->parent = 0;
160 printf("%s%d nodes examined. %ld elements in the hash%s\n",
165 if (keyinfoa->colour == 0) {
167 printf("Can't find a link from 0x%08" PRIx64
168 " to 0x%08" PRIx64 "%s\n",
173 printf("Can't find any further paths%s\n",
178 printf("%d steps from 0x%08" PRIx64 " to 0x%08" PRIx64
180 keyinfoa->colour, have & 0xFFFFFFFF,
184 while (curkey != NULL && curkey->keyid != 0) {
185 uid = config.dbbackend->keyid2uid(
187 if (html && uid == NULL) {
188 printf("<a href=\"lookup?op=get&search="
189 "0x%08" PRIx64 "\">0x%08" PRIx64
191 "User id not found])%s<BR>\n",
192 curkey->keyid & 0xFFFFFFFF,
193 curkey->keyid & 0xFFFFFFFF,
194 (curkey->keyid == fullwant) ?
196 } else if (html && uid != NULL) {
197 printf("<a href=\"lookup?op=get&search="
198 "0x%08" PRIx64 "\">0x%08"
200 " (<a href=\"lookup?op=vindex&"
201 "search=0x%08" PRIx64
204 curkey->keyid & 0xFFFFFFFF,
205 curkey->keyid & 0xFFFFFFFF,
206 curkey->keyid & 0xFFFFFFFF,
208 (curkey->keyid == fullwant) ?
211 printf("0x%08" PRIx64 " (%s)%s\n",
212 curkey->keyid & 0xFFFFFFFF,
214 "[User id not found]" :
216 (curkey->keyid == fullwant) ?
223 if (curkey != keyinfoa && curkey != keyinfob) {
224 curkey->disabled = true;
226 curkey = findinhash(curkey->parent);
229 puts("<P>List of key ids in path:</P>");
231 puts("List of key ids in path:");
234 while (curkey != NULL && curkey->keyid != 0) {
235 printf("0x%08" PRIx64 " ",
236 curkey->keyid & 0xFFFFFFFF);
237 curkey = findinhash(curkey->parent);
247 struct stats_key *furthestkey(struct stats_key *have)
249 unsigned long count = 0;
250 unsigned long curdegree = 0;
251 struct ll *curll, *nextll, *tmp;
252 struct ll *sigs = NULL;
253 struct stats_key *max;
263 curll = lladd(NULL, have);
265 while (curll != NULL) {
266 sigs = config.dbbackend->cached_getkeysigs(((struct stats_key *)
267 curll->object)->keyid);
268 while (sigs != NULL) {
269 if (((struct stats_key *) sigs->object)->colour == 0) {
271 * We've never seen it. Count it, mark it and
272 * explore its subtree.
275 max = (struct stats_key *)sigs->object;
276 ((struct stats_key *)sigs->object)->colour =
278 ((struct stats_key *)sigs->object)->parent =
279 ((struct stats_key *)
280 curll->object)->keyid;
282 nextll=lladd(nextll, sigs->object);