mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
move closer to being able to reload config on HUP
rename APPort to SocksPort introduce new tor_free() macro svn:r642
This commit is contained in:
@@ -481,7 +481,7 @@ void circuit_close(circuit_t *circ) {
|
||||
circuit_t *youngest=NULL;
|
||||
|
||||
assert(circ);
|
||||
if(options.APPort) {
|
||||
if(options.SocksPort) {
|
||||
youngest = circuit_get_newest_open();
|
||||
log_fn(LOG_DEBUG,"youngest %d, circ %d.",(int)youngest, (int)circ);
|
||||
}
|
||||
@@ -496,7 +496,7 @@ void circuit_close(circuit_t *circ) {
|
||||
for(conn=circ->p_streams; conn; conn=conn->next_stream) {
|
||||
connection_send_destroy(circ->p_aci, conn);
|
||||
}
|
||||
if(options.APPort && youngest == circ) { /* check this after we've sent the destroys, to reduce races */
|
||||
if(options.SocksPort && youngest == circ) { /* check this after we've sent the destroys, to reduce races */
|
||||
/* our current circuit just died. Launch another one pronto. */
|
||||
log_fn(LOG_INFO,"Youngest circuit dying. Launching a replacement.");
|
||||
circuit_launch_new(1);
|
||||
@@ -616,7 +616,7 @@ void circuit_expire_unused_circuits(void) {
|
||||
void circuit_launch_new(int failure_status) {
|
||||
static int failures=0;
|
||||
|
||||
if(!options.APPort) /* we're not an application proxy. no need for circuits. */
|
||||
if(!options.SocksPort) /* we're not an application proxy. no need for circuits. */
|
||||
return;
|
||||
|
||||
if(failure_status == -1) { /* I was called because a circuit succeeded */
|
||||
|
||||
+35
-14
@@ -131,6 +131,7 @@ static int config_compare(struct config_line *c, char *key, int type, void *arg)
|
||||
*(int *)arg = i;
|
||||
break;
|
||||
case CONFIG_TYPE_STRING:
|
||||
tor_free(*(char **)arg);
|
||||
*(char **)arg = tor_strdup(c->value);
|
||||
break;
|
||||
case CONFIG_TYPE_DOUBLE:
|
||||
@@ -159,10 +160,12 @@ static void config_assign(or_options_t *options, struct config_line *list) {
|
||||
config_compare(list, "Nickname", CONFIG_TYPE_STRING, &options->Nickname) ||
|
||||
config_compare(list, "Address", CONFIG_TYPE_STRING, &options->Address) ||
|
||||
config_compare(list, "ExitPolicy", CONFIG_TYPE_STRING, &options->ExitPolicy) ||
|
||||
config_compare(list, "SocksBindAddress",CONFIG_TYPE_STRING,&options->SocksBindAddress) ||
|
||||
config_compare(list, "ORBindAddress", CONFIG_TYPE_STRING, &options->ORBindAddress) ||
|
||||
|
||||
/* int options */
|
||||
config_compare(list, "MaxConn", CONFIG_TYPE_INT, &options->MaxConn) ||
|
||||
config_compare(list, "APPort", CONFIG_TYPE_INT, &options->APPort) ||
|
||||
config_compare(list, "SocksPort", CONFIG_TYPE_INT, &options->SocksPort) ||
|
||||
config_compare(list, "ORPort", CONFIG_TYPE_INT, &options->ORPort) ||
|
||||
config_compare(list, "DirPort", CONFIG_TYPE_INT, &options->DirPort) ||
|
||||
config_compare(list, "DirFetchPostPeriod",CONFIG_TYPE_INT, &options->DirFetchPostPeriod) ||
|
||||
@@ -195,20 +198,27 @@ void print_usage(void) {
|
||||
|
||||
}
|
||||
|
||||
/* return 0 if success, <0 if failure. */
|
||||
int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
struct config_line *cl;
|
||||
FILE *cf;
|
||||
char *fname;
|
||||
int i;
|
||||
int result = 0;
|
||||
void free_options(or_options_t *options) {
|
||||
tor_free(options->LogLevel);
|
||||
tor_free(options->LogFile);
|
||||
tor_free(options->DebugLogFile);
|
||||
tor_free(options->DataDirectory);
|
||||
tor_free(options->RouterFile);
|
||||
tor_free(options->Nickname);
|
||||
tor_free(options->Address);
|
||||
tor_free(options->PidFile);
|
||||
tor_free(options->ExitPolicy);
|
||||
}
|
||||
|
||||
void init_options(or_options_t *options) {
|
||||
/* give reasonable values for each option. Defaults to zero. */
|
||||
memset(options,0,sizeof(or_options_t));
|
||||
options->LogLevel = "info";
|
||||
options->ExitPolicy = "reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*";
|
||||
options->LogLevel = tor_strdup("info");
|
||||
options->ExitPolicy = tor_strdup("reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*");
|
||||
options->SocksBindAddress = tor_strdup("127.0.0.1");
|
||||
options->ORBindAddress = tor_strdup("0.0.0.0");
|
||||
options->loglevel = LOG_INFO;
|
||||
options->PidFile = "tor.pid";
|
||||
options->PidFile = tor_strdup("tor.pid");
|
||||
options->DataDirectory = NULL;
|
||||
options->CoinWeight = 0.1;
|
||||
options->MaxConn = 900;
|
||||
@@ -218,6 +228,17 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
options->NewCircuitPeriod = 60; /* once a minute */
|
||||
options->TotalBandwidth = 800000; /* at most 800kB/s total sustained incoming */
|
||||
options->NumCpus = 1;
|
||||
}
|
||||
|
||||
/* return 0 if success, <0 if failure. */
|
||||
int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
struct config_line *cl;
|
||||
FILE *cf;
|
||||
char *fname;
|
||||
int i;
|
||||
int result = 0;
|
||||
|
||||
init_options(options);
|
||||
|
||||
if(argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1],"--help"))) {
|
||||
print_usage();
|
||||
@@ -295,8 +316,8 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->APPort < 0) {
|
||||
log(LOG_WARN,"APPort option can't be negative.");
|
||||
if(options->SocksPort < 0) {
|
||||
log(LOG_WARN,"SocksPort option can't be negative.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
@@ -305,7 +326,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->APPort > 1 &&
|
||||
if(options->SocksPort > 1 &&
|
||||
(options->CoinWeight < 0.0 || options->CoinWeight >= 1.0)) {
|
||||
log(LOG_WARN,"CoinWeight option must be >=0.0 and <1.0.");
|
||||
result = -1;
|
||||
|
||||
@@ -100,8 +100,7 @@ void connection_free(connection_t *conn) {
|
||||
buf_free(conn->inbuf);
|
||||
buf_free(conn->outbuf);
|
||||
}
|
||||
if(conn->address)
|
||||
free(conn->address);
|
||||
tor_free(conn->address);
|
||||
|
||||
if(connection_speaks_cells(conn)) {
|
||||
directory_set_dirty();
|
||||
@@ -115,8 +114,7 @@ void connection_free(connection_t *conn) {
|
||||
crypto_free_pk_env(conn->link_pkey);
|
||||
if (conn->identity_pkey)
|
||||
crypto_free_pk_env(conn->identity_pkey);
|
||||
if (conn->nickname)
|
||||
free(conn->nickname);
|
||||
tor_free(conn->nickname);
|
||||
|
||||
if(conn->s >= 0) {
|
||||
log_fn(LOG_INFO,"closing fd %d.",conn->s);
|
||||
|
||||
@@ -85,8 +85,7 @@ void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *route
|
||||
conn->link_pkey = crypto_pk_dup_key(router->link_pkey);
|
||||
conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
|
||||
conn->nickname = tor_strdup(router->nickname);
|
||||
if(conn->address)
|
||||
free(conn->address);
|
||||
tor_free(conn->address);
|
||||
conn->address = tor_strdup(router->address);
|
||||
}
|
||||
|
||||
|
||||
+6
-10
@@ -165,10 +165,8 @@ static int n_descriptors = 0;
|
||||
|
||||
static void free_descriptor_entry(descriptor_entry_t *desc)
|
||||
{
|
||||
if (desc->descriptor)
|
||||
free(desc->descriptor);
|
||||
if (desc->nickname)
|
||||
free(desc->nickname);
|
||||
tor_free(desc->descriptor);
|
||||
tor_free(desc->nickname);
|
||||
free(desc);
|
||||
}
|
||||
|
||||
@@ -218,7 +216,7 @@ dirserv_add_descriptor(const char **desc)
|
||||
log(LOG_WARN, "Couldn't parse descriptor");
|
||||
goto err;
|
||||
}
|
||||
free(desc_tmp); desc_tmp = NULL;
|
||||
tor_free(desc_tmp);
|
||||
/* Okay. Now check whether the fingerprint is recognized. */
|
||||
if (!dirserv_router_fingerprint_is_known(ri)) {
|
||||
log(LOG_WARN, "Identity is unrecognized for descriptor");
|
||||
@@ -238,7 +236,7 @@ dirserv_add_descriptor(const char **desc)
|
||||
/* We already have a newer descriptor */
|
||||
log_fn(LOG_INFO,"We already have a newer desc for nickname %s. Not adding.",ri->nickname);
|
||||
/* This isn't really an error; return. */
|
||||
if (desc_tmp) free(desc_tmp);
|
||||
tor_free(desc_tmp);
|
||||
if (ri) routerinfo_free(ri);
|
||||
*desc = end;
|
||||
return 0;
|
||||
@@ -263,8 +261,7 @@ dirserv_add_descriptor(const char **desc)
|
||||
routerinfo_free(ri);
|
||||
return 0;
|
||||
err:
|
||||
if (desc_tmp)
|
||||
free(desc_tmp);
|
||||
tor_free(desc_tmp);
|
||||
if (ri)
|
||||
routerinfo_free(ri);
|
||||
|
||||
@@ -417,8 +414,7 @@ size_t dirserv_get_directory(const char **directory)
|
||||
free(new_directory);
|
||||
return 0;
|
||||
}
|
||||
if (the_directory)
|
||||
free(the_directory);
|
||||
tor_free(the_directory);
|
||||
the_directory = new_directory;
|
||||
the_directory_len = strlen(the_directory);
|
||||
log_fn(LOG_INFO,"New directory (size %d):\n%s",the_directory_len,
|
||||
|
||||
+2
-2
@@ -337,7 +337,7 @@ static void run_scheduled_events(time_t now) {
|
||||
/* 2. Every NewCircuitPeriod seconds, we expire old circuits and make a
|
||||
* new one as needed.
|
||||
*/
|
||||
if(options.APPort && time_to_new_circuit < now) {
|
||||
if(options.SocksPort && time_to_new_circuit < now) {
|
||||
circuit_expire_unused_circuits();
|
||||
circuit_launch_new(-1); /* tell it to forget about previous failures */
|
||||
circ = circuit_get_newest_open();
|
||||
@@ -595,7 +595,7 @@ static int do_main_loop(void) {
|
||||
* and start the listeners.
|
||||
*/
|
||||
retry_all_connections((uint16_t) options.ORPort,
|
||||
(uint16_t) options.APPort,
|
||||
(uint16_t) options.SocksPort,
|
||||
(uint16_t) options.DirPort);
|
||||
|
||||
for(;;) {
|
||||
|
||||
@@ -222,7 +222,7 @@ static unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len,
|
||||
for(i=0;i<*routelen;i++) {
|
||||
// log_fn(LOG_DEBUG,"Choosing hop %u.",i);
|
||||
if (CRYPTO_PSEUDO_RAND_INT(choice)) {
|
||||
free((void *)route);
|
||||
free(route);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ onion_skin_create(crypto_pk_env_t *dest_router_key,
|
||||
|
||||
return 0;
|
||||
err:
|
||||
if (pubkey) free(pubkey);
|
||||
tor_free(pubkey);
|
||||
if (dh) crypto_dh_free(dh);
|
||||
if (cipher) crypto_free_cipher_env(cipher);
|
||||
return -1;
|
||||
|
||||
+4
-2
@@ -335,7 +335,7 @@ typedef struct {
|
||||
|
||||
uint32_t addr; /* all host order */
|
||||
uint16_t or_port;
|
||||
uint16_t ap_port;
|
||||
uint16_t socks_port;
|
||||
uint16_t dir_port;
|
||||
|
||||
time_t published_on;
|
||||
@@ -426,9 +426,11 @@ typedef struct {
|
||||
char *Address;
|
||||
char *PidFile;
|
||||
char *ExitPolicy;
|
||||
char *SocksBindAddress;
|
||||
char *ORBindAddress;
|
||||
double CoinWeight;
|
||||
int ORPort;
|
||||
int APPort;
|
||||
int SocksPort;
|
||||
int DirPort;
|
||||
int MaxConn;
|
||||
int OnionRouter;
|
||||
|
||||
+16
-23
@@ -144,10 +144,8 @@ void routerinfo_free(routerinfo_t *router)
|
||||
if (!router)
|
||||
return;
|
||||
|
||||
if (router->address)
|
||||
free(router->address);
|
||||
if (router->nickname)
|
||||
free(router->nickname);
|
||||
tor_free(router->address);
|
||||
tor_free(router->nickname);
|
||||
if (router->onion_pkey)
|
||||
crypto_free_pk_env(router->onion_pkey);
|
||||
if (router->link_pkey)
|
||||
@@ -157,9 +155,9 @@ void routerinfo_free(routerinfo_t *router)
|
||||
while (router->exit_policy) {
|
||||
e = router->exit_policy;
|
||||
router->exit_policy = e->next;
|
||||
if (e->string) free(e->string);
|
||||
if (e->address) free(e->address);
|
||||
if (e->port) free(e->port);
|
||||
tor_free(e->string);
|
||||
tor_free(e->address);
|
||||
tor_free(e->port);
|
||||
free(e);
|
||||
}
|
||||
free(router);
|
||||
@@ -170,10 +168,8 @@ void directory_free(directory_t *dir)
|
||||
int i;
|
||||
for (i = 0; i < dir->n_routers; ++i)
|
||||
routerinfo_free(dir->routers[i]);
|
||||
if (dir->routers)
|
||||
free(dir->routers);
|
||||
if(dir->software_versions)
|
||||
free(dir->software_versions);
|
||||
tor_free(dir->routers);
|
||||
tor_free(dir->software_versions);
|
||||
free(dir);
|
||||
}
|
||||
|
||||
@@ -825,8 +821,8 @@ routerinfo_t *router_get_entry_from_string(char**s) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Router->ap_port */
|
||||
router->ap_port = atoi(ARGS[3]);
|
||||
/* Router->socks_port */
|
||||
router->socks_port = atoi(ARGS[3]);
|
||||
|
||||
/* Router->dir_port */
|
||||
router->dir_port = atoi(ARGS[4]);
|
||||
@@ -838,8 +834,8 @@ routerinfo_t *router_get_entry_from_string(char**s) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
log_fn(LOG_DEBUG,"or_port %d, ap_port %d, dir_port %d, bandwidth %d.",
|
||||
router->or_port, router->ap_port, router->dir_port, router->bandwidth);
|
||||
log_fn(LOG_DEBUG,"or_port %d, socks_port %d, dir_port %d, bandwidth %d.",
|
||||
router->or_port, router->socks_port, router->dir_port, router->bandwidth);
|
||||
|
||||
/* XXX Later, require platform before published. */
|
||||
NEXT_TOKEN();
|
||||
@@ -1039,12 +1035,9 @@ static int router_add_exit_policy(routerinfo_t *router,
|
||||
policy_read_failed:
|
||||
assert(newe->string);
|
||||
log_fn(LOG_WARN,"Couldn't parse line '%s'. Dropping", newe->string);
|
||||
if(newe->string)
|
||||
free(newe->string);
|
||||
if(newe->address)
|
||||
free(newe->address);
|
||||
if(newe->port)
|
||||
free(newe->port);
|
||||
tor_free(newe->string);
|
||||
tor_free(newe->address);
|
||||
tor_free(newe->port);
|
||||
free(newe);
|
||||
return -1;
|
||||
}
|
||||
@@ -1121,7 +1114,7 @@ int router_rebuild_descriptor(void) {
|
||||
ri->nickname = tor_strdup(options.Nickname);
|
||||
/* No need to set addr. */
|
||||
ri->or_port = options.ORPort;
|
||||
ri->ap_port = options.APPort;
|
||||
ri->socks_port = options.SocksPort;
|
||||
ri->dir_port = options.DirPort;
|
||||
ri->published_on = time(NULL);
|
||||
ri->onion_pkey = crypto_pk_dup_key(get_onion_key());
|
||||
@@ -1202,7 +1195,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
||||
router->nickname,
|
||||
router->address,
|
||||
router->or_port,
|
||||
router->ap_port,
|
||||
router->socks_port,
|
||||
router->dir_port,
|
||||
router->bandwidth,
|
||||
platform,
|
||||
|
||||
+8
-8
@@ -517,7 +517,7 @@ test_dir_format()
|
||||
r1.addr = 0xc0a80001u; /* 192.168.0.1 */
|
||||
r1.published_on = 0;
|
||||
r1.or_port = 9000;
|
||||
r1.ap_port = 9002;
|
||||
r1.socks_port = 9002;
|
||||
r1.dir_port = 9003;
|
||||
r1.onion_pkey = pk1;
|
||||
r1.identity_pkey = pk2;
|
||||
@@ -539,7 +539,7 @@ test_dir_format()
|
||||
r2.addr = 0x0a030201u; /* 10.3.2.1 */
|
||||
r2.published_on = 5;
|
||||
r2.or_port = 9005;
|
||||
r2.ap_port = 0;
|
||||
r2.socks_port = 0;
|
||||
r2.dir_port = 0;
|
||||
r2.onion_pkey = pk2;
|
||||
r2.identity_pkey = pk1;
|
||||
@@ -580,7 +580,7 @@ test_dir_format()
|
||||
test_assert(rp1);
|
||||
test_streq(rp1->address, r1.address);
|
||||
test_eq(rp1->or_port, r1.or_port);
|
||||
test_eq(rp1->ap_port, r1.ap_port);
|
||||
test_eq(rp1->socks_port, r1.socks_port);
|
||||
test_eq(rp1->dir_port, r1.dir_port);
|
||||
test_eq(rp1->bandwidth, r1.bandwidth);
|
||||
test_assert(crypto_pk_cmp_keys(rp1->onion_pkey, pk1) == 0);
|
||||
@@ -603,7 +603,7 @@ test_dir_format()
|
||||
test_assert(rp2);
|
||||
test_streq(rp2->address, r2.address);
|
||||
test_eq(rp2->or_port, r2.or_port);
|
||||
test_eq(rp2->ap_port, r2.ap_port);
|
||||
test_eq(rp2->socks_port, r2.socks_port);
|
||||
test_eq(rp2->dir_port, r2.dir_port);
|
||||
test_eq(rp2->bandwidth, r2.bandwidth);
|
||||
test_assert(crypto_pk_cmp_keys(rp2->onion_pkey, pk2) == 0);
|
||||
@@ -636,14 +636,14 @@ test_dir_format()
|
||||
test_eq(2, dir2->n_routers);
|
||||
#endif
|
||||
|
||||
if (pk1_str) free(pk1_str);
|
||||
if (pk2_str) free(pk2_str);
|
||||
tor_free(pk1_str);
|
||||
tor_free(pk2_str);
|
||||
if (pk1) crypto_free_pk_env(pk1);
|
||||
if (pk2) crypto_free_pk_env(pk2);
|
||||
if (rp1) routerinfo_free(rp1);
|
||||
if (rp2) routerinfo_free(rp2);
|
||||
if (dir1) free(dir1); /* And more !*/
|
||||
if (dir1) free(dir2); /* And more !*/
|
||||
tor_free(dir1); /* And more !*/
|
||||
tor_free(dir2); /* And more !*/
|
||||
|
||||
/* make sure compare_recommended_versions() works */
|
||||
test_eq(0, compare_recommended_versions("abc", "abc"));
|
||||
|
||||
Reference in New Issue
Block a user