[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] start using OR_CONN_EVENT_NEW.
Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or
Modified Files:
connection.c control.c or.h
Log Message:
start using OR_CONN_EVENT_NEW.
also fixes a seg fault in tor (bug 261).
Index: connection.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.444
retrieving revision 1.445
diff -u -p -d -r1.444 -r1.445
--- connection.c 5 Mar 2006 09:50:25 -0000 1.444
+++ connection.c 8 Mar 2006 22:29:07 -0000 1.445
@@ -733,6 +733,7 @@ connection_init_accepted_conn(connection
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;
Index: control.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -p -d -r1.172 -r1.173
--- control.c 6 Mar 2006 19:47:54 -0000 1.172
+++ control.c 8 Mar 2006 22:29:07 -0000 1.173
@@ -1407,17 +1407,26 @@ handle_getinfo_helper(const char *questi
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_
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_
}
send_control1_event(EVENT_OR_CONN_STATUS,
"650 ORCONN %s %s\r\n",
- conn->nickname, status);
+ name, status);
}
return 0;
}
Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.799
retrieving revision 1.800
diff -u -p -d -r1.799 -r1.800
--- or.h 8 Mar 2006 06:29:52 -0000 1.799
+++ or.h 8 Mar 2006 22:29:08 -0000 1.800
@@ -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);