]> git.sommitrealweird.co.uk Git - onak.git/blob - maxpath.c
2f813dec734e555a2359fb1278c95d6e658e2fac
[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 "onak-conf.h"
18 #include "stats.h"
19
20 void findmaxpath(unsigned long max)
21 {
22         struct stats_key *from, *to, *tmp;
23         struct ll *curkey;
24         unsigned long distance, loop;
25
26         distance = 0;
27         from = to = tmp = NULL;
28
29         /*
30          * My (noodles@earth.li, DSA) key is in the strongly connected set of
31          * keys, so we use it as a suitable starting seed.
32          */
33         cached_getkeysigs(0xF1BD4BE45B430367);
34
35         /*
36          * Loop through the hash examining each key present and finding the
37          * furthest key from it. If it's further than our current max then
38          * store it as our new max and print out the fact we've found a new
39          * max.
40          */
41         for (loop = 0; (loop < HASHSIZE) && (distance < max); loop++) {
42                 curkey = gethashtableentry(loop);
43                 while (curkey != NULL && distance < max) {
44                         cached_getkeysigs(((struct stats_key *)
45                                         curkey->object)->keyid);
46                         initcolour(false);
47                         tmp = furthestkey((struct stats_key *)
48                                                 curkey->object);
49                         if (tmp->colour > distance) {
50                                 from = (struct stats_key *)curkey->object;
51                                 to = tmp;
52                                 distance = to->colour;
53                                 printf("Current max path (#%ld) is from %llX"
54                                                 " to %llX (%ld steps)\n", 
55                                                 loop,
56                                                 from->keyid,
57                                                 to->keyid,
58                                                 distance);
59                         }
60                         curkey=curkey->next;
61                 }
62         }
63         printf("Max path is from %llX to %llX (%ld steps)\n",
64                         from->keyid,
65                         to->keyid,
66                         distance);
67         dofindpath(to->keyid, from->keyid, false, 1);
68 }
69
70 int main(int argc, char *argv[])
71 {
72         readconfig();
73         initdb();
74         inithash();
75         findmaxpath(30);
76         printf("--------\n");
77         findmaxpath(30);
78         destroyhash();
79         cleanupdb();
80         cleanupconfig();
81         
82         return EXIT_SUCCESS;
83 }