mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-09-20 04:56:21 +02:00
general cleanup
svn:r29
This commit is contained in:
parent
bb163ca830
commit
b86fecbf47
@ -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.");
|
||||
|
@ -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))) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;i<rarray_len;i++)
|
||||
{
|
||||
for(i=0;i<rarray_len;i++) {
|
||||
router = router_array[i];
|
||||
if ((router->addr == 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<nfds) { /* we just replaced the one at i with a new one.
|
||||
process it too. */
|
||||
check_conn_read(i);
|
||||
check_conn_marked(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -373,23 +387,11 @@ int main(int argc, char *argv[]) {
|
||||
log(LOG_ERR,"MaxConn option required but not found.");
|
||||
exit(1);
|
||||
}
|
||||
#if 0
|
||||
if (!options[TrafficShaping].err)
|
||||
{
|
||||
options[TrafficShaping].r.i = DEFAULT_POLICY;
|
||||
}
|
||||
else if ((options[TrafficShaping].r.i < 0) || (options[TrafficShaping].r.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;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user