]> git.sommitrealweird.co.uk Git - onak.git/blob - maxpath.c
81a2b22b8d2f4fbfa126dcc7751ee08e4f645cc6
[onak.git] / maxpath.c
1 /*
2  * maxpath.c - Find the longest trust path in the key database.
3  *
4  * Copyright 2001-2002 Jonathan McDowell <noodles@earth.li>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51
17  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "stats.h"
25 #include "hash.h"
26 #include "keydb.h"
27 #include "ll.h"
28 #include "log.h"
29 #include "onak-conf.h"
30 #include "stats.h"
31
32 void findmaxpath(unsigned long max)
33 {
34         struct stats_key *from, *to, *tmp;
35         struct ll *curkey;
36         unsigned long distance, loop;
37
38         distance = 0;
39         from = to = tmp = NULL;
40
41         /*
42          * My (noodles@earth.li, RSA) key is in the strongly connected set of
43          * keys, so we use it as a suitable starting seed.
44          */
45         config.dbbackend->cached_getkeysigs(0x94FA372B2DA8B985);
46
47         /*
48          * Loop through the hash examining each key present and finding the
49          * furthest key from it. If it's further than our current max then
50          * store it as our new max and print out the fact we've found a new
51          * max.
52          */
53         for (loop = 0; (loop < HASHSIZE) && (distance < max); loop++) {
54                 curkey = gethashtableentry(loop);
55                 while (curkey != NULL && distance < max) {
56                         config.dbbackend->cached_getkeysigs(
57                                         ((struct stats_key *)
58                                         curkey->object)->keyid);
59                         initcolour(false);
60                         tmp = furthestkey((struct stats_key *)
61                                                 curkey->object);
62                         if (tmp->colour > distance) {
63                                 from = (struct stats_key *)curkey->object;
64                                 to = tmp;
65                                 distance = to->colour;
66                                 printf("Current max path (#%ld) is from %"
67                                                 PRIX64 " to %" PRIX64 
68                                                 " (%ld steps)\n", 
69                                                 loop,
70                                                 from->keyid,
71                                                 to->keyid,
72                                                 distance);
73                         }
74                         curkey=curkey->next;
75                 }
76         }
77         printf("Max path is from %" PRIX64 " to %" PRIX64 " (%ld steps)\n",
78                         from->keyid,
79                         to->keyid,
80                         distance);
81         dofindpath(to->keyid, from->keyid, false, 1);
82 }
83
84 int main(int argc, char *argv[])
85 {
86         readconfig(NULL);
87         initlogthing("maxpath", config.logfile);
88         config.dbbackend->initdb(true);
89         inithash();
90         findmaxpath(30);
91         printf("--------\n");
92         findmaxpath(30);
93         destroyhash();
94         config.dbbackend->cleanupdb();
95         cleanuplogthing();
96         cleanupconfig();
97         
98         return EXIT_SUCCESS;
99 }