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"
 
  17 #include "onak-conf.h"
 
  20 unsigned long countdegree(struct stats_key *have, bool sigs, int maxdegree)
 
  22         unsigned long     count = 0, curdegree = 0;
 
  23         struct ll        *curll, *nextll, *sigll, *tmp;
 
  24         struct stats_key *key = NULL;
 
  29         curll = lladd(NULL, have);
 
  31         while (curll != NULL && curdegree <= maxdegree) {
 
  33                         sigll = cached_getkeysigs(((struct stats_key *)
 
  34                                 curll->object)->keyid);
 
  37                         key = findinhash(((struct stats_key *)
 
  38                                 curll->object)->keyid);
 
  43                 while (sigll != NULL) {
 
  44                         if (((struct stats_key *) sigll->object)->colour==0) {
 
  45                                 /* We've never seen it. Count it, mark it and
 
  46                                         explore its subtree */
 
  48                                 ((struct stats_key *)sigll->object)->colour = 
 
  50                                 ((struct stats_key *)sigll->object)->parent = 
 
  52                                          curll->object)->keyid;
 
  53                                 nextll=lladd(nextll, sigll->object);
 
  78 void sixdegrees(uint64_t keyid)
 
  80         struct stats_key *keyinfo;
 
  85         cached_getkeysigs(keyid);
 
  87         if ((keyinfo = findinhash(keyid)) == NULL) {
 
  88                 printf("Couldn't find key 0x%llX.\n", keyid);
 
  92         uid = keyid2uid(keyinfo->keyid);
 
  93         printf("Six degrees for 0x%llX (%s):\n", keyinfo->keyid, uid);
 
  98          * Cheat. This prefills the ->sign part of all the keys we want to
 
  99          * look at so that we can output that info at the same time as the
 
 100          * signers. However we're assuming that the signers and signees are
 
 101          * reasonably closely related otherwise the info is wildly off - the
 
 102          * only way to get 100% accurate results is to examine every key to see
 
 103          * if it's signed by the key we're looking at.
 
 106         degree = countdegree(keyinfo, true, 7);
 
 108         puts("\t\tSigned by\t\tSigns");
 
 109         for (loop = 1; loop < 7; loop++) {
 
 111                 degree = countdegree(keyinfo, true, loop);
 
 112                 printf("Degree %d:\t%8ld", loop, degree);
 
 115                 degree = countdegree(keyinfo, false, loop);
 
 116                 printf("\t\t%8ld\n", degree);
 
 120 int main(int argc, char *argv[])
 
 122         uint64_t keyid = 0x5B430367;
 
 125                 keyid = strtoll(argv[1], NULL, 16);
 
 129         initlogthing("sixdegrees", config.logfile);
 
 132         sixdegrees(getfullkeyid(keyid));