mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
relay: Simplify some relay_config code
Part of 32213.
This commit is contained in:
parent
d3c8486724
commit
4d9a5c77f8
@ -242,6 +242,7 @@ parse_ports_relay(or_options_t *options,
|
|||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
smartlist_t *ports = smartlist_new();
|
smartlist_t *ports = smartlist_new();
|
||||||
|
int n_low_ports = 0;
|
||||||
|
|
||||||
if (BUG(!options))
|
if (BUG(!options))
|
||||||
goto err;
|
goto err;
|
||||||
@ -255,40 +256,40 @@ parse_ports_relay(or_options_t *options,
|
|||||||
if (BUG(!have_low_ports_out))
|
if (BUG(!have_low_ports_out))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (! options->ClientOnly) {
|
if (options->ClientOnly) {
|
||||||
if (parse_port_config(ports,
|
retval = 0;
|
||||||
options->ORPort_lines,
|
goto err;
|
||||||
"OR", CONN_TYPE_OR_LISTENER,
|
}
|
||||||
"0.0.0.0", 0,
|
|
||||||
CL_PORT_SERVER_OPTIONS) < 0) {
|
if (parse_port_config(ports,
|
||||||
*msg = tor_strdup("Invalid ORPort configuration");
|
options->ORPort_lines,
|
||||||
goto err;
|
"OR", CONN_TYPE_OR_LISTENER,
|
||||||
}
|
"0.0.0.0", 0,
|
||||||
if (parse_port_config(ports,
|
CL_PORT_SERVER_OPTIONS) < 0) {
|
||||||
options->ExtORPort_lines,
|
*msg = tor_strdup("Invalid ORPort configuration");
|
||||||
"ExtOR", CONN_TYPE_EXT_OR_LISTENER,
|
goto err;
|
||||||
"127.0.0.1", 0,
|
}
|
||||||
CL_PORT_SERVER_OPTIONS|CL_PORT_WARN_NONLOCAL) < 0) {
|
if (parse_port_config(ports,
|
||||||
*msg = tor_strdup("Invalid ExtORPort configuration");
|
options->ExtORPort_lines,
|
||||||
goto err;
|
"ExtOR", CONN_TYPE_EXT_OR_LISTENER,
|
||||||
}
|
"127.0.0.1", 0,
|
||||||
if (parse_port_config(ports,
|
CL_PORT_SERVER_OPTIONS|CL_PORT_WARN_NONLOCAL) < 0) {
|
||||||
options->DirPort_lines,
|
*msg = tor_strdup("Invalid ExtORPort configuration");
|
||||||
"Dir", CONN_TYPE_DIR_LISTENER,
|
goto err;
|
||||||
"0.0.0.0", 0,
|
}
|
||||||
CL_PORT_SERVER_OPTIONS) < 0) {
|
if (parse_port_config(ports,
|
||||||
*msg = tor_strdup("Invalid DirPort configuration");
|
options->DirPort_lines,
|
||||||
goto err;
|
"Dir", CONN_TYPE_DIR_LISTENER,
|
||||||
}
|
"0.0.0.0", 0,
|
||||||
|
CL_PORT_SERVER_OPTIONS) < 0) {
|
||||||
|
*msg = tor_strdup("Invalid DirPort configuration");
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int n_low_ports = 0;
|
|
||||||
if (check_server_ports(ports, options, &n_low_ports) < 0) {
|
if (check_server_ports(ports, options, &n_low_ports) < 0) {
|
||||||
*msg = tor_strdup("Misconfigured server ports");
|
*msg = tor_strdup("Misconfigured server ports");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if (*have_low_ports_out < 0)
|
|
||||||
*have_low_ports_out = (n_low_ports > 0);
|
|
||||||
|
|
||||||
smartlist_add_all(ports_out, ports);
|
smartlist_add_all(ports_out, ports);
|
||||||
smartlist_free(ports);
|
smartlist_free(ports);
|
||||||
@ -296,6 +297,8 @@ parse_ports_relay(or_options_t *options,
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
if (*have_low_ports_out < 0)
|
||||||
|
*have_low_ports_out = (n_low_ports > 0);
|
||||||
if (ports) {
|
if (ports) {
|
||||||
SMARTLIST_FOREACH(ports, port_cfg_t *, p, port_cfg_free(p));
|
SMARTLIST_FOREACH(ports, port_cfg_t *, p, port_cfg_free(p));
|
||||||
smartlist_free(ports);
|
smartlist_free(ports);
|
||||||
@ -314,6 +317,9 @@ update_port_set_relay(or_options_t *options,
|
|||||||
if (BUG(!ports))
|
if (BUG(!ports))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (options->ClientOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Update the relay *Port_set options. The !! here is to force a boolean
|
/* Update the relay *Port_set options. The !! here is to force a boolean
|
||||||
* out of an integer. */
|
* out of an integer. */
|
||||||
options->ORPort_set =
|
options->ORPort_set =
|
||||||
@ -343,12 +349,14 @@ options_validate_relay_os(const or_options_t *old_options,
|
|||||||
if (BUG(!msg))
|
if (BUG(!msg))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (!server_mode(options))
|
||||||
|
return 0;
|
||||||
|
|
||||||
const char *uname = get_uname();
|
const char *uname = get_uname();
|
||||||
|
|
||||||
if (server_mode(options) &&
|
if (!strcmpstart(uname, "Windows 95") ||
|
||||||
(!strcmpstart(uname, "Windows 95") ||
|
!strcmpstart(uname, "Windows 98") ||
|
||||||
!strcmpstart(uname, "Windows 98") ||
|
!strcmpstart(uname, "Windows Me")) {
|
||||||
!strcmpstart(uname, "Windows Me"))) {
|
|
||||||
log_warn(LD_CONFIG, "Tor is running as a server, but you are "
|
log_warn(LD_CONFIG, "Tor is running as a server, but you are "
|
||||||
"running %s; this probably won't work. See "
|
"running %s; this probably won't work. See "
|
||||||
"https://www.torproject.org/docs/faq.html#BestOSForRelay "
|
"https://www.torproject.org/docs/faq.html#BestOSForRelay "
|
||||||
@ -572,19 +580,22 @@ options_validate_relay_padding(const or_options_t *old_options,
|
|||||||
if (BUG(!msg))
|
if (BUG(!msg))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (server_mode(options) && options->ConnectionPadding != -1) {
|
if (!server_mode(options))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (options->ConnectionPadding != -1) {
|
||||||
REJECT("Relays must use 'auto' for the ConnectionPadding setting.");
|
REJECT("Relays must use 'auto' for the ConnectionPadding setting.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server_mode(options) && options->ReducedConnectionPadding != 0) {
|
if (options->ReducedConnectionPadding != 0) {
|
||||||
REJECT("Relays cannot set ReducedConnectionPadding. ");
|
REJECT("Relays cannot set ReducedConnectionPadding. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server_mode(options) && options->CircuitPadding == 0) {
|
if (options->CircuitPadding == 0) {
|
||||||
REJECT("Relays cannot set CircuitPadding to 0. ");
|
REJECT("Relays cannot set CircuitPadding to 0. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server_mode(options) && options->ReducedCircuitPadding == 1) {
|
if (options->ReducedCircuitPadding == 1) {
|
||||||
REJECT("Relays cannot set ReducedCircuitPadding. ");
|
REJECT("Relays cannot set ReducedCircuitPadding. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1408,6 +1419,9 @@ options_act_relay_dir(const or_options_t *old_options)
|
|||||||
|
|
||||||
const or_options_t *options = get_options();
|
const or_options_t *options = get_options();
|
||||||
|
|
||||||
|
if (!public_server_mode(options))
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Load the webpage we're going to serve every time someone asks for '/' on
|
/* Load the webpage we're going to serve every time someone asks for '/' on
|
||||||
our DirPort. */
|
our DirPort. */
|
||||||
tor_free(global_dirfrontpagecontents);
|
tor_free(global_dirfrontpagecontents);
|
||||||
|
Loading…
Reference in New Issue
Block a user