[or-cvs] Add a new circuit purpose "controller" to let the controller
arma at seul.org
arma at seul.org
Thu Feb 23 06:51:11 UTC 2006
Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv18546
Modified Files:
control.c or.h
Log Message:
Add a new circuit purpose 'controller' to let the controller
ask for a circuit that Tor won't try to use.
Extend the EXTENDCIRCUIT controller command to let you specify
the purpose if you're starting a new circuit.
Add a new SETCIRCUITPURPOSE controller command to let you
change a circuit's purpose after it's been created.
Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -p -d -r1.170 -r1.171
--- control.c 20 Feb 2006 01:24:26 -0000 1.170
+++ control.c 23 Feb 2006 06:51:09 -0000 1.171
@@ -169,6 +169,8 @@ static int handle_control_getinfo(connec
const char *body);
static int handle_control_extendcircuit(connection_t *conn, uint32_t len,
const char *body);
+static int handle_control_setcircuitpurpose(connection_t *conn, uint32_t len,
+ const char *body);
static int handle_control_attachstream(connection_t *conn, uint32_t len,
const char *body);
static int handle_control_postdescriptor(connection_t *conn, uint32_t len,
@@ -1541,6 +1543,25 @@ handle_control_getinfo(connection_t *con
return 0;
}
+/** If <b>string</b> contains a recognized circuit purpose,
+ * possibly prefaced with the string "purpose=", then assign it
+ * and return 0. Otherwise return -1. */
+static int
+get_purpose(char *string, uint8_t *purpose)
+{
+ if (!strcmpstart(string, "purpose="))
+ string += strlen("purpose=");
+
+ if (!strcmp(string, "general"))
+ *purpose = CIRCUIT_PURPOSE_C_GENERAL;
+ else if (!strcmp(string, "controller"))
+ *purpose = CIRCUIT_PURPOSE_CONTROLLER;
+ else { /* not a recognized purpose */
+ return -1;
+ }
+ return 0;
+}
+
/** Called when we get an EXTENDCIRCUIT message. Try to extend the listed
* circuit, and report success or failure. */
static int
@@ -1552,6 +1573,7 @@ handle_control_extendcircuit(connection_
circuit_t *circ = NULL;
int zero_circ, v0;
char reply[4];
+ uint8_t intended_purpose = CIRCUIT_PURPOSE_C_GENERAL;
v0 = STATE_IS_V0(conn->state);
router_nicknames = smartlist_create();
@@ -1600,6 +1622,13 @@ handle_control_extendcircuit(connection_
if (!zero_circ && !circ) {
goto done;
}
+ if (zero_circ && smartlist_len(args)>2) {
+ if (get_purpose(smartlist_get(args,2), &intended_purpose) < 0) {
+ connection_printf_to_buf(conn, "552 Unknown purpose \"%s\"\r\n",
+ (char *)smartlist_get(args,2));
+ goto done;
+ }
+ }
}
routers = smartlist_create();
@@ -1625,7 +1654,7 @@ handle_control_extendcircuit(connection_
if (zero_circ) {
/* start a new circuit */
- circ = circuit_init(CIRCUIT_PURPOSE_C_GENERAL, 0, 0, 0);
+ circ = circuit_init(intended_purpose, 0, 0, 0);
}
/* now circ refers to something that is ready to be extended */
@@ -1677,6 +1706,44 @@ handle_control_extendcircuit(connection_
return 0;
}
+/** Called when we get a SETCIRCUITPURPOSE message. If we can find
+ * the circuit and it's a valid purpose, change it. */
+static int
+handle_control_setcircuitpurpose(connection_t *conn, uint32_t len,
+ const char *body)
+{
+ circuit_t *circ;
+ uint8_t new_purpose;
+ smartlist_t *args = smartlist_create();
+ smartlist_split_string(args, body, " ",
+ SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+ if (smartlist_len(args)<2) {
+ connection_printf_to_buf(conn,
+ "512 Missing argument to SETCIRCUITPURPOSE\r\n");
+ goto done;
+ }
+
+ if (!(circ = get_circ(smartlist_get(args,0)))) {
+ connection_printf_to_buf(conn, "552 Unknown circuit \"%s\"\r\n",
+ (char*)smartlist_get(args, 0));
+ goto done;
+ }
+
+ if (get_purpose(smartlist_get(args,1), &new_purpose) < 0) {
+ connection_printf_to_buf(conn, "552 Unknown purpose \"%s\"\r\n",
+ (char *)smartlist_get(args,1));
+ goto done;
+ }
+
+ circ->purpose = new_purpose;
+ connection_write_str_to_buf("250 OK\r\n", conn);
+
+done:
+ SMARTLIST_FOREACH(args, char *, cp, tor_free(cp));
+ smartlist_free(args);
+ return 0;
+}
+
/** Called when we get an ATTACHSTREAM message. Try to attach the requested
* stream, and report success or failure. */
static int
@@ -2187,6 +2254,9 @@ connection_control_process_inbuf_v1(conn
} else if (!strcasecmp(conn->incoming_cmd, "EXTENDCIRCUIT")) {
if (handle_control_extendcircuit(conn, data_len, args))
return -1;
+ } else if (!strcasecmp(conn->incoming_cmd, "SETCIRCUITPURPOSE")) {
+ if (handle_control_setcircuitpurpose(conn, data_len, args))
+ return -1;
} else if (!strcasecmp(conn->incoming_cmd, "ATTACHSTREAM")) {
if (handle_control_attachstream(conn, data_len, args))
return -1;
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.796
retrieving revision 1.797
diff -u -p -d -r1.796 -r1.797
--- or.h 19 Feb 2006 22:02:02 -0000 1.796
+++ or.h 23 Feb 2006 06:51:09 -0000 1.797
@@ -423,7 +423,9 @@ typedef enum {
#define CIRCUIT_PURPOSE_S_REND_JOINED 16
/** A testing circuit; not meant to be used for actual traffic. */
#define CIRCUIT_PURPOSE_TESTING 17
-#define _CIRCUIT_PURPOSE_MAX 17
+/** A controller made this circuit and Tor should not use it. */
+#define CIRCUIT_PURPOSE_CONTROLLER 18
+#define _CIRCUIT_PURPOSE_MAX 18
/** True iff the circuit purpose <b>p</b> is for a circuit that
* originated at this node. */
More information about the tor-commits
mailing list