[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r16981: {tor} Code to serve a current stability calculations from /tor/dbg (in tor/trunk: . src/or)
Author: nickm
Date: 2008-09-26 14:02:48 -0400 (Fri, 26 Sep 2008)
New Revision: 16981
Modified:
tor/trunk/ChangeLog
tor/trunk/src/or/directory.c
tor/trunk/src/or/or.h
tor/trunk/src/or/rephist.c
Log:
Code to serve a current stability calculations from /tor/dbg-stability.txt. Untested: somebody please run this on an authority and let me know if it is broken.
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2008-09-26 17:58:35 UTC (rev 16980)
+++ tor/trunk/ChangeLog 2008-09-26 18:02:48 UTC (rev 16981)
@@ -81,6 +81,8 @@
servers.
- Drop the requirement to have an open dir port for storing and serving
v2 hidden service descriptors.
+ - Authorities now serve a /tor/dbg-stability.txt URL to help debug
+ WFU and MTBF calculations.
o Code simplifications and refactoring:
- Revise the connection_new functions so that a more typesafe variant
Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c 2008-09-26 17:58:35 UTC (rev 16980)
+++ tor/trunk/src/or/directory.c 2008-09-26 18:02:48 UTC (rev 16981)
@@ -3004,6 +3004,21 @@
goto done;
}
+ if (!strcmp(url,"/tor/dbg-stability.txt")) {
+ const char *stability;
+ size_t len;
+ if (! authdir_mode_tests_reachability(options) ||
+ ! (stability = rep_hist_get_router_stability_doc(time(NULL)))) {
+ write_http_status_line(conn, 404, "Not found.");
+ goto done;
+ }
+
+ len = strlen(stability);
+ write_http_response_header(conn, len, 0, 0);
+ connection_write_to_buf(stability, len, TO_CONN(conn));
+ goto done;
+ }
+
#if defined(EXPORTMALLINFO) && defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
#define ADD_MALLINFO_LINE(x) do { \
tor_snprintf(tmp, sizeof(tmp), "%s %d\n", #x, mi.x); \
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2008-09-26 17:58:35 UTC (rev 16980)
+++ tor/trunk/src/or/or.h 2008-09-26 18:02:48 UTC (rev 16981)
@@ -3841,6 +3841,7 @@
double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when);
long rep_hist_get_weighted_time_known(const char *id, time_t when);
int rep_hist_have_measured_enough_stability(void);
+const char *rep_hist_get_router_stability_doc(time_t now);
void rep_hist_note_used_port(time_t now, uint16_t port);
smartlist_t *rep_hist_get_predicted_ports(time_t now);
Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c 2008-09-26 17:58:35 UTC (rev 16980)
+++ tor/trunk/src/or/rephist.c 2008-09-26 18:02:48 UTC (rev 16981)
@@ -765,6 +765,101 @@
return -1;
}
+/** DOCDOC */
+static char *
+rep_hist_format_router_status(or_history_t *hist, time_t now)
+{
+ char buf[1024];
+ char sor_buf[ISO_TIME_LEN+1];
+ char sod_buf[ISO_TIME_LEN+1];
+ double wfu;
+ double mtbf;
+ int up = 0, down = 0;
+
+ if (hist->start_of_run) {
+ format_iso_time(sor_buf, hist->start_of_run);
+ up = 1;
+ }
+ if (hist->start_of_downtime) {
+ format_iso_time(sor_buf, hist->start_of_downtime);
+ down = 1;
+ }
+
+ wfu = get_weighted_fractional_uptime(hist, now);
+ mtbf = get_stability(hist, now);
+ tor_snprintf(buf, sizeof(buf),
+ "%s%s%s"
+ "%s%s%s"
+ "wfu %0.3lf\n"
+ " weighted-time %lu\n"
+ " weighted-uptime %lu\n"
+ "mtbf %0.1lf\n"
+ " weighted-run-length %lu\n"
+ " total-run-weights %lf\n",
+ up?"uptime-started ":"", up?sor_buf:"", up?" UTC\n":"",
+ down?"downtime-started ":"", down?sod_buf:"", down?" UTC\n":"",
+ wfu,
+ hist->total_weighted_time,
+ hist->weighted_uptime,
+ mtbf,
+ hist->weighted_run_length,
+ hist->total_run_weights
+ );
+
+ return tor_strdup(buf);
+}
+
+/* DOCDOC */
+static char *last_stability_doc = NULL;
+static time_t built_last_stability_doc_at = 0;
+#define MAX_STABILITY_DOC_BUILD_RATE (3*60)
+
+/* DOCDOC */
+const char *
+rep_hist_get_router_stability_doc(time_t now)
+{
+ char *result;
+ smartlist_t *chunks;
+ if (built_last_stability_doc_at + MAX_STABILITY_DOC_BUILD_RATE > now)
+ return last_stability_doc;
+
+ if (!history_map)
+ return NULL;
+
+ tor_free(last_stability_doc);
+ chunks = smartlist_create();
+
+ DIGESTMAP_FOREACH(history_map, id, or_history_t *, hist) {
+ routerinfo_t *ri;
+ char dbuf[BASE64_DIGEST_LEN+1];
+ char header_buf[128];
+ char *info;
+ digest_to_base64(dbuf, id);
+ ri = router_get_by_digest(id);
+ if (ri) {
+ char *ip = tor_dup_ip(ri->addr);
+ tor_snprintf(header_buf, sizeof(header_buf), "router %s %s %s\n",
+ dbuf, ri->nickname, ip);
+ tor_free(ip);
+ } else {
+ tor_snprintf(header_buf, sizeof(header_buf),
+ "router %s {no descriptor}\n", dbuf);
+ }
+ smartlist_add(chunks, tor_strdup(header_buf));
+ info = rep_hist_format_router_status(hist, now);
+ if (info)
+ smartlist_add(chunks, info);
+ } DIGESTMAP_FOREACH_END;
+
+ result = smartlist_join_strings(chunks, "", 0, NULL);
+ SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp));
+ smartlist_free(chunks);
+
+ last_stability_doc = result;
+ built_last_stability_doc_at = time(NULL);
+ return result;
+}
+
/** Helper: return the first j >= i such that !strcmpstart(sl[j], prefix) and
* such that no line sl[k] with i <= k < j starts with "R ". Return -1 if no
* such line exists. */
@@ -1693,6 +1788,8 @@
digestmap_free(history_map, free_or_history);
tor_free(read_array);
tor_free(write_array);
+ tor_free(last_stability_doc);
+ built_last_stability_doc_at = 0;
predicted_ports_free();
}