2 * sixdegrees.c - List the size of the six degrees of trust away from a key.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2001-2002 Project Purple.
14 #include "keystructs.h"
16 #include "onak-conf.h"
19 unsigned long countdegree(struct stats_key *have, bool sigs, int maxdegree)
21 unsigned long count = 0, curdegree = 0;
22 struct ll *curll, *nextll, *sigll, *tmp;
23 struct stats_key *key = NULL;
28 curll = lladd(NULL, have);
30 while (curll != NULL && curdegree <= maxdegree) {
32 sigll = cached_getkeysigs(((struct stats_key *)
33 curll->object)->keyid);
36 key = findinhash(((struct stats_key *)
37 curll->object)->keyid);
42 while (sigll != NULL) {
43 if (((struct stats_key *) sigll->object)->colour==0) {
44 /* We've never seen it. Count it, mark it and
45 explore its subtree */
47 ((struct stats_key *)sigll->object)->colour =
49 ((struct stats_key *)sigll->object)->parent =
51 curll->object)->keyid;
52 nextll=lladd(nextll, sigll->object);
77 void sixdegrees(uint64_t keyid)
79 struct stats_key *keyinfo;
84 cached_getkeysigs(keyid);
86 if ((keyinfo = findinhash(keyid)) == NULL) {
87 printf("Couldn't find key 0x%llX.\n", keyid);
91 uid = keyid2uid(keyinfo->keyid);
92 printf("Six degrees for 0x%llX (%s):\n", keyinfo->keyid, uid);
97 * Cheat. This prefills the ->sign part of all the keys we want to
98 * look at so that we can output that info at the same time as the
99 * signers. However we're assuming that the signers and signees are
100 * reasonably closely related otherwise the info is wildly off - the
101 * only way to get 100% accurate results is to examine every key to see
102 * if it's signed by the key we're looking at.
105 degree = countdegree(keyinfo, true, 7);
107 puts("\t\tSigned by\t\tSigns");
108 for (loop = 1; loop < 7; loop++) {
110 degree = countdegree(keyinfo, true, loop);
111 printf("Degree %d:\t%8ld", loop, degree);
114 degree = countdegree(keyinfo, false, loop);
115 printf("\t\t%8ld\n", degree);
119 int main(int argc, char *argv[])
121 uint64_t keyid = 0x5B430367;
124 keyid = strtoll(argv[1], NULL, 16);
130 sixdegrees(getfullkeyid(keyid));