diff options
author | Roger Dingledine <arma@torproject.org> | 2004-11-06 05:18:11 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-11-06 05:18:11 +0000 |
commit | 6c61ed4fb5d33a8c51ff342165a26ac70765dd26 (patch) | |
tree | 6a767b637d976bf392a275e99386798bbf094e74 /src/or/connection.c | |
parent | f490e5cdb6a60779ddadfba3dd022ba904c00b43 (diff) | |
download | tor-6c61ed4fb5d33a8c51ff342165a26ac70765dd26.tar.gz tor-6c61ed4fb5d33a8c51ff342165a26ac70765dd26.zip |
Make options no longer a global variable.
Now we can try setting an option but back out if it fails to parse, or
if it's disallowed (e.g. changing RunAsDaemon from 1 to 0).
Use parse_line_from_str rather than parse_line_from_file.
svn:r2692
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 809e115733..e08c1d08cb 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -12,8 +12,6 @@ /********* START VARIABLES **********/ -extern or_options_t options; /* command-line and config-file options */ - /** Array of strings to make conn-\>type human-readable. */ const char *conn_type_to_string[] = { "", /* 0 */ @@ -488,6 +486,7 @@ static int connection_init_accepted_conn(connection_t *conn) { int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port) { int s; struct sockaddr_in dest_addr; + or_options_t *options = get_options(); s=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); if (s < 0) { @@ -496,15 +495,15 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_ return -1; } - if (options.OutboundBindAddress) { + if (options->OutboundBindAddress) { struct sockaddr_in ext_addr; memset(&ext_addr, 0, sizeof(ext_addr)); ext_addr.sin_family = AF_INET; ext_addr.sin_port = 0; - if (!tor_inet_aton(options.OutboundBindAddress, &ext_addr.sin_addr)) { + if (!tor_inet_aton(options->OutboundBindAddress, &ext_addr.sin_addr)) { log_fn(LOG_WARN,"Outbound bind address '%s' didn't parse. Ignoring.", - options.OutboundBindAddress); + options->OutboundBindAddress); } else { if(bind(s, (struct sockaddr*)&ext_addr, sizeof(ext_addr)) < 0) { log_fn(LOG_WARN,"Error binding network socket: %s", @@ -641,18 +640,19 @@ static int retry_listeners(int type, struct config_line_t *cfg, * connections for a given type. */ int retry_all_listeners(int force) { + or_options_t *options = get_options(); - if (retry_listeners(CONN_TYPE_OR_LISTENER, options.ORBindAddress, - options.ORPort, "0.0.0.0", force)<0) + if (retry_listeners(CONN_TYPE_OR_LISTENER, options->ORBindAddress, + options->ORPort, "0.0.0.0", force)<0) return -1; - if (retry_listeners(CONN_TYPE_DIR_LISTENER, options.DirBindAddress, - options.DirPort, "0.0.0.0", force)<0) + if (retry_listeners(CONN_TYPE_DIR_LISTENER, options->DirBindAddress, + options->DirPort, "0.0.0.0", force)<0) return -1; - if (retry_listeners(CONN_TYPE_AP_LISTENER, options.SocksBindAddress, - options.SocksPort, "127.0.0.1", force)<0) + if (retry_listeners(CONN_TYPE_AP_LISTENER, options->SocksBindAddress, + options->SocksPort, "127.0.0.1", force)<0) return -1; if (retry_listeners(CONN_TYPE_CONTROL_LISTENER, NULL, - options.ControlPort, "127.0.0.1", force)<0) + options->ControlPort, "127.0.0.1", force)<0) return -1; return 0; @@ -702,11 +702,12 @@ static void connection_read_bucket_decrement(connection_t *conn, int num_read) { } } -/** Initiatialize the global read bucket to options.BandwidthBurstBytes, +/** Initiatialize the global read bucket to options->BandwidthBurstBytes, * and current_time to the current time. */ void connection_bucket_init(void) { - global_read_bucket = options.BandwidthBurstBytes; /* start it at max traffic */ - global_write_bucket = options.BandwidthBurstBytes; /* start it at max traffic */ + or_options_t *options = get_options(); + global_read_bucket = options->BandwidthBurstBytes; /* start it at max traffic */ + global_write_bucket = options->BandwidthBurstBytes; /* start it at max traffic */ } /** A second has rolled over; increment buckets appropriately. */ @@ -714,14 +715,15 @@ void connection_bucket_refill(struct timeval *now) { int i, n; connection_t *conn; connection_t **carray; + or_options_t *options = get_options(); /* refill the global buckets */ - if(global_read_bucket < options.BandwidthBurstBytes) { - global_read_bucket += options.BandwidthRateBytes; + if(global_read_bucket < options->BandwidthBurstBytes) { + global_read_bucket += options->BandwidthRateBytes; log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket); } - if(global_write_bucket < options.BandwidthBurstBytes) { - global_write_bucket += options.BandwidthRateBytes; + if(global_write_bucket < options->BandwidthBurstBytes) { + global_write_bucket += options->BandwidthRateBytes; log_fn(LOG_DEBUG,"global_write_bucket now %d.", global_write_bucket); } |