]> git.sommitrealweird.co.uk Git - onak.git/blob - maxpath.c
"Recognize" some extra subpacket types
[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 %llX"
56                                                 " to %llX (%ld steps)\n", 
57                                                 loop,
58                                                 from->keyid,
59                                                 to->keyid,
60                                                 distance);
61                         }
62                         curkey=curkey->next;
63                 }
64         }
65         printf("Max path is from %llX to %llX (%ld steps)\n",
66                         from->keyid,
67                         to->keyid,
68                         distance);
69         dofindpath(to->keyid, from->keyid, false, 1);
70 }
71
72 int main(int argc, char *argv[])
73 {
74         readconfig(NULL);
75         initlogthing("maxpath", config.logfile);
76         config.dbbackend->initdb(true);
77         inithash();
78         findmaxpath(30);
79         printf("--------\n");
80         findmaxpath(30);
81         destroyhash();
82         config.dbbackend->cleanupdb();
83         cleanuplogthing();
84         cleanupconfig();
85         
86         return EXIT_SUCCESS;
87 }