diff options
author | Roger Dingledine <arma@torproject.org> | 2003-03-18 01:49:55 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-03-18 01:49:55 +0000 |
commit | 64e46988f65176c0a12700e24b7738b26fd2cdd0 (patch) | |
tree | edf4e223dcd1f233aa587cd4317cae5e226ac879 /src | |
parent | d5c42576a3cde4228ccef6503e92c2a02d8510c0 (diff) | |
download | tor-64e46988f65176c0a12700e24b7738b26fd2cdd0.tar tor-64e46988f65176c0a12700e24b7738b26fd2cdd0.tar.gz |
greatly simplify this notion of 'roles':
if your ORPort is non-zero then you must connect to all nodes
if your DirPort is non-zero then you must act like a directory server
svn:r192
Diffstat (limited to 'src')
-rw-r--r-- | src/or/config.c | 67 | ||||
-rw-r--r-- | src/or/connection.c | 12 | ||||
-rw-r--r-- | src/or/connection_ap.c | 4 | ||||
-rw-r--r-- | src/or/directory.c | 2 | ||||
-rw-r--r-- | src/or/main.c | 20 | ||||
-rw-r--r-- | src/or/onion.c | 5 | ||||
-rw-r--r-- | src/or/or.h | 16 | ||||
-rw-r--r-- | src/or/routers.c | 3 |
8 files changed, 43 insertions, 86 deletions
diff --git a/src/or/config.c b/src/or/config.c index f69d7ea4c..e15a1c5aa 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -149,8 +149,8 @@ int config_compare(struct config_line *c, char *key, int type, void *arg) { case CONFIG_TYPE_BOOL: i = atoi(c->value); if (i != 0 && i != 1) { - log(LOG_ERR, "Boolean keyword '%s' expects 0 or 1", c->key); - return 0; + log(LOG_ERR, "Boolean keyword '%s' expects 0 or 1", c->key); + return 0; } *(int *)arg = i; break; @@ -179,13 +179,11 @@ void config_assign(or_options_t *options, struct config_line *list) { config_compare(list, "RouterFile", CONFIG_TYPE_STRING, &options->RouterFile) || /* int options */ - config_compare(list, "Role", CONFIG_TYPE_INT, &options->Role) || config_compare(list, "MaxConn", CONFIG_TYPE_INT, &options->MaxConn) || config_compare(list, "APPort", CONFIG_TYPE_INT, &options->APPort) || config_compare(list, "OPPort", CONFIG_TYPE_INT, &options->OPPort) || config_compare(list, "ORPort", CONFIG_TYPE_INT, &options->ORPort) || config_compare(list, "DirPort", CONFIG_TYPE_INT, &options->DirPort) || - config_compare(list, "DirRebuildPeriod",CONFIG_TYPE_INT, &options->DirRebuildPeriod) || config_compare(list, "DirFetchPeriod", CONFIG_TYPE_INT, &options->DirFetchPeriod) || config_compare(list, "KeepalivePeriod", CONFIG_TYPE_INT, &options->KeepalivePeriod) || config_compare(list, "MaxOnionsPending",CONFIG_TYPE_INT, &options->MaxOnionsPending) || @@ -223,12 +221,10 @@ int getconfig(int argc, char **argv, or_options_t *options) { options->loglevel = LOG_DEBUG; options->CoinWeight = 0.8; options->LinkPadding = 0; - options->DirRebuildPeriod = 300; options->DirFetchPeriod = 600; options->KeepalivePeriod = 300; options->MaxOnionsPending = 10; // options->ReconnectPeriod = 6001; - options->Role = ROLE_OR_LISTEN | ROLE_OR_CONNECT_ALL | ROLE_OP_LISTEN | ROLE_AP_LISTEN; /* get config lines from /etc/torrc and assign them */ cmd = basename(argv[0]); @@ -270,9 +266,8 @@ int getconfig(int argc, char **argv, or_options_t *options) { /* print config */ if (options->loglevel == LOG_DEBUG) { - printf("LogLevel=%s, Role=%d\n", - options->LogLevel, - options->Role); + printf("LogLevel=%s\n", + options->LogLevel); printf("RouterFile=%s, PrivateKeyFile=%s\n", options->RouterFile ? options->RouterFile : "(undefined)", options->PrivateKeyFile ? options->PrivateKeyFile : "(undefined)"); @@ -284,8 +279,7 @@ int getconfig(int argc, char **argv, or_options_t *options) { options->MaxConn, options->TrafficShaping, options->LinkPadding); - printf("DirRebuildPeriod=%d, DirFetchPeriod=%d KeepalivePeriod=%d\n", - options->DirRebuildPeriod, + printf("DirFetchPeriod=%d KeepalivePeriod=%d\n", options->DirFetchPeriod, options->KeepalivePeriod); printf("Daemon=%d", options->Daemon); @@ -316,48 +310,43 @@ int getconfig(int argc, char **argv, or_options_t *options) { } } - if(options->Role < 0 || options->Role > 63) { - log(LOG_ERR,"Role option must be an integer between 0 and 63 (inclusive)."); - result = -1; - } - if(options->RouterFile == NULL) { log(LOG_ERR,"RouterFile option required, but not found."); result = -1; } - if(ROLE_IS_OR(options->Role) && options->PrivateKeyFile == NULL) { - log(LOG_ERR,"PrivateKeyFile option required for OR, but not found."); + if(options->ORPort < 0) { + log(LOG_ERR,"ORPort option required and must be a positive integer value."); result = -1; } - if((options->Role & ROLE_OR_LISTEN) && options->ORPort < 1) { - log(LOG_ERR,"ORPort option required and must be a positive integer value."); + if(options->ORPort > 0 && options->PrivateKeyFile == NULL) { + log(LOG_ERR,"PrivateKeyFile option required for OR, but not found."); result = -1; } - if((options->Role & ROLE_OP_LISTEN) && options->OPPort < 1) { - log(LOG_ERR,"OPPort option required and must be a positive integer value."); + if(options->OPPort < 0) { + log(LOG_ERR,"OPPort option can't be negative."); result = -1; } - if((options->Role & ROLE_AP_LISTEN) && options->APPort < 1) { - log(LOG_ERR,"APPort option required and must be a positive integer value."); + if(options->APPort < 0) { + log(LOG_ERR,"APPort option can't be negative."); result = -1; } - if((options->Role & ROLE_DIR_LISTEN) && options->DirPort < 1) { - log(LOG_ERR,"DirPort option required and must be a positive integer value."); + if(options->DirPort < 0) { + log(LOG_ERR,"DirPort option can't be negative."); result = -1; } - if((options->Role & ROLE_AP_LISTEN) && + if(options->APPort > 1 && (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."); + log(LOG_ERR,"CoinWeight option must be >=0.0 and <1.0."); result = -1; } - if(options->MaxConn <= 0) { + if(options->MaxConn < 1) { log(LOG_ERR,"MaxConn option must be a non-zero positive integer."); result = -1; } @@ -367,26 +356,6 @@ int getconfig(int argc, char **argv, or_options_t *options) { result = -1; } - if(options->Daemon != 0 && options->Daemon != 1) { - log(LOG_ERR,"TrafficShaping option must be either 0 or 1."); - result = -1; - } - - if(options->TrafficShaping != 0 && options->TrafficShaping != 1) { - log(LOG_ERR,"TrafficShaping option must be either 0 or 1."); - result = -1; - } - - if(options->LinkPadding != 0 && options->LinkPadding != 1) { - log(LOG_ERR,"LinkPadding option must be either 0 or 1."); - result = -1; - } - - if(options->DirRebuildPeriod < 1) { - log(LOG_ERR,"DirRebuildPeriod option must be positive."); - result = -1; - } - if(options->DirFetchPeriod < 1) { log(LOG_ERR,"DirFetchPeriod option must be positive."); result = -1; diff --git a/src/or/connection.c b/src/or/connection.c index cb02161fd..366264fe9 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -286,14 +286,14 @@ int connection_handle_listener_read(connection_t *conn, int new_type, int new_st return 0; } -int retry_all_connections(int role, uint16_t or_listenport, +int retry_all_connections(uint16_t or_listenport, uint16_t op_listenport, uint16_t ap_listenport, uint16_t dir_listenport) { /* start all connections that should be up but aren't */ struct sockaddr_in bindaddr; /* where to bind */ - if(role & ROLE_OR_CONNECT_ALL) { + if(or_listenport) { router_retry_connections(); } @@ -301,28 +301,28 @@ int retry_all_connections(int role, uint16_t or_listenport, bindaddr.sin_family = AF_INET; bindaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* anyone can connect */ - if(role & ROLE_OR_LISTEN) { + if(or_listenport) { bindaddr.sin_port = htons(or_listenport); if(!connection_get_by_type(CONN_TYPE_OR_LISTENER)) { connection_or_create_listener(&bindaddr); } } - if(role & ROLE_OP_LISTEN) { + if(op_listenport) { bindaddr.sin_port = htons(op_listenport); if(!connection_get_by_type(CONN_TYPE_OP_LISTENER)) { connection_op_create_listener(&bindaddr); } } - if(role & ROLE_DIR_LISTEN) { + if(dir_listenport) { bindaddr.sin_port = htons(dir_listenport); if(!connection_get_by_type(CONN_TYPE_DIR_LISTENER)) { connection_dir_create_listener(&bindaddr); } } - if(role & ROLE_AP_LISTEN) { + if(ap_listenport) { bindaddr.sin_port = htons(ap_listenport); inet_aton("127.0.0.1", &(bindaddr.sin_addr)); /* the AP listens only on localhost! */ if(!connection_get_by_type(CONN_TYPE_AP_LISTENER)) { diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index 339c14137..9c9cfb149 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -4,7 +4,7 @@ #include "or.h" -extern int global_role; /* from main.c */ +extern or_options_t options; /* command-line and config-file options */ int connection_ap_process_inbuf(connection_t *conn) { @@ -221,7 +221,7 @@ int ap_handshake_establish_circuit(connection_t *conn, unsigned int *route, int if(!n_conn || n_conn->state != OR_CONN_STATE_OPEN) { /* not currently connected */ circ->n_addr = firsthop->addr; circ->n_port = firsthop->or_port; - if(global_role & ROLE_OR_CONNECT_ALL) { /* we would be connected if he were up. but he's not. */ + if(options.ORPort) { /* we would be connected if he were up. but he's not. */ log(LOG_DEBUG,"ap_handshake_establish_circuit(): Route's firsthop isn't connected."); circuit_close(circ); return -1; diff --git a/src/or/directory.c b/src/or/directory.c index e3c7b7821..28344934b 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -144,7 +144,7 @@ int connection_dir_process_inbuf(connection_t *conn) { if(router_get_list_from_string(the_directory) < 0) { log(LOG_DEBUG,"connection_dir_process_inbuf(): ...but parsing failed. Ignoring."); } - if(options.Role & ROLE_OR_CONNECT_ALL) { /* connect to them all */ + if(options.ORPort) { /* connect to them all */ router_retry_connections(); } return -1; diff --git a/src/or/main.c b/src/or/main.c index fc310424f..2421a804f 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -7,7 +7,6 @@ /********* START VARIABLES **********/ or_options_t options; /* command-line and config-file options */ -int global_role; static connection_t *connection_array[MAXCONNECTIONS] = { NULL }; @@ -311,7 +310,7 @@ int prepare_for_poll(int *timeout) { if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */ - if(!(options.Role & ROLE_DIR_SERVER)) { + if(!options.DirPort) { if(time_to_fetch_directory < now.tv_sec) { /* it's time to fetch a new directory */ /* NOTE directory servers do not currently fetch directories. @@ -332,7 +331,7 @@ int prepare_for_poll(int *timeout) { if(!connection_speaks_cells(tmpconn)) continue; /* this conn type doesn't send cells */ if(now.tv_sec >= tmpconn->timestamp_lastwritten + options.KeepalivePeriod) { - if((!(options.Role & ROLE_OR_CONNECT_ALL) && !circuit_get_by_conn(tmpconn)) || + if((!options.ORPort && !circuit_get_by_conn(tmpconn)) || (!connection_state_is_open(tmpconn))) { /* we're an onion proxy, with no circuits; or our handshake has expired. kill it. */ log(LOG_DEBUG,"prepare_for_poll(): Expiring connection to %d (%s:%d).", @@ -415,7 +414,7 @@ int do_main_loop(void) { } /* load the private key, if we're supposed to have one */ - if(ROLE_IS_OR(global_role)) { + if(options.ORPort) { prkey = crypto_new_pk_env(CRYPTO_PK_RSA); if (!prkey) { log(LOG_ERR,"Error creating a crypto environment."); @@ -429,9 +428,11 @@ int do_main_loop(void) { setprivatekey(prkey); } - /* 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 */ - retry_all_connections(options.Role, options.ORPort, + /* start up the necessary connections based on which ports are + * non-zero. This is where we try to connect to all the other ORs, + * and start the listeners + */ + retry_all_connections(options.ORPort, options.OPPort, options.APPort, options.DirPort); for(;;) { @@ -440,7 +441,7 @@ int do_main_loop(void) { please_dumpstats = 0; } if(please_fetch_directory) { - if(options.Role & ROLE_DIR_SERVER) { + if(options.DirPort) { if(router_get_list_from_file(options.RouterFile) < 0) { log(LOG_ERR,"Error reloading router list. Continuing with old list."); } @@ -631,12 +632,11 @@ int main(int argc, char *argv[]) { if(getconfig(argc,argv,&options)) exit(1); log(options.loglevel,NULL); /* assign logging severity level from options */ - global_role = options.Role; /* assign global_role from options. FIXME: remove from global namespace later. */ if (options.Daemon) daemonize(); - if(options.Role & ROLE_OR_LISTEN) { /* only spawn dns handlers if we're a router */ + if(options.ORPort) { /* only spawn dns handlers if we're a router */ if(dns_master_start() < 0) { log(LOG_ERR,"main(): We're running without a dns handler. Bad news."); } diff --git a/src/or/onion.c b/src/or/onion.c index 080f53d1a..132950cb7 100644 --- a/src/or/onion.c +++ b/src/or/onion.c @@ -4,7 +4,6 @@ #include "or.h" -extern int global_role; /* from main.c */ extern or_options_t options; /* command-line and config-file options */ static int onion_process(circuit_t *circ); @@ -351,7 +350,7 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r for(i=0;i<rarray_len;i++) { log(LOG_DEBUG,"Contemplating whether router %d is a new option...",i); - if( (global_role & ROLE_OR_CONNECT_ALL) && + if(options.ORPort && !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; @@ -398,7 +397,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 && !crypto_pk_cmp_keys(rarray[choice]->pkey, rarray[oldchoice]->pkey)) || - ((global_role & ROLE_OR_CONNECT_ALL) && !connection_twin_get_by_addr_port(rarray[choice]->addr, rarray[choice]->or_port))) { + (options.ORPort && !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. */ diff --git a/src/or/or.h b/src/or/or.h index a35fb26b2..4c9d1514f 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -55,16 +55,6 @@ #define ACI_TYPE_HIGHER 1 #define ACI_TYPE_BOTH 2 -/* bitvector of the roles that we might want to play. You can or (|) them together */ -#define ROLE_OR_LISTEN 1 -#define ROLE_OR_CONNECT_ALL 2 -#define ROLE_OP_LISTEN 4 -#define ROLE_AP_LISTEN 8 -#define ROLE_DIR_LISTEN 16 -#define ROLE_DIR_SERVER 32 - -#define ROLE_IS_OR(role) ((role & ROLE_OR_LISTEN) || (role & ROLE_OR_CONNECT_ALL) || (role & ROLE_OP_LISTEN)) - #define CONN_TYPE_OP_LISTENER 1 #define CONN_TYPE_OP 2 #define CONN_TYPE_OR_LISTENER 3 @@ -559,7 +549,7 @@ int connection_create_listener(struct sockaddr_in *bindaddr, int type); int connection_handle_listener_read(connection_t *conn, int new_type, int new_state); /* start all connections that should be up but aren't */ -int retry_all_connections(int role, uint16_t or_listenport, +int retry_all_connections(uint16_t or_listenport, uint16_t op_listenport, uint16_t ap_listenport, uint16_t dir_listenport); int connection_read_to_buf(connection_t *conn); @@ -568,9 +558,9 @@ int connection_fetch_from_buf(char *string, int len, connection_t *conn); #ifdef USE_ZLIB int connection_compress_from_buf(char *string, int len, connection_t *conn, - int flush); + int flush); int connection_decompress_to_buf(char *string, int len, connection_t *conn, - int flush); + int flush); #endif int connection_outbuf_too_full(connection_t *conn); diff --git a/src/or/routers.c b/src/or/routers.c index 0861ca4cc..9a31b5d9e 100644 --- a/src/or/routers.c +++ b/src/or/routers.c @@ -19,7 +19,6 @@ static routerinfo_t **router_array = NULL; static int rarray_len = 0; -extern int global_role; /* from main.c */ extern or_options_t options; /* command-line and config-file options */ extern routerinfo_t *my_routerinfo; /* from main.c */ @@ -125,7 +124,7 @@ int router_is_me(uint32_t addr, uint16_t port) { struct sockaddr_in me; /* my router identity */ - if(!ROLE_IS_OR(global_role)) { + if(!options.ORPort) { /* we're not an OR. This obviously isn't us. */ return 0; } |