Commit 975bb680 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

simplify: options.OnionRouter==1 iff options.ORPort>0


svn:r857
parent 84fffd36
......@@ -748,7 +748,7 @@ int circuit_establish_circuit(void) {
if(!n_conn || n_conn->state != OR_CONN_STATE_OPEN) { /* not currently connected */
circ->n_addr = firsthop->addr;
circ->n_port = firsthop->or_port;
if(options.OnionRouter) { /* we would be connected if he were up. but he's not. */
if(options.ORPort) { /* we would be connected if he were up. and he's not. */
log_fn(LOG_INFO,"Route's firsthop isn't connected.");
circuit_close(circ);
return -1;
......
......@@ -182,7 +182,6 @@ static void config_assign(or_options_t *options, struct config_line *list) {
config_compare(list, "ORPort", CONFIG_TYPE_INT, &options->ORPort) ||
config_compare(list, "ORBindAddress", CONFIG_TYPE_STRING, &options->ORBindAddress) ||
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) ||
......@@ -283,7 +282,6 @@ int getconfig(int argc, char **argv, or_options_t *options) {
static int backup_argc;
char *previous_pidfile = NULL;
int previous_runasdaemon = 0;
int previous_onionrouter = -1;
if(first_load) { /* first time we're called. save commandline args */
backup_argv = argv;
......@@ -296,7 +294,6 @@ int getconfig(int argc, char **argv, or_options_t *options) {
/* record some previous values, so we can fail if they change */
previous_pidfile = tor_strdup(options->PidFile);
previous_runasdaemon = options->RunAsDaemon;
previous_onionrouter = options->OnionRouter;
free_options(options);
}
init_options(options);
......@@ -349,11 +346,6 @@ int getconfig(int argc, char **argv, or_options_t *options) {
log_fn(LOG_WARN,"During reload, change from RunAsDaemon=1 to =0 not allowed. Failing.");
return -1;
}
if(previous_onionrouter >= 0 && previous_onionrouter != options->OnionRouter) {
log_fn(LOG_WARN,"During reload, OnionRouter changed from %d to %d. Failing.",
previous_onionrouter, options->OnionRouter);
return -1;
}
if(options->LogLevel) {
if(!strcmp(options->LogLevel,"err"))
......@@ -380,18 +372,13 @@ int getconfig(int argc, char **argv, or_options_t *options) {
result = -1;
}
if(options->OnionRouter && options->ORPort == 0) {
log(LOG_WARN,"If OnionRouter is set, then ORPort must be positive.");
result = -1;
}
if(options->OnionRouter && options->DataDirectory == NULL) {
log(LOG_WARN,"DataDirectory option required for OnionRouter, but not found.");
if(options->ORPort && options->DataDirectory == NULL) {
log(LOG_WARN,"DataDirectory option required if ORPort is set, but not found.");
result = -1;
}
if(options->OnionRouter && options->Nickname == NULL) {
log_fn(LOG_WARN,"Nickname required for OnionRouter, but not found.");
if(options->ORPort && options->Nickname == NULL) {
log_fn(LOG_WARN,"Nickname required if ORPort is set, but not found.");
result = -1;
}
......
......@@ -186,7 +186,7 @@ static int connection_tls_finish_handshake(connection_t *conn) {
connection_watch_events(conn, POLLIN);
log_fn(LOG_DEBUG,"tls handshake done. verifying.");
if (! tor_tls_peer_has_cert(conn->tls)) { /* It's an OP. */
if (options.OnionRouter) { /* I'm an OR; good. */
if (options.ORPort) { /* I'm an OR; good. */
conn->receiver_bucket = conn->bandwidth = DEFAULT_BANDWIDTH_OP;
return 0;
} else { /* Neither side sent a certificate: ouch. */
......@@ -236,7 +236,7 @@ static int connection_tls_finish_handshake(connection_t *conn) {
nickname, conn->nickname);
return -1;
}
if (!options.OnionRouter) { /* If I'm an OP... */
if (!options.ORPort) { /* If I'm an OP... */
conn->receiver_bucket = conn->bandwidth = DEFAULT_BANDWIDTH_OP;
circuit_n_conn_open(conn); /* send the pending creates, if any. */
}
......
......@@ -125,7 +125,7 @@ int connection_dir_process_inbuf(connection_t *conn) {
} else {
log_fn(LOG_INFO,"updated routers.");
}
if(options.OnionRouter) { /* connect to them all */
if(options.ORPort) { /* connect to them all */
router_retry_connections();
}
return -1;
......
......@@ -292,7 +292,7 @@ static void run_connection_housekeeping(int i, time_t now) {
return;
if(now >= conn->timestamp_lastwritten + options.KeepalivePeriod) {
if((!options.OnionRouter && !circuit_get_by_conn(conn)) ||
if((!options.ORPort && !circuit_get_by_conn(conn)) ||
(!connection_state_is_open(conn))) {
/* we're an onion proxy, with no circuits; or our handshake has expired. kill it. */
log_fn(LOG_INFO,"Expiring connection to %d (%s:%d).",
......@@ -322,7 +322,7 @@ static void run_scheduled_events(time_t now) {
* our descriptor (if any). */
if(time_to_fetch_directory < now) {
/* it's time to fetch a new directory and/or post our descriptor */
if(options.OnionRouter) {
if(options.ORPort) {
router_rebuild_descriptor();
router_upload_desc_to_dirservers();
}
......@@ -485,7 +485,7 @@ static int init_keys(void)
crypto_pk_env_t *prkey;
/* OP's don't need keys. Just initialize the TLS context.*/
if (!options.OnionRouter) {
if (!options.ORPort) {
assert(!options.DirPort);
if (tor_tls_context_new(NULL, 0, NULL)<0) {
log_fn(LOG_ERR, "Error creating TLS context for OP.");
......@@ -652,7 +652,7 @@ static int do_main_loop(void) {
return -1;
}
if(options.OnionRouter) {
if(options.ORPort) {
cpu_init(); /* launch cpuworkers. Need to do this *after* we've read the onion key. */
router_upload_desc_to_dirservers(); /* upload our descriptor to all dirservers */
}
......@@ -674,7 +674,7 @@ static int do_main_loop(void) {
please_dumpstats = 0;
}
if(please_reset) {
log_fn(LOG_INFO,"Hupped. Reloading config.");
log_fn(LOG_WARN,"Received sighup. Reloading config.");
/* first, reload config variables, in case they've changed */
if (init_from_config(0, NULL) < 0) {
/* no need to provide argc/v, they've been cached inside init_from_config */
......@@ -828,7 +828,7 @@ int tor_main(int argc, char *argv[]) {
if (init_from_config(argc,argv) < 0)
return -1;
if(options.OnionRouter) { /* only spawn dns handlers if we're a router */
if(options.ORPort) { /* only spawn dns handlers if we're a router */
dns_init(); /* initialize the dns resolve tree, and spawn workers */
}
if(options.SocksPort) {
......
......@@ -386,7 +386,7 @@ static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len) {
log_fn(LOG_DEBUG,"Nope, the directory says %d is not running.",i);
goto next_i_loop;
}
if(options.OnionRouter) {
if(options.ORPort) {
conn = connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port);
if(!conn || conn->type != CONN_TYPE_OR || conn->state != OR_CONN_STATE_OPEN) {
log_fn(LOG_DEBUG,"Nope, %d is not connected.",i);
......@@ -457,6 +457,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
return -1;
}
start:
/* XXX through each of these, don't pick nodes that are down */
if(cur_len == 0) { /* picking entry node */
log_fn(LOG_DEBUG, "Contemplating first hop: random choice.");
choice = rarray[crypto_pseudo_rand_int(rarray_len)];
......@@ -474,7 +475,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
!strcasecmp(choice->nickname, state->chosen_exit)) {
goto again;
}
for (i = 0, cpath = *head_ptr; i < cur_len; ++i, cpath=cpath->next) {
r = router_get_by_addr_port(cpath->addr, cpath->port);
if ((r && !crypto_pk_cmp_keys(r->onion_pkey, choice->onion_pkey))
......@@ -482,7 +483,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
!strcasecmp(choice->nickname, state->chosen_exit))
|| (cpath->addr == choice->addr &&
cpath->port == choice->or_port)
|| (options.OnionRouter &&
|| (options.ORPort &&
!(connection_twin_get_by_addr_port(choice->addr,
choice->or_port)))) {
goto again;
......
......@@ -451,7 +451,6 @@ typedef struct {
int SocksPort;
int DirPort;
int MaxConn;
int OnionRouter;
int TrafficShaping;
int LinkPadding;
int IgnoreVersion;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment