diff options
author | Roger Dingledine <arma@torproject.org> | 2004-03-31 22:02:13 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-03-31 22:02:13 +0000 |
commit | a0b0d169816f819b2c59f56c9503380755fc35dc (patch) | |
tree | 3645d5cb53302d9f5e0d9fe53f40d014603db60a /src/or/directory.c | |
parent | 28adda81e6b035d9a592378b9635535bb0b673b6 (diff) | |
download | tor-a0b0d169816f819b2c59f56c9503380755fc35dc.tar tor-a0b0d169816f819b2c59f56c9503380755fc35dc.tar.gz |
Add an ap_bridge function to do a socketpair and skip socks.
This allows us to do a directory connection *through* tor just
as if we're doing it as an application.
Make ap_conns tolerate it when the application sends stuff before
The socks handshake is done (it just buffers it).
Tell directory_initiate_command the length of the payload (because
it might include nuls).
Add a directory_has_arrived function to, for example, start building
the rendezvous service descriptor.
svn:r1412
Diffstat (limited to 'src/or/directory.c')
-rw-r--r-- | src/or/directory.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 61b507eaf..06f49b692 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -4,8 +4,8 @@ #include "or.h" -static void directory_send_command(connection_t *conn, - int purpose, const char *payload); +static void directory_send_command(connection_t *conn, int purpose, + const char *payload, int payload_len); static int directory_handle_command(connection_t *conn); /********* START VARIABLES **********/ @@ -18,23 +18,18 @@ extern int has_fetched_directory; /********* END VARIABLES ************/ -void directory_initiate_command(routerinfo_t *router, int purpose, const char *payload) { +void directory_initiate_command(routerinfo_t *router, int purpose, + const char *payload, int payload_len) { connection_t *conn; - switch(purpose) { - case DIR_PURPOSE_FETCH_DIR: - log_fn(LOG_DEBUG,"initiating directory fetch"); - break; - case DIR_PURPOSE_FETCH_HIDSERV: - log_fn(LOG_DEBUG,"initiating hidden-service descriptor fetch"); - break; - case DIR_PURPOSE_UPLOAD_DIR: - log_fn(LOG_DEBUG,"initiating server descriptor upload"); - break; - case DIR_PURPOSE_UPLOAD_HIDSERV: - log_fn(LOG_DEBUG,"initiating hidden-service descriptor upload"); - break; - } + if(purpose == DIR_PURPOSE_FETCH_DIR) + log_fn(LOG_DEBUG,"initiating directory fetch"); + if(purpose == DIR_PURPOSE_FETCH_HIDSERV) + log_fn(LOG_DEBUG,"initiating hidden-service descriptor fetch"); + if(purpose == DIR_PURPOSE_UPLOAD_DIR) + log_fn(LOG_DEBUG,"initiating server descriptor upload"); + if(purpose == DIR_PURPOSE_UPLOAD_HIDSERV) + log_fn(LOG_DEBUG,"initiating hidden-service descriptor upload"); if (!router) { /* i guess they didn't have one in mind for me to use */ log_fn(LOG_WARN,"No running dirservers known. Not trying. (purpose %d)", purpose); @@ -59,7 +54,7 @@ void directory_initiate_command(routerinfo_t *router, int purpose, const char *p } /* queue the command on the outbuf */ - directory_send_command(conn, purpose, payload); + directory_send_command(conn, purpose, payload, payload_len); if(purpose == DIR_PURPOSE_FETCH_DIR || purpose == DIR_PURPOSE_UPLOAD_DIR) { @@ -86,14 +81,20 @@ void directory_initiate_command(routerinfo_t *router, int purpose, const char *p * populate it and add it at the right state * socketpair and hook up both sides */ + conn->s = connection_ap_make_bridge(conn->address, conn->port); + if(conn->s < 0) { + log_fn(LOG_WARN,"Making AP bridge to dirserver failed."); + connection_mark_for_close(conn, 0); + return; + } conn->state = DIR_CONN_STATE_CLIENT_SENDING; connection_set_poll_socket(conn); } } -static void directory_send_command(connection_t *conn, - int purpose, const char *payload) { +static void directory_send_command(connection_t *conn, int purpose, + const char *payload, int payload_len) { char fetchstring[] = "GET / HTTP/1.0\r\n\r\n"; char tmp[8192]; @@ -107,7 +108,7 @@ static void directory_send_command(connection_t *conn, case DIR_PURPOSE_UPLOAD_DIR: assert(payload); snprintf(tmp, sizeof(tmp), "POST / HTTP/1.0\r\nContent-Length: %d\r\n\r\n%s", - (int)strlen(payload), payload); + payload_len, payload); connection_write_to_buf(tmp, strlen(tmp), conn); break; case DIR_PURPOSE_FETCH_HIDSERV: @@ -118,9 +119,10 @@ static void directory_send_command(connection_t *conn, case DIR_PURPOSE_UPLOAD_HIDSERV: assert(payload); snprintf(tmp, sizeof(tmp), - "POST /hidserv/ HTTP/1.0\r\nContent-Length: %d\r\n\r\n%s", - (int)strlen(payload), payload); + "POST /hidserv/ HTTP/1.0\r\nContent-Length: %d\r\n\r\n", payload_len); connection_write_to_buf(tmp, strlen(tmp), conn); + /* could include nuls, need to write it separately */ + connection_write_to_buf(payload, payload_len, conn); break; } } @@ -230,7 +232,10 @@ int connection_dir_process_inbuf(connection_t *conn) { } else { log_fn(LOG_INFO,"updated routers."); } - has_fetched_directory=1; + if (has_fetched_directory==0) { + has_fetched_directory=1; + directory_has_arrived(); /* do things we've been waiting to do */ + } if(options.ORPort) { /* connect to them all */ router_retry_connections(); } |