aboutsummaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2005-03-22 00:42:38 +0000
committerRoger Dingledine <arma@torproject.org>2005-03-22 00:42:38 +0000
commit35953edae073e69efe06f4ea313066b514b772a0 (patch)
tree3f89981b90370e5c4c727e3b86905813871828d9 /src/or/control.c
parent5d5b12ce750e60041f7654449129fe268ed76a2e (diff)
downloadtor-35953edae073e69efe06f4ea313066b514b772a0.tar
tor-35953edae073e69efe06f4ea313066b514b772a0.tar.gz
Implement controller's "extendcircuit" directive.
Also refactor circuit building so we plan the whole path ahead of time. svn:r3797
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/or/control.c b/src/or/control.c
index e8f6d0e35..39e82c166 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -642,12 +642,6 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
send_control_error(conn, ERR_SYNTAX, "extendcircuit message too short");
return 0;
}
- circ_id = ntohl(get_uint32(body));
- if (!(circ = circuit_get_by_global_id(circ_id))) {
- send_control_error(conn, ERR_NO_STREAM,
- "No connection found with given ID");
- return 0;
- }
router_nicknames = smartlist_create();
routers = smartlist_create();
@@ -661,20 +655,45 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
}
smartlist_add(routers, r);
});
+ if (!smartlist_len(routers)) {
+ send_control_error(conn, ERR_SYNTAX, "No router names provided");
+ goto done;
+ }
+
+ circ_id = ntohl(get_uint32(body));
+ if (!circ_id) {
+ /* start a new circuit */
+ circ = circuit_init(CIRCUIT_PURPOSE_C_GENERAL, 0, 0, 0);
+ } else {
+ circ = circuit_get_by_global_id(circ_id);
+ if (!circ) {
+ send_control_error(conn, ERR_NO_CIRC,
+ "No circuit found with given ID");
+ goto done;
+ }
+ }
+
+ /* now circ refers to something that is ready to be extended */
-#if 1
- /*XXXX RD*/
- send_control_error(conn, ERR_INTERNAL, "EXTENDCIRCUIT not implemented.");
-#else
SMARTLIST_FOREACH(routers, routerinfo_t *, r,
{
- /*XXXX RD*/
- if (circuit_extend_path(circ, r)<0) {
- send_control_error(conn, ERR_INTERNAL, "Unable to extend path.");
- goto done;
- }
+ circuit_append_new_exit(circ, r);
});
-#endif
+
+ /* now that we've populated the cpath, start extending */
+ if (!circ_id) {
+ if (circuit_handle_first_hop(circ) < 0) {
+ circuit_mark_for_close(circ);
+ }
+ } else {
+ if (circ->state == CIRCUIT_STATE_OPEN) {
+ circ->state = CIRCUIT_STATE_BUILDING;
+ if (circuit_send_next_onion_skin(circ) < 0) {
+ log_fn(LOG_INFO,"send_next_onion_skin failed; circuit marked for closing.");
+ circuit_mark_for_close(circ);
+ }
+ }
+ }
send_control_done(conn);
done: