commit b4a8fd895802801198229574c55b3df975aa2244 Author: Nick Mathewson nickm@torproject.org Date: Thu Jan 29 14:14:59 2015 -0500
When there are no package lines, make consensus/packages say "".
Also, give a better error message when there is no consensus. --- src/or/networkstatus.c | 6 +++++- src/or/routerparse.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index 9d6d5ab..da110fd 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -1916,7 +1916,9 @@ getinfo_helper_networkstatus(control_connection_t *conn, } else if (!strcmp(question, "consensus/packages")) { const networkstatus_t *ns = networkstatus_get_latest_consensus(); if (ns && ns->package_lines) - *answer = smartlist_join_strings(ns->package_lines, "\n", 1, NULL); + *answer = smartlist_join_strings(ns->package_lines, "\n", 0, NULL); + else + *errmsg = "No consensus available"; return *answer ? 0 : -1; } else if (!strcmp(question, "consensus/valid-after") || !strcmp(question, "consensus/fresh-until") || @@ -1934,6 +1936,8 @@ getinfo_helper_networkstatus(control_connection_t *conn, char tbuf[ISO_TIME_LEN+1]; format_iso_time(tbuf, t); *answer = tor_strdup(tbuf); + } else { + *errmsg = "No consensus available"; } return *answer ? 0 : -1; } else { diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 6f3acd0..f7687e0 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -2630,8 +2630,8 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
{ smartlist_t *package_lst = find_all_by_keyword(tokens, K_PACKAGE); + ns->package_lines = smartlist_new(); if (package_lst) { - ns->package_lines = smartlist_new(); SMARTLIST_FOREACH(package_lst, directory_token_t *, t, smartlist_add(ns->package_lines, tor_strdup(t->args[0]))); }