aboutsummaryrefslogtreecommitdiff
path: root/src/or/rephist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/rephist.c')
-rw-r--r--src/or/rephist.c76
1 files changed, 47 insertions, 29 deletions
diff --git a/src/or/rephist.c b/src/or/rephist.c
index fb282f469..cdc25567b 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -7,6 +7,8 @@
* \brief Basic history functionality for reputation module.
**/
+/* DOCDOC references to 'nicknames' in docs here are mostly wrong. */
+
#include "or.h"
/** History of an OR-\>OR link. */
@@ -47,15 +49,18 @@ static strmap_t *history_map = NULL;
/** Return the or_history_t for the named OR, creating it if necessary.
*/
-static or_history_t *get_or_history(const char* nickname)
+static or_history_t *get_or_history(const char* id)
{
or_history_t *hist;
- hist = (or_history_t*) strmap_get(history_map, nickname);
+ char hexid[HEX_DIGEST_LEN+1];
+ base16_encode(hexid, HEX_DIGEST_LEN+1, id, DIGEST_LEN);
+
+ hist = (or_history_t*) strmap_get(history_map, hexid);
if (!hist) {
hist = tor_malloc_zero(sizeof(or_history_t));
hist->link_history_map = strmap_new();
hist->since = time(NULL);
- strmap_set(history_map, nickname, hist);
+ strmap_set(history_map, hexid, hist);
}
return hist;
}
@@ -63,17 +68,19 @@ static or_history_t *get_or_history(const char* nickname)
/** Return the link_history_t for the link from the first named OR to
* the second, creating it if necessary.
*/
-static link_history_t *get_link_history(const char *from_name,
- const char *to_name)
+static link_history_t *get_link_history(const char *from_id,
+ const char *to_id)
{
or_history_t *orhist;
link_history_t *lhist;
- orhist = get_or_history(from_name);
- lhist = (link_history_t*) strmap_get(orhist->link_history_map, to_name);
+ char to_hexid[HEX_DIGEST_LEN+1];
+ orhist = get_or_history(from_id);
+ base16_encode(to_hexid, HEX_DIGEST_LEN+1, to_id, DIGEST_LEN);
+ lhist = (link_history_t*) strmap_get(orhist->link_history_map, to_hexid);
if (!lhist) {
lhist = tor_malloc_zero(sizeof(link_history_t));
lhist->since = time(NULL);
- strmap_set(orhist->link_history_map, to_name, lhist);
+ strmap_set(orhist->link_history_map, to_hexid, lhist);
}
return lhist;
}
@@ -104,10 +111,10 @@ void rep_hist_init(void)
/** Remember that an attempt to connect to the OR <b>nickname</b> failed at
* <b>when</b>.
*/
-void rep_hist_note_connect_failed(const char* nickname, time_t when)
+void rep_hist_note_connect_failed(const char* id, time_t when)
{
or_history_t *hist;
- hist = get_or_history(nickname);
+ hist = get_or_history(id);
++hist->n_conn_fail;
if (hist->up_since) {
hist->uptime += (when - hist->up_since);
@@ -120,10 +127,10 @@ void rep_hist_note_connect_failed(const char* nickname, time_t when)
/** Remember that an attempt to connect to the OR <b>nickname</b> succeeded
* at <b>when</b>.
*/
-void rep_hist_note_connect_succeeded(const char* nickname, time_t when)
+void rep_hist_note_connect_succeeded(const char* id, time_t when)
{
or_history_t *hist;
- hist = get_or_history(nickname);
+ hist = get_or_history(id);
++hist->n_conn_ok;
if (hist->down_since) {
hist->downtime += (when - hist->down_since);
@@ -136,10 +143,10 @@ void rep_hist_note_connect_succeeded(const char* nickname, time_t when)
/** Remember that we intentionally closed our connection to the OR
* <b>nickname</b> at <b>when</b>.
*/
-void rep_hist_note_disconnect(const char* nickname, time_t when)
+void rep_hist_note_disconnect(const char* id, time_t when)
{
or_history_t *hist;
- hist = get_or_history(nickname);
+ hist = get_or_history(id);
++hist->n_conn_ok;
if (hist->up_since) {
hist->uptime += (when - hist->up_since);
@@ -147,20 +154,21 @@ void rep_hist_note_disconnect(const char* nickname, time_t when)
}
}
-/** Remember that our connection to the OR <b>nickname</b> had an error and
+/** Remember that our connection to the OR <b>id</b> had an error and
* stopped working at <b>when</b>.
*/
-void rep_hist_note_connection_died(const char* nickname, time_t when)
+void rep_hist_note_connection_died(const char* id, time_t when)
{
or_history_t *hist;
- if(!nickname) {
+ if(!id) {
+ /* XXXX008 not so. */
/* If conn has no nickname, it's either an OP, or it is an OR
* which didn't complete its handshake (or did and was unapproved).
* Ignore it.
*/
return;
}
- hist = get_or_history(nickname);
+ hist = get_or_history(id);
if (hist->up_since) {
hist->uptime += (when - hist->up_since);
hist->up_since = 0;
@@ -172,23 +180,23 @@ void rep_hist_note_connection_died(const char* nickname, time_t when)
/** Remember that we successfully extended from the OR <b>from_name</b> to
* the OR <b>to_name</b>.
*/
-void rep_hist_note_extend_succeeded(const char *from_name,
- const char *to_name)
+void rep_hist_note_extend_succeeded(const char *from_id,
+ const char *to_id)
{
link_history_t *hist;
/* log_fn(LOG_WARN, "EXTEND SUCCEEDED: %s->%s",from_name,to_name); */
- hist = get_link_history(from_name, to_name);
+ hist = get_link_history(from_id, to_id);
++hist->n_extend_ok;
}
/** Remember that we tried to extend from the OR <b>from_name</b> to the OR
* <b>to_name</b>, but failed.
*/
-void rep_hist_note_extend_failed(const char *from_name, const char *to_name)
+void rep_hist_note_extend_failed(const char *from_id, const char *to_id)
{
link_history_t *hist;
/* log_fn(LOG_WARN, "EXTEND FAILED: %s->%s",from_name,to_name); */
- hist = get_link_history(from_name, to_name);
+ hist = get_link_history(from_id, to_id);
++hist->n_extend_fail;
}
@@ -199,7 +207,7 @@ void rep_hist_dump_stats(time_t now, int severity)
{
strmap_iter_t *lhist_it;
strmap_iter_t *orhist_it;
- const char *name1, *name2;
+ const char *name1, *name2, *hexdigest1, *hexdigest2;
or_history_t *or_history;
link_history_t *link_history;
void *or_history_p, *link_history_p;
@@ -207,14 +215,20 @@ void rep_hist_dump_stats(time_t now, int severity)
char buffer[2048];
int len;
unsigned long upt, downt;
+ routerinfo_t *r;
log(severity, "--------------- Dumping history information:");
for (orhist_it = strmap_iter_init(history_map); !strmap_iter_done(orhist_it);
orhist_it = strmap_iter_next(history_map,orhist_it)) {
- strmap_iter_get(orhist_it, &name1, &or_history_p);
+ strmap_iter_get(orhist_it, &hexdigest1, &or_history_p);
or_history = (or_history_t*) or_history_p;
+ if ((r = router_get_by_hexdigest(hexdigest1)))
+ name1 = r->nickname;
+ else
+ name1 = "(unknown)";
+
update_or_history(or_history, now);
upt = or_history->uptime;
downt = or_history->downtime;
@@ -224,8 +238,8 @@ void rep_hist_dump_stats(time_t now, int severity)
uptime=1.0;
}
log(severity,
- "OR %s: %ld/%ld good connections; uptime %ld/%ld sec (%.2f%%)",
- name1,
+ "OR %s [%s]: %ld/%ld good connections; uptime %ld/%ld sec (%.2f%%)",
+ name1, hexdigest1,
or_history->n_conn_ok, or_history->n_conn_fail+or_history->n_conn_ok,
upt, upt+downt, uptime*100.0);
@@ -234,7 +248,12 @@ void rep_hist_dump_stats(time_t now, int severity)
for (lhist_it = strmap_iter_init(or_history->link_history_map);
!strmap_iter_done(lhist_it);
lhist_it = strmap_iter_next(or_history->link_history_map, lhist_it)) {
- strmap_iter_get(lhist_it, &name2, &link_history_p);
+ strmap_iter_get(lhist_it, &hexdigest2, &link_history_p);
+ if ((r = router_get_by_hexdigest(hexdigest2)))
+ name2 = r->nickname;
+ else
+ name2 = "(unknown)";
+
link_history = (link_history_t*) link_history_p;
len += snprintf(buffer+len, 2048-len, "%s(%ld/%ld); ", name2,
link_history->n_extend_ok,
@@ -275,7 +294,6 @@ void write_rep_history(const char *filename)
name1, or_history->since1,
}
-
done:
if (f)
fclose(f);