]> git.sommitrealweird.co.uk Git - onak.git/blob - maxpath.c
Fix path bug in sendkeysync.
[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         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                         cached_getkeysigs(((struct stats_key *)
46                                         curkey->object)->keyid);
47                         initcolour(false);
48                         tmp = furthestkey((struct stats_key *)
49                                                 curkey->object);
50                         if (tmp->colour > distance) {
51                                 from = (struct stats_key *)curkey->object;
52                                 to = tmp;
53                                 distance = to->colour;
54                                 printf("Current max path (#%ld) is from %llX"
55                                                 " to %llX (%ld steps)\n", 
56                                                 loop,
57                                                 from->keyid,
58                                                 to->keyid,
59                                                 distance);
60                         }
61                         curkey=curkey->next;
62                 }
63         }
64         printf("Max path is from %llX to %llX (%ld steps)\n",
65                         from->keyid,
66                         to->keyid,
67                         distance);
68         dofindpath(to->keyid, from->keyid, false, 1);
69 }
70
71 int main(int argc, char *argv[])
72 {
73         readconfig(NULL);
74         initlogthing("maxpath", config.logfile);
75         initdb(true);
76         inithash();
77         findmaxpath(30);
78         printf("--------\n");
79         findmaxpath(30);
80         destroyhash();
81         cleanupdb();
82         cleanuplogthing();
83         cleanupconfig();
84         
85         return EXIT_SUCCESS;
86 }