Use LD_BUG as appropriate; convert rend* and router* to new logging interface; use new circ_log_path interface

svn:r5302
This commit is contained in:
Nick Mathewson 2005-10-24 19:39:45 +00:00
parent fa338d85db
commit f9b0be526e
13 changed files with 250 additions and 247 deletions

View File

@ -87,7 +87,7 @@ buf_normalize(buf_t *buf)
} else {
char *newmem, *oldmem;
size_t sz = (buf->mem+buf->len)-buf->cur;
warn(LD_GENERAL, "Unexpected non-normalized buffer.");
warn(LD_BUG, "Unexpected non-normalized buffer.");
newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(buf->len)));
SET_GUARDS(newmem, buf->len);
memcpy(newmem, buf->cur, sz);
@ -807,7 +807,7 @@ fetch_from_buf_http(buf_t *buf,
buf_normalize(buf);
if (buf_nul_terminate(buf)<0) {
warn(LD_GENERAL,"Couldn't nul-terminate buffer");
warn(LD_BUG,"Couldn't nul-terminate buffer");
return -1;
}
headers = buf->cur;

View File

@ -248,7 +248,7 @@ circuit_expire_building(time_t now)
else
log_fn(LOG_INFO,"Abandoning circ %d (state %d:%s, purpose %d)", victim->n_circ_id,
victim->state, circuit_state_to_string(victim->state), victim->purpose);
circuit_log_path(LOG_INFO,victim);
circuit_log_path(LOG_INFO,LD_CIRC,victim);
circuit_mark_for_close(victim);
}
}
@ -1123,7 +1123,7 @@ connection_ap_handshake_attach_circuit(connection_t *conn)
log_fn(LOG_DEBUG,"Attaching apconn to circ %d (stream %d sec old).",
circ->n_circ_id, conn_age);
/* here, print the circ's path. so people can figure out which circs are sucking. */
circuit_log_path(LOG_INFO,circ);
circuit_log_path(LOG_INFO,LD_APP,circ);
/* We have found a suitable circuit for our conn. Hurray. */
return connection_ap_handshake_attach_chosen_circuit(conn, circ);

View File

@ -359,7 +359,7 @@ connection_ap_expire_beginning(void)
log_fn(LOG_NOTICE,"Stream is %d seconds late on address '%s'. Retrying.",
(int)(now - conn->timestamp_lastread),
safe_str(conn->socks_request->address));
circuit_log_path(LOG_NOTICE, circ);
circuit_log_path(LOG_NOTICE, LD_APP, circ);
/* send an end down the circuit */
connection_edge_end(conn, END_STREAM_REASON_TIMEOUT, conn->cpath_layer);
/* un-mark it as ending, since we're going to reuse it */

View File

@ -1327,7 +1327,7 @@ handle_getinfo_helper(const char *question, char **answer)
case AP_CONN_STATE_OPEN:
state = "SUCCEEDED"; break;
default:
warn(LD_GENERAL, "Asked for stream in unknown state %d",
warn(LD_BUG, "Asked for stream in unknown state %d",
conns[i]->state);
continue;
}
@ -2318,7 +2318,7 @@ control_event_circuit_status(circuit_t *circ, circuit_status_event_t tp)
case CIRC_EVENT_FAILED: status = "FAILED"; break;
case CIRC_EVENT_CLOSED: status = "CLOSED"; break;
default:
warn(LD_GENERAL, "Unrecognized status code %d", (int)tp);
warn(LD_BUG, "Unrecognized status code %d", (int)tp);
return 0;
}
send_control1_event(EVENT_CIRCUIT_STATUS,
@ -2389,7 +2389,7 @@ control_event_stream_status(connection_t *conn, stream_status_event_t tp)
case STREAM_EVENT_NEW_RESOLVE: status = "NEWRESOLVE"; break;
case STREAM_EVENT_FAILED_RETRIABLE: status = "DETACHED"; break;
default:
warn(LD_GENERAL, "Unrecognized status code %d", (int)tp);
warn(LD_BUG, "Unrecognized status code %d", (int)tp);
return 0;
}
circ = circuit_get_by_edge_conn(conn);
@ -2431,7 +2431,7 @@ control_event_or_conn_status(connection_t *conn,or_conn_status_event_t tp)
case OR_CONN_EVENT_FAILED: status = "FAILED"; break;
case OR_CONN_EVENT_CLOSED: status = "CLOSED"; break;
default:
warn(LD_GENERAL, "Unrecognized status code %d", (int)tp);
warn(LD_BUG, "Unrecognized status code %d", (int)tp);
return 0;
}
send_control1_event(EVENT_OR_CONN_STATUS,

View File

@ -117,7 +117,6 @@ onion_pending_remove(circuit_t *circ)
} else { /* we need to hunt through the rest of the list */
for ( ;tmpo->next && tmpo->next->circ != circ; tmpo=tmpo->next) ;
if (!tmpo->next) {
/* XX is there a better category here? */
debug(LD_GENERAL,"circ (p_circ_id %d) not in list, probably at cpuworker.",circ->p_circ_id);
return;
}

View File

@ -676,7 +676,7 @@ connection_edge_process_end_not_open(
if (client_dns_incr_failures(conn->socks_request->address)
< MAX_RESOLVE_FAILURES) {
/* We haven't retried too many times; reattach the connection. */
circuit_log_path(LOG_INFO,circ);
circuit_log_path(LOG_INFO,LD_APP,circ);
tor_assert(circ->timestamp_dirty);
circ->timestamp_dirty -= get_options()->MaxCircuitDirtiness;
@ -708,7 +708,7 @@ connection_edge_process_end_not_open(
log_fn(LOG_INFO,"Edge got end (%s) before we're connected. Marking for close.",
connection_edge_end_reason_str(rh->length > 0 ? reason : -1));
if (conn->type == CONN_TYPE_AP) {
circuit_log_path(LOG_INFO,circ);
circuit_log_path(LOG_INFO,LD_APP,circ);
connection_mark_unattached_ap(conn, reason);
} else {
conn->has_sent_end = 1; /* we just got an 'end', don't need to send one */
@ -757,7 +757,7 @@ connection_edge_process_relay_cell_not_open(
client_dns_set_addressmap(conn->socks_request->address, addr,
conn->chosen_exit_name, ttl);
}
circuit_log_path(LOG_INFO,circ);
circuit_log_path(LOG_INFO,LD_APP,circ);
connection_ap_handshake_socks_reply(conn, NULL, 0, SOCKS5_SUCCEEDED);
/* handle anything that might have queued */
if (connection_edge_package_raw_inbuf(conn, 1) < 0) {

View File

@ -34,7 +34,7 @@ rend_client_send_establish_rendezvous(circuit_t *circ)
info(LD_REND, "Sending an ESTABLISH_RENDEZVOUS cell");
if (crypto_rand(circ->rend_cookie, REND_COOKIE_LEN) < 0) {
warn(LD_GENERAL, "Internal error: Couldn't produce random cookie.");
warn(LD_BUG, "Internal error: Couldn't produce random cookie.");
circuit_mark_for_close(circ);
return -1;
}
@ -76,7 +76,7 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc)
/* first 20 bytes of payload are the hash of bob's pk */
if (crypto_pk_get_digest(entry->parsed->pk, payload)<0) {
warn(LD_GENERAL, "Internal error: couldn't hash public key.");
warn(LD_BUG, "Internal error: couldn't hash public key.");
goto err;
}
@ -87,11 +87,11 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc)
tor_malloc_zero(sizeof(crypt_path_t));
cpath->magic = CRYPT_PATH_MAGIC;
if (!(cpath->dh_handshake_state = crypto_dh_new())) {
warn(LD_GENERAL, "Internal error: couldn't allocate DH.");
warn(LD_BUG, "Internal error: couldn't allocate DH.");
goto err;
}
if (crypto_dh_generate_public(cpath->dh_handshake_state)<0) {
warn(LD_GENERAL, "Internal error: couldn't generate g^x.");
warn(LD_BUG, "Internal error: couldn't generate g^x.");
goto err;
}
}
@ -120,7 +120,7 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc)
if (crypto_dh_get_public(cpath->dh_handshake_state, tmp+dh_offset,
DH_KEY_LEN)<0) {
warn(LD_GENERAL, "Internal error: couldn't extract g^x.");
warn(LD_BUG, "Internal error: couldn't extract g^x.");
goto err;
}
@ -130,7 +130,7 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc)
dh_offset+DH_KEY_LEN,
PK_PKCS1_OAEP_PADDING, 0);
if (r<0) {
warn(LD_GENERAL,"Internal error: hybrid pk encrypt failed.");
warn(LD_BUG,"Internal error: hybrid pk encrypt failed.");
goto err;
}
@ -142,7 +142,7 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc)
payload, payload_len,
introcirc->cpath->prev)<0) {
/* introcirc is already marked for close. leave rendcirc alone. */
warn(LD_GENERAL, "Couldn't send INTRODUCE1 cell");
warn(LD_BUG, "Couldn't send INTRODUCE1 cell");
return -1;
}
@ -269,7 +269,7 @@ rend_client_remove_intro_point(extend_info_t *failed_intro, const char *query)
r = rend_cache_lookup_entry(query, -1, &ent);
if (r<0) {
warn(LD_GENERAL, "Bug: malformed service ID '%s'.", safe_str(query));
warn(LD_BUG, "Bug: malformed service ID '%s'.", safe_str(query));
return -1;
}
if (r==0) {

View File

@ -366,7 +366,7 @@ rend_cache_store(const char *desc, size_t desc_len)
return -1;
}
if (rend_get_service_id(parsed->pk, query)<0) {
warn(LD_GENERAL,"Couldn't compute service ID.");
warn(LD_BUG,"Couldn't compute service ID.");
rend_service_descriptor_free(parsed);
return -1;
}

View File

@ -50,7 +50,7 @@ rend_mid_establish_intro(circuit_t *circ, const char *request, size_t request_le
memcpy(buf, circ->handshake_digest, DIGEST_LEN);
memcpy(buf+DIGEST_LEN, "INTRODUCE", 9);
if (crypto_digest(expected_digest, buf, DIGEST_LEN+9) < 0) {
warn(LD_GENERAL, "Internal error computing digest.");
warn(LD_BUG, "Internal error computing digest.");
goto err;
}
if (memcmp(expected_digest, request+2+asn1len, DIGEST_LEN)) {
@ -67,7 +67,7 @@ rend_mid_establish_intro(circuit_t *circ, const char *request, size_t request_le
/* The request is valid. First, compute the hash of Bob's PK.*/
if (crypto_pk_get_digest(pk, pk_digest)<0) {
warn(LD_GENERAL, "Internal error: couldn't hash public key.");
warn(LD_BUG, "Internal error: couldn't hash public key.");
goto err;
}

View File

@ -343,11 +343,11 @@ rend_service_load_keys(void)
/* Create service file */
if (rend_get_service_id(s->private_key, s->service_id)<0) {
warn(LD_GENERAL, "Internal error: couldn't encode service ID.");
warn(LD_BUG, "Internal error: couldn't encode service ID.");
return -1;
}
if (crypto_pk_get_digest(s->private_key, s->pk_digest)<0) {
warn(LD_GENERAL, "Bug: Couldn't compute hash of public key.");
warn(LD_BUG, "Bug: Couldn't compute hash of public key.");
return -1;
}
if (strlcpy(fname,s->directory,sizeof(fname)) >= sizeof(fname) ||
@ -534,12 +534,12 @@ rend_service_introduce(circuit_t *circuit, const char *request, size_t request_l
/* Try DH handshake... */
dh = crypto_dh_new();
if (!dh || crypto_dh_generate_public(dh)<0) {
warn(LD_GENERAL,"Internal error: couldn't build DH state or generate public key.");
warn(LD_BUG,"Internal error: couldn't build DH state or generate public key.");
goto err;
}
if (crypto_dh_compute_secret(dh, ptr+REND_COOKIE_LEN, DH_KEY_LEN, keys,
DIGEST_LEN+CPATH_KEY_MATERIAL_LEN)<0) {
warn(LD_GENERAL, "Internal error: couldn't complete DH handshake");
warn(LD_BUG, "Internal error: couldn't complete DH handshake");
goto err;
}
@ -714,7 +714,7 @@ rend_service_intro_has_opened(circuit_t *circuit)
len += 20;
r = crypto_pk_private_sign_digest(service->private_key, buf+len, buf, len);
if (r<0) {
warn(LD_GENERAL, "Internal error: couldn't sign introduction request.");
warn(LD_BUG, "Internal error: couldn't sign introduction request.");
goto err;
}
len += r;
@ -881,7 +881,7 @@ upload_service_descriptor(rend_service_t *service, int version)
version,
service->private_key,
&desc, &desc_len)<0) {
warn(LD_GENERAL, "Internal error: couldn't encode service descriptor; not uploading.");
warn(LD_BUG, "Internal error: couldn't encode service descriptor; not uploading.");
return;
}

View File

@ -5,6 +5,7 @@
/* $Id$ */
const char router_c_id[] = "$Id$";
#define NEW_LOG_INTERFACE
#include "or.h"
/**
@ -135,11 +136,11 @@ rotate_onion_key(void)
tor_snprintf(fname_prev,sizeof(fname_prev),
"%s/keys/secret_onion_key.old",get_options()->DataDirectory);
if (!(prkey = crypto_new_pk_env())) {
log(LOG_ERR, "Error creating crypto environment.");
err("Error creating crypto environment.");
goto error;
}
if (crypto_pk_generate_key(prkey)) {
log(LOG_ERR, "Error generating onion key");
err("Error generating onion key");
goto error;
}
if (file_status(fname) == FN_FILE) {
@ -147,10 +148,10 @@ rotate_onion_key(void)
goto error;
}
if (crypto_pk_write_private_key_to_filename(prkey, fname)) {
log(LOG_ERR, "Couldn't write generated key to \"%s\".", fname);
err("Couldn't write generated key to \"%s\".", fname);
goto error;
}
log_fn(LOG_INFO, "Rotating onion key");
info(LD_GENERAL, "Rotating onion key");
tor_mutex_acquire(key_lock);
if (lastonionkey)
crypto_free_pk_env(lastonionkey);
@ -161,7 +162,7 @@ rotate_onion_key(void)
mark_my_descriptor_dirty();
return;
error:
log_fn(LOG_WARN, "Couldn't rotate onion key.");
warn(LD_GENERAL, "Couldn't rotate onion key.");
}
/* Read an RSA secret key key from a file that was once named fname_old,
@ -177,8 +178,8 @@ init_key_from_file_name_changed(const char *fname_old,
/* The old filename exists, and the new one doesn't. Rename and load. */
if (rename(fname_old, fname_new) < 0) {
log_fn(LOG_ERR, "Couldn't rename \"%s\" to \"%s\": %s", fname_old, fname_new,
strerror(errno));
log_fn(LOG_ERR, LD_FS, "Couldn't rename \"%s\" to \"%s\": %s",
fname_old, fname_new, strerror(errno));
return NULL;
}
return init_key_from_file(fname_new);
@ -195,34 +196,34 @@ init_key_from_file(const char *fname)
FILE *file = NULL;
if (!(prkey = crypto_new_pk_env())) {
log(LOG_ERR, "Error creating crypto environment.");
err("Error creating crypto environment.");
goto error;
}
switch (file_status(fname)) {
case FN_DIR:
case FN_ERROR:
log(LOG_ERR, "Can't read key from \"%s\"", fname);
err("Can't read key from \"%s\"", fname);
goto error;
case FN_NOENT:
log(LOG_INFO, "No key found in \"%s\"; generating fresh key.", fname);
info(LD_GENERAL, "No key found in \"%s\"; generating fresh key.", fname);
if (crypto_pk_generate_key(prkey)) {
log(LOG_ERR, "Error generating onion key");
err("Error generating onion key");
goto error;
}
if (crypto_pk_check_key(prkey) <= 0) {
log(LOG_ERR, "Generated key seems invalid");
err("Generated key seems invalid");
goto error;
}
log(LOG_INFO, "Generated key seems valid");
info(LD_GENERAL, "Generated key seems valid");
if (crypto_pk_write_private_key_to_filename(prkey, fname)) {
log(LOG_ERR, "Couldn't write generated key to \"%s\".", fname);
err("Couldn't write generated key to \"%s\".", fname);
goto error;
}
return prkey;
case FN_FILE:
if (crypto_pk_read_private_key_from_filename(prkey, fname)) {
log(LOG_ERR, "Error loading private key.");
err("Error loading private key.");
goto error;
}
return prkey;
@ -273,7 +274,7 @@ init_keys(void)
if (tor_tls_context_new(get_identity_key(), 1,
options->Nickname ? options->Nickname : "client",
MAX_SSL_KEY_LIFETIME) < 0) {
log_fn(LOG_ERR, "Error creating TLS context for OP.");
err("Error creating TLS context for OP.");
return -1;
}
return 0;
@ -293,14 +294,14 @@ init_keys(void)
/* 1. Read identity key. Make it if none is found. */
tor_snprintf(keydir,sizeof(keydir),"%s/keys/identity.key",datadir);
tor_snprintf(keydir2,sizeof(keydir2),"%s/keys/secret_id_key",datadir);
log_fn(LOG_INFO,"Reading/making identity key \"%s\"...",keydir2);
info(LD_GENERAL,"Reading/making identity key \"%s\"...",keydir2);
prkey = init_key_from_file_name_changed(keydir,keydir2);
if (!prkey) return -1;
set_identity_key(prkey);
/* 2. Read onion key. Make it if none is found. */
tor_snprintf(keydir,sizeof(keydir),"%s/keys/onion.key",datadir);
tor_snprintf(keydir2,sizeof(keydir2),"%s/keys/secret_onion_key",datadir);
log_fn(LOG_INFO,"Reading/making onion key \"%s\"...",keydir2);
info(LD_GENERAL,"Reading/making onion key \"%s\"...",keydir2);
prkey = init_key_from_file_name_changed(keydir,keydir2);
if (!prkey) return -1;
set_onion_key(prkey);
@ -314,46 +315,46 @@ init_keys(void)
/* 3. Initialize link key and TLS context. */
if (tor_tls_context_new(get_identity_key(), 1, options->Nickname,
MAX_SSL_KEY_LIFETIME) < 0) {
log_fn(LOG_ERR, "Error initializing TLS context");
err("Error initializing TLS context");
return -1;
}
/* 4. Dump router descriptor to 'router.desc' */
/* Must be called after keys are initialized. */
mydesc = router_get_my_descriptor();
if (!mydesc) {
log_fn(LOG_ERR, "Error initializing descriptor.");
err("Error initializing descriptor.");
return -1;
}
if (authdir_mode(options)) {
const char *m;
/* We need to add our own fingerprint so it gets recognized. */
if (dirserv_add_own_fingerprint(options->Nickname, get_identity_key())) {
log_fn(LOG_ERR, "Error adding own fingerprint to approved set");
err("Error adding own fingerprint to approved set");
return -1;
}
if (dirserv_add_descriptor(mydesc, &m) < 0) {
log(LOG_ERR, "Unable to add own descriptor to directory: %s",
err("Unable to add own descriptor to directory: %s",
m?m:"<unknown error>");
return -1;
}
}
tor_snprintf(keydir,sizeof(keydir),"%s/router.desc", datadir);
log_fn(LOG_INFO,"Dumping descriptor to \"%s\"...",keydir);
info(LD_GENERAL,"Dumping descriptor to \"%s\"...",keydir);
if (write_str_to_file(keydir, mydesc,0)) {
return -1;
}
/* 5. Dump fingerprint to 'fingerprint' */
tor_snprintf(keydir,sizeof(keydir),"%s/fingerprint", datadir);
log_fn(LOG_INFO,"Dumping fingerprint to \"%s\"...",keydir);
info(LD_GENERAL,"Dumping fingerprint to \"%s\"...",keydir);
if (crypto_pk_get_fingerprint(get_identity_key(), fingerprint, 1)<0) {
log_fn(LOG_ERR, "Error computing fingerprint");
err("Error computing fingerprint");
return -1;
}
tor_assert(strlen(options->Nickname) <= MAX_NICKNAME_LEN);
if (tor_snprintf(fingerprint_line, sizeof(fingerprint_line),
"%s %s\n",options->Nickname, fingerprint) < 0) {
log_fn(LOG_ERR, "Error writing fingerprint line");
err("Error writing fingerprint line");
return -1;
}
if (write_str_to_file(keydir, fingerprint_line, 0))
@ -362,9 +363,9 @@ init_keys(void)
return 0;
/* 6. [authdirserver only] load approved-routers file */
tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", datadir);
log_fn(LOG_INFO,"Loading approved fingerprints from \"%s\"...",keydir);
info(LD_DIRSERV,"Loading approved fingerprints from \"%s\"...",keydir);
if (dirserv_parse_fingerprint_file(keydir) < 0) {
log_fn(LOG_ERR, "Error loading fingerprints");
err("Error loading fingerprints");
return -1;
}
/* 6b. [authdirserver only] add own key to approved directories. */
@ -452,7 +453,7 @@ consider_testing_reachability(void)
{
routerinfo_t *me = router_get_my_routerinfo();
if (!me) {
log_fn(LOG_WARN,"Bug: router_get_my_routerinfo() did not find my routerinfo?");
warn(LD_BUG,"Bug: router_get_my_routerinfo() did not find my routerinfo?");
return;
}
@ -473,7 +474,7 @@ router_orport_found_reachable(void)
{
if (!can_reach_or_port) {
if (!clique_mode(get_options()))
log(LOG_NOTICE,"Self-testing indicates your ORPort is reachable from the outside. Excellent.%s",
notice(LD_OR,"Self-testing indicates your ORPort is reachable from the outside. Excellent.%s",
get_options()->NoPublish ? "" : " Publishing server descriptor.");
can_reach_or_port = 1;
mark_my_descriptor_dirty();
@ -486,7 +487,7 @@ void
router_dirport_found_reachable(void)
{
if (!can_reach_dir_port) {
log(LOG_NOTICE,"Self-testing indicates your DirPort is reachable from the outside. Excellent.");
notice(LD_DIRSERV,"Self-testing indicates your DirPort is reachable from the outside. Excellent.");
can_reach_dir_port = 1;
}
}
@ -623,7 +624,7 @@ router_retry_connections(int force)
if (force ||
!connection_get_by_identity_digest(router->identity_digest,
CONN_TYPE_OR)) {
log_fn(LOG_DEBUG,"%sconnecting to %s at %s:%u.",
debug(LD_OR,"%sconnecting to %s at %s:%u.",
clique_mode(options) ? "(forced) " : "",
router->nickname, router->address, router->or_port);
/* Remember when we started trying to determine reachability */
@ -667,7 +668,7 @@ router_upload_dir_desc_to_dirservers(int force)
s = router_get_my_descriptor();
if (!s) {
log_fn(LOG_WARN, "No descriptor; skipping upload");
warn(LD_GENERAL, "No descriptor; skipping upload");
return;
}
if (!force && !desc_needs_upload)
@ -748,7 +749,7 @@ router_get_my_descriptor(void)
if (router_rebuild_descriptor(1))
return NULL;
}
log_fn(LOG_DEBUG,"my desc is '%s'",desc_routerinfo->signed_descriptor);
debug(LD_GENERAL,"my desc is '%s'",desc_routerinfo->signed_descriptor);
return desc_routerinfo->signed_descriptor;
}
@ -772,7 +773,7 @@ router_rebuild_descriptor(int force)
return 0;
if (resolve_my_address(options, &addr, NULL) < 0) {
log_fn(LOG_WARN,"options->Address didn't resolve into an IP.");
warn(LD_CONFIG,"options->Address didn't resolve into an IP.");
return -1;
}
@ -825,7 +826,7 @@ router_rebuild_descriptor(int force)
member = router_get_by_nickname(name, 1);
if (!member) {
if (!smartlist_string_isin(warned_nonexistent_family, name)) {
log_fn(LOG_WARN, "I have no descriptor for the router named \"%s\" "
warn(LD_CONFIG, "I have no descriptor for the router named \"%s\" "
"in my declared family; I'll use the nickname as is, but "
"this may confuse clients.", name);
smartlist_add(warned_nonexistent_family, tor_strdup(name));
@ -848,7 +849,7 @@ router_rebuild_descriptor(int force)
ri->signed_descriptor = tor_malloc(8192);
if (router_dump_router_to_string(ri->signed_descriptor, 8192,
ri, get_identity_key())<0) {
log_fn(LOG_WARN, "Couldn't allocate string for descriptor.");
warn(LD_BUG, "Couldn't allocate string for descriptor.");
return -1;
}
ri->signed_descriptor_len = strlen(ri->signed_descriptor);
@ -896,7 +897,7 @@ check_descriptor_bandwidth_changed(time_t now)
cur > prev*2 ||
cur < prev/2) {
if (last_changed+MAX_BANDWIDTH_CHANGE_FREQ < now) {
log_fn(LOG_INFO,"Measured bandwidth has changed; rebuilding descriptor.");
info(LD_GENERAL,"Measured bandwidth has changed; rebuilding descriptor.");
mark_my_descriptor_dirty();
last_changed = now;
}
@ -920,7 +921,7 @@ check_descriptor_ipaddress_changed(time_t now)
prev = desc_routerinfo->addr;
if (resolve_my_address(options, &cur, NULL) < 0) {
log_fn(LOG_WARN,"options->Address didn't resolve into an IP.");
warn(LD_CONFIG,"options->Address didn't resolve into an IP.");
return;
}
@ -937,7 +938,7 @@ check_descriptor_ipaddress_changed(time_t now)
tor_inet_ntoa(&in_cur, addrbuf_cur, sizeof(addrbuf_cur));
if (last_changed+MAX_IPADDRESS_CHANGE_FREQ < now) {
log_fn(LOG_INFO,"Our IP Address has changed from %s to %s; rebuilding descriptor.", addrbuf_prev, addrbuf_cur);
info(LD_GENERAL,"Our IP Address has changed from %s to %s; rebuilding descriptor.", addrbuf_prev, addrbuf_cur);
mark_my_descriptor_dirty();
last_changed = now;
last_warned_lastchangetime = 0;
@ -945,7 +946,7 @@ check_descriptor_ipaddress_changed(time_t now)
else
{
if (last_warned_lastchangetime != last_changed) {
log_fn(LOG_WARN,"Our IP Address seems to be flapping. It has changed twice within one hour (from %s to %s this time). Ignoring for now.", addrbuf_prev, addrbuf_cur);
warn(LD_GENERAL,"Our IP Address seems to be flapping. It has changed twice within one hour (from %s to %s this time). Ignoring for now.", addrbuf_prev, addrbuf_cur);
last_warned_lastchangetime = last_changed;
}
}
@ -1001,27 +1002,27 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
/* Make sure the identity key matches the one in the routerinfo. */
if (crypto_pk_cmp_keys(ident_key, router->identity_pkey)) {
log_fn(LOG_WARN,"Tried to sign a router with a private key that didn't match router's public key!");
warn(LD_BUG,"Tried to sign a router with a private key that didn't match router's public key!");
return -1;
}
/* record our fingerprint, so we can include it in the descriptor */
if (crypto_pk_get_fingerprint(router->identity_pkey, fingerprint, 1)<0) {
log_fn(LOG_ERR, "Error computing fingerprint");
err("Error computing fingerprint");
return -1;
}
/* PEM-encode the onion key */
if (crypto_pk_write_public_key_to_string(router->onion_pkey,
&onion_pkey,&onion_pkeylen)<0) {
log_fn(LOG_WARN,"write onion_pkey to string failed!");
warn(LD_BUG,"write onion_pkey to string failed!");
return -1;
}
/* PEM-encode the identity key key */
if (crypto_pk_write_public_key_to_string(router->identity_pkey,
&identity_pkey,&identity_pkeylen)<0) {
log_fn(LOG_WARN,"write identity_pkey to string failed!");
warn(LD_BUG,"write identity_pkey to string failed!");
tor_free(onion_pkey);
return -1;
}
@ -1141,7 +1142,7 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
if (router_append_dirobj_signature(s+written,maxlen-written,
digest,ident_key)<0) {
log_fn(LOG_WARN, "Couldn't sign router descriptor");
warn(LD_BUG, "Couldn't sign router descriptor");
return -1;
}
written += strlen(s+written);
@ -1156,8 +1157,7 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
cp = s_tmp = s_dup = tor_strdup(s);
ri_tmp = router_parse_entry_from_string(cp, NULL);
if (!ri_tmp) {
log_fn(LOG_ERR, "We just generated a router descriptor we can't parse: <<%s>>",
s);
err("We just generated a router descriptor we can't parse: <<%s>>", s);
return -1;
}
tor_free(s_dup);
@ -1175,8 +1175,9 @@ is_legal_nickname(const char *s)
tor_assert(s);
len = strlen(s);
return len > 0 && len <= MAX_NICKNAME_LEN &&
strspn(s,LEGAL_NICKNAME_CHARACTERS)==len;
strspn(s,LEGAL_NICKNAME_CHARACTERS) == len;
}
/** Return true iff <b>s</b> is a legally valid server nickname or
* hex-encoded identity-key digest. */
int

View File

@ -12,6 +12,7 @@ const char routerlist_c_id[] = "$Id$";
* servers.
**/
#define NEW_LOG_INTERFACE
#include "or.h"
/****************************************************************************/
@ -105,7 +106,7 @@ router_reload_networkstatus(void)
continue;
if (strlen(fn) != HEX_DIGEST_LEN ||
base16_decode(buf, sizeof(buf), fn, strlen(fn))) {
log_fn(LOG_INFO,
info(LD_DIR,
"Skipping cached-status file with unexpected name \"%s\"",fn);
continue;
}
@ -115,7 +116,7 @@ router_reload_networkstatus(void)
if (s) {
stat(filename, &st);
if (router_set_networkstatus(s, st.st_mtime, NS_FROM_CACHE, NULL)<0) {
log_fn(LOG_WARN, "Couldn't load networkstatus from \"%s\"",filename);
warn(LD_FS, "Couldn't load networkstatus from \"%s\"",filename);
}
tor_free(s);
}
@ -171,7 +172,7 @@ router_append_to_journal(const char *s, size_t len)
len = strlen(s);
if (append_bytes_to_file(fname, s, len, 0)) {
log_fn(LOG_WARN, "Unable to store router descriptor");
warn(LD_FS, "Unable to store router descriptor");
tor_free(fname);
return -1;
}
@ -213,8 +214,8 @@ router_rebuild_store(int force)
{
sized_chunk_t *c;
if (!ri->signed_descriptor) {
log_fn(LOG_WARN, "Bug! No descriptor stored for router '%s'.",
ri->nickname);
warn(LD_BUG, "Bug! No descriptor stored for router '%s'.",
ri->nickname);
goto done;
}
c = tor_malloc(sizeof(sized_chunk_t));
@ -224,7 +225,7 @@ router_rebuild_store(int force)
});
if (write_chunks_to_file(fname, chunk_list, 0)<0) {
log_fn(LOG_WARN, "Error writing router store to disk.");
warn(LD_FS, "Error writing router store to disk.");
goto done;
}
@ -328,7 +329,7 @@ router_pick_directory_server(int requireother,
if (choice || !retry_if_no_servers)
return choice;
log_fn(LOG_INFO,"No reachable router entries for dirservers. Trying them all again.");
info(LD_DIR,"No reachable router entries for dirservers. Trying them all again.");
/* mark all authdirservers as up again */
mark_all_trusteddirservers_up();
/* try again */
@ -337,7 +338,7 @@ router_pick_directory_server(int requireother,
if (choice)
return choice;
log_fn(LOG_INFO,"Still no %s router entries. Reloading and trying again.",
info(LD_DIR,"Still no %s router entries. Reloading and trying again.",
firewall_is_fascist() ? "reachable" : "known");
has_fetched_directory=0; /* reset it */
if (router_reload_router_list()) {
@ -382,7 +383,7 @@ router_pick_trusteddirserver(int need_v1_support,
if (choice || !retry_if_no_servers)
return choice;
log_fn(LOG_INFO,"No trusted dirservers are reachable. Trying them all again.");
info(LD_DIR,"No trusted dirservers are reachable. Trying them all again.");
mark_all_trusteddirservers_up();
return router_pick_trusteddirserver_impl(need_v1_support,
requireother, fascistfirewall);
@ -580,7 +581,7 @@ add_nickname_list_to_smartlist(smartlist_t *sl, const char *list, int warn_if_do
SMARTLIST_FOREACH(nickname_list, const char *, nick, {
int warned;
if (!is_legal_nickname_or_hexdigest(nick)) {
log_fn(LOG_WARN,"Nickname %s is misformed; skipping", nick);
warn(LD_CONFIG, "Nickname %s is misformed; skipping", nick);
continue;
}
router = router_get_by_nickname(nick, warn_if_unnamed);
@ -592,14 +593,14 @@ add_nickname_list_to_smartlist(smartlist_t *sl, const char *list, int warn_if_do
smartlist_string_remove(warned_nicknames, nick);
} else {
if (!warned) {
log_fn(warn_if_down ? LOG_WARN : LOG_DEBUG,
log_fn(warn_if_down ? LOG_WARN : LOG_DEBUG, LD_CONFIG,
"Nickname list includes '%s' which is known but down.",nick);
smartlist_add(warned_nicknames, tor_strdup(nick));
}
}
} else {
if (!warned) {
log_fn(has_fetched_directory ? LOG_WARN : LOG_INFO,
log_fn(has_fetched_directory ? LOG_WARN : LOG_INFO, LD_CONFIG,
"Nickname list includes '%s' which isn't a known router.",nick);
smartlist_add(warned_nicknames, tor_strdup(nick));
}
@ -831,7 +832,7 @@ router_choose_random_node(const char *preferred,
}
smartlist_free(excludednodes);
if (!choice)
log_fn(LOG_WARN,"No available nodes when trying to choose node. Failing.");
warn(LD_CIRC,"No available nodes when trying to choose node. Failing.");
return choice;
}
@ -930,7 +931,7 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed)
});
if (any_unwarned) {
char *alternatives = smartlist_join_strings(fps, "; ",0,NULL);
log_fn(LOG_WARN, "There are multiple matches for the nickname \"%s\","
warn(LD_CONFIG, "There are multiple matches for the nickname \"%s\","
" but none is listed as named by the directory authories. "
"Choosing one arbitrarily. If you meant one in particular, "
"you should say %s.", nickname, alternatives);
@ -944,7 +945,7 @@ router_get_by_nickname(const char *nickname, int warn_if_unnamed)
if (rs && !rs->name_lookup_warned) {
char fp[HEX_DIGEST_LEN+1];
base16_encode(fp, sizeof(fp), best_match->identity_digest, DIGEST_LEN);
log_fn(LOG_WARN, "You specified a server \"%s\" by name, but the "
warn(LD_CONFIG, "You specified a server \"%s\" by name, but the "
"directory authorities do not have a listing for this name. "
"To make sure you get the same server in the future, refer to "
"it by key, as \"$%s\".", nickname, fp);
@ -1272,9 +1273,9 @@ router_mark_as_down(const char *digest)
router = router_get_by_digest(digest);
if (!router) /* we don't seem to know about him in the first place */
return;
log_fn(LOG_DEBUG,"Marking router '%s' as down.",router->nickname);
debug(LD_DIR,"Marking router '%s' as down.",router->nickname);
if (router_is_me(router) && !we_are_hibernating())
log_fn(LOG_WARN, "We just marked ourself as down. Are your external addresses reachable?");
warn(LD_NET, "We just marked ourself as down. Are your external addresses reachable?");
router->is_running = 0;
}
@ -1338,7 +1339,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
if (!crypto_pk_cmp_keys(router->identity_pkey,old_router->identity_pkey)) {
if (router->published_on <= old_router->published_on) {
/* Same key, but old */
log_fn(LOG_DEBUG, "Skipping not-new descriptor for router '%s'",
debug(LD_DIR, "Skipping not-new descriptor for router '%s'",
router->nickname);
routerinfo_free(router);
*msg = "Router descriptor was not new.";
@ -1346,7 +1347,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
} else {
/* Same key, new. */
int unreachable = 0;
log_fn(LOG_DEBUG, "Replacing entry for router '%s/%s' [%s]",
debug(LD_DIR, "Replacing entry for router '%s/%s' [%s]",
router->nickname, old_router->nickname,
hex_str(id_digest,DIGEST_LEN));
if (router->addr == old_router->addr &&
@ -1361,11 +1362,11 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
dirserv_thinks_router_is_blatantly_unreachable(router, time(NULL))) {
if (router->num_unreachable_notifications >= 3) {
unreachable = 1;
log_fn(LOG_NOTICE, "Notifying server '%s' that it's unreachable. (ContactInfo '%s', platform '%s').",
notice(LD_DIR, "Notifying server '%s' that it's unreachable. (ContactInfo '%s', platform '%s').",
router->nickname, router->contact_info ? router->contact_info : "",
router->platform ? router->platform : "");
} else {
log_fn(LOG_INFO,"'%s' may be unreachable -- the %d previous descriptors were thought to be unreachable.", router->nickname, router->num_unreachable_notifications);
info(LD_DIR,"'%s' may be unreachable -- the %d previous descriptors were thought to be unreachable.", router->nickname, router->num_unreachable_notifications);
router->num_unreachable_notifications++;
}
}
@ -1393,7 +1394,8 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
connection_t *conn;
while ((conn = connection_get_by_identity_digest(
old_router->identity_digest, CONN_TYPE_OR))) {
log_fn(LOG_INFO,"Closing conn to obsolete router '%s'",
// And LD_OR? XXXXNM
info(LD_DIR,"Closing conn to router '%s'; there is now a named router with that name.",
old_router->nickname);
connection_mark_for_close(conn);
}
@ -1401,7 +1403,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
routerinfo_free(old_router);
} else if (old_router->is_named) {
/* Can't replace a verified router with an unverified one. */
log_fn(LOG_DEBUG, "Skipping unverified entry for verified router '%s'",
debug(LD_DIR, "Skipping unverified entry for verified router '%s'",
router->nickname);
routerinfo_free(router);
*msg = "Already have named router with same nickname and different key.";
@ -1436,7 +1438,7 @@ routerlist_remove_old_routers(int age)
router = smartlist_get(routerlist->routers, i);
if (router->published_on <= cutoff) {
/* Too old. Remove it. */
log_fn(LOG_INFO,"Forgetting obsolete routerinfo for router '%s'", router->nickname);
info(LD_DIR,"Forgetting obsolete (too old) routerinfo for router '%s'", router->nickname);
routerlist_remove(routerlist, router, i--);
routerinfo_free(router);
}
@ -1464,12 +1466,12 @@ router_load_single_router(const char *s, const char **msg)
*msg = NULL;
if (!(ri = router_parse_entry_from_string(s, NULL))) {
log_fn(LOG_WARN, "Error parsing router descriptor; dropping.");
warn(LD_DIR, "Error parsing router descriptor; dropping.");
*msg = "Couldn't parse router descriptor.";
return -1;
}
if (router_is_me(ri)) {
log_fn(LOG_WARN, "Router's identity key matches mine; dropping.");
warn(LD_DIR, "Router's identity key matches mine; dropping.");
*msg = "Router's identity key matches mine.";
routerinfo_free(ri);
return 0;
@ -1480,7 +1482,7 @@ router_load_single_router(const char *s, const char **msg)
routers_update_status_from_networkstatus(lst, 0, 1);
if (router_add_to_routerlist(ri, msg, 0)<0) {
log_fn(LOG_WARN, "Couldn't add router to list: %s Dropping.",
warn(LD_DIR, "Couldn't add router to list: %s Dropping.",
*msg?*msg:"(No message).");
/* we've already assigned to *msg now, and ri is already freed */
smartlist_free(lst);
@ -1488,7 +1490,7 @@ router_load_single_router(const char *s, const char **msg)
} else {
control_event_descriptors_changed(lst);
smartlist_free(lst);
log_fn(LOG_DEBUG, "Added router to list");
debug(LD_DIR, "Added router to list");
return 1;
}
}
@ -1523,7 +1525,7 @@ router_load_routers_from_string(const char *s, int from_cache,
} else {
char *requested =
smartlist_join_strings(requested_fingerprints," ",0,NULL);
log_fn(LOG_WARN, "We received a router descriptor with a fingerprint (%s) that we never requested. (We asked for: %s.) Dropping.", fp, requested);
warn(LD_DIR, "We received a router descriptor with a fingerprint (%s) that we never requested. (We asked for: %s.) Dropping.", fp, requested);
tor_free(requested);
routerinfo_free(ri);
continue;
@ -1609,11 +1611,11 @@ router_set_networkstatus(const char *s, time_t arrived_at,
ns = networkstatus_parse_from_string(s);
if (!ns) {
log_fn(LOG_WARN, "Couldn't parse network status.");
warn(LD_DIR, "Couldn't parse network status.");
return -1;
}
if (!(trusted_dir=router_get_trusteddirserver_by_digest(ns->identity_digest))) {
log_fn(LOG_INFO, "Network status was signed, but not by an authoritative directory we recognize.");
info(LD_DIR, "Network status was signed, but not by an authoritative directory we recognize.");
networkstatus_free(ns);
return -1;
}
@ -1626,7 +1628,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
format_iso_time(published, ns->published_on);
if (ns->published_on > now + NETWORKSTATUS_ALLOW_SKEW) {
log_fn(LOG_WARN, "Network status from %s was published in the future (%s GMT). Somebody is skewed here: check your clock. Not caching.", trusted_dir->description, published);
warn(LD_GENERAL, "Network status from %s was published in the future (%s GMT). Somebody is skewed here: check your clock. Not caching.", trusted_dir->description, published);
skewed = 1;
}
@ -1646,7 +1648,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
smartlist_string_remove(requested_fingerprints, fp);
} else {
char *requested = smartlist_join_strings(requested_fingerprints," ",0,NULL);
log_fn(LOG_WARN, "We received a network status with a fingerprint (%s) that we never requested. (We asked for: %s.) Dropping.", fp, requested);
warn(LD_DIR, "We received a network status with a fingerprint (%s) that we never requested. (We asked for: %s.) Dropping.", fp, requested);
tor_free(requested);
return 0;
}
@ -1664,7 +1666,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
ns->networkstatus_digest, DIGEST_LEN)) {
/* Same one we had before. */
networkstatus_free(ns);
log_fn(LOG_INFO,
info(LD_DIR,
"Not replacing network-status from %s (published %s); "
"we already have it.",
trusted_dir->description, published);
@ -1681,7 +1683,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
} else if (old_ns->published_on >= ns->published_on) {
char old_published[ISO_TIME_LEN+1];
format_iso_time(old_published, old_ns->published_on);
log_fn(LOG_INFO,
info(LD_DIR,
"Not replacing network-status from %s (published %s);"
" we have a newer one (published %s) for this authority.",
trusted_dir->description, published,
@ -1700,7 +1702,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
if (!found)
smartlist_add(networkstatus_list, ns);
log_fn(LOG_INFO, "Setting networkstatus %s %s (published %s)",
info(LD_DIR, "Setting networkstatus %s %s (published %s)",
source == NS_FROM_CACHE?"cached from":
(source==NS_FROM_DIR?"downloaded from":"generated for"),
trusted_dir->description, published);
@ -1711,7 +1713,7 @@ router_set_networkstatus(const char *s, time_t arrived_at,
if (source != NS_FROM_CACHE && !skewed) {
char *fn = networkstatus_get_cache_filename(ns);
if (write_str_to_file(fn, s, 0)<0) {
log_fn(LOG_NOTICE, "Couldn't write cached network status to \"%s\"", fn);
notice(LD_FS, "Couldn't write cached network status to \"%s\"", fn);
}
tor_free(fn);
}
@ -1747,7 +1749,7 @@ networkstatus_list_clean(time_t now)
smartlist_del(networkstatus_list, i--);
fname = networkstatus_get_cache_filename(ns);
if (file_status(fname) == FN_FILE) {
log_fn(LOG_INFO, "Removing too-old networkstatus in %s", fname);
info(LD_DIR, "Removing too-old networkstatus in %s", fname);
unlink(fname);
}
tor_free(fname);
@ -1917,14 +1919,14 @@ update_networkstatus_client_downloads(time_t now)
needed = n_running_dirservers;
if (needed)
log_fn(LOG_INFO, "For %d/%d running directory servers, we have %d live"
info(LD_DIR, "For %d/%d running directory servers, we have %d live"
" network-status documents. Downloading %d.",
n_running_dirservers, n_dirservers, n_live, needed);
/* Also, download at least 1 every NETWORKSTATUS_CLIENT_DL_INTERVAL. */
if (n_running_dirservers &&
most_recent_received < now-NETWORKSTATUS_CLIENT_DL_INTERVAL && needed < 1) {
log_fn(LOG_INFO, "Our most recent network-status document (from %s) "
info(LD_DIR, "Our most recent network-status document (from %s) "
"is %d seconds old; downloading another.",
most_recent?most_recent->description:"nobody",
(int)(now-most_recent_received));
@ -2144,7 +2146,7 @@ exit_policy_implicitly_allows_local_networks(addr_policy_t *policy,
if (policy_includes_addr_mask_implicitly(
policy, private_networks[i].addr, private_networks[i].mask, &p)) {
if (warn)
log_fn(LOG_WARN, "Exit policy %s implicitly accepts %s",
warn(LD_CONFIG, "Exit policy %s implicitly accepts %s",
p?p->string:"(default)",
private_networks[i].network);
r = 1;
@ -2179,13 +2181,13 @@ add_trusted_dir_server(const char *nickname, const char *address,
if (!address) { /* The address is us; we should guess. */
if (resolve_my_address(get_options(), &a, &hostname) < 0) {
log_fn(LOG_WARN, "Couldn't find a suitable address. Returning.");
warn(LD_CONFIG, "Couldn't find a suitable address when adding ourself as a trusted directory server.");
return;
}
} else {
if (tor_lookup_hostname(address, &a)) {
log_fn(LOG_WARN, "Unable to lookup address for directory server at %s",
address);
warn(LD_CONFIG, "Unable to lookup address for directory server at %s",
address);
return;
}
hostname = tor_strdup(address);
@ -2287,11 +2289,11 @@ routers_update_all_from_networkstatus(void)
if (n_recent >= 2 && n_listing >= 2) {
if (n_valid <= n_recent/2) {
log_fn(LOG_WARN, "%d/%d recent directory servers list us as invalid. Please consider sending your identity fingerprint to the tor-ops.",
warn(LD_GENERAL, "%d/%d recent directory servers list us as invalid. Please consider sending your identity fingerprint to the tor-ops.",
n_recent-n_valid, n_recent);
have_warned_about_unverified_status = 1;
} else if (n_named <= n_recent/2) {
log_fn(LOG_WARN, "%d/%d recent directory servers list us as unnamed. Please consider sending your identity fingerprint to the tor-ops.",
warn(LD_GENERAL, "%d/%d recent directory servers list us as unnamed. Please consider sending your identity fingerprint to the tor-ops.",
n_recent-n_valid, n_recent);
have_warned_about_unverified_status = 1;
}
@ -2324,19 +2326,19 @@ routers_update_all_from_networkstatus(void)
if (n_recent > 2 && n_recommended < n_recent/2) {
if (consensus == VS_NEW || consensus == VS_NEW_IN_SERIES) {
if (!have_warned_about_new_version) {
log_fn(LOG_NOTICE, "This version of Tor (%s) is newer than any recommended version%s, according to %d/%d recent network statuses.",
notice(LD_GENERAL, "This version of Tor (%s) is newer than any recommended version%s, according to %d/%d recent network statuses.",
VERSION, consensus == VS_NEW_IN_SERIES ? " in its series" : "",
n_recent-n_recommended, n_recent);
have_warned_about_new_version = 1;
}
} else {
log_fn(LOG_NOTICE, "This version of Tor (%s) is %s, according to %d/%d recent network statuses.",
notice(LD_GENERAL, "This version of Tor (%s) is %s, according to %d/%d recent network statuses.",
VERSION, consensus == VS_OLD ? "obsolete" : "not recommended",
n_recent-n_recommended, n_recent);
have_warned_about_old_version = 1;
}
} else {
log_fn(LOG_INFO, "%d/%d recent directories think my version is ok.",
info(LD_GENERAL, "%d/%d recent directories think my version is ok.",
n_recommended, n_recent);
}
}
@ -2377,7 +2379,7 @@ networkstatus_list_update_recent(time_t now)
ns->published_on + DEFAULT_RUNNING_INTERVAL > now) {
if (!ns->is_recent) {
format_iso_time(published, ns->published_on);
log_fn(LOG_INFO,
info(LD_DIR,
"Networkstatus from %s (published %s) is now \"recent\"",
src, published);
changed = 1;
@ -2387,7 +2389,7 @@ networkstatus_list_update_recent(time_t now)
} else {
if (ns->is_recent) {
format_iso_time(published, ns->published_on);
log_fn(LOG_INFO,
info(LD_DIR,
"Networkstatus from %s (published %s) is no longer \"recent\"",
src, published);
changed = 1;
@ -2435,12 +2437,12 @@ routerstatus_list_update_from_networkstatus(time_t now)
if (n_statuses < (n_trusted/2)+1) {
/* Not enough statuses to adjust status. */
log_fn(LOG_NOTICE,"Not enough statuses to update router status list. (%d/%d)",
notice(LD_DIR,"Not enough statuses to update router status list. (%d/%d)",
n_statuses, n_trusted);
return;
}
log_fn(LOG_INFO, "Rebuilding router status list.");
info(LD_DIR, "Rebuilding router status list.");
index = tor_malloc(sizeof(int)*n_statuses);
size = tor_malloc(sizeof(int)*n_statuses);
@ -2479,7 +2481,7 @@ routerstatus_list_update_from_networkstatus(time_t now)
char fp2[HEX_DIGEST_LEN+1];
base16_encode(fp1, sizeof(fp1), other_digest, DIGEST_LEN);
base16_encode(fp2, sizeof(fp2), rs->identity_digest, DIGEST_LEN);
log_fn(should_warn ? LOG_WARN : LOG_INFO,
log_fn(should_warn ? LOG_WARN : LOG_INFO, LD_DIR,
"Naming authorities disagree about which key goes with %s. ($%s vs $%s)",
rs->nickname, fp1, fp2);
strmap_set_lc(name_map, rs->nickname, conflict);
@ -2549,7 +2551,7 @@ routerstatus_list_update_from_networkstatus(time_t now)
char hd[HEX_DIGEST_LEN+1];
base16_encode(hd, HEX_DIGEST_LEN+1, rs->identity_digest, DIGEST_LEN);
if (! smartlist_string_isin(warned_conflicts, hd)) {
log_fn(LOG_WARN, "Naming authorities disagree about nicknames for $%s (\"%s\" vs \"%s\")",
warn(LD_DIR, "Naming authorities disagree about nicknames for $%s (\"%s\" vs \"%s\")",
hd, the_name, rs->nickname);
smartlist_add(warned_conflicts, tor_strdup(hd));
}
@ -2569,7 +2571,7 @@ routerstatus_list_update_from_networkstatus(time_t now)
rs_out->name_lookup_warned = rs_old->name_lookup_warned;
}
smartlist_add(result, rs_out);
log_fn(LOG_DEBUG, "Router '%s' is listed by %d/%d directories, "
debug(LD_DIR, "Router '%s' is listed by %d/%d directories, "
"named by %d/%d, validated by %d/%d, and %d/%d recent directories "
"think it's running.",
rs_out->status.nickname,
@ -2789,7 +2791,7 @@ router_list_downloadable(void)
});
}
log_fn(LOG_INFO, "%d router descriptors are downloadable; "
info(LD_DIR, "%d router descriptors are downloadable; "
"%d are up to date; %d are in progress; "
"%d are not ready to retry; "
"%d are not published recently enough to be worthwhile; "
@ -2842,7 +2844,7 @@ update_router_descriptor_downloads(time_t now)
get_all = 1;
if (get_all) {
log_fn(LOG_NOTICE, "Launching request for all routers");
notice(LD_DIR, "Launching request for all routers");
last_routerdesc_download_attempted = now;
directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,"all.z",1);
return;
@ -2851,11 +2853,11 @@ update_router_descriptor_downloads(time_t now)
downloadable = router_list_downloadable();
n_downloadable = smartlist_len(downloadable);
if (n_downloadable >= MAX_DL_TO_DELAY) {
log_fn(LOG_DEBUG,
debug(LD_DIR,
"There are enough downloadable routerdescs to launch requests.");
should_delay = 0;
} else if (n_downloadable == 0) {
log_fn(LOG_DEBUG, "No routerdescs need to be downloaded.");
debug(LD_DIR, "No routerdescs need to be downloaded.");
should_delay = 1;
} else {
if (dirserv) {
@ -2866,9 +2868,9 @@ update_router_descriptor_downloads(time_t now)
MAX_CLIENT_INTERVAL_WITHOUT_REQUEST) > now;
}
if (should_delay)
log_fn(LOG_DEBUG, "There are not many downloadable routerdescs; waiting till we have some more.");
debug(LD_DIR, "There are not many downloadable routerdescs; waiting till we have some more.");
else
log_fn(LOG_INFO, "There are not many downloadable routerdescs, but we've been waiting long enough (%d seconds). Downloading.",
info(LD_DIR, "There are not many downloadable routerdescs, but we've been waiting long enough (%d seconds). Downloading.",
(int)(now-last_routerdesc_download_attempted));
}
@ -2884,7 +2886,7 @@ update_router_descriptor_downloads(time_t now)
if (n_per_request < MIN_DL_PER_REQUEST)
n_per_request = MIN_DL_PER_REQUEST;
}
log_fn(LOG_INFO, "Launching %d request%s for %d router%s, %d at a time",
info(LD_DIR, "Launching %d request%s for %d router%s, %d at a time",
(n_downloadable+n_per_request-1)/n_per_request,
n_downloadable>n_per_request?"s":"",
n_downloadable, n_downloadable>1?"s":"", n_per_request);

View File

@ -10,6 +10,7 @@ const char routerparse_c_id[] = "$Id$";
* \brief Code to parse and validate router descriptors and directories.
**/
#define NEW_LOG_INTERFACE
#include "or.h"
/****************************************************************************/
@ -223,7 +224,7 @@ router_append_dirobj_signature(char *buf, size_t buf_len, const char *digest,
if (crypto_pk_private_sign(private_key, signature, digest, DIGEST_LEN) < 0) {
log_fn(LOG_WARN,"Couldn't sign digest.");
warn(LD_BUG,"Couldn't sign digest.");
return -1;
}
if (strlcat(buf, "-----BEGIN SIGNATURE-----\n", buf_len) >= buf_len)
@ -231,7 +232,7 @@ router_append_dirobj_signature(char *buf, size_t buf_len, const char *digest,
i = strlen(buf);
if (base64_encode(buf+i, buf_len-i, signature, 128) < 0) {
log_fn(LOG_WARN,"couldn't base64-encode signature");
warn(LD_BUG,"couldn't base64-encode signature");
tor_free(buf);
return -1;
}
@ -241,7 +242,7 @@ router_append_dirobj_signature(char *buf, size_t buf_len, const char *digest,
return 0;
truncated:
log_fn(LOG_WARN,"tried to exceed string length.");
warn(LD_BUG,"tried to exceed string length.");
return -1;
}
@ -270,11 +271,11 @@ tor_version_is_obsolete(const char *myversion, const char *versionlist)
vl = versionlist;
log_fn(LOG_DEBUG,"Checking whether version '%s' is in '%s'",
debug(LD_CONFIG,"Checking whether version '%s' is in '%s'",
myversion, versionlist);
if (tor_version_parse(myversion, &mine)) {
log_fn(LOG_ERR, "I couldn't parse my own version (%s)", myversion);
err("I couldn't parse my own version (%s)", myversion);
tor_assert(0);
}
version_sl = smartlist_create();
@ -370,29 +371,29 @@ router_parse_directory(const char *str)
* tuoch it. */
if (router_get_dir_hash(str, digest)) {
log_fn(LOG_WARN, "Unable to compute digest of directory");
warn(LD_DIR, "Unable to compute digest of directory");
goto err;
}
log_fn(LOG_DEBUG,"Received directory hashes to %s",hex_str(digest,4));
debug(LD_DIR,"Received directory hashes to %s",hex_str(digest,4));
/* Check signature first, before we try to tokenize. */
cp = str;
while (cp && (end = strstr(cp+1, "\ndirectory-signature")))
cp = end;
if (cp == str || !cp) {
log_fn(LOG_WARN, "No signature found on directory."); goto err;
warn(LD_DIR, "No signature found on directory."); goto err;
}
++cp;
tokens = smartlist_create();
if (tokenize_string(cp,strchr(cp,'\0'),tokens,DIR)) {
log_fn(LOG_WARN, "Error tokenizing directory signature"); goto err;
warn(LD_DIR, "Error tokenizing directory signature"); goto err;
}
if (smartlist_len(tokens) != 1) {
log_fn(LOG_WARN, "Unexpected number of tokens in signature"); goto err;
warn(LD_DIR, "Unexpected number of tokens in signature"); goto err;
}
tok=smartlist_get(tokens,0);
if (tok->tp != K_DIRECTORY_SIGNATURE) {
log_fn(LOG_WARN,"Expected a single directory signature"); goto err;
warn(LD_DIR,"Expected a single directory signature"); goto err;
}
declared_key = find_dir_signing_key(str);
if (check_directory_signature(digest, tok, NULL, declared_key, 1)<0)
@ -413,11 +414,11 @@ router_parse_directory(const char *str)
tokens = smartlist_create();
if (tokenize_string(str,end,tokens,DIR)) {
log_fn(LOG_WARN, "Error tokenizing directory"); goto err;
warn(LD_DIR, "Error tokenizing directory"); goto err;
}
if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
log_fn(LOG_WARN, "Missing published time on directory.");
warn(LD_DIR, "Missing published time on directory.");
goto err;
}
tor_assert(tok->n_args == 1);
@ -458,26 +459,26 @@ router_parse_runningrouters(const char *str)
smartlist_t *tokens = NULL;
if (router_get_runningrouters_hash(str, digest)) {
log_fn(LOG_WARN, "Unable to compute digest of directory");
warn(LD_DIR, "Unable to compute digest of directory");
goto err;
}
tokens = smartlist_create();
if (tokenize_string(str,str+strlen(str),tokens,DIR)) {
log_fn(LOG_WARN, "Error tokenizing directory"); goto err;
warn(LD_DIR, "Error tokenizing directory"); goto err;
}
if ((tok = find_first_by_keyword(tokens, _UNRECOGNIZED))) {
log_fn(LOG_WARN, "Unrecognized keyword '%s'; can't parse running-routers",
warn(LD_DIR, "Unrecognized keyword '%s'; can't parse running-routers",
tok->args[0]);
goto err;
}
tok = smartlist_get(tokens,0);
if (tok->tp != K_NETWORK_STATUS) {
log_fn(LOG_WARN, "Network-status starts with wrong token");
warn(LD_DIR, "Network-status starts with wrong token");
goto err;
}
if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
log_fn(LOG_WARN, "Missing published time on directory.");
warn(LD_DIR, "Missing published time on directory.");
goto err;
}
tor_assert(tok->n_args == 1);
@ -485,7 +486,7 @@ router_parse_runningrouters(const char *str)
goto err;
}
if (!(tok = find_first_by_keyword(tokens, K_DIRECTORY_SIGNATURE))) {
log_fn(LOG_WARN, "Missing signature on running-routers");
warn(LD_DIR, "Missing signature on running-routers");
goto err;
}
declared_key = find_dir_signing_key(str);
@ -527,11 +528,11 @@ find_dir_signing_key(const char *str)
tok = get_next_token(&cp, DIR);
if (!tok) {
log_fn(LOG_WARN, "Unparseable dir-signing-key token");
warn(LD_DIR, "Unparseable dir-signing-key token");
return NULL;
}
if (tok->tp != K_DIR_SIGNING_KEY) {
log_fn(LOG_WARN, "Dir-signing-key token did not parse as expected");
warn(LD_DIR, "Dir-signing-key token did not parse as expected");
return NULL;
}
@ -543,11 +544,11 @@ find_dir_signing_key(const char *str)
* can remove this logic. */
key = crypto_pk_DER64_decode_public_key(tok->args[0]);
if (!key) {
log_fn(LOG_WARN, "Unparseable dir-signing-key argument");
warn(LD_DIR, "Unparseable dir-signing-key argument");
return NULL;
}
} else {
log_fn(LOG_WARN, "Dir-signing-key token contained no key");
warn(LD_DIR, "Dir-signing-key token contained no key");
return NULL;
}
@ -563,11 +564,11 @@ dir_signing_key_is_trusted(crypto_pk_env_t *key)
char digest[DIGEST_LEN];
if (!key) return 0;
if (crypto_pk_get_digest(key, digest) < 0) {
log_fn(LOG_WARN, "Error computing dir-signing-key digest");
warn(LD_DIR, "Error computing dir-signing-key digest");
return 0;
}
if (!router_digest_is_trusted_dir(digest)) {
log_fn(LOG_WARN, "Listed dir-signing-key is not trusted");
warn(LD_DIR, "Listed dir-signing-key is not trusted");
return 0;
}
return 1;
@ -596,7 +597,7 @@ check_directory_signature(const char *digest,
crypto_pk_env_t *_pkey = NULL;
if (tok->n_args != 1) {
log_fn(LOG_WARN, "Too many or too few arguments to directory-signature");
warn(LD_DIR, "Too many or too few arguments to directory-signature");
return -1;
}
@ -609,12 +610,12 @@ check_directory_signature(const char *digest,
_pkey = pkey;
}
if (!_pkey) {
log_fn(LOG_WARN, "Obsolete directory format (dir signing key not present) or signing key not trusted--rejecting.");
warn(LD_DIR, "Obsolete directory format (dir signing key not present) or signing key not trusted--rejecting.");
return -1;
}
if (strcmp(tok->object_type, "SIGNATURE") || tok->object_size != 128) {
log_fn(LOG_WARN, "Bad object type or length on directory signature");
warn(LD_DIR, "Bad object type or length on directory signature");
return -1;
}
@ -622,12 +623,12 @@ check_directory_signature(const char *digest,
if (crypto_pk_public_checksig(_pkey, signed_digest, tok->object_body, 128)
!= 20) {
log_fn(LOG_WARN, "Error reading directory: invalid signature.");
warn(LD_DIR, "Error reading directory: invalid signature.");
return -1;
}
log_fn(LOG_DEBUG,"Signed directory hash starts %s", hex_str(signed_digest,4));
debug(LD_DIR,"Signed directory hash starts %s", hex_str(signed_digest,4));
if (memcmp(digest, signed_digest, DIGEST_LEN)) {
log_fn(LOG_WARN, "Error reading directory: signature does not match.");
warn(LD_DIR, "Error reading directory: signature does not match.");
return -1;
}
return 0;
@ -674,7 +675,7 @@ router_parse_list_from_string(const char **s, smartlist_t *dest)
* descriptor */
if (strcmpstart(cp, "\n-----END SIGNATURE-----\n")) {
log_fn(LOG_INFO, "Ignoring truncated router descriptor.");
info(LD_DIR, "Ignoring truncated router descriptor.");
continue;
}
@ -682,7 +683,7 @@ router_parse_list_from_string(const char **s, smartlist_t *dest)
*s = end;
if (!router) {
log_fn(LOG_WARN, "Error reading router; skipping");
warn(LD_DIR, "Error reading router; skipping");
continue;
}
smartlist_add(dest, router);
@ -716,28 +717,28 @@ router_parse_entry_from_string(const char *s, const char *end)
--end;
if (router_get_router_hash(s, digest) < 0) {
log_fn(LOG_WARN, "Couldn't compute router hash.");
warn(LD_DIR, "Couldn't compute router hash.");
return NULL;
}
tokens = smartlist_create();
if (tokenize_string(s,end,tokens,RTR)) {
log_fn(LOG_WARN, "Error tokeninzing router descriptor.");
warn(LD_DIR, "Error tokeninzing router descriptor.");
goto err;
}
if (smartlist_len(tokens) < 2) {
log_fn(LOG_WARN, "Impossibly short router descriptor.");
warn(LD_DIR, "Impossibly short router descriptor.");
goto err;
}
if ((tok = find_first_by_keyword(tokens, _UNRECOGNIZED))) {
log_fn(LOG_INFO, "Unrecognized critical keyword '%s'; skipping descriptor. (It may be from another version of Tor.)",
warn(LD_DIR, "Unrecognized critical keyword '%s'; skipping descriptor. (It may be from another version of Tor.)",
tok->args[0]);
goto err;
}
tok = smartlist_get(tokens,0);
if (tok->tp != K_ROUTER) {
log_fn(LOG_WARN,"Entry does not start with \"router\"");
warn(LD_DIR,"Entry does not start with \"router\"");
goto err;
}
@ -750,12 +751,12 @@ router_parse_entry_from_string(const char *s, const char *end)
if (tok->n_args == 2 || tok->n_args == 5 || tok->n_args == 6) {
router->nickname = tor_strdup(tok->args[0]);
if (!is_legal_nickname(router->nickname)) {
log_fn(LOG_WARN,"Router nickname is invalid");
warn(LD_DIR,"Router nickname is invalid");
goto err;
}
router->address = tor_strdup(tok->args[1]);
if (!tor_inet_aton(router->address, &in)) {
log_fn(LOG_WARN,"Router address is not an IP.");
warn(LD_DIR,"Router address is not an IP.");
goto err;
}
router->addr = ntohl(in.s_addr);
@ -766,17 +767,17 @@ router_parse_entry_from_string(const char *s, const char *end)
ports_set = 1;
}
} else {
log_fn(LOG_WARN,"Wrong # of arguments to \"router\" (%d)",tok->n_args);
warn(LD_DIR,"Wrong # of arguments to \"router\" (%d)",tok->n_args);
goto err;
}
tok = find_first_by_keyword(tokens, K_PORTS);
if (tok && ports_set) {
log_fn(LOG_WARN,"Redundant ports line");
warn(LD_DIR,"Redundant ports line");
goto err;
} else if (tok) {
if (tok->n_args != 3) {
log_fn(LOG_WARN,"Wrong # of arguments to \"ports\"");
warn(LD_DIR,"Wrong # of arguments to \"ports\"");
goto err;
}
router->or_port = (uint16_t) tor_parse_long(tok->args[0],10,0,65535,NULL,NULL);
@ -786,12 +787,12 @@ router_parse_entry_from_string(const char *s, const char *end)
tok = find_first_by_keyword(tokens, K_BANDWIDTH);
if (tok && bw_set) {
log_fn(LOG_WARN,"Redundant bandwidth line");
warn(LD_DIR,"Redundant bandwidth line");
goto err;
} else if (tok) {
if (tok->n_args < 3) {
/* XXXX Once 0.0.7 is *really* dead, restore this warning to its old form*/
log_fn(LOG_WARN,"Not enough arguments to \"bandwidth\": must be an obsolete server. Rejecting one server (nickname '%s').", router->nickname);
warn(LD_DIR,"Not enough arguments to \"bandwidth\": must be an obsolete server. Rejecting one server (nickname '%s').", router->nickname);
goto err;
}
router->bandwidthrate = tor_parse_long(tok->args[0],10,0,INT_MAX,NULL,NULL);
@ -802,7 +803,7 @@ router_parse_entry_from_string(const char *s, const char *end)
if ((tok = find_first_by_keyword(tokens, K_UPTIME))) {
if (tok->n_args != 1) {
log_fn(LOG_WARN, "Unrecognized number of args on K_UPTIME; skipping.");
warn(LD_DIR, "Unrecognized number of args on K_UPTIME; skipping.");
} else {
router->uptime = tor_parse_long(tok->args[0],10,0,LONG_MAX,NULL,NULL);
}
@ -810,7 +811,7 @@ router_parse_entry_from_string(const char *s, const char *end)
if ((tok = find_first_by_keyword(tokens, K_HIBERNATING))) {
if (tok->n_args < 1) {
log_fn(LOG_WARN, "Too few args on 'hibernating' keyword. Skipping.");
warn(LD_DIR, "Too few args on 'hibernating' keyword. Skipping.");
} else {
router->is_hibernating
= (tor_parse_long(tok->args[0],10,0,LONG_MAX,NULL,NULL) != 0);
@ -818,17 +819,17 @@ router_parse_entry_from_string(const char *s, const char *end)
}
if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
log_fn(LOG_WARN, "Missing published time"); goto err;
warn(LD_DIR, "Missing published time"); goto err;
}
tor_assert(tok->n_args == 1);
if (parse_iso_time(tok->args[0], &router->published_on) < 0)
goto err;
if (!(tok = find_first_by_keyword(tokens, K_ONION_KEY))) {
log_fn(LOG_WARN, "Missing onion key"); goto err;
warn(LD_DIR, "Missing onion key"); goto err;
}
if (crypto_pk_keysize(tok->key) != PK_BYTES) {
log_fn(LOG_WARN, "Wrong size on onion key: %d bits!",
warn(LD_DIR, "Wrong size on onion key: %d bits!",
(int)crypto_pk_keysize(tok->key)*8);
goto err;
}
@ -836,17 +837,17 @@ router_parse_entry_from_string(const char *s, const char *end)
tok->key = NULL; /* Prevent free */
if (!(tok = find_first_by_keyword(tokens, K_SIGNING_KEY))) {
log_fn(LOG_WARN, "Missing identity key"); goto err;
warn(LD_DIR, "Missing identity key"); goto err;
}
if (crypto_pk_keysize(tok->key) != PK_BYTES) {
log_fn(LOG_WARN, "Wrong size on identity key: %d bits!",
warn(LD_DIR, "Wrong size on identity key: %d bits!",
(int)crypto_pk_keysize(tok->key)*8);
goto err;
}
router->identity_pkey = tok->key;
tok->key = NULL; /* Prevent free */
if (crypto_pk_get_digest(router->identity_pkey,router->identity_digest)) {
log_fn(LOG_WARN, "Couldn't calculate key digest"); goto err;
warn(LD_DIR, "Couldn't calculate key digest"); goto err;
}
if ((tok = find_first_by_keyword(tokens, K_PLATFORM))) {
@ -860,7 +861,7 @@ router_parse_entry_from_string(const char *s, const char *end)
exit_policy_tokens = find_all_exitpolicy(tokens);
SMARTLIST_FOREACH(exit_policy_tokens, directory_token_t *, t,
if (router_add_exit_policy(router,t)<0) {
log_fn(LOG_WARN,"Error in exit policy");
warn(LD_DIR,"Error in exit policy");
goto err;
});
@ -869,7 +870,7 @@ router_parse_entry_from_string(const char *s, const char *end)
router->declared_family = smartlist_create();
for (i=0;i<tok->n_args;++i) {
if (!is_legal_nickname_or_hexdigest(tok->args[i])) {
log_fn(LOG_WARN, "Illegal nickname '%s' in family line", tok->args[i]);
warn(LD_DIR, "Illegal nickname '%s' in family line", tok->args[i]);
goto err;
}
smartlist_add(router->declared_family, tor_strdup(tok->args[i]));
@ -877,37 +878,37 @@ router_parse_entry_from_string(const char *s, const char *end)
}
if (!(tok = find_first_by_keyword(tokens, K_ROUTER_SIGNATURE))) {
log_fn(LOG_WARN, "Missing router signature");
warn(LD_DIR, "Missing router signature");
goto err;
}
if (strcmp(tok->object_type, "SIGNATURE") || tok->object_size != 128) {
log_fn(LOG_WARN, "Bad object type or length on router signature");
warn(LD_DIR, "Bad object type or length on router signature");
goto err;
}
if ((t=crypto_pk_public_checksig(router->identity_pkey, signed_digest,
tok->object_body, 128)) != 20) {
log_fn(LOG_WARN, "Invalid signature %d",t);
warn(LD_DIR, "Invalid signature %d",t);
goto err;
}
if (memcmp(digest, signed_digest, DIGEST_LEN)) {
log_fn(LOG_WARN, "Mismatched signature");
warn(LD_DIR, "Mismatched signature");
goto err;
}
if (!ports_set) {
log_fn(LOG_WARN,"No ports declared; failing.");
warn(LD_DIR,"No ports declared; failing.");
goto err;
}
if (!bw_set) {
log_fn(LOG_WARN,"No bandwidth declared; failing.");
warn(LD_DIR,"No bandwidth declared; failing.");
goto err;
}
if (!router->or_port) {
log_fn(LOG_WARN,"or_port unreadable or 0. Failing.");
warn(LD_DIR,"or_port unreadable or 0. Failing.");
goto err;
}
if (!router->bandwidthrate) {
log_fn(LOG_WARN,"bandwidthrate unreadable or 0. Failing.");
warn(LD_DIR,"bandwidthrate unreadable or 0. Failing.");
goto err;
}
if (!router->platform) {
@ -964,54 +965,54 @@ routerstatus_parse_entry_from_string(const char **s, smartlist_t *tokens)
eos = find_start_of_next_routerstatus(*s);
if (tokenize_string(*s, eos, tokens, RTRSTATUS)) {
log_fn(LOG_WARN, "Error tokenizing router status");
warn(LD_DIR, "Error tokenizing router status");
goto err;
}
if (smartlist_len(tokens) < 1) {
log_fn(LOG_WARN, "Impossibly short router status");
warn(LD_DIR, "Impossibly short router status");
goto err;
}
if ((tok = find_first_by_keyword(tokens, _UNRECOGNIZED))) {
log_fn(LOG_WARN, "Unrecognized keyword \"%s\" in router status; skipping.",
warn(LD_DIR, "Unrecognized keyword \"%s\" in router status; skipping.",
tok->args[0]);
goto err;
}
if (!(tok = find_first_by_keyword(tokens, K_R))) {
log_fn(LOG_WARN, "Missing 'r' keywork in router status; skipping.");
warn(LD_DIR, "Missing 'r' keywork in router status; skipping.");
goto err;
}
if (tok->n_args < 8) {
log_fn(LOG_WARN,
warn(LD_DIR,
"Too few arguments to 'r' keywork in router status; skipping.");
}
rs = tor_malloc_zero(sizeof(routerstatus_t));
if (!is_legal_nickname(tok->args[0])) {
log_fn(LOG_WARN,
warn(LD_DIR,
"Invalid nickname '%s' in router status; skipping.", tok->args[0]);
goto err;
}
strlcpy(rs->nickname, tok->args[0], sizeof(rs->nickname));
if (digest_from_base64(rs->identity_digest, tok->args[1])) {
log_fn(LOG_WARN, "Error decoding digest '%s'", tok->args[1]);
warn(LD_DIR, "Error decoding digest '%s'", tok->args[1]);
goto err;
}
if (digest_from_base64(rs->descriptor_digest, tok->args[2])) {
log_fn(LOG_WARN, "Error decoding digest '%s'", tok->args[2]);
warn(LD_DIR, "Error decoding digest '%s'", tok->args[2]);
goto err;
}
if (tor_snprintf(timebuf, sizeof(timebuf), "%s %s",
tok->args[3], tok->args[4]) < 0 ||
parse_iso_time(timebuf, &rs->published_on)<0) {
log_fn(LOG_WARN, "Error parsing time '%s %s'", tok->args[3], tok->args[4]);
warn(LD_DIR, "Error parsing time '%s %s'", tok->args[3], tok->args[4]);
goto err;
}
if (tor_inet_aton(tok->args[5], &in) == 0) {
log_fn(LOG_WARN, "Error parsing address '%s'", tok->args[5]);
warn(LD_DIR, "Error parsing address '%s'", tok->args[5]);
goto err;
}
rs->addr = ntohl(in.s_addr);
@ -1082,17 +1083,17 @@ networkstatus_parse_from_string(const char *s)
int i;
if (router_get_networkstatus_v2_hash(s, ns_digest)) {
log_fn(LOG_WARN, "Unable to compute digest of network-status");
warn(LD_DIR, "Unable to compute digest of network-status");
goto err;
}
eos = find_start_of_next_routerstatus(s);
if (tokenize_string(s, eos, tokens, NETSTATUS)) {
log_fn(LOG_WARN, "Error tokenizing network-status header.");
warn(LD_DIR, "Error tokenizing network-status header.");
goto err;
}
if ((tok = find_first_by_keyword(tokens, _UNRECOGNIZED))) {
log_fn(LOG_WARN, "Unrecognized keyword '%s'; can't parse network-status",
warn(LD_DIR, "Unrecognized keyword '%s'; can't parse network-status",
tok->args[0]);
goto err;
}
@ -1100,42 +1101,42 @@ networkstatus_parse_from_string(const char *s)
memcpy(ns->networkstatus_digest, ns_digest, DIGEST_LEN);
if (!(tok = find_first_by_keyword(tokens, K_NETWORK_STATUS_VERSION))) {
log_fn(LOG_WARN, "Couldn't find network-status-version keyword");
warn(LD_DIR, "Couldn't find network-status-version keyword");
goto err;
}
if (!(tok = find_first_by_keyword(tokens, K_DIR_SOURCE))) {
log_fn(LOG_WARN, "Couldn't find dir-source keyword");
warn(LD_DIR, "Couldn't find dir-source keyword");
goto err;
}
if (tok->n_args < 3) {
log_fn(LOG_WARN, "Too few arguments to dir-source keyword");
warn(LD_DIR, "Too few arguments to dir-source keyword");
goto err;
}
ns->source_address = tok->args[0]; tok->args[0] = NULL;
if (tor_inet_aton(tok->args[1], &in) == 0) {
log_fn(LOG_WARN, "Error parsing address '%s'", tok->args[1]);
warn(LD_DIR, "Error parsing address '%s'", tok->args[1]);
goto err;
}
ns->source_addr = ntohl(in.s_addr);
ns->source_dirport =
(uint16_t) tor_parse_long(tok->args[2],10,0,65535,NULL,NULL);
if (ns->source_dirport == 0) {
log_fn(LOG_WARN, "Directory source without dirport; skipping.");
warn(LD_DIR, "Directory source without dirport; skipping.");
goto err;
}
if (!(tok = find_first_by_keyword(tokens, K_FINGERPRINT))) {
log_fn(LOG_WARN, "Couldn't find fingerprint keyword");
warn(LD_DIR, "Couldn't find fingerprint keyword");
goto err;
}
if (tok->n_args < 1) {
log_fn(LOG_WARN, "Too few arguments to fingerprint");
warn(LD_DIR, "Too few arguments to fingerprint");
goto err;
}
if (base16_decode(ns->identity_digest, DIGEST_LEN, tok->args[0],
strlen(tok->args[0]))) {
log_fn(LOG_WARN, "Couldn't decode fingerprint '%s'", tok->args[0]);
warn(LD_DIR, "Couldn't decode fingerprint '%s'", tok->args[0]);
goto err;
}
@ -1145,18 +1146,18 @@ networkstatus_parse_from_string(const char *s)
}
if (!(tok = find_first_by_keyword(tokens, K_DIR_SIGNING_KEY)) || !tok->key) {
log_fn(LOG_WARN, "Missing dir-signing-key");
warn(LD_DIR, "Missing dir-signing-key");
goto err;
}
ns->signing_key = tok->key;
tok->key = NULL;
if (crypto_pk_get_digest(ns->signing_key, tmp_digest)<0) {
log_fn(LOG_WARN, "Couldn't compute signing key digest");
warn(LD_DIR, "Couldn't compute signing key digest");
goto err;
}
if (memcmp(tmp_digest, ns->identity_digest, DIGEST_LEN)) {
log_fn(LOG_WARN, "network-status fingerprint did not match dir-signing-key");
warn(LD_DIR, "network-status fingerprint did not match dir-signing-key");
goto err;
}
@ -1172,14 +1173,14 @@ networkstatus_parse_from_string(const char *s)
if (ns->recommends_versions) {
if (!(tok = find_first_by_keyword(tokens, K_CLIENT_VERSIONS)) ||
tok->n_args<1) {
log_fn(LOG_WARN, "Missing client-versions");
warn(LD_DIR, "Missing client-versions");
}
ns->client_versions = tok->args[0];
tok->args[0] = NULL;
if (!(tok = find_first_by_keyword(tokens, K_SERVER_VERSIONS)) ||
tok->n_args<1) {
log_fn(LOG_WARN, "Missing server-versions on versioning directory");
warn(LD_DIR, "Missing server-versions on versioning directory");
goto err;
}
ns->server_versions = tok->args[0];
@ -1187,7 +1188,7 @@ networkstatus_parse_from_string(const char *s)
}
if (!(tok = find_first_by_keyword(tokens, K_PUBLISHED))) {
log_fn(LOG_WARN, "Missing published time on directory.");
warn(LD_DIR, "Missing published time on directory.");
goto err;
}
tor_assert(tok->n_args == 1);
@ -1212,23 +1213,23 @@ networkstatus_parse_from_string(const char *s)
routerstatus_t *rs2 = smartlist_get(ns->entries, i+1);
if (!memcmp(rs1->identity_digest,
rs2->identity_digest, DIGEST_LEN)) {
log_fn(LOG_WARN, "Network-status has two entries for the same router. Dropping one.");
warn(LD_DIR, "Network-status has two entries for the same router. Dropping one.");
smartlist_del_keeporder(ns->entries, i--);
routerstatus_free(rs1);
}
}
if (tokenize_string(s, NULL, tokens, NETSTATUS)) {
log_fn(LOG_WARN, "Error tokenizing network-status footer.");
warn(LD_DIR, "Error tokenizing network-status footer.");
goto err;
}
if (smartlist_len(tokens) < 1) {
log_fn(LOG_WARN, "Too few items in network-status footer.");
warn(LD_DIR, "Too few items in network-status footer.");
goto err;
}
tok = smartlist_get(tokens, smartlist_len(tokens)-1);
if (tok->tp != K_DIRECTORY_SIGNATURE) {
log_fn(LOG_WARN, "Expected network-status footer to end with a signature.");
warn(LD_DIR, "Expected network-status footer to end with a signature.");
goto err;
}
@ -1279,11 +1280,11 @@ router_parse_addr_policy_from_string(const char *s, int assume_action)
}
tok = get_next_token(&cp, RTR);
if (tok->tp == _ERR) {
log_fn(LOG_WARN, "Error reading exit policy: %s", tok->error);
warn(LD_DIR, "Error reading exit policy: %s", tok->error);
goto err;
}
if (tok->tp != K_ACCEPT && tok->tp != K_REJECT) {
log_fn(LOG_WARN, "Expected 'accept' or 'reject'.");
warn(LD_DIR, "Expected 'accept' or 'reject'.");
goto err;
}
@ -1374,7 +1375,7 @@ router_parse_addr_policy(directory_token_t *tok)
policy_read_failed:
tor_assert(newe->string);
log_fn(LOG_WARN,"Couldn't parse line '%s'. Dropping", newe->string);
warn(LD_DIR,"Couldn't parse line '%s'. Dropping", newe->string);
tor_free(newe->string);
tor_free(newe);
return NULL;
@ -1635,7 +1636,7 @@ tokenize_string(const char *start, const char *end, smartlist_t *out,
while (*s < end && (!tok || tok->tp != _EOF)) {
tok = get_next_token(s, where);
if (tok->tp == _ERR) {
log_fn(LOG_WARN, "parse error: %s", tok->error);
warn(LD_DIR, "parse error: %s", tok->error);
return -1;
}
smartlist_add(out, tok);
@ -1683,28 +1684,28 @@ router_get_hash_impl(const char *s, char *digest,
char *start, *end;
start = strstr(s, start_str);
if (!start) {
log_fn(LOG_WARN,"couldn't find \"%s\"",start_str);
warn(LD_DIR,"couldn't find \"%s\"",start_str);
return -1;
}
if (start != s && *(start-1) != '\n') {
log_fn(LOG_WARN, "first occurrence of \"%s\" is not at the start of a line",
warn(LD_DIR, "first occurrence of \"%s\" is not at the start of a line",
start_str);
return -1;
}
end = strstr(start+strlen(start_str), end_str);
if (!end) {
log_fn(LOG_WARN,"couldn't find \"%s\"",end_str);
warn(LD_DIR,"couldn't find \"%s\"",end_str);
return -1;
}
end = strchr(end+strlen(end_str), '\n');
if (!end) {
log_fn(LOG_WARN,"couldn't find EOL");
warn(LD_DIR,"couldn't find EOL");
return -1;
}
++end;
if (crypto_digest(digest, start, end-start)) {
log_fn(LOG_WARN,"couldn't compute digest");
warn(LD_DIR,"couldn't compute digest");
return -1;
}
@ -1723,7 +1724,7 @@ tor_version_as_new_as(const char *platform, const char *cutoff)
char tmp[128];
if (tor_version_parse(cutoff, &cutoff_version)<0) {
log_fn(LOG_WARN,"Bug: cutoff version '%s' unparseable.",cutoff);
warn(LD_DIR,"Bug: cutoff version '%s' unparseable.",cutoff);
return 0;
}
if (strcmpstart(platform,"Tor ")) /* nonstandard Tor; be safe and say yes */
@ -1737,7 +1738,7 @@ tor_version_as_new_as(const char *platform, const char *cutoff)
strlcpy(tmp, start, s-start+1);
if (tor_version_parse(tmp, &router_version)<0) {
log_fn(LOG_INFO,"Router version '%s' unparseable.",tmp);
info(LD_DIR,"Router version '%s' unparseable.",tmp);
return 1; /* be safe and say yes */
}