new controller event NEWCONSENSUS that lists the networkstatus

lines for every recommended relay.

still needs docdoc and changelog entry.


svn:r18556
This commit is contained in:
Roger Dingledine 2009-02-16 06:18:03 +00:00
parent 323b33386f
commit 9ded433abb
4 changed files with 52 additions and 8 deletions

View File

@ -1558,6 +1558,12 @@ $Id$
Syntax:
"650" "+" "NS" CRLF 1*NetworkStatus "." CRLF "650" SP "OK" CRLF
The event is used whenever our local view of a relay status changes.
This happens when we get a new v3 consensus (in which case the entries
we see are a duplicate of what we see in the NEWCONSENSUS event,
below), but it also happens when we decide to mark a relay as up or
down in our local status, for example based on connection attempts.
[First added in 0.1.2.3-alpha]
4.1.13. Bandwidth used on an application stream
@ -1596,6 +1602,20 @@ $Id$
set of "countrycode=count" pairs. For example,
650-CLIENTS_SEEN TimeStarted="Thu Dec 25 23:50:43 EST 2008"
650 CountrySummary=us=16,de=8,uk=8
[XXX Matt Edman informs me that the time format above is wrong. -RD]
4.1.15. New consensus networkstatus has arrived.
The syntax is:
"650" "+" "NEWCONSENSUS" CRLF 1*NetworkStatus "." CRLF "650" SP
"OK" CRLF
A new consensus networkstatus has arrived. We include NS-style lines for
every relay in the consensus. NEWCONSENSUS is a separate event from the
NS event, because the list here represents every usable relay: so any
relay *not* mentioned in this list is implicitly no longer recommended.
[First added in 0.2.1.13-alpha]
5. Implementation notes

View File

@ -42,7 +42,8 @@
#define EVENT_GUARD 0x0013
#define EVENT_STREAM_BANDWIDTH_USED 0x0014
#define EVENT_CLIENTS_SEEN 0x0015
#define _EVENT_MAX 0x0015
#define EVENT_NEWCONSENSUS 0x0016
#define _EVENT_MAX 0x0016
/* If _EVENT_MAX ever hits 0x0020, we need to make the mask wider. */
/** Bitfield: The bit 1&lt;&lt;e is set if <b>any</b> open control
@ -999,6 +1000,8 @@ handle_control_setevents(control_connection_t *conn, uint32_t len,
event_code = EVENT_STREAM_BANDWIDTH_USED;
else if (!strcasecmp(ev, "CLIENTS_SEEN"))
event_code = EVENT_CLIENTS_SEEN;
else if (!strcasecmp(ev, "NEWCONSENSUS"))
event_code = EVENT_NEWCONSENSUS;
else {
connection_printf_to_buf(conn, "552 Unrecognized event \"%s\"\r\n",
ev);
@ -3516,16 +3519,20 @@ control_event_or_authdir_new_descriptor(const char *action,
/** Called when the routerstatus_ts <b>statuses</b> have changed: sends
* an NS event to any controller that cares. */
int
control_event_networkstatus_changed(smartlist_t *statuses)
static int
control_event_networkstatus_changed_helper(smartlist_t *statuses,
uint16_t event,
const char *event_string)
{
smartlist_t *strs;
char *s, *esc = NULL;
if (!EVENT_IS_INTERESTING(EVENT_NS) || !smartlist_len(statuses))
if (!EVENT_IS_INTERESTING(event) || !smartlist_len(statuses))
return 0;
strs = smartlist_create();
smartlist_add(strs, tor_strdup("650+NS\r\n"));
smartlist_add(strs, tor_strdup("650+"));
smartlist_add(strs, tor_strdup(event_string));
smartlist_add(strs, tor_strdup("\r\n"));
SMARTLIST_FOREACH(statuses, routerstatus_t *, rs,
{
s = networkstatus_getinfo_helper_single(rs);
@ -3538,14 +3545,27 @@ control_event_networkstatus_changed(smartlist_t *statuses)
SMARTLIST_FOREACH(strs, char *, cp, tor_free(cp));
smartlist_free(strs);
tor_free(s);
send_control_event_string(EVENT_NS, ALL_NAMES|ALL_FORMATS, esc);
send_control_event_string(EVENT_NS, ALL_NAMES|ALL_FORMATS,
send_control_event_string(event, ALL_NAMES|ALL_FORMATS, esc);
send_control_event_string(event, ALL_NAMES|ALL_FORMATS,
"650 OK\r\n");
tor_free(esc);
return 0;
}
int
control_event_networkstatus_changed(smartlist_t *statuses)
{
return control_event_networkstatus_changed_helper(statuses, EVENT_NS, "NS");
}
int
control_event_newconsensus(const networkstatus_t *consensus)
{
return control_event_networkstatus_changed_helper(
consensus->routerstatus_list, EVENT_NEWCONSENSUS, "NEWCONSENSUS");
}
/** Called when a single local_routerstatus_t has changed: Sends an NS event
* to any countroller that cares. */
int

View File

@ -1317,6 +1317,9 @@ notify_control_networkstatus_changed(const networkstatus_t *old_c,
smartlist_t *changed;
if (old_c == new_c)
return;
control_event_newconsensus(new_c);
if (!old_c) {
control_event_networkstatus_changed(new_c->routerstatus_list);
return;

View File

@ -3236,6 +3236,7 @@ int control_event_or_authdir_new_descriptor(const char *action,
const char *msg);
int control_event_my_descriptor_changed(void);
int control_event_networkstatus_changed(smartlist_t *statuses);
int control_event_newconsensus(const networkstatus_t *consensus);
int control_event_networkstatus_changed_single(routerstatus_t *rs);
int control_event_general_status(int severity, const char *format, ...)
CHECK_PRINTF(2,3);