Remove unused variables
[onak.git] / maxpath.c
1 /*
2  * maxpath.c - Find the longest trust path in the key database.
3  * 
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2001-2002 Project Purple.
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "stats.h"
14 #include "hash.h"
15 #include "keydb.h"
16 #include "ll.h"
17 #include "log.h"
18 #include "onak-conf.h"
19 #include "stats.h"
20
21 void findmaxpath(unsigned long max)
22 {
23         struct stats_key *from, *to, *tmp;
24         struct ll *curkey;
25         unsigned long distance, loop;
26
27         distance = 0;
28         from = to = tmp = NULL;
29
30         /*
31          * My (noodles@earth.li, DSA) key is in the strongly connected set of
32          * keys, so we use it as a suitable starting seed.
33          */
34         config.dbbackend->cached_getkeysigs(0xF1BD4BE45B430367);
35
36         /*
37          * Loop through the hash examining each key present and finding the
38          * furthest key from it. If it's further than our current max then
39          * store it as our new max and print out the fact we've found a new
40          * max.
41          */
42         for (loop = 0; (loop < HASHSIZE) && (distance < max); loop++) {
43                 curkey = gethashtableentry(loop);
44                 while (curkey != NULL && distance < max) {
45                         config.dbbackend->cached_getkeysigs(
46                                         ((struct stats_key *)
47                                         curkey->object)->keyid);
48                         initcolour(false);
49                         tmp = furthestkey((struct stats_key *)
50                                                 curkey->object);
51                         if (tmp->colour > distance) {
52                                 from = (struct stats_key *)curkey->object;
53                                 to = tmp;
54                                 distance = to->colour;
55                                 printf("Current max path (#%ld) is from %"
56                                                 PRIX64 " to %" PRIX64 
57                                                 " (%ld steps)\n", 
58                                                 loop,
59                                                 from->keyid,
60                                                 to->keyid,
61                                                 distance);
62                         }
63                         curkey=curkey->next;
64                 }
65         }
66         printf("Max path is from %" PRIX64 " to %" PRIX64 " (%ld steps)\n",
67                         from->keyid,
68                         to->keyid,
69                         distance);
70         dofindpath(to->keyid, from->keyid, false, 1);
71 }
72
73 int main(int argc, char *argv[])
74 {
75         readconfig(NULL);
76         initlogthing("maxpath", config.logfile);
77         config.dbbackend->initdb(true);
78         inithash();
79         findmaxpath(30);
80         printf("--------\n");
81         findmaxpath(30);
82         destroyhash();
83         config.dbbackend->cleanupdb();
84         cleanuplogthing();
85         cleanupconfig();
86         
87         return EXIT_SUCCESS;
88 }