aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-03-04 21:08:28 +0000
committerNick Mathewson <nickm@torproject.org>2007-03-04 21:08:28 +0000
commit92f62b36846e3c82f5521fa17f7a4f5afde827af (patch)
tree0be93b2e4b4513bf20ac1649f26b441d2879f07a
parent4a6e29b0296531beb0463afd5495347f7b6d9dc1 (diff)
downloadtor-92f62b36846e3c82f5521fa17f7a4f5afde827af.tar
tor-92f62b36846e3c82f5521fa17f7a4f5afde827af.tar.gz
r12077@catbus: nickm | 2007-03-04 16:08:23 -0500
Remove support for v0 control protocol from 0.2.0.x trunk; send back error when we receive a v0 control message. (Leave "if(v1){...}"blocks indented for now so this patch is easier to read.) ((Finally, the linecount goes _down_ a little.)) svn:r9735
-rw-r--r--ChangeLog6
-rw-r--r--doc/TODO4
-rw-r--r--src/or/buffers.c56
-rw-r--r--src/or/connection.c12
-rw-r--r--src/or/control.c1051
-rw-r--r--src/or/or.h16
6 files changed, 188 insertions, 957 deletions
diff --git a/ChangeLog b/ChangeLog
index c16ceafe6..462560298 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,12 @@ Changes in version 0.2.0.1-alpha - 2007-??-??
o Minor features (logging):
- Always prepend "Bug: " to any log message about a bug.
+ o Removed features:
+ - Removed support for the old binary "version 0" controller protocol.
+ This has been deprecated since 0.1.1, and warnings have been issued
+ since 0.1.2. When we encounter a v0 control message, we now send back
+ an error and close the connection.
+
Changes in version 0.1.2.10-rc - 2007-03-??
o Major bugfixes (Windows):
diff --git a/doc/TODO b/doc/TODO
index d199ab6e3..a15519dde 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -139,8 +139,8 @@ Things we'd like to do in 0.2.0.x:
- Blocking
- It would be potentially helpful to https requests on the OR port by
acting like an HTTPS server.
- - Deprecations:
- - Remove v0 control protocol.
+ o Deprecations:
+ o Remove v0 control protocol.
Deferred from 0.1.2.x:
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 366704ee0..2caec5860 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -1228,54 +1228,20 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
}
}
-/** If there is a complete version 0 control message waiting on buf, then store
- * its contents into *<b>type_out</b>, store its body's length into
- * *<b>len_out</b>, allocate and store a string for its body into
- * *<b>body_out</b>, and return 1. (body_out will always be NUL-terminated,
- * even if the control message body doesn't end with NUL.)
- *
- * If there is not a complete control message waiting, return 0.
- *
- * Return -1 on error; return -2 on "seems to be control protocol v1."
- */
+/** Return 1 iff buf looks more like it has an (obsolete) v0 controller
+ * command on it than any valid v1 controller command. */
int
-fetch_from_buf_control0(buf_t *buf, uint32_t *len_out, uint16_t *type_out,
- char **body_out, int check_for_v1)
+peek_buf_has_control0_command(buf_t *buf)
{
- uint32_t msglen;
- uint16_t type;
- char tmp[4];
-
- tor_assert(buf);
- tor_assert(len_out);
- tor_assert(type_out);
- tor_assert(body_out);
-
- *len_out = 0;
- *body_out = NULL;
-
- if (buf->datalen < 4)
- return 0;
-
- peek_from_buf(tmp, 4, buf);
-
- msglen = ntohs(get_uint16(tmp));
- type = ntohs(get_uint16(tmp+2));
- if (type > 255 && check_for_v1)
- return -2;
-
- if (buf->datalen < 4 + (unsigned)msglen)
- return 0;
-
- *len_out = msglen;
- *type_out = type;
- buf_remove_from_front(buf, 4);
- if (msglen) {
- *body_out = tor_malloc(msglen+1);
- fetch_from_buf(*body_out, msglen, buf);
- (*body_out)[msglen] = '\0';
+ if (buf->datalen >= 4) {
+ char header[4];
+ uint16_t cmd;
+ peek_from_buf(header, sizeof(header), buf);
+ cmd = ntohs(get_uint16(header+2));
+ if (cmd <= 0x14)
+ return 1; /* This is definitely not a v1 control command. */
}
- return 1;
+ return 0;
}
/** Helper: return a pointer to the first instance of <b>c</b> in the
diff --git a/src/or/connection.c b/src/or/connection.c
index b2afe178d..c04d3bc37 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -132,11 +132,8 @@ conn_state_to_string(int type, int state)
break;
case CONN_TYPE_CONTROL:
switch (state) {
- case CONTROL_CONN_STATE_OPEN_V0: return "open (protocol v0)";
- case CONTROL_CONN_STATE_OPEN_V1: return "open (protocol v1)";
- case CONTROL_CONN_STATE_NEEDAUTH_V0:
- return "waiting for authentication (protocol unknown)";
- case CONTROL_CONN_STATE_NEEDAUTH_V1:
+ case CONTROL_CONN_STATE_OPEN: return "open (protocol v1)";
+ case CONTROL_CONN_STATE_NEEDAUTH:
return "waiting for authentication (protocol v1)";
}
break;
@@ -860,7 +857,7 @@ connection_init_accepted_conn(connection_t *conn, uint8_t listener_type)
conn->state = DIR_CONN_STATE_SERVER_COMMAND_WAIT;
break;
case CONN_TYPE_CONTROL:
- conn->state = CONTROL_CONN_STATE_NEEDAUTH_V0;
+ conn->state = CONTROL_CONN_STATE_NEEDAUTH;
break;
}
return 0;
@@ -2121,8 +2118,7 @@ connection_state_is_open(connection_t *conn)
(conn->type == CONN_TYPE_AP && conn->state == AP_CONN_STATE_OPEN) ||
(conn->type == CONN_TYPE_EXIT && conn->state == EXIT_CONN_STATE_OPEN) ||
(conn->type == CONN_TYPE_CONTROL &&
- (conn->state == CONTROL_CONN_STATE_OPEN_V0 ||
- conn->state == CONTROL_CONN_STATE_OPEN_V1)))
+ conn->state == CONTROL_CONN_STATE_OPEN))
return 1;
return 0;
diff --git a/src/or/control.c b/src/or/control.c
index bfe628157..8c7a393b2 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -7,64 +7,14 @@ const char control_c_id[] =
/**
* \file control.c
* \brief Implementation for Tor's control-socket interface.
+ * See control-spec.txt for full details on protocol.
**/
#include "or.h"
/** Yield true iff <b>s</b> is the state of a control_connection_t that has
* finished authentication and is accepting commands. */
-#define STATE_IS_OPEN(s) ((s) == CONTROL_CONN_STATE_OPEN_V0 || \
- (s) == CONTROL_CONN_STATE_OPEN_V1)
-/** Yield true iff <b>s</b> is the state of a control_connection_t that is
- * speaking the V0 protocol.
- */
-#define STATE_IS_V0(s) ((s) == CONTROL_CONN_STATE_NEEDAUTH_V0 || \
- (s) == CONTROL_CONN_STATE_OPEN_V0)
-
-/*
- * See control-spec.txt and control-spec-v0.txt for full details on
- * protocol(s).
- */
-
-/* Recognized version 0 message type codes; do not add new codes to this list.
- * Version 0 is dead; version 1 doesn't use codes. */
-#define CONTROL0_CMD_ERROR 0x0000
-#define CONTROL0_CMD_DONE 0x0001
-#define CONTROL0_CMD_SETCONF 0x0002
-#define CONTROL0_CMD_GETCONF 0x0003
-#define CONTROL0_CMD_CONFVALUE 0x0004
-#define CONTROL0_CMD_SETEVENTS 0x0005
-#define CONTROL0_CMD_EVENT 0x0006
-#define CONTROL0_CMD_AUTHENTICATE 0x0007
-#define CONTROL0_CMD_SAVECONF 0x0008
-#define CONTROL0_CMD_SIGNAL 0x0009
-#define CONTROL0_CMD_MAPADDRESS 0x000A
-#define CONTROL0_CMD_GETINFO 0x000B
-#define CONTROL0_CMD_INFOVALUE 0x000C
-#define CONTROL0_CMD_EXTENDCIRCUIT 0x000D
-#define CONTROL0_CMD_ATTACHSTREAM 0x000E
-#define CONTROL0_CMD_POSTDESCRIPTOR 0x000F
-#define CONTROL0_CMD_FRAGMENTHEADER 0x0010
-#define CONTROL0_CMD_FRAGMENT 0x0011
-#define CONTROL0_CMD_REDIRECTSTREAM 0x0012
-#define CONTROL0_CMD_CLOSESTREAM 0x0013
-#define CONTROL0_CMD_CLOSECIRCUIT 0x0014
-#define _CONTROL0_CMD_MAX_RECOGNIZED 0x0014
-
-/* Recognized version 0 error codes. Do not expand. */
-#define ERR_UNSPECIFIED 0x0000
-#define ERR_INTERNAL 0x0001
-#define ERR_UNRECOGNIZED_TYPE 0x0002
-#define ERR_SYNTAX 0x0003
-#define ERR_UNRECOGNIZED_CONFIG_KEY 0x0004
-#define ERR_INVALID_CONFIG_VALUE 0x0005
-#define ERR_UNRECOGNIZED_EVENT_CODE 0x0006
-#define ERR_UNAUTHORIZED 0x0007
-#define ERR_REJECTED_AUTHENTICATION 0x0008
-#define ERR_RESOURCE_EXHAUSTED 0x0009
-#define ERR_NO_STREAM 0x000A
-#define ERR_NO_CIRC 0x000B
-#define ERR_NO_ROUTER 0x000C
+#define STATE_IS_OPEN(s) ((s) == CONTROL_CONN_STATE_OPEN)
/* Recognized asynchronous event types. It's okay to expand this list
* because it is used both as a list of v0 event types, and as indices
@@ -75,14 +25,13 @@ const char control_c_id[] =
#define EVENT_STREAM_STATUS 0x0002
#define EVENT_OR_CONN_STATUS 0x0003
#define EVENT_BANDWIDTH_USED 0x0004
-#define EVENT_LOG_OBSOLETE 0x0005
+#define EVENT_LOG_OBSOLETE 0x0005 /* Can reclaim this. */
#define EVENT_NEW_DESC 0x0006
#define EVENT_DEBUG_MSG 0x0007
#define EVENT_INFO_MSG 0x0008
#define EVENT_NOTICE_MSG 0x0009
#define EVENT_WARN_MSG 0x000A
#define EVENT_ERR_MSG 0x000B
-#define LAST_V0_EVENT 0x000B
#define EVENT_ADDRMAP 0x000C
#define EVENT_AUTHDIR_NEWDESCS 0x000D
#define EVENT_DESCCHANGED 0x000E
@@ -95,33 +44,6 @@ const char control_c_id[] =
#define _EVENT_MAX 0x0014
/* If _EVENT_MAX ever hits 0x0020, we need to make the mask wider. */
-/** Array mapping from message type codes to human-readable message
- * type names. Used for compatibility with version 0 of the control
- * protocol. Do not add new items to this list. */
-static const char * CONTROL0_COMMANDS[_CONTROL0_CMD_MAX_RECOGNIZED+1] = {
- "error",
- "done",
- "setconf",
- "getconf",
- "confvalue",
- "setevents",
- "events",
- "authenticate",
- "saveconf",
- "signal",
- "mapaddress",
- "getinfo",
- "infovalue",
- "extendcircuit",
- "attachstream",
- "postdescriptor",
- "fragmentheader",
- "fragment",
- "redirectstream",
- "closestream",
- "closecircuit",
-};
-
/** Bitfield: The bit 1&lt;&lt;e is set if <b>any</b> open control
* connection is interested in events of type <b>e</b>. We use this
* so that we can decide to skip generating event messages that nobody
@@ -129,7 +51,6 @@ static const char * CONTROL0_COMMANDS[_CONTROL0_CMD_MAX_RECOGNIZED+1] = {
* list to find out.
**/
typedef uint32_t event_mask_t;
-static event_mask_t global_event_mask0 = 0;
static event_mask_t global_event_mask1long = 0;
static event_mask_t global_event_mask1short = 0;
@@ -138,14 +59,10 @@ static int disable_log_messages = 0;
/** Macro: true if any control connection is interested in events of type
* <b>e</b>. */
-#define EVENT_IS_INTERESTING0(e) (global_event_mask0 & (1<<(e)))
-#define EVENT_IS_INTERESTING1(e) \
+#define EVENT_IS_INTERESTING(e) \
((global_event_mask1long|global_event_mask1short) & (1<<(e)))
#define EVENT_IS_INTERESTING1L(e) (global_event_mask1long & (1<<(e)))
#define EVENT_IS_INTERESTING1S(e) (global_event_mask1short & (1<<(e)))
-#define EVENT_IS_INTERESTING(e) \
- ((global_event_mask0|global_event_mask1short|global_event_mask1long) \
- & (1<<(e)))
/** If we're using cookie-type authentication, how long should our cookies be?
*/
@@ -171,19 +88,11 @@ static void connection_printf_to_buf(control_connection_t *conn,
int translate_newlines, char **out);
/*static*/ size_t read_escaped_data(const char *data, size_t len,
int translate_newlines, char **out);
-static void send_control0_message(control_connection_t *conn, uint16_t type,
- uint32_t len, const char *body);
static void send_control_done(control_connection_t *conn);
-static void send_control_done2(control_connection_t *conn, const char *msg,
- size_t len);
-static void send_control0_error(control_connection_t *conn, uint16_t error,
- const char *message);
-static void send_control0_event(uint16_t event, uint32_t len,
- const char *body);
-static void send_control1_event(uint16_t event, event_format_t which,
- const char *format, ...)
+static void send_control_event(uint16_t event, event_format_t which,
+ const char *format, ...)
CHECK_PRINTF(3,4);
-static void send_control1_event_extended(uint16_t event, event_format_t which,
+static void send_control_event_extended(uint16_t event, event_format_t which,
const char *format, ...)
CHECK_PRINTF(3,4);
static int handle_control_setconf(control_connection_t *conn, uint32_t len,
@@ -234,15 +143,6 @@ static int write_stream_target_to_buf(edge_connection_t *conn, char *buf,
static void orconn_target_get_name(int long_names, char *buf, size_t len,
or_connection_t *conn);
-/** Given a possibly invalid message type code <b>cmd</b>, return a
- * human-readable string equivalent. */
-static INLINE const char *
-control_cmd_to_string(uint16_t cmd)
-{
- return (cmd<=_CONTROL0_CMD_MAX_RECOGNIZED) ?
- CONTROL0_COMMANDS[cmd] : "Unknown";
-}
-
/** Given a control event code for a message event, return the corresponding
* log severity. */
static INLINE int
@@ -280,11 +180,9 @@ control_update_global_event_mask(void)
connection_t **conns;
int n_conns, i;
event_mask_t old_mask, new_mask;
- old_mask = global_event_mask0;
- old_mask |= global_event_mask1short;
+ old_mask = global_event_mask1short;
old_mask |= global_event_mask1long;
- global_event_mask0 = 0;
global_event_mask1short = 0;
global_event_mask1long = 0;
get_connection_array(&conns, &n_conns);
@@ -292,17 +190,14 @@ control_update_global_event_mask(void)
if (conns[i]->type == CONN_TYPE_CONTROL &&
STATE_IS_OPEN(conns[i]->state)) {
control_connection_t *conn = TO_CONTROL_CONN(conns[i]);
- if (STATE_IS_V0(conn->_base.state))
- global_event_mask0 |= conn->event_mask;
- else if (conn->use_long_names)
+ if (conn->use_long_names)
global_event_mask1long |= conn->event_mask;
else
global_event_mask1short |= conn->event_mask;
}
}
- new_mask = global_event_mask0;
- new_mask |= global_event_mask1short;
+ new_mask = global_event_mask1short;
new_mask |= global_event_mask1long;
/* Handle the aftermath. Set up the log callback to tell us only what
@@ -547,114 +442,11 @@ connection_printf_to_buf(control_connection_t *conn, const char *format, ...)
connection_write_to_buf(buf, len, TO_CONN(conn));
}
-/** Send a message of type <b>type</b> containing <b>len</b> bytes
- * from <b>body</b> along the control connection <b>conn</b> */
-static void
-send_control0_message(control_connection_t *conn, uint16_t type, uint32_t len,
- const char *body)
-{
- char buf[10];
- tor_assert(conn);
- tor_assert(STATE_IS_V0(conn->_base.state));
- tor_assert(len || !body);
- tor_assert(type <= _CONTROL0_CMD_MAX_RECOGNIZED);
- if (len < 65536) {
- set_uint16(buf, htons(len));
- set_uint16(buf+2, htons(type));
- connection_write_to_buf(buf, 4, TO_CONN(conn));
- if (len)
- connection_write_to_buf(body, len, TO_CONN(conn));
- } else {
- set_uint16(buf, htons(65535));
- set_uint16(buf+2, htons(CONTROL0_CMD_FRAGMENTHEADER));
- set_uint16(buf+4, htons(type));
- set_uint32(buf+6, htonl(len));
- connection_write_to_buf(buf, 10, TO_CONN(conn));
- connection_write_to_buf(body, 65535-6, TO_CONN(conn));
- len -= (65535-6);
- body += (65535-6);
- while (len) {
- size_t chunklen = (len<65535)?len:65535;
- set_uint16(buf, htons((uint16_t)chunklen));
- set_uint16(buf+2, htons(CONTROL0_CMD_FRAGMENT));
- connection_write_to_buf(buf, 4, TO_CONN(conn));
- connection_write_to_buf(body, chunklen, TO_CONN(conn));
- len -= chunklen;
- body += chunklen;
- }
- }
-}
-
/** Send a "DONE" message down the control connection <b>conn</b> */
static void
send_control_done(control_connection_t *conn)
{
- if (STATE_IS_V0(conn->_base.state)) {
- send_control0_message(conn, CONTROL0_CMD_DONE, 0, NULL);
- } else {
- connection_write_str_to_buf("250 OK\r\n", conn);
- }
-}
-
-/** Send a "DONE" message down the v0 control message <b>conn</b>, with body
- * as provided in the <b>len</b> bytes at <b>msg</b>.
- */
-static void
-send_control_done2(control_connection_t *conn, const char *msg, size_t len)
-{
- if (len==0)
- len = strlen(msg);
- send_control0_message(conn, CONTROL0_CMD_DONE, len, msg);
-}
-
-/** Send an error message with error code <b>error</b> and body
- * <b>message</b> down the connection <b>conn</b> */
-static void
-send_control0_error(control_connection_t *conn, uint16_t error,
- const char *message)
-{
- char buf[256];
- size_t len;
- set_uint16(buf, htons(error));
- len = strlen(message);
- tor_assert(len < (256-2));
- memcpy(buf+2, message, len);
- send_control0_message(conn, CONTROL0_CMD_ERROR, (uint16_t)(len+2), buf);
-}
-
-/** Send an 'event' message of event type <b>event</b>, containing
- * <b>len</b> bytes in <b>body</b> to every control connection that
- * is interested in it. */
-static void
-send_control0_event(uint16_t event, uint32_t len, const char *body)
-{
- connection_t **conns;
- int n_conns, i;
- size_t buflen;
- char *buf;
-
- tor_assert(event >= _EVENT_MIN && event <= LAST_V0_EVENT);
-
- buflen = len + 2;
- buf = tor_malloc_zero(buflen);
- set_uint16(buf, htons(event));
- memcpy(buf+2, body, len);
-
- get_connection_array(&conns, &n_conns);
- for (i = 0; i < n_conns; ++i) {
- if (conns[i]->type == CONN_TYPE_CONTROL &&
- !conns[i]->marked_for_close &&
- conns[i]->state == CONTROL_CONN_STATE_OPEN_V0) {
- control_connection_t *control_conn = TO_CONTROL_CONN(conns[i]);
- if (control_conn->event_mask & (1<<event)) {
- send_control0_message(control_conn, CONTROL0_CMD_EVENT, buflen, buf);
- if (event == EVENT_ERR_MSG)
- connection_handle_write(TO_CONN(control_conn), 1);
- }
- }
- }
-
- tor_free(buf);
+ connection_write_str_to_buf("250 OK\r\n", conn);
}
/* Send an event to all v1 controllers that are listening for code
@@ -668,8 +460,8 @@ send_control0_event(uint16_t event, uint32_t len, const char *body)
* The EXTENDED_FORMAT and NONEXTENDED_FORMAT flags behave similarly with
* respect to the EXTENDED_EVENTS feature. */
static void
-send_control1_event_string(uint16_t event, event_format_t which,
- const char *msg)
+send_control_event_string(uint16_t event, event_format_t which,
+ const char *msg)
{
connection_t **conns;
int n_conns, i;
@@ -680,7 +472,7 @@ send_control1_event_string(uint16_t event, event_format_t which,
for (i = 0; i < n_conns; ++i) {
if (conns[i]->type == CONN_TYPE_CONTROL &&
!conns[i]->marked_for_close &&
- conns[i]->state == CONTROL_CONN_STATE_OPEN_V1) {
+ conns[i]->state == CONTROL_CONN_STATE_OPEN) {
control_connection_t *control_conn = TO_CONTROL_CONN(conns[i]);
if (control_conn->use_long_names) {
if (!(which & LONG_NAMES))
@@ -726,7 +518,7 @@ send_control1_event_string(uint16_t event, event_format_t which,
* Currently the length of the message is limited to 1024 (including the
* ending \n\r\0). */
static void
-send_control1_event_impl(uint16_t event, event_format_t which, int extended,
+send_control_event_impl(uint16_t event, event_format_t which, int extended,
const char *format, va_list ap)
{
/* This is just a little longer than the longest allowed log message */
@@ -753,11 +545,11 @@ send_control1_event_impl(uint16_t event, event_format_t which, int extended,
if (extended && (cp = strchr(buf, '@'))) {
which &= ~ALL_FORMATS;
*cp = ' ';
- send_control1_event_string(event, which|EXTENDED_FORMAT, buf);
+ send_control_event_string(event, which|EXTENDED_FORMAT, buf);
memcpy(cp, "\r\n\0", 3);
- send_control1_event_string(event, which|NONEXTENDED_FORMAT, buf);
+ send_control_event_string(event, which|NONEXTENDED_FORMAT, buf);
} else {
- send_control1_event_string(event, which|ALL_FORMATS, buf);
+ send_control_event_string(event, which|ALL_FORMATS, buf);
}
}
@@ -768,12 +560,12 @@ send_control1_event_impl(uint16_t event, event_format_t which, int extended,
* Currently the length of the message is limited to 1024 (including the
* ending \n\r\0. */
static void
-send_control1_event(uint16_t event, event_format_t which,
+send_control_event(uint16_t event, event_format_t which,
const char *format, ...)
{
va_list ap;
va_start(ap, format);
- send_control1_event_impl(event, which, 0, format, ap);
+ send_control_event_impl(event, which, 0, format, ap);
va_end(ap);
}
@@ -788,12 +580,12 @@ send_control1_event(uint16_t event, event_format_t which,
* Currently the length of the message is limited to 1024 (including the
* ending \n\r\0. */
static void
-send_control1_event_extended(uint16_t event, event_format_t which,
+send_control_event_extended(uint16_t event, event_format_t which,
const char *format, ...)
{
va_list ap;
va_start(ap, format);
- send_control1_event_impl(event, which, 1, format, ap);
+ send_control_event_impl(event, which, 1, format, ap);
va_end(ap);
}
@@ -831,15 +623,15 @@ get_stream(const char *id)
*/
static int
control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
- int use_defaults, int clear_first)
+ int use_defaults)
{
int r;
config_line_t *lines=NULL;
char *start = body;
char *errstring = NULL;
- int v0 = STATE_IS_V0(conn->_base.state);
+ const int clear_first = 1;
- if (!v0) {
+ if (1) {
char *config;
smartlist_t *entries = smartlist_create();
/* We have a string, "body", of the format '(key(=val|="val")?)' entries
@@ -898,46 +690,30 @@ control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
return 0;
}
tor_free(config);
- } else {
- if (config_get_lines(body, &lines) < 0) {
- log_warn(LD_CONTROL,
- "V0 controller gave us config lines we can't parse.");
- send_control0_error(conn, ERR_SYNTAX, "Couldn't parse configuration");
- return 0;
- }
}
if ((r=options_trial_assign(lines, use_defaults,
clear_first, &errstring)) < 0) {
- int v0_err;
const char *msg;
log_warn(LD_CONTROL,
"Controller gave us config lines that didn't validate: %s.",
errstring);
switch (r) {
case -1:
- v0_err = ERR_UNRECOGNIZED_CONFIG_KEY;
msg = "552 Unrecognized option";
break;
case -2:
- v0_err = ERR_INVALID_CONFIG_VALUE;
msg = "513 Unacceptable option value";
break;
case -3:
- v0_err = ERR_INVALID_CONFIG_VALUE;
msg = "553 Transition not allowed";
break;
case -4:
default:
- v0_err = ERR_INVALID_CONFIG_VALUE;
msg = "553 Unable to set option";
break;
}
- if (v0) {
- send_control0_error(conn, v0_err, msg);
- } else {
- connection_printf_to_buf(conn, "%s: %s\r\n", msg, errstring);
- }
+ connection_printf_to_buf(conn, "%s: %s\r\n", msg, errstring);
config_free_lines(lines);
tor_free(errstring);
return 0;
@@ -953,7 +729,7 @@ control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
static int
handle_control_setconf(control_connection_t *conn, uint32_t len, char *body)
{
- return control_setconf_helper(conn, len, body, 0, 1);
+ return control_setconf_helper(conn, len, body, 0);
}
/** Called when we receive a RESETCONF message: parse the body and try
@@ -962,9 +738,7 @@ handle_control_setconf(control_connection_t *conn, uint32_t len, char *body)
static int
handle_control_resetconf(control_connection_t *conn, uint32_t len, char *body)
{
- int v0 = STATE_IS_V0(conn->_base.state);
- tor_assert(!v0);
- return control_setconf_helper(conn, len, body, 1, 1);
+ return control_setconf_helper(conn, len, body, 1);
}
/** Called when we receive a GETCONF message. Parse the request, and
@@ -979,31 +753,20 @@ handle_control_getconf(control_connection_t *conn, uint32_t body_len,
char *msg = NULL;
size_t msg_len;
or_options_t *options = get_options();
- int v0 = STATE_IS_V0(conn->_base.state);
questions = smartlist_create();
(void) body_len; /* body is nul-terminated; so we can ignore len. */
- if (v0) {
- smartlist_split_string(questions, body, "\n",
- SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- } else {
- smartlist_split_string(questions, body, " ",
- SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- }
+ smartlist_split_string(questions, body, " ",
+ SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
answers = smartlist_create();
unrecognized = smartlist_create();
SMARTLIST_FOREACH(questions, char *, q,
{
if (!option_is_recognized(q)) {
- if (v0) {
- send_control0_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, q);
- goto done;
- } else {
- smartlist_add(unrecognized, q);
- }
+ smartlist_add(unrecognized, q);
} else {
config_line_t *answer = option_get_assignment(options,q);
- if (!v0 && !answer) {
+ if (!answer) {
const char *name = option_get_canonical_name(q);
size_t alen = strlen(name)+8;
char *astr = tor_malloc(alen);
@@ -1015,11 +778,8 @@ handle_control_getconf(control_connection_t *conn, uint32_t body_len,
config_line_t *next;
size_t alen = strlen(answer->key)+strlen(answer->value)+8;
char *astr = tor_malloc(alen);
- if (v0)
- tor_snprintf(astr, alen, "%s %s\n", answer->key, answer->value);
- else
- tor_snprintf(astr, alen, "250-%s=%s\r\n",
- answer->key, answer->value);
+ tor_snprintf(astr, alen, "250-%s=%s\r\n",
+ answer->key, answer->value);
smartlist_add(answers, astr);
next = answer->next;
@@ -1031,11 +791,7 @@ handle_control_getconf(control_connection_t *conn, uint32_t body_len,
}
});
- if (v0) {
- msg = smartlist_join_strings(answers, "", 0, &msg_len);
- send_control0_message(conn, CONTROL0_CMD_CONFVALUE,
- (uint16_t)msg_len, msg_len?msg:NULL);
- } else {
+ if (1) {
int i,len;
if ((len = smartlist_len(unrecognized))) {
for (i=0; i < len-1; ++i)
@@ -1056,7 +812,6 @@ handle_control_getconf(control_connection_t *conn, uint32_t body_len,
}
}
- done:
if (answers) {
SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
smartlist_free(answers);
@@ -1080,24 +835,9 @@ handle_control_setevents(control_connection_t *conn, uint32_t len,
uint16_t event_code;
uint32_t event_mask = 0;
unsigned int extended = 0;
+ (void) len;
- if (STATE_IS_V0(conn->_base.state)) {
- if (len % 2) {
- send_control0_error(conn, ERR_SYNTAX,
- "Odd number of bytes in setevents message");
- return 0;
- }
-
- for (; len; len -= 2, body += 2) {
- event_code = ntohs(get_uint16(body));
- if (event_code < _EVENT_MIN || event_code > LAST_V0_EVENT) {
- send_control0_error(conn, ERR_UNRECOGNIZED_EVENT_CODE,
- "Unrecognized event code");
- return 0;
- }
- event_mask |= (1 << event_code);
- }
- } else {
+ if (1) {
smartlist_t *events = smartlist_create();
smartlist_split_string(events, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@@ -1203,10 +943,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
const char *errstr = NULL;
char *password;
size_t password_len;
- if (STATE_IS_V0(conn->_base.state)) {
- password = (char*)body;
- password_len = len;
- } else {
+ if (1) {
if (TOR_ISXDIGIT(body[0])) {
int i = 0;
while (TOR_ISXDIGIT(body[i]))
@@ -1274,26 +1011,17 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
}
err:
- if (STATE_IS_V0(conn->_base.state))
- send_control0_error(conn,ERR_REJECTED_AUTHENTICATION,
- "Authentication failed");
- else {
- tor_free(password);
- if (!errstr)
- errstr = "Unknown reason.";
- connection_printf_to_buf(conn, "515 Authentication failed: %s\r\n",
- errstr);
- }
+ tor_free(password);
+ if (!errstr)
+ errstr = "Unknown reason.";
+ connection_printf_to_buf(conn, "515 Authentication failed: %s\r\n",
+ errstr);
return 0;
ok:
log_info(LD_CONTROL, "Authenticated control connection (%d)", conn->_base.s);
send_control_done(conn);
- if (STATE_IS_V0(conn->_base.state))
- conn->_base.state = CONTROL_CONN_STATE_OPEN_V0;
- else {
- conn->_base.state = CONTROL_CONN_STATE_OPEN_V1;
- tor_free(password);
- }
+ conn->_base.state = CONTROL_CONN_STATE_OPEN;
+ tor_free(password);
return 0;
}
@@ -1306,12 +1034,8 @@ handle_control_saveconf(control_connection_t *conn, uint32_t len,
(void) len;
(void) body;
if (options_save_current()<0) {
- if (STATE_IS_V0(conn->_base.state))
- send_control0_error(conn, ERR_INTERNAL,
- "Unable to write configuration to disk.");
- else
- connection_write_str_to_buf(
- "551 Unable to write configuration to disk.\r\n", conn);
+ connection_write_str_to_buf(
+ "551 Unable to write configuration to disk.\r\n", conn);
} else {
send_control_done(conn);
}
@@ -1326,27 +1050,9 @@ handle_control_signal(control_connection_t *conn, uint32_t len,
const char *body)
{
int sig;
- if (STATE_IS_V0(conn->_base.state)) {
- if (len != 1) {
- send_control0_error(conn, ERR_SYNTAX,
- "Body of SIGNAL command too long or too short.");
- return 0;
- } else {
- sig = (uint8_t)body[0];
- switch (sig)
- {
- case 1: sig = SIGHUP; break;
- case 2: sig = SIGINT; break;
- case 10: sig = SIGUSR1; break;
- case 12: sig = SIGUSR2; break;
- case 15: sig = SIGTERM; break;
- case SIGNEWNYM: break;
- default:
- send_control0_error(conn, ERR_SYNTAX, "Unrecognized signal number.");
- return 0;
- }
- }
- } else {
+ (void) len;
+
+ if (1) {
int n = 0;
char *s;
while (body[n] && ! TOR_ISSPACE(body[n]))
@@ -1393,37 +1099,26 @@ handle_control_mapaddress(control_connection_t *conn, uint32_t len,
smartlist_t *reply;
char *r;
size_t sz;
- int v0 = STATE_IS_V0(conn->_base.state);
(void) len; /* body is nul-terminated, so it's safe to ignore the length. */
lines = smartlist_create();
elts = smartlist_create();
reply = smartlist_create();
- if (v0)
- smartlist_split_string(lines, body, "\n",
- SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- else
- smartlist_split_string(lines, body, " ",
- SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+ smartlist_split_string(lines, body, " ",
+ SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
SMARTLIST_FOREACH(lines, char *, line,
{
tor_strlower(line);
- if (v0)
- smartlist_split_string(elts, line, " ", 0, 2);
- else
- smartlist_split_string(elts, line, "=", 0, 2);
+ smartlist_split_string(elts, line, "=", 0, 2);
if (smartlist_len(elts) == 2) {
const char *from = smartlist_get(elts,0);
const char *to = smartlist_get(elts,1);
size_t anslen = strlen(line)+512;
char *ans = tor_malloc(anslen);
if (address_is_invalid_destination(to, 1)) {
- if (!v0) {
- tor_snprintf(ans, anslen,
- "512-syntax error: invalid address '%s'", to);
- smartlist_add(reply, ans);
- } else
- tor_free(ans); /* don't respond if v0 */
+ tor_snprintf(ans, anslen,
+ "512-syntax error: invalid address '%s'", to);
+ smartlist_add(reply, ans);
log_warn(LD_CONTROL,
"Skipping invalid argument '%s' in MapAddress msg", to);
} else if (!strcmp(from, ".") || !strcmp(from, "0.0.0.0")) {
@@ -1431,38 +1126,27 @@ handle_control_mapaddress(control_connection_t *conn, uint32_t len,
!strcmp(from,".") ? RESOLVED_TYPE_HOSTNAME : RESOLVED_TYPE_IPV4,
tor_strdup(to));
if (!address) {
- if (!v0) {
- tor_snprintf(ans, anslen,
- "451-resource exhausted: skipping '%s'", line);
- smartlist_add(reply, ans);
- } else
- tor_free(ans); /* don't respond if v0 */
+ tor_snprintf(ans, anslen,
+ "451-resource exhausted: skipping '%s'", line);
+ smartlist_add(reply, ans);
log_warn(LD_CONTROL,
"Unable to allocate address for '%s' in MapAddress msg",
safe_str(line));
} else {
- if (v0)
- tor_snprintf(ans, anslen, "%s %s", address, to);
- else
- tor_snprintf(ans, anslen, "250-%s=%s", address, to);
+ tor_snprintf(ans, anslen, "250-%s=%s", address, to);
smartlist_add(reply, ans);
}
} else {
addressmap_register(from, tor_strdup(to), 1);
- if (v0)
- tor_snprintf(ans, anslen, "%s", line);
- else
- tor_snprintf(ans, anslen, "250-%s", line);
+ tor_snprintf(ans, anslen, "250-%s", line);
smartlist_add(reply, ans);
}
} else {
- if (!v0) {
- size_t anslen = strlen(line)+256;
- char *ans = tor_malloc(anslen);
- tor_snprintf(ans, anslen, "512-syntax error: mapping '%s' is "
- "not of expected form 'foo=bar'.", line);
- smartlist_add(reply, ans);
- }
+ size_t anslen = strlen(line)+256;
+ char *ans = tor_malloc(anslen);
+ tor_snprintf(ans, anslen, "512-syntax error: mapping '%s' is "
+ "not of expected form 'foo=bar'.", line);
+ smartlist_add(reply, ans);
log_info(LD_CONTROL, "Skipping MapAddress '%s': wrong "
"number of items.", safe_str(line));
}
@@ -1473,11 +1157,7 @@ handle_control_mapaddress(control_connection_t *conn, uint32_t len,
smartlist_free(lines);
smartlist_free(elts);
- if (v0) {
- r = smartlist_join_strings(reply, "\n", 1, &sz);
- send_control_done2(conn,r,sz);
- tor_free(r);
- } else {
+ if (1) {
if (smartlist_len(reply)) {
((char*)smartlist_get(reply,smartlist_len(reply)-1))[3] = ' ';
r = smartlist_join_strings(reply, "\r\n", 1, &sz);
@@ -1937,34 +1617,21 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
smartlist_t *answers = NULL;
smartlist_t *unrecognized = NULL;
char *msg = NULL, *ans = NULL;
- size_t msg_len;
- int v0 = STATE_IS_V0(conn->_base.state);
(void) len; /* body is nul-terminated, so it's safe to ignore the length. */
questions = smartlist_create();
- if (v0)
- smartlist_split_string(questions, body, "\n",
- SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- else
- smartlist_split_string(questions, body, " ",
- SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+ smartlist_split_string(questions, body, " ",
+ SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
answers = smartlist_create();
unrecognized = smartlist_create();
SMARTLIST_FOREACH(questions, const char *, q,
{
if (handle_getinfo_helper(conn, q, &ans) < 0) {
- if (v0)
- send_control0_error(conn, ERR_INTERNAL, body);
- else
- connection_write_str_to_buf("551 Internal error\r\n", conn);
+ connection_write_str_to_buf("551 Internal error\r\n", conn);
goto done;
}
if (!ans) {
- if (v0) {
- send_control0_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, body);
- goto done;
- } else
- smartlist_add(unrecognized, (char*)q);
+ smartlist_add(unrecognized, (char*)q);
} else {
smartlist_add(answers, tor_strdup(q));
smartlist_add(answers, ans);
@@ -1972,7 +1639,6 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
});
if (smartlist_len(unrecognized)) {
int i;
- tor_assert(!v0);
for (i=0; i < smartlist_len(unrecognized)-1; ++i)
connection_printf_to_buf(conn,
"552-Unrecognized key \"%s\"\r\n",
@@ -1983,12 +1649,7 @@ handle_control_getinfo(control_connection_t *conn, uint32_t len,
goto done;
}
- if (v0) {
- msg = smartlist_join_strings2(answers, "\0", 1, 1, &msg_len);
- tor_assert(msg_len > 0); /* it will at least be terminated */
- send_control0_message(conn, CONTROL0_CMD_INFOVALUE,
- msg_len, msg);
- } else {
+ if (1) {
int i;
for (i = 0; i < smartlist_len(answers); i += 2) {
char *k = smartlist_get(answers, i);
@@ -2056,35 +1717,14 @@ handle_control_extendcircuit(control_connection_t *conn, uint32_t len,
const char *body)
{
smartlist_t *router_nicknames=NULL, *routers=NULL;
- uint32_t circ_id;
origin_circuit_t *circ = NULL;
- int zero_circ, v0;
- char reply[4];
+ int zero_circ;
uint8_t intended_purpose = CIRCUIT_PURPOSE_C_GENERAL;
+ (void) len;
- v0 = STATE_IS_V0(conn->_base.state);
router_nicknames = smartlist_create();
- if (v0) {
- if (len<5) {
- send_control0_error(conn, ERR_SYNTAX, "extendcircuit message too short");
- goto done;
- }
- smartlist_split_string(router_nicknames, body+4, ",", 0, 0);
- circ_id = ntohl(get_uint32(body));
- if (!circ_id) {
- /* start a new circuit */
- zero_circ = 1;
- } else {
- circ = circuit_get_by_global_id(circ_id);
- zero_circ = 0;
- if (!circ) {
- send_control0_error(conn, ERR_NO_CIRC,
- "No circuit found with given ID");
- goto done;
- }
- }
- } else { /* v1 */
+ if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
@@ -2125,19 +1765,13 @@ handle_control_extendcircuit(control_connection_t *conn, uint32_t len,
{
routerinfo_t *r = router_get_by_nickname(n, 1);
if (!r) {
- if (v0)
- send_control0_error(conn, ERR_NO_ROUTER, n);
- else
- connection_printf_to_buf(conn, "552 No such router \"%s\"\r\n", n);
+ connection_printf_to_buf(conn, "552 No such router \"%s\"\r\n", n);
goto done;
}
smartlist_add(routers, r);
});
if (!smartlist_len(routers)) {
- if (v0)
- send_control0_error(conn, ERR_SYNTAX, "No router names provided");
- else
- connection_write_str_to_buf("512 No router names provided\r\n", conn);
+ connection_write_str_to_buf("512 No router names provided\r\n", conn);
goto done;
}
@@ -2159,10 +1793,7 @@ handle_control_extendcircuit(control_connection_t *conn, uint32_t len,
int err_reason = 0;
if ((err_reason = circuit_handle_first_hop(circ)) < 0) {
circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
- if (v0)
- send_control0_error(conn, ERR_INTERNAL, "couldn't start circuit");
- else
- connection_write_str_to_buf("551 Couldn't start circuit\r\n", conn);
+ connection_write_str_to_buf("551 Couldn't start circuit\r\n", conn);
goto done;
}
} else {
@@ -2173,22 +1804,14 @@ handle_control_extendcircuit(control_connection_t *conn, uint32_t len,
log_info(LD_CONTROL,
"send_next_onion_skin failed; circuit marked for closing.");
circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
- if (v0)
- send_control0_error(conn, ERR_INTERNAL, "couldn't send onion skin");
- else
- connection_write_str_to_buf("551 Couldn't send onion skinr\n", conn);
+ connection_write_str_to_buf("551 Couldn't send onion skinr\n", conn);
goto done;
}
}
}
- if (v0) {
- set_uint32(reply, htonl(circ->global_identifier));
- send_control_done2(conn, reply, sizeof(reply));
- } else {
- connection_printf_to_buf(conn, "250 EXTENDED %lu\r\n",
+ connection_printf_to_buf(conn, "250 EXTENDED %lu\r\n",
(unsigned long)circ->global_identifier);
- }
done:
SMARTLIST_FOREACH(router_nicknames, char *, n, tor_free(n));
smartlist_free(router_nicknames);
@@ -2261,29 +1884,9 @@ handle_control_attachstream(control_connection_t *conn, uint32_t len,
edge_connection_t *ap_conn = NULL;
origin_circuit_t *circ = NULL;
int zero_circ;
+ (void) len;
- if (STATE_IS_V0(conn->_base.state)) {
- uint32_t conn_id;
- uint32_t circ_id;
- if (len < 8) {
- send_control0_error(conn, ERR_SYNTAX, "attachstream message too short");
- return 0;
- }
-
- conn_id = ntohl(get_uint32(body));
- circ_id = ntohl(get_uint32(body+4));
- zero_circ = circ_id == 0;
-
- if (!(ap_conn = connection_get_by_global_id(conn_id))) {
- send_control0_error(conn, ERR_NO_STREAM,
- "No connection found with given ID");
- return 0;
- }
- if (circ_id && !(circ = circuit_get_by_global_id(circ_id))) {
- send_control0_error(conn, ERR_NO_CIRC, "No circuit found with given ID");
- return 0;
- }
- } else {
+ if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
@@ -2314,14 +1917,9 @@ handle_control_attachstream(control_connection_t *conn, uint32_t len,
if (ap_conn->_base.state != AP_CONN_STATE_CONTROLLER_WAIT &&
ap_conn->_base.state != AP_CONN_STATE_CONNECT_WAIT &&
ap_conn->_base.state != AP_CONN_STATE_RESOLVE_WAIT) {
- if (STATE_IS_V0(conn->_base.state)) {
- send_control0_error(conn, ERR_NO_STREAM,
- "Connection is not managed by controller.");
- } else {
- connection_write_str_to_buf(
- "555 Connection is not managed by controller.\r\n",
- conn);
- }
+ connection_write_str_to_buf(
+ "555 Connection is not managed by controller.\r\n",
+ conn);
return 0;
}
@@ -2339,30 +1937,18 @@ handle_control_attachstream(control_connection_t *conn, uint32_t len,
}
if (circ && (circ->_base.state != CIRCUIT_STATE_OPEN)) {
- if (STATE_IS_V0(conn->_base.state))
- send_control0_error(conn, ERR_INTERNAL,
- "Refuse to attach stream to non-open, origin circ.");
- else
- connection_write_str_to_buf(
- "551 Can't attach stream to non-open, origin circuit\r\n",
- conn);
+ connection_write_str_to_buf(
+ "551 Can't attach stream to non-open, origin circuit\r\n",
+ conn);
return 0;
}
if (circ && circuit_get_cpath_len(circ) < 2) {
- if (STATE_IS_V0(conn->_base.state))
- send_control0_error(conn, ERR_INTERNAL,
- "Refuse to attach stream to one-hop circuit.");
- else
- connection_write_str_to_buf(
- "551 Can't attach stream to one-hop circuit.\r\n",
- conn);
+ connection_write_str_to_buf(
+ "551 Can't attach stream to one-hop circuit.\r\n", conn);
return 0;
}
if (connection_ap_handshake_rewrite_and_attach(ap_conn, circ) < 0) {
- if (STATE_IS_V0(conn->_base.state))
- send_control0_error(conn, ERR_INTERNAL, "Unable to attach stream.");
- else
- connection_write_str_to_buf("551 Unable to attach stream\r\n", conn);
+ connection_write_str_to_buf("551 Unable to attach stream\r\n", conn);
return 0;
}
send_control_done(conn);
@@ -2376,13 +1962,10 @@ handle_control_postdescriptor(control_connection_t *conn, uint32_t len,
const char *body)
{
char *desc;
- int v0 = STATE_IS_V0(conn->_base.state);
const char *msg=NULL;
uint8_t purpose = ROUTER_PURPOSE_GENERAL;
- if (v0)
- desc = (char*)body;
- else {
+ if (1) {
char *cp = memchr(body, '\n', len);
smartlist_t *args = smartlist_create();
tor_assert(cp);
@@ -2407,25 +1990,18 @@ handle_control_postdescriptor(control_connection_t *conn, uint32_t len,
switch (router_load_single_router(desc, purpose, &msg)) {
case -1:
if (!msg) msg = "Could not parse descriptor";
- if (v0)
- send_control0_error(conn,ERR_SYNTAX,msg);
- else
- connection_printf_to_buf(conn, "554 %s\r\n", msg);
+ connection_printf_to_buf(conn, "554 %s\r\n", msg);
break;
case 0:
if (!msg) msg = "Descriptor not added";
- if (v0)
- send_control_done2(conn,msg,0);
- else
- connection_printf_to_buf(conn, "251 %s\r\n",msg);
+ connection_printf_to_buf(conn, "251 %s\r\n",msg);
break;
case 1:
send_control_done(conn);
break;
}
- if (!v0)
- tor_free(desc);
+ tor_free(desc);
return 0;
}
@@ -2436,26 +2012,11 @@ handle_control_redirectstream(control_connection_t *conn, uint32_t len,
const char *body)
{
edge_connection_t *ap_conn = NULL;
- uint32_t conn_id;
char *new_addr = NULL;
uint16_t new_port = 0;
- if (STATE_IS_V0(conn->_base.state)) {
- if (len < 6) {
- send_control0_error(conn, ERR_SYNTAX,
- "redirectstream message too short");
- return 0;
- }
- conn_id = ntohl(get_uint32(body));
+ (void) len;
- if (!(ap_conn = connection_get_by_global_id(conn_id))
- || ap_conn->_base.state != CONN_TYPE_AP
- || ap_conn->socks_request) {
- send_control0_error(conn, ERR_NO_STREAM,
- "No AP connection found with given ID");
- return 0;
- }
- new_addr = tor_strdup(body+4);
- } else {
+ if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
@@ -2504,25 +2065,9 @@ handle_control_closestream(control_connection_t *conn, uint32_t len,
{
edge_connection_t *ap_conn=NULL;
uint8_t reason=0;
+ (void) len;
- if (STATE_IS_V0(conn->_base.state)) {
- uint32_t conn_id;
- if (len < 6) {
- send_control0_error(conn, ERR_SYNTAX, "closestream message too short");
- return 0;
- }
-
- conn_id = ntohl(get_uint32(body));
- reason = *(uint8_t*)(body+4);
-
- if (!(ap_conn = connection_get_by_global_id(conn_id))
- || ap_conn->_base.state != CONN_TYPE_AP
- || ap_conn->socks_request) {
- send_control0_error(conn, ERR_NO_STREAM,
- "No AP connection found with given ID");
- return 0;
- }
- } else {
+ if (1) {
smartlist_t *args;
int ok;
args = smartlist_create();
@@ -2562,22 +2107,9 @@ handle_control_closecircuit(control_connection_t *conn, uint32_t len,
{
origin_circuit_t *circ = NULL;
int safe = 0;
+ (void) len;
- if (STATE_IS_V0(conn->_base.state)) {
- uint32_t circ_id;
- if (len < 5) {
- send_control0_error(conn, ERR_SYNTAX, "closecircuit message too short");
- return 0;
- }
- circ_id = ntohl(get_uint32(body));
- safe = (*(uint8_t*)(body+4)) & 1;
-
- if (!(circ = circuit_get_by_global_id(circ_id))) {
- send_control0_error(conn, ERR_NO_CIRC,
- "No circuit found with given ID");
- return 0;
- }
- } else {
+ if (1) {
smartlist_t *args;
args = smartlist_create();
smartlist_split_string(args, body, " ",
@@ -2623,7 +2155,6 @@ handle_control_usefeature(control_connection_t *conn,
int verbose_names = 0, extended_events = 0;
int bad = 0;
(void) len; /* body is nul-terminated; it's safe to ignore the length */
- tor_assert(! STATE_IS_V0(conn->_base.state));
args = smartlist_create();
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@@ -2662,52 +2193,6 @@ handle_control_usefeature(control_connection_t *conn,
return 0;
}
-/** Called when we get a v0 FRAGMENTHEADER or FRAGMENT command; try to append
- * the data to conn->incoming_cmd, setting conn->incoming_(type|len|cur_len)
- * as appropriate. If the command is malformed, drop it and all pending
- * fragments and report failure.
- */
-static int
-handle_control_fragments(control_connection_t *conn, uint16_t command_type,
- uint32_t body_len, const char *body)
-{
- if (command_type == CONTROL0_CMD_FRAGMENTHEADER) {
- if (conn->incoming_cmd) {
- log_warn(LD_CONTROL, "Dropping incomplete fragmented command; new "
- "fragmented command was begun.");
- tor_free(conn->incoming_cmd);
- }
- if (body_len < 6) {
- send_control0_error(conn, ERR_SYNTAX, "FRAGMENTHEADER too short.");
- return 0;
- }
- conn->incoming_cmd_type = ntohs(get_uint16(body));
- conn->incoming_cmd_len = ntohl(get_uint32(body+2));
- conn->incoming_cmd_cur_len = 0;
- conn->incoming_cmd = tor_malloc(conn->incoming_cmd_len);
- body += 6;
- body_len -= 6;
- } else if (command_type == CONTROL0_CMD_FRAGMENT) {
- if (!conn->incoming_cmd) {
- send_control0_error(conn, ERR_SYNTAX, "Out-of-place FRAGMENT");
- return 0;
- }
- } else {
- tor_assert(0);
- }
-
- if (conn->incoming_cmd_cur_len + body_len > conn->incoming_cmd_len) {
- tor_free(conn->incoming_cmd);
- send_control0_error(conn, ERR_SYNTAX,
- "Fragmented data exceeds declared length");
- return 0;
- }
- memcpy(conn->incoming_cmd + conn->incoming_cmd_cur_len,
- body, body_len);
- conn->incoming_cmd_cur_len += body_len;
- return 0;
-}
-
/** Called when <b>conn</b> has no more bytes left on its outbuf. */
int
connection_control_finished_flushing(control_connection_t *conn)
@@ -2732,16 +2217,16 @@ connection_control_reached_eof(control_connection_t *conn)
/** Called when data has arrived on a v1 control connection: Try to fetch
* commands from conn->inbuf, and execute them.
*/
-static int
-connection_control_process_inbuf_v1(control_connection_t *conn)
+int
+connection_control_process_inbuf(control_connection_t *conn)
{
size_t data_len;
int cmd_len;
char *args;
tor_assert(conn);
- tor_assert(conn->_base.state == CONTROL_CONN_STATE_OPEN_V1 ||
- conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH_V1);
+ tor_assert(conn->_base.state == CONTROL_CONN_STATE_OPEN ||
+ conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH);
if (!conn->incoming_cmd) {
conn->incoming_cmd = tor_malloc(1024);
@@ -2749,6 +2234,23 @@ connection_control_process_inbuf_v1(control_connection_t *conn)
conn->incoming_cmd_cur_len = 0;
}
+ if (conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH &&
+ peek_buf_has_control0_command(conn->_base.inbuf)) {
+ /* Detect v0 commands and send a "no more v0" message. */
+ size_t body_len;
+ char buf[128];
+ set_uint16(buf+2, htons(0x0000)); /* type == error */
+ set_uint16(buf+4, htons(0x0001)); /* code == internal error */
+ strlcpy(buf+6, "The v0 control protocol no longer supported in "VERSION"; "
+ "use Tor 0.1.2.x or upgrade your controller", sizeof(buf)-6);
+ body_len = 2+strlen(buf+6)+2; /* code, msg, nul. */
+ set_uint16(buf+0, htons(body_len));
+ connection_write_to_buf(buf, 4+body_len, TO_CONN(conn));
+ connection_mark_for_close(TO_CONN(conn));
+ conn->_base.hold_open_until_flushed = 1;
+ return 0;
+ }
+
again:
while (1) {
size_t last_idx;
@@ -2810,7 +2312,7 @@ connection_control_process_inbuf_v1(control_connection_t *conn)
return 0;
}
- if (conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH_V1 &&
+ if (conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH &&
strcasecmp(conn->incoming_cmd, "AUTHENTICATE")) {
connection_write_str_to_buf("514 Authentication required.\r\n", conn);
conn->incoming_cmd_cur_len = 0;
@@ -2880,179 +2382,6 @@ connection_control_process_inbuf_v1(control_connection_t *conn)
goto again;
}
-/** Called when data has arrived on a v0 control connection: Try to fetch
- * commands from conn->inbuf, and execute them.
- */
-static int
-connection_control_process_inbuf_v0(control_connection_t *conn)
-{
- uint32_t body_len;
- uint16_t command_type;
- char *body=NULL;
- static int have_warned_about_v0_protocol = 0;
-
- again:
- /* Try to suck a control message from the buffer. */
- switch (fetch_from_buf_control0(conn->_base.inbuf, &body_len, &command_type,
- &body,
- conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH_V0))
- {
- case -2:
- tor_free(body);
- log_info(LD_CONTROL,
- "Detected v1 control protocol on connection (fd %d)",
- conn->_base.s);
- conn->_base.state = CONTROL_CONN_STATE_NEEDAUTH_V1;
- return connection_control_process_inbuf_v1(conn);
- case -1:
- tor_free(body);
- log_warn(LD_CONTROL, "Error in control command. Failing.");
- return -1;
- case 0:
- /* Control command not all here yet. Wait. */
- return 0;
- case 1:
- /* We got a command. Process it. */
- break;
- default:
- tor_assert(0);
- }
-
- if (!have_warned_about_v0_protocol) {
- log_warn(LD_CONTROL, "An application has connected to us using the "
- "version 0 control prototol, which has been deprecated since "
- "Tor 0.1.1.1-alpha. This protocol will not be supported by "
- "future versions of Tor; please use the v1 control protocol "
- "instead.");
- have_warned_about_v0_protocol = 1;
- }
-
- /* We got a command. If we need authentication, only authentication
- * commands will be considered. */
- if (conn->_base.state == CONTROL_CONN_STATE_NEEDAUTH_V0 &&
- command_type != CONTROL0_CMD_AUTHENTICATE) {
- log_info(LD_CONTROL, "Rejecting '%s' command; authentication needed.",
- control_cmd_to_string(command_type));
- send_control0_error(conn, ERR_UNAUTHORIZED, "Authentication required");
- tor_free(body);
- goto again;
- }
-
- if (command_type == CONTROL0_CMD_FRAGMENTHEADER ||
- command_type == CONTROL0_CMD_FRAGMENT) {
- if (handle_control_fragments(conn, command_type, body_len, body))
- return -1;
- tor_free(body);
- if (conn->incoming_cmd_cur_len != conn->incoming_cmd_len)
- goto again;
-
- command_type = conn->incoming_cmd_type;
- body_len = conn->incoming_cmd_len;
- body = conn->incoming_cmd;
- conn->incoming_cmd = NULL;
- } else if (conn->incoming_cmd) {
- log_warn(LD_CONTROL, "Dropping incomplete fragmented command");
- tor_free(conn->incoming_cmd);
- }
-
- /* Okay, we're willing to process the command. */
- switch (command_type)
- {
- case CONTROL0_CMD_SETCONF:
- if (handle_control_setconf(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_GETCONF:
- if (handle_control_getconf(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_SETEVENTS:
- if (handle_control_setevents(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_AUTHENTICATE:
- if (handle_control_authenticate(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_SAVECONF:
- if (handle_control_saveconf(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_SIGNAL:
- if (handle_control_signal(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_MAPADDRESS:
- if (handle_control_mapaddress(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_GETINFO:
- if (handle_control_getinfo(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_EXTENDCIRCUIT:
- if (handle_control_extendcircuit(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_ATTACHSTREAM:
- if (handle_control_attachstream(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_POSTDESCRIPTOR:
- if (handle_control_postdescriptor(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_REDIRECTSTREAM:
- if (handle_control_redirectstream(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_CLOSESTREAM:
- if (handle_control_closestream(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_CLOSECIRCUIT:
- if (handle_control_closecircuit(conn, body_len, body))
- return -1;
- break;
- case CONTROL0_CMD_ERROR:
- case CONTROL0_CMD_DONE:
- case CONTROL0_CMD_CONFVALUE:
- case CONTROL0_CMD_EVENT:
- case CONTROL0_CMD_INFOVALUE:
- log_warn(LD_CONTROL, "Received client-only '%s' command; ignoring.",
- control_cmd_to_string(command_type));
- send_control0_error(conn, ERR_UNRECOGNIZED_TYPE,
- "Command type only valid from server to tor client");
- break;
- case CONTROL0_CMD_FRAGMENTHEADER:
- case CONTROL0_CMD_FRAGMENT:
- log_warn(LD_CONTROL,
- "Recieved command fragment out of order; ignoring.");
- send_control0_error(conn, ERR_SYNTAX, "Bad fragmentation on command.");
- default:
- log_warn(LD_CONTROL, "Received unrecognized command type %d; ignoring.",
- (int)command_type);
- send_control0_error(conn, ERR_UNRECOGNIZED_TYPE,
- "Unrecognized command type");
- break;
- }
- tor_free(body);
- goto again; /* There might be more data. */
-}
-
-/** Called when <b>conn</b> has received more bytes on its inbuf.
- */
-int
-connection_control_process_inbuf(control_connection_t *conn)
-{
- tor_assert(conn);
-
- if (STATE_IS_V0(conn->_base.state))
- return connection_control_process_inbuf_v0(conn);
- else
- return connection_control_process_inbuf_v1(conn);
-}
-
/** Convert a numeric reason for destroying a circuit into a string for a
* CIRCUIT event. */
static const char *
@@ -3105,25 +2434,15 @@ int
control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp,
int reason_code)
{
- char *path=NULL, *msg;
+ char *path=NULL;
if (!EVENT_IS_INTERESTING(EVENT_CIRCUIT_STATUS))
return 0;
tor_assert(circ);
- if (EVENT_IS_INTERESTING0(EVENT_CIRCUIT_STATUS) ||
- EVENT_IS_INTERESTING1S(EVENT_CIRCUIT_STATUS))
+ if (EVENT_IS_INTERESTING1S(EVENT_CIRCUIT_STATUS))
path = circuit_list_path(circ,0);
- if (EVENT_IS_INTERESTING0(EVENT_CIRCUIT_STATUS)) {
- size_t path_len = strlen(path);
- msg = tor_malloc(1+4+path_len+1); /* event, circid, path, NUL. */
- msg[0] = (uint8_t) tp;
- set_uint32(msg+1, htonl(circ->global_identifier));
- strlcpy(msg+5,path,path_len+1);
-
- send_control0_event(EVENT_CIRCUIT_STATUS, (uint32_t)(path_len+6), msg);
- tor_free(msg);
- }
- if (EVENT_IS_INTERESTING1(EVENT_CIRCUIT_STATUS)) {
+
+ if (1) {
const char *status;
char reason_buf[64];
int providing_reason=0;
@@ -3161,12 +2480,12 @@ control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp,
if (EVENT_IS_INTERESTING1S(EVENT_CIRCUIT_STATUS)) {
const char *sp = strlen(path) ? " " : "";
if (providing_reason)
- send_control1_event_extended(EVENT_CIRCUIT_STATUS, SHORT_NAMES,
+ send_control_event_extended(EVENT_CIRCUIT_STATUS, SHORT_NAMES,
"650 CIRC %lu %s%s%s@%s\r\n",
(unsigned long)circ->global_identifier,
status, sp, path, reason_buf);
else
- send_control1_event_extended(EVENT_CIRCUIT_STATUS, SHORT_NAMES,
+ send_control_event_extended(EVENT_CIRCUIT_STATUS, SHORT_NAMES,
"650 CIRC %lu %s%s%s\r\n",
(unsigned long)circ->global_identifier,
status, sp, path);
@@ -3175,12 +2494,12 @@ control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t tp,
char *vpath = circuit_list_path_for_controller(circ);
const char *sp = strlen(vpath) ? " " : "";
if (providing_reason)
- send_control1_event_extended(EVENT_CIRCUIT_STATUS, LONG_NAMES,
+ send_control_event_extended(EVENT_CIRCUIT_STATUS, LONG_NAMES,
"650 CIRC %lu %s%s%s@%s\r\n",
(unsigned long)circ->global_identifier,
status, sp, vpath, reason_buf);
else
- send_control1_event_extended(EVENT_CIRCUIT_STATUS, LONG_NAMES,
+ send_control_event_extended(EVENT_CIRCUIT_STATUS, LONG_NAMES,
"650 CIRC %lu %s%s%s\r\n",
(unsigned long)circ->global_identifier,
status, sp, vpath);
@@ -3248,8 +2567,6 @@ int
control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp,
int reason_code)
{
- char *msg;
- size_t len;
char buf[256];
tor_assert(conn->socks_request);
@@ -3261,17 +2578,8 @@ control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp,
return 0;
write_stream_target_to_buf(conn, buf, sizeof(buf));
- if (EVENT_IS_INTERESTING0(EVENT_STREAM_STATUS)) {
- len = strlen(buf);
- msg = tor_malloc(5+len+1);
- msg[0] = (uint8_t) tp;
- set_uint32(msg+1, htonl(conn->global_identifier));
- strlcpy(msg+5, buf, len+1);
-
- send_control0_event(EVENT_STREAM_STATUS, (uint32_t)(5+len+1), msg);
- tor_free(msg);
- }
- if (EVENT_IS_INTERESTING1(EVENT_STREAM_STATUS)) {
+
+ if (1) {
char reason_buf[64];
const char *status;
circuit_t *circ;
@@ -3326,7 +2634,7 @@ control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp,
circ = circuit_get_by_edge_conn(conn);
if (circ && CIRCUIT_IS_ORIGIN(circ))
origin_circ = TO_ORIGIN_CIRCUIT(circ);
- send_control1_event_extended(EVENT_STREAM_STATUS, ALL_NAMES,
+ send_control_event_extended(EVENT_STREAM_STATUS, ALL_NAMES,
"650 STREAM %lu %s %lu %s@%s\r\n",
(unsigned long)conn->global_identifier, status,
origin_circ?
@@ -3430,20 +2738,12 @@ int
control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp,
int reason)
{
- char buf[HEX_DIGEST_LEN+3]; /* status, dollar, identity, NUL */
- size_t len;
int ncircs = 0;
if (!EVENT_IS_INTERESTING(EVENT_OR_CONN_STATUS))
return 0;
- if (EVENT_IS_INTERESTING0(EVENT_OR_CONN_STATUS)) {
- buf[0] = (uint8_t)tp;
- 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)) {
+ if (1) {
const char *status;
char name[128];
char ncircs_buf[32] = {0}; /* > 8 + log10(2^32)=10 + 2 */
@@ -3467,14 +2767,14 @@ control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp,
if (EVENT_IS_INTERESTING1S(EVENT_OR_CONN_STATUS)) {
orconn_target_get_name(0, name, sizeof(name), conn);
- send_control1_event_extended(EVENT_OR_CONN_STATUS, SHORT_NAMES,
+ send_control_event_extended(EVENT_OR_CONN_STATUS, SHORT_NAMES,
"650 ORCONN %s %s@%s%s\r\n",
name, status,
or_conn_end_reason_to_string(reason), ncircs_buf);
}
if (EVENT_IS_INTERESTING1L(EVENT_OR_CONN_STATUS)) {
orconn_target_get_name(1, name, sizeof(name), conn);
- send_control1_event_extended(EVENT_OR_CONN_STATUS, LONG_NAMES,
+ send_control_event_extended(EVENT_OR_CONN_STATUS, LONG_NAMES,
"650 ORCONN %s %s@%s%s\r\n",
name, status,
or_conn_end_reason_to_string(reason), ncircs_buf);
@@ -3492,8 +2792,7 @@ control_event_stream_bandwidth_used(void)
edge_connection_t *conn;
int n, i;
- if (EVENT_IS_INTERESTING1(EVENT_STREAM_BANDWIDTH_USED)) {
-
+ if (EVENT_IS_INTERESTING(EVENT_STREAM_BANDWIDTH_USED)) {
get_connection_array(&carray, &n);
for (i = 0; i < n; ++i) {
@@ -3503,7 +2802,7 @@ control_event_stream_bandwidth_used(void)
if (!conn->n_read && !conn->n_written)
continue;
- send_control1_event(EVENT_STREAM_BANDWIDTH_USED, ALL_NAMES,
+ send_control_event(EVENT_STREAM_BANDWIDTH_USED, ALL_NAMES,
"650 STREAM_BW %lu %lu %lu\r\n",
(unsigned long)conn->global_identifier,
(unsigned long)conn->n_read,
@@ -3521,15 +2820,8 @@ control_event_stream_bandwidth_used(void)
int
control_event_bandwidth_used(uint32_t n_read, uint32_t n_written)
{
- char buf[8];
-
- if (EVENT_IS_INTERESTING0(EVENT_BANDWIDTH_USED)) {
- set_uint32(buf, htonl(n_read));
- set_uint32(buf+4, htonl(n_written));
- send_control0_event(EVENT_BANDWIDTH_USED, 8, buf);
- }
- if (EVENT_IS_INTERESTING1(EVENT_BANDWIDTH_USED)) {
- send_control1_event(EVENT_BANDWIDTH_USED, ALL_NAMES,
+ if (EVENT_IS_INTERESTING(EVENT_BANDWIDTH_USED)) {
+ send_control_event(EVENT_BANDWIDTH_USED, ALL_NAMES,
"650 BW %lu %lu\r\n",
(unsigned long)n_read,
(unsigned long)n_written);
@@ -3560,7 +2852,7 @@ enable_control_logging(void)
void
control_event_logmsg(int severity, uint32_t domain, const char *msg)
{
- int oldlog, event;
+ int event;
if (disable_log_messages)
return;
@@ -3574,25 +2866,8 @@ control_event_logmsg(int severity, uint32_t domain, const char *msg)
tor_free(esc);
}
- oldlog = EVENT_IS_INTERESTING0(EVENT_LOG_OBSOLETE) &&
- (severity == LOG_NOTICE || severity == LOG_WARN || severity == LOG_ERR);
event = log_severity_to_event(severity);
-
- if (event<0 || !EVENT_IS_INTERESTING0(event))
- event = 0;
-
- if (oldlog || event) {
- size_t len = strlen(msg);
- ++disable_log_messages;
- if (event)
- send_control0_event(event, (uint32_t)(len+1), msg);
- if (oldlog)
- send_control0_event(EVENT_LOG_OBSOLETE, (uint32_t)(len+1), msg);
- --disable_log_messages;
- }
-
- event = log_severity_to_event(severity);
- if (event >= 0 && EVENT_IS_INTERESTING1(event)) {
+ if (event >= 0 && EVENT_IS_INTERESTING(event)) {
char *b = NULL;
const char *s;
if (strchr(msg, '\n')) {
@@ -3611,7 +2886,7 @@ control_event_logmsg(int severity, uint32_t domain, const char *msg)
default: s = "UnknownLogSeverity"; break;
}
++disable_log_messages;
- send_control1_event(event, ALL_NAMES, "650 %s %s\r\n", s, b?b:msg);
+ send_control_event(event, ALL_NAMES, "650 %s %s\r\n", s, b?b:msg);
--disable_log_messages;
tor_free(b);
}
@@ -3631,8 +2906,7 @@ control_event_descriptors_changed(smartlist_t *routers)
if (!EVENT_IS_INTERESTING(EVENT_NEW_DESC))
return 0;
- if (EVENT_IS_INTERESTING0(EVENT_NEW_DESC) ||
- EVENT_IS_INTERESTING1S(EVENT_NEW_DESC)) {
+ if (EVENT_IS_INTERESTING1S(EVENT_NEW_DESC)) {
identities = smartlist_create();
SMARTLIST_FOREACH(routers, routerinfo_t *, r,
{
@@ -3640,17 +2914,12 @@ control_event_descriptors_changed(smartlist_t *routers)
smartlist_add(identities, tor_strdup(buf));
});
}
- if (EVENT_IS_INTERESTING0(EVENT_NEW_DESC)) {
- msg = smartlist_join_strings(identities, ",", 0, &len);
- send_control0_event(EVENT_NEW_DESC, len+1, msg);
- tor_free(msg);
- }
if (EVENT_IS_INTERESTING1S(EVENT_NEW_DESC)) {
char *ids = smartlist_join_strings(identities, " ", 0, &len);
size_t len = strlen(ids)+32;
msg = tor_malloc(len);
tor_snprintf(msg, len, "650 NEWDESC %s\r\n", ids);
- send_control1_event_string(EVENT_NEW_DESC, SHORT_NAMES|ALL_FORMATS, msg);
+ send_control_event_string(EVENT_NEW_DESC, SHORT_NAMES|ALL_FORMATS, msg);
tor_free(ids);
tor_free(msg);
}
@@ -3667,7 +2936,7 @@ control_event_descriptors_changed(smartlist_t *routers)
len = strlen(ids)+32;
msg = tor_malloc(len);
tor_snprintf(msg, len, "650 NEWDESC %s\r\n", ids);
- send_control1_event_string(EVENT_NEW_DESC, LONG_NAMES|ALL_FORMATS, msg);
+ send_control_event_string(EVENT_NEW_DESC, LONG_NAMES|ALL_FORMATS, msg);
tor_free(ids);
tor_free(msg);
SMARTLIST_FOREACH(names, char *, cp, tor_free(cp));
@@ -3685,16 +2954,16 @@ control_event_descriptors_changed(smartlist_t *routers)
int
control_event_address_mapped(const char *from, const char *to, time_t expires)
{
- if (!EVENT_IS_INTERESTING1(EVENT_ADDRMAP))
+ if (!EVENT_IS_INTERESTING(EVENT_ADDRMAP))
return 0;
if (expires < 3)
- send_control1_event(EVENT_ADDRMAP, ALL_NAMES,
+ send_control_event(EVENT_ADDRMAP, ALL_NAMES,
"650 ADDRMAP %s %s NEVER\r\n", from, to);
else {
char buf[ISO_TIME_LEN+1];
format_local_iso_time(buf,expires);
- send_control1_event(EVENT_ADDRMAP, ALL_NAMES,
+ send_control_event(EVENT_ADDRMAP, ALL_NAMES,
"650 ADDRMAP %s %s \"%s\"\r\n",
from, to, buf);
}
@@ -3733,7 +3002,7 @@ control_event_or_authdir_new_descriptor(const char *action,
buf = tor_malloc(totallen);
strlcpy(buf, firstline, totallen);
strlcpy(buf+strlen(firstline), esc, totallen);
- send_control1_event_string(EVENT_AUTHDIR_NEWDESCS, ALL_NAMES|ALL_FORMATS,
+ send_control_event_string(EVENT_AUTHDIR_NEWDESCS, ALL_NAMES|ALL_FORMATS,
buf);
tor_free(esc);
@@ -3765,7 +3034,7 @@ control_event_networkstatus_changed(smartlist_t *statuses)
s = smartlist_join_strings(strs, "", 0, NULL);
SMARTLIST_FOREACH(strs, char *, cp, tor_free(cp));
smartlist_free(strs);
- send_control1_event_string(EVENT_NS, ALL_NAMES|ALL_FORMATS, s);
+ send_control_event_string(EVENT_NS, ALL_NAMES|ALL_FORMATS, s);
tor_free(s);
return 0;
}
@@ -3793,7 +3062,7 @@ control_event_networkstatus_changed_single(local_routerstatus_t *rs)
int
control_event_my_descriptor_changed(void)
{
- send_control1_event(EVENT_DESCCHANGED, ALL_NAMES, "650 DESCCHANGED\r\n");
+ send_control_event(EVENT_DESCCHANGED, ALL_NAMES, "650 DESCCHANGED\r\n");
return 0;
}
@@ -3841,7 +3110,7 @@ control_event_status(int type, int severity, const char *format, va_list args)
return -1;
}
- send_control1_event_impl(type, ALL_NAMES|ALL_FORMATS, 0, format_buf, args);
+ send_control_event_impl(type, ALL_NAMES|ALL_FORMATS, 0, format_buf, args);
return 0;
}
@@ -3852,7 +3121,7 @@ control_event_general_status(int severity, const char *format, ...)
{
va_list ap;
int r;
- if (!EVENT_IS_INTERESTING1(EVENT_STATUS_GENERAL))
+ if (!EVENT_IS_INTERESTING(EVENT_STATUS_GENERAL))
return 0;
va_start(ap, format);
@@ -3868,7 +3137,7 @@ control_event_client_status(int severity, const char *format, ...)
{
va_list ap;
int r;
- if (!EVENT_IS_INTERESTING1(EVENT_STATUS_CLIENT))
+ if (!EVENT_IS_INTERESTING(EVENT_STATUS_CLIENT))
return 0;
va_start(ap, format);
@@ -3884,7 +3153,7 @@ control_event_server_status(int severity, const char *format, ...)
{
va_list ap;
int r;
- if (!EVENT_IS_INTERESTING1(EVENT_STATUS_SERVER))
+ if (!EVENT_IS_INTERESTING(EVENT_STATUS_SERVER))
return 0;
va_start(ap, format);
@@ -3902,7 +3171,7 @@ control_event_guard(const char *nickname, const char *digest,
{
char hbuf[HEX_DIGEST_LEN+1];
base16_encode(hbuf, sizeof(hbuf), digest, DIGEST_LEN);
- if (!EVENT_IS_INTERESTING1(EVENT_GUARD))
+ if (!EVENT_IS_INTERESTING(EVENT_GUARD))
return 0;
if (EVENT_IS_INTERESTING1L(EVENT_GUARD)) {
@@ -3913,11 +3182,11 @@ control_event_guard(const char *nickname, const char *digest,
} else {
tor_snprintf(buf, sizeof(buf), "$%s~%s", hbuf, nickname);
}
- send_control1_event(EVENT_GUARD, LONG_NAMES,
+ send_control_event(EVENT_GUARD, LONG_NAMES,
"650 GUARD ENTRY %s %s\r\n", buf, status);
}
if (EVENT_IS_INTERESTING1S(EVENT_GUARD)) {
- send_control1_event(EVENT_GUARD, SHORT_NAMES,
+ send_control_event(EVENT_GUARD, SHORT_NAMES,
"650 GUARD ENTRY $%s %s\r\n", hbuf, status);
}
return 0;
diff --git a/src/or/or.h b/src/or/or.h
index 585645c8c..8aff19a7f 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -341,18 +341,12 @@ typedef enum {
#define DIR_CONN_IS_SERVER(conn) ((conn)->purpose == DIR_PURPOSE_SERVER)
#define _CONTROL_CONN_STATE_MIN 1
-/** State for a control connection: Authenticated and accepting v0 commands. */
-#define CONTROL_CONN_STATE_OPEN_V0 1
/** State for a control connection: Authenticated and accepting v1 commands. */
-#define CONTROL_CONN_STATE_OPEN_V1 2
-/** State for a control connection: Waiting for authentication; either
- * speaking v0 commands or waiting for evidence that it's a v1
- * connection. */
-#define CONTROL_CONN_STATE_NEEDAUTH_V0 3
+#define CONTROL_CONN_STATE_OPEN 1
/** State for a control connection: Waiting for authentication; speaking
* protocol v1. */
-#define CONTROL_CONN_STATE_NEEDAUTH_V1 4
-#define _CONTROL_CONN_STATE_MAX 4
+#define CONTROL_CONN_STATE_NEEDAUTH 2
+#define _CONTROL_CONN_STATE_MAX 2
#define _DIR_PURPOSE_MIN 1
/** A connection to a directory server: download a directory. */
@@ -1929,11 +1923,11 @@ int fetch_from_buf_http(buf_t *buf,
int force_complete);
int fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
int log_sockstype, int safe_socks);
-int fetch_from_buf_control0(buf_t *buf, uint32_t *len_out, uint16_t *type_out,
- char **body_out, int check_for_v1);
int fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len);
int fetch_from_buf_line_lf(buf_t *buf, char *data_out, size_t *data_len);
+int peek_buf_has_control0_command(buf_t *buf);
+
void assert_buf_ok(buf_t *buf);
/********************************* circuitbuild.c **********************/