[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [tor/master 07/15] Implement a few more node-based functions
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu, 30 Sep 2010 18:37:53 -0400
Subject: Implement a few more node-based functions
Commit: b5341314c17573db15a7cc5999f36569c764c462
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.
---
src/common/util.c | 2 +-
src/or/command.c | 7 +++++--
src/or/nodelist.c | 28 +++++++++++++++++-----------
src/or/rephist.c | 6 +++++-
4 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/src/common/util.c b/src/common/util.c
index b5a3ade..32c3bb3 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -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) {
diff --git a/src/or/command.c b/src/or/command.c
index 46713a5..3a5c6c0 100644
--- a/src/or/command.c
+++ b/src/or/command.c
@@ -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;
}
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 7c03698..9518114 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -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. */
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 97a3c54..1b978d9 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -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"
--
1.7.1