mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
bump default pathlen to 3; clean up surrounding code
svn:r810
This commit is contained in:
parent
56cd147eb9
commit
c8639b2bbc
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -439,7 +439,7 @@ typedef struct {
|
||||
char *RecommendedVersions;
|
||||
char *User;
|
||||
char *Group;
|
||||
double CoinWeight;
|
||||
double PathlenCoinWeight;
|
||||
int ORPort;
|
||||
int SocksPort;
|
||||
int DirPort;
|
||||
|
Loading…
Reference in New Issue
Block a user