aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-11-13 23:01:56 +0000
committerRoger Dingledine <arma@torproject.org>2003-11-13 23:01:56 +0000
commitc8639b2bbcc070ac09609e8032caf7487ef70d0f (patch)
tree952e6d24bdb802af10d82bea0c65be25c6594bf2 /src
parent56cd147eb98e7db83937bf4b6dcf83be45790978 (diff)
downloadtor-c8639b2bbcc070ac09609e8032caf7487ef70d0f.tar
tor-c8639b2bbcc070ac09609e8032caf7487ef70d0f.tar.gz
bump default pathlen to 3; clean up surrounding code
svn:r810
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c13
-rw-r--r--src/or/onion.c29
-rw-r--r--src/or/or.h2
3 files changed, 12 insertions, 32 deletions
diff --git a/src/or/config.c b/src/or/config.c
index edd58f4de..6a4f7965d 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -153,8 +153,6 @@ static void config_assign(or_options_t *options, struct config_line *list) {
/* string options */
config_compare(list, "Address", CONFIG_TYPE_STRING, &options->Address) ||
- config_compare(list, "CoinWeight", CONFIG_TYPE_DOUBLE, &options->CoinWeight) ||
-
config_compare(list, "DebugLogFile", CONFIG_TYPE_STRING, &options->DebugLogFile) ||
config_compare(list, "DataDirectory", CONFIG_TYPE_STRING, &options->DataDirectory) ||
config_compare(list, "DirPort", CONFIG_TYPE_INT, &options->DirPort) ||
@@ -187,10 +185,11 @@ static void config_assign(or_options_t *options, struct config_line *list) {
config_compare(list, "OnionRouter", CONFIG_TYPE_BOOL, &options->OnionRouter) ||
config_compare(list, "PidFile", CONFIG_TYPE_STRING, &options->PidFile) ||
+ config_compare(list, "PathlenCoinWeight",CONFIG_TYPE_DOUBLE, &options->PathlenCoinWeight) ||
config_compare(list, "RouterFile", CONFIG_TYPE_STRING, &options->RouterFile) ||
config_compare(list, "RunAsDaemon", CONFIG_TYPE_BOOL, &options->RunAsDaemon) ||
- config_compare(list, "RecommendedVersions", CONFIG_TYPE_STRING, &options->RecommendedVersions) ||
+ config_compare(list, "RecommendedVersions",CONFIG_TYPE_STRING, &options->RecommendedVersions) ||
config_compare(list, "SocksPort", CONFIG_TYPE_INT, &options->SocksPort) ||
config_compare(list, "SocksBindAddress",CONFIG_TYPE_STRING,&options->SocksBindAddress) ||
@@ -262,7 +261,7 @@ void init_options(or_options_t *options) {
options->loglevel = LOG_INFO;
options->PidFile = tor_strdup("tor.pid");
options->DataDirectory = NULL;
- options->CoinWeight = 0.1;
+ options->PathlenCoinWeight = 0.3;
options->MaxConn = 900;
options->DirFetchPostPeriod = 600;
options->KeepalivePeriod = 300;
@@ -338,7 +337,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
/* Validate options */
- /* first check if some of the previous options have changed but aren't allowed to */
+ /* first check if any of the previous options have changed but aren't allowed to */
if(previous_pidfile && strcmp(previous_pidfile,options->PidFile)) {
log_fn(LOG_WARN,"During reload, PidFile changed from %s to %s. Failing.",
previous_pidfile, options->PidFile);
@@ -412,8 +411,8 @@ int getconfig(int argc, char **argv, or_options_t *options) {
}
if(options->SocksPort > 1 &&
- (options->CoinWeight < 0.0 || options->CoinWeight >= 1.0)) {
- log(LOG_WARN,"CoinWeight option must be >=0.0 and <1.0.");
+ (options->PathlenCoinWeight < 0.0 || options->PathlenCoinWeight >= 1.0)) {
+ log(LOG_WARN,"PathlenCoinWeight option must be >=0.0 and <1.0.");
result = -1;
}
diff --git a/src/or/onion.c b/src/or/onion.c
index 7c124a560..f68b7958b 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -187,34 +187,15 @@ char **parse_nickname_list(char *list, int *num) {
return out;
}
-/* uses a weighted coin with weight cw to choose a route length */
-static int chooselen(double cw) {
- int len = 2;
-
- if ((cw < 0) || (cw >= 1)) /* invalid parameter */
- return -1;
-
- while(1)
- {
- if (crypto_pseudo_rand_int(255) > cw*255) /* don't extend */
- break;
- else
- len++;
- }
-
- return len;
-}
-
static int new_route_len(double cw, routerinfo_t **rarray, int rarray_len) {
int num_acceptable_routers;
int routelen;
- assert((cw >= 0) && (cw < 1) && (rarray) ); /* valid parameters */
+ assert((cw >= 0) && (cw < 1) && rarray); /* valid parameters */
- routelen = chooselen(cw);
- if (routelen == -1) {
- log_fn(LOG_WARN,"Choosing route length failed.");
- return -1;
+ for(routelen=3; ; routelen++) { /* 3, increment until coinflip says we're done */
+ if (crypto_pseudo_rand_int(255) >= cw*255) /* don't extend */
+ break;
}
log_fn(LOG_DEBUG,"Chosen route length %d (%d routers available).",routelen, rarray_len);
@@ -242,7 +223,7 @@ int onion_new_route_len(void) {
directory_t *dir;
router_get_directory(&dir);
- return new_route_len(options.CoinWeight, dir->routers, dir->n_routers);
+ return new_route_len(options.PathlenCoinWeight, dir->routers, dir->n_routers);
}
static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len) {
diff --git a/src/or/or.h b/src/or/or.h
index 32f98ded9..c9eee8a18 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -439,7 +439,7 @@ typedef struct {
char *RecommendedVersions;
char *User;
char *Group;
- double CoinWeight;
+ double PathlenCoinWeight;
int ORPort;
int SocksPort;
int DirPort;