From b86fecbf47c51b9d1fd4fca0f828d84420d111fb Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Fri, 5 Jul 2002 06:27:23 +0000 Subject: [PATCH] general cleanup svn:r29 --- src/or/cell.c | 3 +-- src/or/circuit.c | 10 +++---- src/or/connection_ap.c | 1 - src/or/connection_exit.c | 14 +++++----- src/or/connection_op.c | 5 ---- src/or/main.c | 58 +++++++++++++++++++++------------------- 6 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/or/cell.c b/src/or/cell.c index ef53a9eae1..fef8e8c6dd 100644 --- a/src/or/cell.c +++ b/src/or/cell.c @@ -3,8 +3,7 @@ int check_sane_cell(cell_t *cell) { - if(!cell) - return -1; + assert(cell); if(cell->aci == 0) { log(LOG_DEBUG,"check_sane_cell(): Cell has aci=0. Dropping."); diff --git a/src/or/circuit.c b/src/or/circuit.c index 5f323dd500..6de76a6333 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -3,7 +3,7 @@ /********* START VARIABLES **********/ -circuit_t *global_circuitlist=NULL; +static circuit_t *global_circuitlist=NULL; /********* END VARIABLES ************/ @@ -22,8 +22,7 @@ void circuit_add(circuit_t *circ) { void circuit_remove(circuit_t *circ) { circuit_t *tmpcirc; - if(!circ || !global_circuitlist) - return; + assert(circ && global_circuitlist); if(global_circuitlist == circ) { global_circuitlist = global_circuitlist->next; @@ -36,11 +35,9 @@ void circuit_remove(circuit_t *circ) { return; } } - } circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) { - circuit_t *circ; circ = (circuit_t *)malloc(sizeof(circuit_t)); @@ -55,7 +52,7 @@ circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) { /* ACIs */ circ->p_aci = p_aci; - circ->n_aci = 0; /* we need to have identified the next hop to choose a correct ACI */ + /* circ->n_aci remains 0 because we haven't identified the next hop yet */ circuit_add(circ); @@ -363,7 +360,6 @@ void circuit_about_to_close_connection(connection_t *conn) { /* currently, we assume it's too late to flush conn's buf here. * down the road, maybe we'll consider that eof doesn't mean can't-write */ - circuit_t *circ; while((circ = circuit_get_by_conn(conn))) { diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index cd57d90ed8..666dd16cb4 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -212,7 +212,6 @@ int ap_handshake_establish_circuit(connection_t *conn, unsigned int *route, int /* ok, launch the connection */ n_conn = connect_to_router_as_op(firsthop); - /* FIXME react to this somehow */ if(!n_conn) { /* connect failed, forget the whole thing */ log(LOG_DEBUG,"ap_handshake_establish_circuit(): connect to firsthop failed. Closing."); circuit_close(circ); diff --git a/src/or/connection_exit.c b/src/or/connection_exit.c index eec917a8e7..13c5f55fd1 100644 --- a/src/or/connection_exit.c +++ b/src/or/connection_exit.c @@ -63,7 +63,8 @@ int connection_exit_finished_flushing(connection_t *conn) { int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) { struct hostent *rent; struct sockaddr_in dest_addr; - int s; + int retval; + int s; /* for the new socket, if we're on connecting_wait */ /* an outgoing data cell has arrived */ @@ -148,14 +149,15 @@ int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) { connection_set_poll_socket(conn); conn->state = EXIT_CONN_STATE_OPEN; connection_watch_events(conn, POLLIN); - } else { /* i'm not sure what this would be */ - log(LOG_DEBUG,"connection_exit_process_cell(): in connecting_wait, not sure why."); + return 0; } - return 0; + log(LOG_DEBUG,"connection_exit_process_cell(): in connecting_wait, but I've already received everything. Closing."); + return -1; case EXIT_CONN_STATE_CONNECTING: log(LOG_DEBUG,"connection_exit_process_cell(): Data receiving while connecting. Queueing."); - /* FIXME kludge. shouldn't call write_to_buf directly. */ - return write_to_buf(cell->payload, cell->length, &conn->outbuf, &conn->outbuflen, &conn->outbuf_datalen); + retval = connection_write_to_buf(cell->payload, cell->length, conn); + connection_watch_events(conn, POLLIN); /* make it stop trying to write */ + return retval; case EXIT_CONN_STATE_OPEN: return connection_write_to_buf(cell->payload, cell->length, conn); } diff --git a/src/or/connection_op.c b/src/or/connection_op.c index 8ac5ceb4b2..c2c932f5d6 100644 --- a/src/or/connection_op.c +++ b/src/or/connection_op.c @@ -81,11 +81,6 @@ int op_handshake_process_keys(connection_t *conn) { EVP_EncryptInit(&conn->b_ctx, EVP_des_ofb(), conn->b_session_key, conn->b_session_iv); EVP_DecryptInit(&conn->f_ctx, EVP_des_ofb(), conn->f_session_key, conn->f_session_iv); -#if 0 - /* FIXME must choose conn->aci here? What does it mean for a connection to have an aci? */ - log(LOG_DEBUG,"new_entry_connection : Chosen ACI %u.",conn->aci); -#endif - conn->state = OP_CONN_STATE_OPEN; connection_watch_events(conn, POLLIN); diff --git a/src/or/main.c b/src/or/main.c index 4fede2aa2f..13ea9184b4 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -6,7 +6,7 @@ /* valid command-line options */ static char *args = "hf:e:n:l:"; -int loglevel = LOG_DEBUG; +int loglevel = LOG_DEBUG; /* global variable */ //int global_role = ROLE_AP_LISTEN; int global_role = ROLE_OR_LISTEN | ROLE_OR_CONNECT_ALL | ROLE_OP_LISTEN | ROLE_AP_LISTEN; @@ -29,26 +29,31 @@ enum opts { RouterFile=0, PrivateKeyFile, APPort, OPPort, ORPort, CoinWeight, MaxConn, TrafficShaping }; -connection_t *connection_array[MAXCONNECTIONS] = +static connection_t *connection_array[MAXCONNECTIONS] = { NULL }; -struct pollfd poll_array[MAXCONNECTIONS] = +static struct pollfd poll_array[MAXCONNECTIONS] = { [0 ... MAXCONNECTIONS-1] = { -1, 0, 0 } }; -int nfds=0; /* number of connections currently active */ - -/* default logging threshold */ -extern int loglevel; +static int nfds=0; /* number of connections currently active */ /* private key */ -RSA *prkey = NULL; +static RSA *prkey = NULL; /* router array */ -routerinfo_t **router_array = NULL; -int rarray_len = 0; +static routerinfo_t **router_array = NULL; +static int rarray_len = 0; /********* END VARIABLES ************/ +/**************************************************************************** +* +* This section contains accessors and other methods on the connection_array +* and poll_array variables (which are global within this file and unavailable +* outside it). +* +****************************************************************************/ + int connection_add(connection_t *conn) { if(nfds >= MAXCONNECTIONS-2) { /* 2, for some breathing room. should count the fenceposts. */ @@ -133,22 +138,27 @@ connection_t *connection_get_by_type(int type) { return NULL; } + + + +/* the next 4 functions should move to routers.c once we get it + * cleaned up more. The router_array and rarray_len variables should + * move there too. + */ + routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { int i; routerinfo_t *router; - if (!router_array) - return NULL; + assert(router_array); - for(i=0;iaddr == addr) && (router->or_port == port)) return router; } return NULL; - } routerinfo_t *router_get_first_in_route(unsigned int *route, size_t routelen) { @@ -165,6 +175,10 @@ unsigned char *router_create_onion(unsigned int *route, size_t routelen, size_t return create_onion(router_array,rarray_len,route,routelen,lenp,cpathp); } + + + + connection_t *connect_to_router_as_op(routerinfo_t *router) { return connection_connect_to_router_as_op(router, prkey, options[ORPort].r.i); } @@ -261,7 +275,7 @@ void check_conn_marked(int i) { connection_free(conn); if(i 1)) - { - log(LOG_ERR,"Invalid value for the TrafficShaping option."); - exit(1); - } -#endif ERR_load_crypto_strings(); retval = do_main_loop(); ERR_free_strings(); return retval; - }