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.
8 * $Id: sixdegrees.c,v 1.5 2003/10/15 21:15:21 noodles Exp $
16 #include "keystructs.h"
18 #include "onak-conf.h"
21 unsigned long countdegree(struct stats_key *have, bool sigs, int maxdegree)
23 unsigned long count = 0, curdegree = 0;
24 struct ll *curll, *nextll, *sigll, *tmp;
25 struct stats_key *key = NULL;
30 curll = lladd(NULL, have);
32 while (curll != NULL && curdegree <= maxdegree) {
34 sigll = cached_getkeysigs(((struct stats_key *)
35 curll->object)->keyid);
38 key = findinhash(((struct stats_key *)
39 curll->object)->keyid);
44 while (sigll != NULL) {
45 if (((struct stats_key *) sigll->object)->colour==0) {
46 /* We've never seen it. Count it, mark it and
47 explore its subtree */
49 ((struct stats_key *)sigll->object)->colour =
51 ((struct stats_key *)sigll->object)->parent =
53 curll->object)->keyid;
54 nextll=lladd(nextll, sigll->object);
79 void sixdegrees(uint64_t keyid)
81 struct stats_key *keyinfo;
86 cached_getkeysigs(keyid);
88 if ((keyinfo = findinhash(keyid)) == NULL) {
89 printf("Couldn't find key 0x%llX.\n", keyid);
93 uid = keyid2uid(keyinfo->keyid);
94 printf("Six degrees for 0x%llX (%s):\n", keyinfo->keyid, uid);
99 * Cheat. This prefills the ->sign part of all the keys we want to
100 * look at so that we can output that info at the same time as the
101 * signers. However we're assuming that the signers and signees are
102 * reasonably closely related otherwise the info is wildly off - the
103 * only way to get 100% accurate results is to examine every key to see
104 * if it's signed by the key we're looking at.
107 degree = countdegree(keyinfo, true, 7);
109 puts("\t\tSigned by\t\tSigns");
110 for (loop = 1; loop < 7; loop++) {
112 degree = countdegree(keyinfo, true, loop);
113 printf("Degree %d:\t%8ld", loop, degree);
116 degree = countdegree(keyinfo, false, loop);
117 printf("\t\t%8ld\n", degree);
121 int main(int argc, char *argv[])
123 uint64_t keyid = 0x5B430367;
126 keyid = strtoll(argv[1], NULL, 16);
132 sixdegrees(getfullkeyid(keyid));