diff options
author | Roger Dingledine <arma@torproject.org> | 2006-03-08 22:29:08 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2006-03-08 22:29:08 +0000 |
commit | 946317ae13b37d2e354f5bb793eef2856805dd56 (patch) | |
tree | cfef3e883b6b5a5d7601bb1d3a8268b648a17ce8 /src/or/control.c | |
parent | 39964206d8fb32d79ebccd9fd52755b76c29e722 (diff) | |
download | tor-946317ae13b37d2e354f5bb793eef2856805dd56.tar.gz tor-946317ae13b37d2e354f5bb793eef2856805dd56.zip |
start using OR_CONN_EVENT_NEW.
also fixes a seg fault in tor (bug 261).
svn:r6101
Diffstat (limited to 'src/or/control.c')
-rw-r--r-- | src/or/control.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/or/control.c b/src/or/control.c index d39ee97538..aa839012c2 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1407,17 +1407,26 @@ handle_getinfo_helper(const char *question, char **answer) for (i=0; i < n_conns; ++i) { const char *state; char *s; + char name[128]; size_t slen; - if (conns[i]->type != CONN_TYPE_OR || conns[i]->marked_for_close) + connection_t *conn = conns[i]; + if (conn->type != CONN_TYPE_OR || conn->marked_for_close) continue; - if (conns[i]->state == OR_CONN_STATE_OPEN) + if (conn->state == OR_CONN_STATE_OPEN) state = "CONNECTED"; - else + else if (conn->nickname) state = "LAUNCHED"; - /* XXX non-open conns may not have nickname assigned yet */ - slen = strlen(conns[i]->nickname)+strlen(state)+2; + else + state = "NEW"; + if (conn->nickname) + strlcpy(name, conn->nickname, sizeof(name)); + else + tor_snprintf(name, sizeof(name), "%s:%d", + conn->address, conn->port); + + slen = strlen(name)+strlen(state)+2; s = tor_malloc(slen+1); - tor_snprintf(s, slen, "%s %s",conns[i]->nickname,state); + tor_snprintf(s, slen, "%s %s", name, state); smartlist_add(status, s); } *answer = smartlist_join_strings(status, "\r\n", 0, NULL); @@ -2579,12 +2588,18 @@ control_event_or_conn_status(connection_t *conn,or_conn_status_event_t tp) if (EVENT_IS_INTERESTING0(EVENT_OR_CONN_STATUS)) { buf[0] = (uint8_t)tp; - strlcpy(buf+1,conn->nickname,sizeof(buf)-1); + strlcpy(buf+1,conn->nickname ? conn->nickname : "",sizeof(buf)-1); len = strlen(buf+1); send_control0_event(EVENT_OR_CONN_STATUS, (uint32_t)(len+1), buf); } if (EVENT_IS_INTERESTING1(EVENT_OR_CONN_STATUS)) { const char *status; + char name[128]; + if (conn->nickname) + strlcpy(name, conn->nickname, sizeof(name)); + else + tor_snprintf(name, sizeof(name), "%s:%d", + conn->address, conn->port); switch (tp) { case OR_CONN_EVENT_LAUNCHED: status = "LAUNCHED"; break; @@ -2597,7 +2612,7 @@ control_event_or_conn_status(connection_t *conn,or_conn_status_event_t tp) } send_control1_event(EVENT_OR_CONN_STATUS, "650 ORCONN %s %s\r\n", - conn->nickname, status); + name, status); } return 0; } |