diff options
author | Roger Dingledine <arma@torproject.org> | 2003-09-25 10:42:07 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-09-25 10:42:07 +0000 |
commit | 3b5191d36dd62af1a7c6e08ce3a171d189870b64 (patch) | |
tree | 8852c3a4b57e7c464e656c6a278bfe2fd2f5d862 /src/or | |
parent | 3d4ccb781ae5d74f0e16a63c89e08459d15cccf1 (diff) | |
download | tor-3b5191d36dd62af1a7c6e08ce3a171d189870b64.tar.gz tor-3b5191d36dd62af1a7c6e08ce3a171d189870b64.zip |
various bugfixes and updates
redo all the config files for the new format (we'll redo them again soon)
fix (another! yuck) segfault in log_fn when input is too large
tor_tls_context_new() returns -1 for error, not NULL
fix segfault in check_conn_marked() on conn's that die during tls handshake
make ORs also initialize conn from router when we're the receiving node
make non-dirserver ORs upload descriptor to every dirserver on startup
add our local address to the descriptor
add Content-Length field to POST command
revert the Content-Length search in fetch_from_buf_http() to previous code
fix segfault in memmove in fetch_from_buf_http()
raise maximum allowed headers/body size in directory.c
svn:r484
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 20 | ||||
-rw-r--r-- | src/or/connection.c | 11 | ||||
-rw-r--r-- | src/or/connection_or.c | 19 | ||||
-rw-r--r-- | src/or/directory.c | 11 | ||||
-rw-r--r-- | src/or/main.c | 23 | ||||
-rw-r--r-- | src/or/or.h | 9 | ||||
-rw-r--r-- | src/or/routers.c | 18 |
7 files changed, 69 insertions, 42 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 3119fec5ad..6dd7185271 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -38,6 +38,10 @@ static int find_str_in_str(const char *str, int str_len, return -1; } +int find_on_inbuf(char *string, int string_len, buf_t *buf) { + return find_str_in_str(string, string_len, buf->buf, buf->datalen); +} + /* Create and return a new buf of size 'size' */ buf_t *buf_new_with_capacity(size_t size) { @@ -206,7 +210,7 @@ int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen) return r; } -int write_to_buf(char *string, int string_len, buf_t *buf) { +int write_to_buf(const char *string, int string_len, buf_t *buf) { /* append string to buf (growing as needed, return -1 if "too big") * return total number of bytes on the buf @@ -285,11 +289,12 @@ int fetch_from_buf_http(buf_t *buf, } #define CONTENT_LENGTH "\r\nContent-Length: " - i = find_str_in_str(CONTENT_LENGTH, sizeof(CONTENT_LENGTH), + i = find_str_in_str(CONTENT_LENGTH, strlen(CONTENT_LENGTH), headers, headerlen); if(i > 0) { contentlen = atoi(headers+i); /* XXX What if content-length is malformed? */ + log_fn(LOG_DEBUG,"Got a contentlen of %d.",contentlen); if(bodylen < contentlen) { log_fn(LOG_DEBUG,"body not all here yet."); return 0; /* not all there yet */ @@ -307,7 +312,7 @@ int fetch_from_buf_http(buf_t *buf, body_out[bodylen] = 0; /* null terminate it */ } buf->datalen -= (headerlen+bodylen); - memmove(buf, buf->buf+headerlen+bodylen, buf->datalen); + memmove(buf->buf, buf->buf+headerlen+bodylen, buf->datalen); return 1; } @@ -401,15 +406,6 @@ int fetch_from_buf_socks(buf_t *buf, return 1; } -int find_on_inbuf(char *string, int string_len, buf_t *buf) { - /* find first instance of needle 'string' on haystack 'buf'. return how - * many bytes from the beginning of buf to the end of string. - * If it's not there, return -1. - */ - - return find_str_in_str(string, string_len, buf->buf, buf->datalen); -} - /* Local Variables: mode:c diff --git a/src/or/connection.c b/src/or/connection.c index 05d337c10a..0f71cc164e 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -304,19 +304,14 @@ static int connection_tls_finish_handshake(connection_t *conn) { return -1; } log_fn(LOG_DEBUG,"The router's pk matches the one we meant to connect to. Good."); - crypto_free_pk_env(pk); } else { if(connection_exact_get_by_addr_port(router->addr,router->or_port)) { log_fn(LOG_INFO,"That router is already connected. Dropping."); return -1; } - conn->link_pkey = pk; - conn->bandwidth = router->bandwidth; - conn->addr = router->addr, conn->port = router->or_port; - if(conn->address) - free(conn->address); - conn->address = strdup(router->address); + connection_or_init_conn_from_router(conn, router); } + crypto_free_pk_env(pk); } else { /* it's an OP */ conn->bandwidth = DEFAULT_BANDWIDTH_OP; } @@ -615,7 +610,7 @@ int connection_handle_write(connection_t *conn) { return 0; } -int connection_write_to_buf(char *string, int len, connection_t *conn) { +int connection_write_to_buf(const char *string, int len, connection_t *conn) { if(!len) return 0; diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 6859cff6e1..d49667ddeb 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -73,6 +73,18 @@ int connection_or_finished_flushing(connection_t *conn) { /*********************/ +void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) { + conn->addr = router->addr; + conn->port = router->or_port; + conn->bandwidth = router->bandwidth; + conn->onion_pkey = crypto_pk_dup_key(router->onion_pkey); + conn->link_pkey = crypto_pk_dup_key(router->link_pkey); + conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey); + if(conn->address) + free(conn->address); + conn->address = strdup(router->address); +} + connection_t *connection_or_connect(routerinfo_t *router) { connection_t *conn; @@ -96,12 +108,7 @@ connection_t *connection_or_connect(routerinfo_t *router) { } /* set up conn so it's got all the data we need to remember */ - conn->addr = router->addr; - conn->port = router->or_port; - conn->bandwidth = router->bandwidth; - conn->onion_pkey = crypto_pk_dup_key(router->onion_pkey); - conn->link_pkey = crypto_pk_dup_key(router->link_pkey); - conn->address = strdup(router->address); + connection_or_init_conn_from_router(conn, router); if(connection_add(conn) < 0) { /* no space, forget it */ connection_free(conn); diff --git a/src/or/directory.c b/src/or/directory.c index d1e0713b5b..36a9a8ee86 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -19,7 +19,6 @@ static int directorylen=0; static int directory_dirty=1; static char fetchstring[] = "GET / HTTP/1.0\r\n\r\n"; -static char uploadstring[] = "POST / HTTP/1.0\r\n\r\n"; static char answerstring[] = "HTTP/1.0 200 OK\r\n\r\n"; /********* END VARIABLES ************/ @@ -88,7 +87,8 @@ void directory_initiate_command(routerinfo_t *router, int command) { } static int directory_send_command(connection_t *conn, int command) { - char *s; + const char *s; + char tmp[8192]; assert(conn && conn->type == CONN_TYPE_DIR); @@ -106,8 +106,9 @@ static int directory_send_command(connection_t *conn, int command) { log_fn(LOG_DEBUG,"Failed to get my descriptor."); return -1; } - if(connection_write_to_buf(uploadstring, strlen(uploadstring), conn) < 0 || - connection_write_to_buf(s, strlen(s), conn) < 0) { + snprintf(tmp, sizeof(tmp), "POST / HTTP/1.0\r\nContent-Length: %d\r\n\r\n%s", + strlen(s), s); + if(connection_write_to_buf(tmp, strlen(tmp), conn) < 0) { log_fn(LOG_DEBUG,"Couldn't write post/descriptor to buffer."); return -1; } @@ -192,7 +193,7 @@ int connection_dir_process_inbuf(connection_t *conn) { static int directory_handle_command(connection_t *conn) { char headers[1024]; - char body[1024]; + char body[50000]; /* XXX */ assert(conn && conn->type == CONN_TYPE_DIR); diff --git a/src/or/main.c b/src/or/main.c index 5676ad95a1..9f9a558a8a 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -12,7 +12,7 @@ static int init_descriptor(void); /********* START VARIABLES **********/ extern char *conn_type_to_string[]; -extern char *conn_state_to_string[][15]; +extern char *conn_state_to_string[][_CONN_TYPE_MAX+1]; or_options_t options; /* command-line and config-file options */ int global_read_bucket; /* max number of bytes I can read this second */ @@ -320,10 +320,12 @@ static void check_conn_marked(int i) { log_fn(LOG_DEBUG,"Cleaning up connection."); if(conn->s >= 0) { /* might be an incomplete edge connection */ /* FIXME there's got to be a better way to check for this -- and make other checks? */ - if(connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING) - flush_buf_tls(conn->tls, conn->outbuf, &conn->outbuf_flushlen); - else + if(connection_speaks_cells(conn)) { + if(conn->state == OR_CONN_STATE_OPEN) + flush_buf_tls(conn->tls, conn->outbuf, &conn->outbuf_flushlen); + } else { flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); + } if(connection_wants_to_flush(conn)) /* not done flushing */ log_fn(LOG_WARNING,"Conn (socket %d) still wants to flush. Losing %d bytes!",conn->s, (int)buf_datalen(conn->inbuf)); } @@ -642,7 +644,9 @@ static int do_main_loop(void) { } if(options.OnionRouter) { - cpu_init(); /* launch cpuworkers. Need to do this *after* we've read the private key. */ + cpu_init(); /* launch cpuworkers. Need to do this *after* we've read the onion key. */ + if(options.DirPort == 0) /* not a dirserver; XXX eventually do this for dirservers too */ + router_upload_desc_to_dirservers(); /* upload our descriptor to all dirservers */ } /* start up the necessary connections based on which ports are @@ -981,13 +985,20 @@ static char descriptor[8192]; /* XXX should this replace my_routerinfo? */ static routerinfo_t *desc_routerinfo; const char *router_get_my_descriptor(void) { + log_fn(LOG_DEBUG,"my desc is '%s'",descriptor); return descriptor; } static int init_descriptor(void) { routerinfo_t *ri; + char localhostname[256]; + + if(gethostname(localhostname,sizeof(localhostname)) < 0) { + log_fn(LOG_ERR,"Error obtaining local hostname"); + return -1; + } ri = tor_malloc(sizeof(routerinfo_t)); - ri->address = strdup("XXXXXXX"); /*XXX*/ + ri->address = strdup(localhostname); ri->nickname = strdup(options.Nickname); /* No need to set addr. ???? */ ri->or_port = options.ORPort; diff --git a/src/or/or.h b/src/or/or.h index 47cc1a5c3e..bc5e21d08f 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -434,6 +434,8 @@ typedef struct { /********************************* buffers.c ***************************/ +int find_on_inbuf(char *string, int string_len, buf_t *buf); + buf_t *buf_new(); buf_t *buf_new_with_capacity(size_t size); void buf_free(buf_t *buf); @@ -448,7 +450,7 @@ int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf); int flush_buf(int s, buf_t *buf, int *buf_flushlen); int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen); -int write_to_buf(char *string, int string_len, buf_t *buf); +int write_to_buf(const char *string, int string_len, buf_t *buf); int fetch_from_buf(char *string, int string_len, buf_t *buf); int fetch_from_buf_http(buf_t *buf, char *headers_out, int max_headerlen, @@ -456,7 +458,6 @@ int fetch_from_buf_http(buf_t *buf, int fetch_from_buf_socks(buf_t *buf, char *addr_out, int max_addrlen, uint16_t *port_out); -int find_on_inbuf(char *string, int string_len, buf_t *buf); /********************************* circuit.c ***************************/ @@ -529,7 +530,7 @@ int connection_wants_to_flush(connection_t *conn); int connection_outbuf_too_full(connection_t *conn); int connection_flush_buf(connection_t *conn); int connection_handle_write(connection_t *conn); -int connection_write_to_buf(char *string, int len, connection_t *conn); +int connection_write_to_buf(const char *string, int len, connection_t *conn); int connection_receiver_bucket_should_increase(connection_t *conn); @@ -562,6 +563,7 @@ int connection_exit_connect(connection_t *conn); int connection_or_process_inbuf(connection_t *conn); int connection_or_finished_flushing(connection_t *conn); +void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router); connection_t *connection_or_connect(routerinfo_t *router); int connection_write_cell_to_buf(const cell_t *cellp, connection_t *conn); @@ -658,6 +660,7 @@ int onion_skin_client_handshake(crypto_dh_env_t *handshake_state, int learn_my_address(struct sockaddr_in *me); void router_retry_connections(void); routerinfo_t *router_pick_directory_server(void); +void router_upload_desc_to_dirservers(void); routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port); routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk); #if 0 diff --git a/src/or/routers.c b/src/or/routers.c index 24baa5a340..ed37772ce7 100644 --- a/src/or/routers.c +++ b/src/or/routers.c @@ -37,14 +37,14 @@ router_resolve_directory(directory_t *dir); int learn_my_address(struct sockaddr_in *me) { /* local host information */ - char localhostname[512]; + char localhostname[256]; struct hostent *localhost; static struct sockaddr_in answer; static int already_learned=0; if(!already_learned) { /* obtain local host information */ - if(gethostname(localhostname,512) < 0) { + if(gethostname(localhostname,sizeof(localhostname)) < 0) { log_fn(LOG_ERR,"Error obtaining local hostname"); return -1; } @@ -100,6 +100,20 @@ routerinfo_t *router_pick_directory_server(void) { return NULL; } +void router_upload_desc_to_dirservers(void) { + int i; + routerinfo_t *router; + + if(!directory) + return; + + for(i=0;i<directory->n_routers;i++) { + router = directory->routers[i]; + if(router->dir_port > 0) + directory_initiate_command(router, DIR_CONN_STATE_CONNECTING_UPLOAD); + } +} + routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { int i; routerinfo_t *router; |