Implement a few more node-based functions

Some of these functions only work for routerinfo-based nodes, and as
such are only usable for advisory purposes.  Fortunately, our uses
of them are compatible with this limitation.
This commit is contained in:
Nick Mathewson 2010-09-30 18:37:53 -04:00
parent f9ea242aca
commit b5341314c1
4 changed files with 28 additions and 15 deletions

View File

@ -934,7 +934,7 @@ esc_for_log(const char *s)
char *result, *outp;
size_t len = 3;
if (!s) {
return tor_strdup("");
return tor_strdup("(null)");
}
for (cp = s; *cp; ++cp) {

View File

@ -273,10 +273,13 @@ command_process_create_cell(cell_t *cell, or_connection_t *conn)
"Received CREATE cell (circID %d) for known circ. "
"Dropping (age %d).",
cell->circ_id, (int)(time(NULL) - conn->_base.timestamp_created));
if (node)
if (node) {
char *p = esc_for_log(node_get_platform(node));
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Details: nickname \"%s\", platform %s.",
node_get_nickname(node), escaped(node_get_platform(node)));
node_get_nickname(node), p);
tor_free(p);
}
return;
}

View File

@ -656,9 +656,10 @@ node_get_address_string(const node_t *node, char *buf, size_t len)
long
node_get_declared_uptime(const node_t *node)
{
(void)node;
UNIMPLEMENTED_NODELIST();
return 0;
if (node->ri)
return node->ri->uptime;
else
return -1;
}
/** Return <b>node</b>'s declared or_port */
@ -673,22 +674,27 @@ node_get_orport(const node_t *node)
return 0;
}
/** Return <b>node</b>'s platform string */
/** Return <b>node</b>'s platform string, or NULL if we don't know it. */
const char *
node_get_platform(const node_t *node)
{
(void)node;
UNIMPLEMENTED_NODELIST();
return NULL;
/* If we wanted, we could record the version in the routerstatus_t, since
* the consensus lists it. We don't, though, so this function just won't
* work with microdescriptors. */
if (node->ri)
return node->ri->platform;
else
return NULL;
}
/** Return <b>node</b>'s time of publication. */
/** Return <b>node</b>'s time of publication, or 0 if we don't have one. */
time_t
node_get_published_on(const node_t *node)
{
(void)node;
UNIMPLEMENTED_NODELIST();
return 0;
if (node->ri)
return node->ri->cache_info.published_on;
else
return 0;
}
/** Return true iff <b>node</b> is one representing this router. */

View File

@ -881,8 +881,12 @@ rep_hist_get_router_stability_doc(time_t now)
if (node) {
char ip[INET_NTOA_BUF_LEN+1];
char tbuf[ISO_TIME_LEN+1];
time_t published = node_get_published_on(node);
node_get_address_string(node,ip,sizeof(ip));
format_iso_time(tbuf, node_get_published_on(node));
if (published > 0)
format_iso_time(tbuf, published);
else
strlcpy(tbuf, "???", sizeof(tbuf));
tor_snprintf(header_buf, sizeof(header_buf),
"router %s %s %s\n"
"published %s\n"