void
merkle_getkeyrange::getkeys_cb (ref<getkeys_arg> arg, ref<getkeys_res> res, 
				clnt_stat err)

{
  if (err) {
    warn << "GETKEYS: rpc error " << err << "\n";
    delete this;
    return;
  } else if (res->status != MERKLE_OK) {
    warn << "GETKEYS: protocol error " << err2str (res->status) << "\n";
    delete this;
    return;
  }

  // Assuming keys are sent back in increasing clockwise order
  vec<chordID> rkeys;
  for (u_int i = 0; i < res->resok->keys.size (); i++) 
    rkeys.push_back (res->resok->keys[i]);

  chordID sentmax = rngmax;
  if (res->resok->keys.size () > 0)
    sentmax = res->resok->keys.back ();
  compare_keylists (lkeys, rkeys, current, sentmax, missing);

  current = incID (sentmax);
  if (!res->resok->morekeys)
    current = incID (rngmax);  // set done
  
  go ();
}
Beispiel #2
0
int
main (int argc, char *argv[])
{
  setprogname (argv[0]);
  if (argc < 2)
    fatal <<  "Usage: " << progname << " [-c] merkletreebdb\n";
  
  bool check = false;
  char *path = argv[1];
  if (!strcmp (path, "-c")) {
    path = argv[2];
    check = true;
  }

  ptr<merkle_tree_bdb> tree = NULL;
  if (merkle_tree_bdb::tree_exists (path)) {
    // Handle case where path is given directly
    tree = New refcounted<merkle_tree_bdb> (path, true, true);
  } else {
    // Handle case where path may owned by adbd.
    char pathbuf[PATH_MAX];
    sprintf (pathbuf, "%s/mtree", path);
    tree = New refcounted<merkle_tree_bdb> (pathbuf, true, true);
    // Fatal if this tree does not exist.
  }

  if (check)
    tree->check_invariants ();

  chordID lastread = 0;
  chordID maxid = (chordID (1) << 160) - 1;
  vec<chordID> keys = tree->get_keyrange (0, maxid, 64);
  while (keys.size ()) {
    for (size_t i = 0; i < keys.size (); i++)
      aout << keys[i] << "\n";
    lastread = keys.back ();
    if (keys.size () < 64)
      break;
    keys = tree->get_keyrange (incID (lastread), maxid, 64);
  }
}