]> git.sommitrealweird.co.uk Git - onak.git/blob - pathtest.c
50dcdcfd7bda9fab738ab9e85e99dcef993c70e4
[onak.git] / pathtest.c
1 //#include <stdint.h>
2 #include <inttypes.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #include "hash.h"
7 #include "keydb.h"
8 #include "stats.h"
9
10 void dofindpath(uint64_t have, uint64_t want, bool html)
11 {
12         struct stats_key *keyinfoa, *keyinfob, *curkey;
13         int rec;
14
15         /*
16          * Make sure the key we have and want are in the cache.
17          */
18         hash_getkeysigs(have);
19         hash_getkeysigs(want);
20
21         if ((keyinfoa = findinhash(have)) == NULL) {
22                 printf("550 Couldn't find key 0x%llX.\n", have);
23                 return;
24         }
25         if ((keyinfob = findinhash(want)) == NULL) {
26                 printf("550 Couldn't find key 0x%llX.\n", want);
27                 return;
28         }
29         
30         /*
31          * Fill the tree info up.
32          */
33         initcolour(true);
34         rec = findpath(keyinfoa, keyinfob);
35         keyinfob->parent = 0;
36
37         printf("%d nodes examined. %ld elements in the hash\n", rec,
38                         hashelements());
39         if (keyinfoa->colour == 0) {
40                 printf("550 Can't find a link from 0x%llX to 0x%llX\n",
41                                 have,
42                                 want);
43         } else {
44                 printf("250-%d steps from 0x%llX to 0x%llX\n",
45                                 keyinfoa->colour, have, want);
46                 curkey = keyinfoa;
47                 while (curkey != NULL) {
48                         printf("250-0x%llX (%s)\n",
49                                         curkey->keyid,
50                                         keyid2uid(curkey->keyid));
51                         curkey = findinhash(curkey->parent);
52                 }
53         }
54 }
55
56 int main(int argc, char *argv[])
57 {
58         initdb();
59         inithash();
60         dofindpath(0x5B430367, 0x3E1D0C1C, false);
61         dofindpath(0x3E1D0C1C, 0x5B430367, false);
62         cleanupdb();
63
64         return EXIT_SUCCESS;
65 }