Loading src/or/config.c +13 −12 Original line number Diff line number Diff line Loading @@ -188,37 +188,44 @@ RETURN VALUE: 0 on success, non-zero on error } } if ( options->Role < 0 || options->Role > 15 ) { log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive)."); code = -1; } if ( options->RouterFile == NULL ) { log(LOG_ERR,"RouterFile option required, but not found."); code = -1; } if ( options->PrivateKeyFile == NULL ) if ( ROLE_IS_OR(options->Role) && options->PrivateKeyFile == NULL ) { log(LOG_ERR,"PrivateKeyFile option required, but not found."); log(LOG_ERR,"PrivateKeyFile option required for OR, but not found."); code = -1; } if ( options->ORPort < 1 ) if ( (options->Role & ROLE_OR_LISTEN) && options->ORPort < 1 ) { log(LOG_ERR,"ORPort option required and must be a positive integer value."); code = -1; } if ( options->OPPort < 1 ) if ( (options->Role & ROLE_OP_LISTEN) && options->OPPort < 1 ) { log(LOG_ERR,"OPPort option required and must be a positive integer value."); code = -1; } if ( options->APPort < 1 ) if ( (options->Role & ROLE_AP_LISTEN) && options->APPort < 1 ) { log(LOG_ERR,"APPort option required and must be a positive integer value."); code = -1; } if ( options->CoinWeight < 0.0 || options->CoinWeight >= 1.0 ) if ( (options->Role & ROLE_AP_LISTEN) && (options->CoinWeight < 0.0 || options->CoinWeight >= 1.0) ) { log(LOG_ERR,"CoinWeight option must be a value from 0.0 upto 1.0, but not including 1.0."); code = -1; Loading Loading @@ -248,12 +255,6 @@ RETURN VALUE: 0 on success, non-zero on error code = -1; } if ( options->Role < 0 || options->Role > 15 ) { log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive)."); code = -1; } return code; } src/or/connection.c +5 −4 Original line number Diff line number Diff line Loading @@ -297,13 +297,13 @@ int retry_all_connections(int role, routerinfo_t **router_array, int rarray_len, return 0; } connection_t *connection_connect_to_router_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, uint16_t local_or_port) { connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port) { struct sockaddr_in local; /* local address */ if(learn_local(&local) < 0) return NULL; local.sin_port = htons(local_or_port); return connection_or_connect_as_op(router, prkey, &local); return connection_or_connect_as_op(router, &local); } int connection_read_to_buf(connection_t *conn) { Loading Loading @@ -356,7 +356,7 @@ int connection_write_to_buf(char *string, int len, connection_t *conn) { if(!len) return 0; if( (conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_OR) || if( (!connection_speaks_cells(conn)) || (!connection_state_is_open(conn)) || (options.LinkPadding == 0) ) { /* connection types other than or and op, or or/op not in 'open' state, should flush immediately */ Loading Loading @@ -528,8 +528,9 @@ int connection_encrypt_cell(cell_t *cellp, connection_t *conn) { } #if 0 printf("Sending: Cell header crypttext: "); px = (char *)&newcell; for(x=0;x<8;x++) { printf("%u ",newheader[x]); printf("%u ",px[x]); } printf("\n"); #endif Loading src/or/connection_or.c +9 −4 Original line number Diff line number Diff line Loading @@ -218,21 +218,25 @@ connection_t *connection_or_connect(routerinfo_t *router, crypto_pk_env_t *prkey * */ connection_t *connection_or_connect_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local) { connection_t *connection_or_connect_as_op(routerinfo_t *router, struct sockaddr_in *local) { connection_t *conn; int result=0; /* so connection_or_connect() can tell us what happened */ assert(router && prkey && local); assert(router && local); if(router->addr == local->sin_addr.s_addr && router->or_port == ntohs(local->sin_port)) { /* this is me! don't connect to me. */ log(LOG_WARNING,"connection_or_connect_as_op(): You just asked me to connect to myself."); return NULL; } /* this function should never be called if we're already connected to router, but */ /* FIXME we should check here if we're already connected, and return the conn */ /* check first to be sure */ conn = connection_exact_get_by_addr_port(router->addr,router->or_port); if(conn) return conn; conn = connection_or_connect(router, prkey, local, router->op_port, &result); conn = connection_or_connect(router, NULL, local, router->op_port, &result); if(!conn) return NULL; Loading Loading @@ -276,6 +280,7 @@ int or_handshake_op_send_keys(connection_t *conn) { *(uint32_t *)message = htonl(bandwidth); memcpy((void *)(message + 4), (void *)conn->f_crypto->key, 8); memcpy((void *)(message + 12), (void *)conn->b_crypto->key, 8); #if 0 printf("f_session_key: "); for(x=0;x<8;x++) { Loading src/or/main.c +14 −11 Original line number Diff line number Diff line Loading @@ -198,8 +198,9 @@ unsigned char *router_create_onion(unsigned int *route, int routelen, int *len, /* FIXME can we cut this function out? */ connection_t *connect_to_router_as_op(routerinfo_t *router) { return connection_connect_to_router_as_op(router, prkey, options.ORPort); return connection_connect_to_router_as_op(router, options.ORPort); } void connection_watch_events(connection_t *conn, short events) { Loading Loading @@ -418,7 +419,8 @@ int do_main_loop(void) { return -1; } /* load the private key */ /* load the private key, if we're supposed to have one */ if(ROLE_IS_OR(global_role)) { prkey = crypto_new_pk_env(CRYPTO_PK_RSA); if (!prkey) { log(LOG_ERR,"Error creating a crypto environment."); Loading @@ -429,6 +431,7 @@ int do_main_loop(void) { log(LOG_ERR,"Error loading private key."); return -1; } } /* start-up the necessary connections based on global_role. This is where we * try to connect to all the other ORs, and start the listeners */ Loading src/or/onion.c +6 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ #include "or.h" extern int global_role; /* from main.c */ /********* START VARIABLES **********/ tracked_onion_t *tracked_onions = NULL; /* linked list of tracked onions */ Loading Loading @@ -109,8 +111,9 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r log(LOG_DEBUG,"new_route(): Chosen route length %d.",*routelen); for(i=0;i<rarray_len;i++) { log(LOG_DEBUG,"Contemplating whether router %d is any good...",i); if(!connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) { log(LOG_DEBUG,"Contemplating whether router %d is a new option...",i); if( (global_role & ROLE_OR_CONNECT_ALL) && !connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) { log(LOG_DEBUG,"Nope, %d is not connected.",i); goto next_i_loop; } Loading Loading @@ -156,7 +159,7 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r log(LOG_DEBUG,"new_route(): Contemplating router %u.",choice); if(choice == oldchoice || (oldchoice < rarray_len && !pkey_cmp(rarray[choice]->pkey, rarray[oldchoice]->pkey)) || !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port)) { ((global_role & ROLE_OR_CONNECT_ALL) && !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port))) { /* Same router as last choice, or router twin, * or no routers with that key are connected to us. * Try again. */ Loading Loading
src/or/config.c +13 −12 Original line number Diff line number Diff line Loading @@ -188,37 +188,44 @@ RETURN VALUE: 0 on success, non-zero on error } } if ( options->Role < 0 || options->Role > 15 ) { log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive)."); code = -1; } if ( options->RouterFile == NULL ) { log(LOG_ERR,"RouterFile option required, but not found."); code = -1; } if ( options->PrivateKeyFile == NULL ) if ( ROLE_IS_OR(options->Role) && options->PrivateKeyFile == NULL ) { log(LOG_ERR,"PrivateKeyFile option required, but not found."); log(LOG_ERR,"PrivateKeyFile option required for OR, but not found."); code = -1; } if ( options->ORPort < 1 ) if ( (options->Role & ROLE_OR_LISTEN) && options->ORPort < 1 ) { log(LOG_ERR,"ORPort option required and must be a positive integer value."); code = -1; } if ( options->OPPort < 1 ) if ( (options->Role & ROLE_OP_LISTEN) && options->OPPort < 1 ) { log(LOG_ERR,"OPPort option required and must be a positive integer value."); code = -1; } if ( options->APPort < 1 ) if ( (options->Role & ROLE_AP_LISTEN) && options->APPort < 1 ) { log(LOG_ERR,"APPort option required and must be a positive integer value."); code = -1; } if ( options->CoinWeight < 0.0 || options->CoinWeight >= 1.0 ) if ( (options->Role & ROLE_AP_LISTEN) && (options->CoinWeight < 0.0 || options->CoinWeight >= 1.0) ) { log(LOG_ERR,"CoinWeight option must be a value from 0.0 upto 1.0, but not including 1.0."); code = -1; Loading Loading @@ -248,12 +255,6 @@ RETURN VALUE: 0 on success, non-zero on error code = -1; } if ( options->Role < 0 || options->Role > 15 ) { log(LOG_ERR,"Role option must be an integer between 0 and 15 (inclusive)."); code = -1; } return code; }
src/or/connection.c +5 −4 Original line number Diff line number Diff line Loading @@ -297,13 +297,13 @@ int retry_all_connections(int role, routerinfo_t **router_array, int rarray_len, return 0; } connection_t *connection_connect_to_router_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, uint16_t local_or_port) { connection_t *connection_connect_to_router_as_op(routerinfo_t *router, uint16_t local_or_port) { struct sockaddr_in local; /* local address */ if(learn_local(&local) < 0) return NULL; local.sin_port = htons(local_or_port); return connection_or_connect_as_op(router, prkey, &local); return connection_or_connect_as_op(router, &local); } int connection_read_to_buf(connection_t *conn) { Loading Loading @@ -356,7 +356,7 @@ int connection_write_to_buf(char *string, int len, connection_t *conn) { if(!len) return 0; if( (conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_OR) || if( (!connection_speaks_cells(conn)) || (!connection_state_is_open(conn)) || (options.LinkPadding == 0) ) { /* connection types other than or and op, or or/op not in 'open' state, should flush immediately */ Loading Loading @@ -528,8 +528,9 @@ int connection_encrypt_cell(cell_t *cellp, connection_t *conn) { } #if 0 printf("Sending: Cell header crypttext: "); px = (char *)&newcell; for(x=0;x<8;x++) { printf("%u ",newheader[x]); printf("%u ",px[x]); } printf("\n"); #endif Loading
src/or/connection_or.c +9 −4 Original line number Diff line number Diff line Loading @@ -218,21 +218,25 @@ connection_t *connection_or_connect(routerinfo_t *router, crypto_pk_env_t *prkey * */ connection_t *connection_or_connect_as_op(routerinfo_t *router, crypto_pk_env_t *prkey, struct sockaddr_in *local) { connection_t *connection_or_connect_as_op(routerinfo_t *router, struct sockaddr_in *local) { connection_t *conn; int result=0; /* so connection_or_connect() can tell us what happened */ assert(router && prkey && local); assert(router && local); if(router->addr == local->sin_addr.s_addr && router->or_port == ntohs(local->sin_port)) { /* this is me! don't connect to me. */ log(LOG_WARNING,"connection_or_connect_as_op(): You just asked me to connect to myself."); return NULL; } /* this function should never be called if we're already connected to router, but */ /* FIXME we should check here if we're already connected, and return the conn */ /* check first to be sure */ conn = connection_exact_get_by_addr_port(router->addr,router->or_port); if(conn) return conn; conn = connection_or_connect(router, prkey, local, router->op_port, &result); conn = connection_or_connect(router, NULL, local, router->op_port, &result); if(!conn) return NULL; Loading Loading @@ -276,6 +280,7 @@ int or_handshake_op_send_keys(connection_t *conn) { *(uint32_t *)message = htonl(bandwidth); memcpy((void *)(message + 4), (void *)conn->f_crypto->key, 8); memcpy((void *)(message + 12), (void *)conn->b_crypto->key, 8); #if 0 printf("f_session_key: "); for(x=0;x<8;x++) { Loading
src/or/main.c +14 −11 Original line number Diff line number Diff line Loading @@ -198,8 +198,9 @@ unsigned char *router_create_onion(unsigned int *route, int routelen, int *len, /* FIXME can we cut this function out? */ connection_t *connect_to_router_as_op(routerinfo_t *router) { return connection_connect_to_router_as_op(router, prkey, options.ORPort); return connection_connect_to_router_as_op(router, options.ORPort); } void connection_watch_events(connection_t *conn, short events) { Loading Loading @@ -418,7 +419,8 @@ int do_main_loop(void) { return -1; } /* load the private key */ /* load the private key, if we're supposed to have one */ if(ROLE_IS_OR(global_role)) { prkey = crypto_new_pk_env(CRYPTO_PK_RSA); if (!prkey) { log(LOG_ERR,"Error creating a crypto environment."); Loading @@ -429,6 +431,7 @@ int do_main_loop(void) { log(LOG_ERR,"Error loading private key."); return -1; } } /* start-up the necessary connections based on global_role. This is where we * try to connect to all the other ORs, and start the listeners */ Loading
src/or/onion.c +6 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ #include "or.h" extern int global_role; /* from main.c */ /********* START VARIABLES **********/ tracked_onion_t *tracked_onions = NULL; /* linked list of tracked onions */ Loading Loading @@ -109,8 +111,9 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r log(LOG_DEBUG,"new_route(): Chosen route length %d.",*routelen); for(i=0;i<rarray_len;i++) { log(LOG_DEBUG,"Contemplating whether router %d is any good...",i); if(!connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) { log(LOG_DEBUG,"Contemplating whether router %d is a new option...",i); if( (global_role & ROLE_OR_CONNECT_ALL) && !connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) { log(LOG_DEBUG,"Nope, %d is not connected.",i); goto next_i_loop; } Loading Loading @@ -156,7 +159,7 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r log(LOG_DEBUG,"new_route(): Contemplating router %u.",choice); if(choice == oldchoice || (oldchoice < rarray_len && !pkey_cmp(rarray[choice]->pkey, rarray[oldchoice]->pkey)) || !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port)) { ((global_role & ROLE_OR_CONNECT_ALL) && !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port))) { /* Same router as last choice, or router twin, * or no routers with that key are connected to us. * Try again. */ Loading