]> git.sommitrealweird.co.uk Git - onak.git/blob - maxpath.c
cscvs to tla changeset 82
[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  * $Id: maxpath.c,v 1.9 2003/06/04 20:57:10 noodles Exp $
9  */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "stats.h"
16 #include "hash.h"
17 #include "keydb.h"
18 #include "ll.h"
19 #include "onak-conf.h"
20 #include "stats.h"
21
22 void findmaxpath(unsigned long max)
23 {
24         struct stats_key *from, *to, *tmp;
25         struct ll *curkey;
26         unsigned long distance, loop;
27
28         distance = 0;
29         from = to = tmp = NULL;
30
31         /*
32          * My (noodles@earth.li, DSA) key is in the strongly connected set of
33          * keys, so we use it as a suitable starting seed.
34          */
35         cached_getkeysigs(0xF1BD4BE45B430367);
36
37         /*
38          * Loop through the hash examining each key present and finding the
39          * furthest key from it. If it's further than our current max then
40          * store it as our new max and print out the fact we've found a new
41          * max.
42          */
43         for (loop = 0; (loop < HASHSIZE) && (distance < max); loop++) {
44                 curkey = gethashtableentry(loop);
45                 while (curkey != NULL && distance < max) {
46                         cached_getkeysigs(((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();
75         initdb();
76         inithash();
77         findmaxpath(30);
78         printf("--------\n");
79         findmaxpath(30);
80         destroyhash();
81         cleanupdb();
82         cleanupconfig();
83         
84         return EXIT_SUCCESS;
85 }