From 946317ae13b37d2e354f5bb793eef2856805dd56 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Wed, 8 Mar 2006 22:29:08 +0000 Subject: [PATCH] start using OR_CONN_EVENT_NEW. also fixes a seg fault in tor (bug 261). svn:r6101 --- src/or/connection.c | 1 + src/or/control.c | 31 +++++++++++++++++++++++-------- src/or/or.h | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/or/connection.c b/src/or/connection.c index d99c5a2e84..1806f6afa1 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -733,6 +733,7 @@ connection_init_accepted_conn(connection_t *conn) switch (conn->type) { case CONN_TYPE_OR: + control_event_or_conn_status(conn, OR_CONN_EVENT_NEW); return connection_tls_start_handshake(conn, 1); case CONN_TYPE_AP: conn->state = AP_CONN_STATE_SOCKS_WAIT; 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; } diff --git a/src/or/or.h b/src/or/or.h index 97501f1def..40e2a27e50 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1815,6 +1815,7 @@ typedef enum or_conn_status_event_t { OR_CONN_EVENT_CONNECTED = 1, OR_CONN_EVENT_FAILED = 2, OR_CONN_EVENT_CLOSED = 3, + OR_CONN_EVENT_NEW = 4, } or_conn_status_event_t; void control_update_global_event_mask(void);