void getsucc_cb (u_int64_t start, chord_node curr, chord_nodelistextres *res, clnt_stat err) { chord_node next; if (err != 0 || res->status != CHORD_OK) { aout << "failed to get a reading from " << curr << "; skipping.\n"; sequential.pop_front (); if (sequential.size () == 0) { fatal << "too many consecutive failures.\n"; } next = sequential[0]; delete res; getsucc (next); return; } size_t sz = res->resok->nlist.size (); vec<chord_node> zs; for (size_t i = 0; i < sz; i++) { chord_node z = make_chord_node (res->resok->nlist[i].n); zs.push_back (z); } delete res; curr = zs[0]; // ensure we talked to who we think we should be talking to. assert (curr.x == sequential[0].x); // Print full information for the node we just talked to int index = curr.vnode_num; assert (index >= 0); char s[128]; sprintf (s, "e=%f", curr.e / Coord::PRED_ERR_MULT); aout << format (strbuf (), curr) << " " << curr.coords[0] << " " << curr.coords[1] << " " << curr.coords[2] << " " << s << " " << (getusec () - start) << "\n"; if (verify) { sequential.pop_front (); verify_succlist (zs); } else { sequential = zs; sequential.pop_front (); } // Out of nodes, done. if (!sequential.size ()) exit (verify_errors == true ? 1 : 0); next = sequential[0]; // wrapped around ring. done. if (next.x == wellknown_ID) exit (verify_errors == true ? 1 : 0); getsucc (next); }
void getsucc_cb (chordID dest, str desthost, chord_nodelistextres *res, u_int64_t start, clnt_stat err, vec<float> coords, float e) { assert (err == 0 && res->status == CHORD_OK); assert (res->resok->nlist.size () >= 2); if (coords.size () == 0) warnx << dest << " " << desthost << "\n"; else { char s[1024]; sprintf (s, "%f %f %f e=%f", coords[0], coords[1], coords[2], e/Coord::PRED_ERR_MULT); warnx << dest << " " << desthost << " " << s << " " << (getusec () - start) << " " << "\n"; } chord_node z = make_chord_node (res->resok->nlist[1].n); // wrapped around ring. done. if (z.x == wellknown_ID) { warnx << getusec () << "--------------------------\n"; exit (0); } getsucc (z); }
int main (int argc, char** argv) { setprogname (argv[0]); random_init (); setup (); str host = "not set"; unsigned short port = 0; errfd = 1; int ch; while ((ch = getopt (argc, argv, "h:j:a:l:f:is:")) != -1) { switch (ch) { case 'j': { char *bs_port = strchr(optarg, ':'); if (!bs_port) usage (); *bs_port = 0; bs_port++; if (inet_addr (optarg) == INADDR_NONE) { //yep, this blocks struct hostent *h = gethostbyname (optarg); if (!h) { warn << "Invalid address or hostname: " << optarg << "\n"; usage (); } struct in_addr *ptr = (struct in_addr *)h->h_addr; host = inet_ntoa (*ptr); } else host = optarg; port = atoi (bs_port); break; } }; } if (host == "not set") usage (); wellknown_ID = make_chordID (host, port, 0); chord_node wellknown_node; wellknown_node.x = wellknown_ID; wellknown_node.r.hostname = host; wellknown_node.r.port = port; wellknown_node.vnode_num = 0; getsucc (wellknown_node); amain (); }
int main (int argc, char** argv) { setprogname (argv[0]); str host = "not set"; unsigned short port (0); unsigned int maxtime (0); int ch; while ((ch = getopt (argc, argv, "j:rt:v")) != -1) { switch (ch) { case 'j': { char *bs_port = strchr(optarg, ':'); if (!bs_port) usage (); *bs_port = 0; bs_port++; if (inet_addr (optarg) == INADDR_NONE) { //yep, this blocks struct hostent *h = gethostbyname (optarg); if (!h) { warn << "Invalid address or hostname: " << optarg << "\n"; usage (); } struct in_addr *ptr = (struct in_addr *)h->h_addr; host = inet_ntoa (*ptr); } else host = optarg; port = atoi (bs_port); break; } case 't': maxtime = atoi (optarg); break; case 'v': verify = true; break; case 'r': succproc = CHORDPROC_GETPRED_EXT; break; default: usage (); break; } } if (host == "not set") usage (); wellknown_ID = make_chordID (host, port, 0); chord_node wellknown_node; wellknown_node.x = wellknown_ID; wellknown_node.r.hostname = host; wellknown_node.r.port = port; wellknown_node.vnode_num = 0; sequential.push_back (wellknown_node); getsucc (wellknown_node); if (maxtime > 0) delaycb (maxtime, wrap (&timedout, maxtime)); amain (); }