Loading src/common/log.h +16 −0 Changes for src/common/log.h: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -51,16 +51,32 @@ #endif /* Logging domains */ /** Catch-all for miscellaneous events and internal errors and fatal * errors. */ #define LD_GENERAL 0 /** The cryptography subsytem */ #define LD_CRYPTO 1 /** Networking */ #define LD_NET 2 /** Parsing and acting on our configuration */ #define LD_CONFIG 3 /** Reading and writing from the filesystem */ #define LD_FS 4 /** Other servers' (non)compliance with the Tor protocol */ #define LD_PROTOCOL 5 /** Memory management */ #define LD_MM 6 /** HTTP implementation */ #define LD_HTTP 7 /** Application (socks) requests */ #define LD_APP 8 /** Communication via the controller protocol */ #define LD_CONTROL 9 /** Building, using, and managing circuits */ #define LD_CIRC 10 /** Hidden services */ #define LD_REND 11 typedef void (*log_callback)(int severity, int domain, const char *msg); Loading src/or/circuitlist.c +10 −8 Changes for src/or/circuitlist.c: 10 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ const char circuitlist_c_id[] = "$Id$"; * \brief Manage the global circuit list. **/ #define NEW_LOG_INTERFACE #include "or.h" /* Define RB_AUGMENT to avoid warnings about if statements with emtpy bodies. Loading Loading @@ -187,7 +188,7 @@ circuit_state_to_string(int state) case CIRCUIT_STATE_OR_WAIT: return "connecting to firsthop"; case CIRCUIT_STATE_OPEN: return "open"; default: log_fn(LOG_WARN, "Bug: unknown circuit state %d", state); warn(LD_GENERAL, "Bug: unknown circuit state %d", state); tor_snprintf(buf, sizeof(buf), "unknown state [%d]", state); return buf; } Loading Loading @@ -374,11 +375,11 @@ circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn) continue; if (circ->p_conn == conn && circ->p_circ_id == circ_id) { log_fn(LOG_WARN, "circuit matches p_conn, but not in tree (Bug!)"); warn(LD_GENERAL, "circuit matches p_conn, but not in tree (Bug!)"); return circ; } if (circ->n_conn == conn && circ->n_circ_id == circ_id) { log_fn(LOG_WARN, "circuit matches n_conn, but not in tree (Bug!)"); warn(LD_GENERAL, "circuit matches n_conn, but not in tree (Bug!)"); return circ; } } Loading @@ -401,7 +402,7 @@ circuit_get_by_edge_conn(connection_t *conn) /* return NULL; */ circ = circuit_get_by_conn(conn); if (circ) { log_fn(LOG_WARN, "BUG: conn->on_circuit==NULL, but there was in fact a circuit there."); warn(LD_GENERAL, "BUG: conn->on_circuit==NULL, but there was in fact a circuit there."); } return circ; } Loading Loading @@ -534,7 +535,7 @@ circuit_get_clean_open(uint8_t purpose, int need_uptime, circuit_t *circ; circuit_t *best=NULL; log_fn(LOG_DEBUG,"Hunting for a circ to cannibalize: purpose %d, uptime %d, capacity %d, internal %d", purpose, need_uptime, need_capacity, internal); debug(LD_CIRC,"Hunting for a circ to cannibalize: purpose %d, uptime %d, capacity %d, internal %d", purpose, need_uptime, need_capacity, internal); for (circ=global_circuitlist; circ; circ = circ->next) { if (CIRCUIT_IS_ORIGIN(circ) && Loading Loading @@ -613,7 +614,8 @@ _circuit_mark_for_close(circuit_t *circ, int line, const char *file) tor_assert(file); if (circ->marked_for_close) { log(LOG_WARN,"Duplicate call to circuit_mark_for_close at %s:%d" log(LOG_WARN,LD_GENERAL, "Duplicate call to circuit_mark_for_close at %s:%d" " (first at %s:%d)", file, line, circ->marked_for_close_file, circ->marked_for_close); return; Loading @@ -640,7 +642,7 @@ _circuit_mark_for_close(circuit_t *circ, int line, const char *file) tor_assert(circ->state == CIRCUIT_STATE_OPEN); tor_assert(circ->build_state->chosen_exit); /* treat this like getting a nack from it */ log_fn(LOG_INFO,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.", info(LD_REND,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.", safe_str(circ->rend_query), safe_str(build_state_get_exit_nickname(circ->build_state))); rend_client_remove_intro_point(circ->build_state->chosen_exit, Loading Loading @@ -701,7 +703,7 @@ assert_cpath_layer_ok(const crypt_path_t *cp) /* tor_assert(cp->dh_handshake_state); */ break; default: log_fn(LOG_ERR,"Unexpected state %d",cp->state); err("Unexpected state %d",cp->state); tor_assert(0); } tor_assert(cp->package_window >= 0); Loading src/or/onion.c +11 −9 Changes for src/or/onion.c: 11 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ const char onion_c_id[] = "$Id$"; * parsing and creation. **/ #define NEW_LOG_INTERFACE #include "or.h" /** Type for a linked list of circuits that are waiting for a free CPU worker Loading Loading @@ -56,7 +57,7 @@ onion_pending_add(circuit_t *circ) tor_assert(!ol_tail->next); if (ol_length >= get_options()->MaxOnionsPending) { log_fn(LOG_NOTICE,"Already have %d onions queued. Closing.", ol_length); notice(LD_GENERAL,"Already have %d onions queued. Closing.", ol_length); tor_free(tmp); return -1; } Loading @@ -68,7 +69,7 @@ onion_pending_add(circuit_t *circ) /* cull elderly requests. */ circ = ol_list->circ; onion_pending_remove(ol_list->circ); log_fn(LOG_INFO,"Circuit create request is too old; cancelling due to overload."); info(LD_CIRC,"Circuit create request is too old; cancelling due to overload."); circuit_mark_for_close(circ); } return 0; Loading Loading @@ -116,7 +117,8 @@ 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) { log_fn(LOG_DEBUG,"circ (p_circ_id %d) not in list, probably at cpuworker.",circ->p_circ_id); /* 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; } /* now we know tmpo->next->circ == circ */ Loading Loading @@ -236,17 +238,17 @@ onion_skin_server_handshake(const char *onion_skin, /* ONIONSKIN_CHALLENGE_LEN b break; } if (len<0) { log_fn(LOG_INFO, "Couldn't decrypt onionskin: client may be using old onion key"); info(LD_PROTOCOL, "Couldn't decrypt onionskin: client may be using old onion key"); goto err; } else if (len != DH_KEY_LEN) { log_fn(LOG_WARN, "Unexpected onionskin length after decryption: %d", warn(LD_PROTOCOL, "Unexpected onionskin length after decryption: %d", len); goto err; } dh = crypto_dh_new(); if (crypto_dh_get_public(dh, handshake_reply_out, DH_KEY_LEN)) { log_fn(LOG_INFO, "crypto_dh_get_public failed."); info(LD_GENERAL, "crypto_dh_get_public failed."); goto err; } Loading @@ -262,7 +264,7 @@ onion_skin_server_handshake(const char *onion_skin, /* ONIONSKIN_CHALLENGE_LEN b len = crypto_dh_compute_secret(dh, challenge, DH_KEY_LEN, key_material, DIGEST_LEN+key_out_len); if (len < 0) { log_fn(LOG_INFO, "crypto_dh_compute_secret failed."); info(LD_GENERAL, "crypto_dh_compute_secret failed."); goto err; } Loading Loading @@ -327,7 +329,7 @@ onion_skin_client_handshake(crypto_dh_env_t *handshake_state, if (memcmp(key_material, handshake_reply+DH_KEY_LEN, 20)) { /* H(K) does *not* match. Something fishy. */ tor_free(key_material); log_fn(LOG_WARN,"Digest DOES NOT MATCH on onion handshake. Bug or attack."); warn(LD_PROTOCOL,"Digest DOES NOT MATCH on onion handshake. Bug or attack."); return -1; } Loading Loading @@ -393,7 +395,7 @@ fast_client_handshake(const char *handshake_state, /* DIGEST_LEN bytes */ if (memcmp(digest, handshake_reply_out+DIGEST_LEN, DIGEST_LEN)) { /* H(K) does *not* match. Something fishy. */ log_fn(LOG_WARN,"Digest DOES NOT MATCH on fast handshake. Bug or attack."); warn(LD_PROTOCOL,"Digest DOES NOT MATCH on fast handshake. Bug or attack."); return -1; } Loading src/or/rendclient.c +35 −33 Changes for src/or/rendclient.c: 35 added lines, 33 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ const char rendclient_c_id[] = "$Id$"; * \brief Client code to access location-hidden services. **/ #define NEW_LOG_INTERFACE #include "or.h" /** Called when we've established a circuit to an introduction point: Loading @@ -19,7 +20,7 @@ rend_client_introcirc_has_opened(circuit_t *circ) tor_assert(CIRCUIT_IS_ORIGIN(circ)); tor_assert(circ->cpath); log_fn(LOG_INFO,"introcirc is open"); info(LD_REND,"introcirc is open"); connection_ap_attach_pending(); } Loading @@ -30,10 +31,10 @@ static int rend_client_send_establish_rendezvous(circuit_t *circ) { tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); log_fn(LOG_INFO, "Sending an ESTABLISH_RENDEZVOUS cell"); info(LD_REND, "Sending an ESTABLISH_RENDEZVOUS cell"); if (crypto_rand(circ->rend_cookie, REND_COOKIE_LEN) < 0) { log_fn(LOG_WARN, "Internal error: Couldn't produce random cookie."); warn(LD_GENERAL, "Internal error: Couldn't produce random cookie."); circuit_mark_for_close(circ); return -1; } Loading @@ -42,7 +43,7 @@ rend_client_send_establish_rendezvous(circuit_t *circ) circ->rend_cookie, REND_COOKIE_LEN, circ->cpath->prev)<0) { /* circ is already marked for close */ log_fn(LOG_WARN, "Couldn't send ESTABLISH_RENDEZVOUS cell"); warn(LD_GENERAL, "Couldn't send ESTABLISH_RENDEZVOUS cell"); return -1; } Loading @@ -68,14 +69,14 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) tor_assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query)); if (rend_cache_lookup_entry(introcirc->rend_query, -1, &entry) < 1) { log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.", warn(LD_REND,"query '%s' didn't have valid rend desc in cache. Failing.", safe_str(introcirc->rend_query)); goto err; } /* first 20 bytes of payload are the hash of bob's pk */ if (crypto_pk_get_digest(entry->parsed->pk, payload)<0) { log_fn(LOG_WARN, "Internal error: couldn't hash public key."); warn(LD_GENERAL, "Internal error: couldn't hash public key."); goto err; } Loading @@ -86,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())) { log_fn(LOG_WARN, "Internal error: couldn't allocate DH."); warn(LD_GENERAL, "Internal error: couldn't allocate DH."); goto err; } if (crypto_dh_generate_public(cpath->dh_handshake_state)<0) { log_fn(LOG_WARN, "Internal error: couldn't generate g^x."); warn(LD_GENERAL, "Internal error: couldn't generate g^x."); goto err; } } Loading Loading @@ -119,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) { log_fn(LOG_WARN, "Internal error: couldn't extract g^x."); warn(LD_GENERAL, "Internal error: couldn't extract g^x."); goto err; } Loading @@ -129,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) { log_fn(LOG_WARN,"Internal error: hybrid pk encrypt failed."); warn(LD_GENERAL,"Internal error: hybrid pk encrypt failed."); goto err; } Loading @@ -141,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. */ log_fn(LOG_WARN, "Couldn't send INTRODUCE1 cell"); warn(LD_GENERAL, "Couldn't send INTRODUCE1 cell"); return -1; } Loading @@ -163,7 +164,7 @@ rend_client_rendcirc_has_opened(circuit_t *circ) tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); tor_assert(CIRCUIT_IS_ORIGIN(circ)); log_fn(LOG_INFO,"rendcirc is open"); info(LD_REND,"rendcirc is open"); /* generate a rendezvous cookie, store it in circ */ if (rend_client_send_establish_rendezvous(circ) < 0) { Loading @@ -180,7 +181,7 @@ rend_client_introduction_acked(circuit_t *circ, circuit_t *rendcirc; if (circ->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) { log_fn(LOG_WARN, "Received REND_INTRODUCE_ACK on unexpected circuit %d.", warn(LD_PROTOCOL, "Received REND_INTRODUCE_ACK on unexpected circuit %d.", circ->n_circ_id); circuit_mark_for_close(circ); return -1; Loading @@ -194,13 +195,13 @@ rend_client_introduction_acked(circuit_t *circ, /* Locate the rend circ which is waiting to hear about this ack, * and tell it. */ log_fn(LOG_INFO,"Received ack. Telling rend circ..."); info(LD_REND,"Received ack. Telling rend circ..."); rendcirc = circuit_get_by_rend_query_and_purpose( circ->rend_query, CIRCUIT_PURPOSE_C_REND_READY); if (rendcirc) { /* remember the ack */ rendcirc->purpose = CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED; } else { log_fn(LOG_INFO,"...Found no rend circ. Dropping on the floor."); info(LD_REND,"...Found no rend circ. Dropping on the floor."); } /* close the circuit: we won't need it anymore. */ circ->purpose = CIRCUIT_PURPOSE_C_INTRODUCE_ACKED; Loading @@ -220,12 +221,13 @@ rend_client_introduction_acked(circuit_t *circ, int result; info = rend_client_get_random_intro(circ->rend_query); if (!info) { log_fn(LOG_WARN, "No introduction points left for %s. Closing.", warn(LD_REND, "No introduction points left for %s. Closing.", safe_str(circ->rend_query)); circuit_mark_for_close(circ); return -1; } log_fn(LOG_INFO,"Got nack for %s from %s. Re-extending circ %d, this time to %s.", info(LD_REND, "Got nack for %s from %s. Re-extending circ %d, this time to %s.", safe_str(circ->rend_query), circ->build_state->chosen_exit->nickname, circ->n_circ_id, info->nickname); Loading @@ -245,7 +247,7 @@ void rend_client_refetch_renddesc(const char *query) { if (connection_get_by_type_state_rendquery(CONN_TYPE_DIR, 0, query)) { log_fn(LOG_INFO,"Would fetch a new renddesc here (for %s), but one is already in progress.", safe_str(query)); info(LD_REND,"Would fetch a new renddesc here (for %s), but one is already in progress.", safe_str(query)); } else { /* not one already; initiate a dir rend desc lookup */ directory_get_from_dirserver(DIR_PURPOSE_FETCH_RENDDESC, query, 1); Loading @@ -267,11 +269,11 @@ rend_client_remove_intro_point(extend_info_t *failed_intro, const char *query) r = rend_cache_lookup_entry(query, -1, &ent); if (r<0) { log_fn(LOG_WARN, "Bug: malformed service ID '%s'.", safe_str(query)); warn(LD_GENERAL, "Bug: malformed service ID '%s'.", safe_str(query)); return -1; } if (r==0) { log_fn(LOG_INFO, "Unknown service %s. Re-fetching descriptor.", info(LD_REND, "Unknown service %s. Re-fetching descriptor.", safe_str(query)); rend_client_refetch_renddesc(query); return 0; Loading Loading @@ -306,7 +308,7 @@ rend_client_remove_intro_point(extend_info_t *failed_intro, const char *query) } if (!ent->parsed->n_intro_points) { log_fn(LOG_INFO,"No more intro points remain for %s. Re-fetching descriptor.", info(LD_REND,"No more intro points remain for %s. Re-fetching descriptor.", safe_str(query)); rend_client_refetch_renddesc(query); Loading @@ -318,7 +320,7 @@ rend_client_remove_intro_point(extend_info_t *failed_intro, const char *query) return 0; } log_fn(LOG_INFO,"%d options left for %s.", info(LD_REND,"%d options left for %s.", ent->parsed->n_intro_points, safe_str(query)); return 1; } Loading @@ -331,11 +333,11 @@ rend_client_rendezvous_acked(circuit_t *circ, const char *request, size_t reques { /* we just got an ack for our establish-rendezvous. switch purposes. */ if (circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) { log_fn(LOG_WARN,"Got a rendezvous ack when we weren't expecting one. Closing circ."); warn(LD_PROTOCOL,"Got a rendezvous ack when we weren't expecting one. Closing circ."); circuit_mark_for_close(circ); return -1; } log_fn(LOG_INFO,"Got rendezvous ack. This circuit is now ready for rendezvous."); info(LD_REND,"Got rendezvous ack. This circuit is now ready for rendezvous."); circ->purpose = CIRCUIT_PURPOSE_C_REND_READY; return 0; } Loading @@ -350,13 +352,13 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t requ if ((circ->purpose != CIRCUIT_PURPOSE_C_REND_READY && circ->purpose != CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) || !circ->build_state->pending_final_cpath) { log_fn(LOG_WARN,"Got rendezvous2 cell from hidden service, but not expecting it. Closing."); warn(LD_PROTOCOL,"Got rendezvous2 cell from hidden service, but not expecting it. Closing."); circuit_mark_for_close(circ); return -1; } if (request_len != DH_KEY_LEN+DIGEST_LEN) { log_fn(LOG_WARN,"Incorrect length (%d) on RENDEZVOUS2 cell.",(int)request_len); warn(LD_PROTOCOL,"Incorrect length (%d) on RENDEZVOUS2 cell.",(int)request_len); goto err; } Loading @@ -367,7 +369,7 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t requ tor_assert(hop->dh_handshake_state); if (crypto_dh_compute_secret(hop->dh_handshake_state, request, DH_KEY_LEN, keys, DIGEST_LEN+CPATH_KEY_MATERIAL_LEN)<0) { log_fn(LOG_WARN, "Couldn't complete DH handshake."); warn(LD_GENERAL, "Couldn't complete DH handshake."); goto err; } /* ... and set up cpath. */ Loading @@ -376,7 +378,7 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t requ /* Check whether the digest is right... */ if (memcmp(keys, request+DH_KEY_LEN, DIGEST_LEN)) { log_fn(LOG_WARN, "Incorrect digest of key material."); warn(LD_PROTOCOL, "Incorrect digest of key material."); goto err; } Loading Loading @@ -418,7 +420,7 @@ rend_client_desc_here(const char *query) entry->parsed->n_intro_points > 0) { /* either this fetch worked, or it failed but there was a * valid entry from before which we should reuse */ log_fn(LOG_INFO,"Rend desc is usable. Launching circuits."); info(LD_REND,"Rend desc is usable. Launching circuits."); conn->state = AP_CONN_STATE_CIRCUIT_WAIT; /* restart their timeout values, so they get a fair shake at Loading @@ -429,12 +431,12 @@ rend_client_desc_here(const char *query) if (connection_ap_handshake_attach_circuit(conn) < 0) { /* it will never work */ log_fn(LOG_WARN,"Rendezvous attempt failed. Closing."); warn(LD_REND,"Rendezvous attempt failed. Closing."); connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_ATTACH); } tor_assert(conn->state != AP_CONN_STATE_RENDDESC_WAIT); /* avoid loop */ } else { /* 404, or fetch didn't get that far */ log_fn(LOG_NOTICE,"Closing stream for '%s.onion': hidden service is unavailable (try again later).", safe_str(query)); notice(LD_REND,"Closing stream for '%s.onion': hidden service is unavailable (try again later).", safe_str(query)); connection_mark_unattached_ap(conn, END_STREAM_REASON_TIMEOUT); } } Loading @@ -451,7 +453,7 @@ rend_client_get_random_intro(const char *query) rend_cache_entry_t *entry; if (rend_cache_lookup_entry(query, -1, &entry) < 1) { log_fn(LOG_WARN,"Query '%s' didn't have valid rend desc in cache. Failing.", warn(LD_REND,"Query '%s' didn't have valid rend desc in cache. Failing.", safe_str(query)); return NULL; } Loading @@ -469,7 +471,7 @@ rend_client_get_random_intro(const char *query) char *choice = entry->parsed->intro_points[i]; routerinfo_t *router = router_get_by_nickname(choice, 0); if (!router) { log_fn(LOG_INFO, "Unknown router with nickname '%s'; trying another.",choice); info(LD_REND, "Unknown router with nickname '%s'; trying another.",choice); tor_free(choice); entry->parsed->intro_points[i] = entry->parsed->intro_points[--entry->parsed->n_intro_points]; Loading src/or/rendcommon.c +12 −11 Changes for src/or/rendcommon.c: 12 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ const char rendcommon_c_id[] = "$Id$"; * introducers, services, clients, and rendezvous points. **/ #define NEW_LOG_INTERFACE #include "or.h" /** Return 0 if one and two are the same service ids, else -1 or 1 */ Loading Loading @@ -178,7 +179,7 @@ rend_parse_service_descriptor(const char *str, size_t len) cp += 8+DIGEST_LEN; if (end-cp < klen) goto truncated; if (!(info->onion_key = crypto_pk_asn1_decode(cp,klen))) { log_fn(LOG_WARN, "Internal error decoding onion key for intro point."); warn(LD_PROTOCOL, "Internal error decoding onion key for intro point."); goto error; } cp += klen; Loading @@ -188,7 +189,7 @@ rend_parse_service_descriptor(const char *str, size_t len) tor_assert(end-cp >= 0); if ((size_t)(end-cp) < keylen) goto truncated; if ((size_t)(end-cp) > keylen) { log_fn(LOG_WARN, "Signature is %d bytes too long on service descriptor.", warn(LD_PROTOCOL, "Signature is %d bytes too long on service descriptor.", (int)((size_t)(end-cp) - keylen)); goto error; } Loading @@ -196,13 +197,13 @@ rend_parse_service_descriptor(const char *str, size_t len) (char*)str,cp-str, /* data */ (char*)cp,end-cp /* signature*/ )<0) { log_fn(LOG_WARN, "Bad signature on service descriptor."); warn(LD_PROTOCOL, "Bad signature on service descriptor."); goto error; } return result; truncated: log_fn(LOG_WARN, "Truncated service descriptor."); warn(LD_PROTOCOL, "Truncated service descriptor."); error: rend_service_descriptor_free(result); return NULL; Loading Loading @@ -361,35 +362,35 @@ rend_cache_store(const char *desc, size_t desc_len) tor_assert(rend_cache); parsed = rend_parse_service_descriptor(desc,desc_len); if (!parsed) { log_fn(LOG_WARN,"Couldn't parse service descriptor."); warn(LD_PROTOCOL,"Couldn't parse service descriptor."); return -1; } if (rend_get_service_id(parsed->pk, query)<0) { log_fn(LOG_WARN,"Couldn't compute service ID."); warn(LD_GENERAL,"Couldn't compute service ID."); rend_service_descriptor_free(parsed); return -1; } tor_snprintf(key, sizeof(key), "%c%s", parsed->version?'1':'0', query); now = time(NULL); if (parsed->timestamp < now-REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) { log_fn(LOG_WARN,"Service descriptor %s is too old.", safe_str(query)); warn(LD_REND,"Service descriptor %s is too old.", safe_str(query)); rend_service_descriptor_free(parsed); return -1; } if (parsed->timestamp > now+REND_CACHE_MAX_SKEW) { log_fn(LOG_WARN,"Service descriptor %s is too far in the future.", warn(LD_REND,"Service descriptor %s is too far in the future.", safe_str(query)); rend_service_descriptor_free(parsed); return -1; } e = (rend_cache_entry_t*) strmap_get_lc(rend_cache, key); if (e && e->parsed->timestamp > parsed->timestamp) { log_fn(LOG_INFO,"We already have a newer service descriptor %s with the same ID and version.", safe_str(query)); info(LD_REND,"We already have a newer service descriptor %s with the same ID and version.", safe_str(query)); rend_service_descriptor_free(parsed); return 0; } if (e && e->len == desc_len && !memcmp(desc,e->desc,desc_len)) { log_fn(LOG_INFO,"We already have this service descriptor %s.", safe_str(query)); info(LD_REND,"We already have this service descriptor %s.", safe_str(query)); e->received = time(NULL); rend_service_descriptor_free(parsed); return 0; Loading @@ -407,7 +408,7 @@ rend_cache_store(const char *desc, size_t desc_len) e->desc = tor_malloc(desc_len); memcpy(e->desc, desc, desc_len); log_fn(LOG_DEBUG,"Successfully stored rend desc '%s', len %d.", debug(LD_REND,"Successfully stored rend desc '%s', len %d.", safe_str(query), (int)desc_len); return 1; } Loading Loading
src/common/log.h +16 −0 Changes for src/common/log.h: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -51,16 +51,32 @@ #endif /* Logging domains */ /** Catch-all for miscellaneous events and internal errors and fatal * errors. */ #define LD_GENERAL 0 /** The cryptography subsytem */ #define LD_CRYPTO 1 /** Networking */ #define LD_NET 2 /** Parsing and acting on our configuration */ #define LD_CONFIG 3 /** Reading and writing from the filesystem */ #define LD_FS 4 /** Other servers' (non)compliance with the Tor protocol */ #define LD_PROTOCOL 5 /** Memory management */ #define LD_MM 6 /** HTTP implementation */ #define LD_HTTP 7 /** Application (socks) requests */ #define LD_APP 8 /** Communication via the controller protocol */ #define LD_CONTROL 9 /** Building, using, and managing circuits */ #define LD_CIRC 10 /** Hidden services */ #define LD_REND 11 typedef void (*log_callback)(int severity, int domain, const char *msg); Loading
src/or/circuitlist.c +10 −8 Changes for src/or/circuitlist.c: 10 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ const char circuitlist_c_id[] = "$Id$"; * \brief Manage the global circuit list. **/ #define NEW_LOG_INTERFACE #include "or.h" /* Define RB_AUGMENT to avoid warnings about if statements with emtpy bodies. Loading Loading @@ -187,7 +188,7 @@ circuit_state_to_string(int state) case CIRCUIT_STATE_OR_WAIT: return "connecting to firsthop"; case CIRCUIT_STATE_OPEN: return "open"; default: log_fn(LOG_WARN, "Bug: unknown circuit state %d", state); warn(LD_GENERAL, "Bug: unknown circuit state %d", state); tor_snprintf(buf, sizeof(buf), "unknown state [%d]", state); return buf; } Loading Loading @@ -374,11 +375,11 @@ circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn) continue; if (circ->p_conn == conn && circ->p_circ_id == circ_id) { log_fn(LOG_WARN, "circuit matches p_conn, but not in tree (Bug!)"); warn(LD_GENERAL, "circuit matches p_conn, but not in tree (Bug!)"); return circ; } if (circ->n_conn == conn && circ->n_circ_id == circ_id) { log_fn(LOG_WARN, "circuit matches n_conn, but not in tree (Bug!)"); warn(LD_GENERAL, "circuit matches n_conn, but not in tree (Bug!)"); return circ; } } Loading @@ -401,7 +402,7 @@ circuit_get_by_edge_conn(connection_t *conn) /* return NULL; */ circ = circuit_get_by_conn(conn); if (circ) { log_fn(LOG_WARN, "BUG: conn->on_circuit==NULL, but there was in fact a circuit there."); warn(LD_GENERAL, "BUG: conn->on_circuit==NULL, but there was in fact a circuit there."); } return circ; } Loading Loading @@ -534,7 +535,7 @@ circuit_get_clean_open(uint8_t purpose, int need_uptime, circuit_t *circ; circuit_t *best=NULL; log_fn(LOG_DEBUG,"Hunting for a circ to cannibalize: purpose %d, uptime %d, capacity %d, internal %d", purpose, need_uptime, need_capacity, internal); debug(LD_CIRC,"Hunting for a circ to cannibalize: purpose %d, uptime %d, capacity %d, internal %d", purpose, need_uptime, need_capacity, internal); for (circ=global_circuitlist; circ; circ = circ->next) { if (CIRCUIT_IS_ORIGIN(circ) && Loading Loading @@ -613,7 +614,8 @@ _circuit_mark_for_close(circuit_t *circ, int line, const char *file) tor_assert(file); if (circ->marked_for_close) { log(LOG_WARN,"Duplicate call to circuit_mark_for_close at %s:%d" log(LOG_WARN,LD_GENERAL, "Duplicate call to circuit_mark_for_close at %s:%d" " (first at %s:%d)", file, line, circ->marked_for_close_file, circ->marked_for_close); return; Loading @@ -640,7 +642,7 @@ _circuit_mark_for_close(circuit_t *circ, int line, const char *file) tor_assert(circ->state == CIRCUIT_STATE_OPEN); tor_assert(circ->build_state->chosen_exit); /* treat this like getting a nack from it */ log_fn(LOG_INFO,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.", info(LD_REND,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.", safe_str(circ->rend_query), safe_str(build_state_get_exit_nickname(circ->build_state))); rend_client_remove_intro_point(circ->build_state->chosen_exit, Loading Loading @@ -701,7 +703,7 @@ assert_cpath_layer_ok(const crypt_path_t *cp) /* tor_assert(cp->dh_handshake_state); */ break; default: log_fn(LOG_ERR,"Unexpected state %d",cp->state); err("Unexpected state %d",cp->state); tor_assert(0); } tor_assert(cp->package_window >= 0); Loading
src/or/onion.c +11 −9 Changes for src/or/onion.c: 11 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ const char onion_c_id[] = "$Id$"; * parsing and creation. **/ #define NEW_LOG_INTERFACE #include "or.h" /** Type for a linked list of circuits that are waiting for a free CPU worker Loading Loading @@ -56,7 +57,7 @@ onion_pending_add(circuit_t *circ) tor_assert(!ol_tail->next); if (ol_length >= get_options()->MaxOnionsPending) { log_fn(LOG_NOTICE,"Already have %d onions queued. Closing.", ol_length); notice(LD_GENERAL,"Already have %d onions queued. Closing.", ol_length); tor_free(tmp); return -1; } Loading @@ -68,7 +69,7 @@ onion_pending_add(circuit_t *circ) /* cull elderly requests. */ circ = ol_list->circ; onion_pending_remove(ol_list->circ); log_fn(LOG_INFO,"Circuit create request is too old; cancelling due to overload."); info(LD_CIRC,"Circuit create request is too old; cancelling due to overload."); circuit_mark_for_close(circ); } return 0; Loading Loading @@ -116,7 +117,8 @@ 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) { log_fn(LOG_DEBUG,"circ (p_circ_id %d) not in list, probably at cpuworker.",circ->p_circ_id); /* 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; } /* now we know tmpo->next->circ == circ */ Loading Loading @@ -236,17 +238,17 @@ onion_skin_server_handshake(const char *onion_skin, /* ONIONSKIN_CHALLENGE_LEN b break; } if (len<0) { log_fn(LOG_INFO, "Couldn't decrypt onionskin: client may be using old onion key"); info(LD_PROTOCOL, "Couldn't decrypt onionskin: client may be using old onion key"); goto err; } else if (len != DH_KEY_LEN) { log_fn(LOG_WARN, "Unexpected onionskin length after decryption: %d", warn(LD_PROTOCOL, "Unexpected onionskin length after decryption: %d", len); goto err; } dh = crypto_dh_new(); if (crypto_dh_get_public(dh, handshake_reply_out, DH_KEY_LEN)) { log_fn(LOG_INFO, "crypto_dh_get_public failed."); info(LD_GENERAL, "crypto_dh_get_public failed."); goto err; } Loading @@ -262,7 +264,7 @@ onion_skin_server_handshake(const char *onion_skin, /* ONIONSKIN_CHALLENGE_LEN b len = crypto_dh_compute_secret(dh, challenge, DH_KEY_LEN, key_material, DIGEST_LEN+key_out_len); if (len < 0) { log_fn(LOG_INFO, "crypto_dh_compute_secret failed."); info(LD_GENERAL, "crypto_dh_compute_secret failed."); goto err; } Loading Loading @@ -327,7 +329,7 @@ onion_skin_client_handshake(crypto_dh_env_t *handshake_state, if (memcmp(key_material, handshake_reply+DH_KEY_LEN, 20)) { /* H(K) does *not* match. Something fishy. */ tor_free(key_material); log_fn(LOG_WARN,"Digest DOES NOT MATCH on onion handshake. Bug or attack."); warn(LD_PROTOCOL,"Digest DOES NOT MATCH on onion handshake. Bug or attack."); return -1; } Loading Loading @@ -393,7 +395,7 @@ fast_client_handshake(const char *handshake_state, /* DIGEST_LEN bytes */ if (memcmp(digest, handshake_reply_out+DIGEST_LEN, DIGEST_LEN)) { /* H(K) does *not* match. Something fishy. */ log_fn(LOG_WARN,"Digest DOES NOT MATCH on fast handshake. Bug or attack."); warn(LD_PROTOCOL,"Digest DOES NOT MATCH on fast handshake. Bug or attack."); return -1; } Loading
src/or/rendclient.c +35 −33 Changes for src/or/rendclient.c: 35 added lines, 33 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ const char rendclient_c_id[] = "$Id$"; * \brief Client code to access location-hidden services. **/ #define NEW_LOG_INTERFACE #include "or.h" /** Called when we've established a circuit to an introduction point: Loading @@ -19,7 +20,7 @@ rend_client_introcirc_has_opened(circuit_t *circ) tor_assert(CIRCUIT_IS_ORIGIN(circ)); tor_assert(circ->cpath); log_fn(LOG_INFO,"introcirc is open"); info(LD_REND,"introcirc is open"); connection_ap_attach_pending(); } Loading @@ -30,10 +31,10 @@ static int rend_client_send_establish_rendezvous(circuit_t *circ) { tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); log_fn(LOG_INFO, "Sending an ESTABLISH_RENDEZVOUS cell"); info(LD_REND, "Sending an ESTABLISH_RENDEZVOUS cell"); if (crypto_rand(circ->rend_cookie, REND_COOKIE_LEN) < 0) { log_fn(LOG_WARN, "Internal error: Couldn't produce random cookie."); warn(LD_GENERAL, "Internal error: Couldn't produce random cookie."); circuit_mark_for_close(circ); return -1; } Loading @@ -42,7 +43,7 @@ rend_client_send_establish_rendezvous(circuit_t *circ) circ->rend_cookie, REND_COOKIE_LEN, circ->cpath->prev)<0) { /* circ is already marked for close */ log_fn(LOG_WARN, "Couldn't send ESTABLISH_RENDEZVOUS cell"); warn(LD_GENERAL, "Couldn't send ESTABLISH_RENDEZVOUS cell"); return -1; } Loading @@ -68,14 +69,14 @@ rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) tor_assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query)); if (rend_cache_lookup_entry(introcirc->rend_query, -1, &entry) < 1) { log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.", warn(LD_REND,"query '%s' didn't have valid rend desc in cache. Failing.", safe_str(introcirc->rend_query)); goto err; } /* first 20 bytes of payload are the hash of bob's pk */ if (crypto_pk_get_digest(entry->parsed->pk, payload)<0) { log_fn(LOG_WARN, "Internal error: couldn't hash public key."); warn(LD_GENERAL, "Internal error: couldn't hash public key."); goto err; } Loading @@ -86,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())) { log_fn(LOG_WARN, "Internal error: couldn't allocate DH."); warn(LD_GENERAL, "Internal error: couldn't allocate DH."); goto err; } if (crypto_dh_generate_public(cpath->dh_handshake_state)<0) { log_fn(LOG_WARN, "Internal error: couldn't generate g^x."); warn(LD_GENERAL, "Internal error: couldn't generate g^x."); goto err; } } Loading Loading @@ -119,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) { log_fn(LOG_WARN, "Internal error: couldn't extract g^x."); warn(LD_GENERAL, "Internal error: couldn't extract g^x."); goto err; } Loading @@ -129,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) { log_fn(LOG_WARN,"Internal error: hybrid pk encrypt failed."); warn(LD_GENERAL,"Internal error: hybrid pk encrypt failed."); goto err; } Loading @@ -141,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. */ log_fn(LOG_WARN, "Couldn't send INTRODUCE1 cell"); warn(LD_GENERAL, "Couldn't send INTRODUCE1 cell"); return -1; } Loading @@ -163,7 +164,7 @@ rend_client_rendcirc_has_opened(circuit_t *circ) tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND); tor_assert(CIRCUIT_IS_ORIGIN(circ)); log_fn(LOG_INFO,"rendcirc is open"); info(LD_REND,"rendcirc is open"); /* generate a rendezvous cookie, store it in circ */ if (rend_client_send_establish_rendezvous(circ) < 0) { Loading @@ -180,7 +181,7 @@ rend_client_introduction_acked(circuit_t *circ, circuit_t *rendcirc; if (circ->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) { log_fn(LOG_WARN, "Received REND_INTRODUCE_ACK on unexpected circuit %d.", warn(LD_PROTOCOL, "Received REND_INTRODUCE_ACK on unexpected circuit %d.", circ->n_circ_id); circuit_mark_for_close(circ); return -1; Loading @@ -194,13 +195,13 @@ rend_client_introduction_acked(circuit_t *circ, /* Locate the rend circ which is waiting to hear about this ack, * and tell it. */ log_fn(LOG_INFO,"Received ack. Telling rend circ..."); info(LD_REND,"Received ack. Telling rend circ..."); rendcirc = circuit_get_by_rend_query_and_purpose( circ->rend_query, CIRCUIT_PURPOSE_C_REND_READY); if (rendcirc) { /* remember the ack */ rendcirc->purpose = CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED; } else { log_fn(LOG_INFO,"...Found no rend circ. Dropping on the floor."); info(LD_REND,"...Found no rend circ. Dropping on the floor."); } /* close the circuit: we won't need it anymore. */ circ->purpose = CIRCUIT_PURPOSE_C_INTRODUCE_ACKED; Loading @@ -220,12 +221,13 @@ rend_client_introduction_acked(circuit_t *circ, int result; info = rend_client_get_random_intro(circ->rend_query); if (!info) { log_fn(LOG_WARN, "No introduction points left for %s. Closing.", warn(LD_REND, "No introduction points left for %s. Closing.", safe_str(circ->rend_query)); circuit_mark_for_close(circ); return -1; } log_fn(LOG_INFO,"Got nack for %s from %s. Re-extending circ %d, this time to %s.", info(LD_REND, "Got nack for %s from %s. Re-extending circ %d, this time to %s.", safe_str(circ->rend_query), circ->build_state->chosen_exit->nickname, circ->n_circ_id, info->nickname); Loading @@ -245,7 +247,7 @@ void rend_client_refetch_renddesc(const char *query) { if (connection_get_by_type_state_rendquery(CONN_TYPE_DIR, 0, query)) { log_fn(LOG_INFO,"Would fetch a new renddesc here (for %s), but one is already in progress.", safe_str(query)); info(LD_REND,"Would fetch a new renddesc here (for %s), but one is already in progress.", safe_str(query)); } else { /* not one already; initiate a dir rend desc lookup */ directory_get_from_dirserver(DIR_PURPOSE_FETCH_RENDDESC, query, 1); Loading @@ -267,11 +269,11 @@ rend_client_remove_intro_point(extend_info_t *failed_intro, const char *query) r = rend_cache_lookup_entry(query, -1, &ent); if (r<0) { log_fn(LOG_WARN, "Bug: malformed service ID '%s'.", safe_str(query)); warn(LD_GENERAL, "Bug: malformed service ID '%s'.", safe_str(query)); return -1; } if (r==0) { log_fn(LOG_INFO, "Unknown service %s. Re-fetching descriptor.", info(LD_REND, "Unknown service %s. Re-fetching descriptor.", safe_str(query)); rend_client_refetch_renddesc(query); return 0; Loading Loading @@ -306,7 +308,7 @@ rend_client_remove_intro_point(extend_info_t *failed_intro, const char *query) } if (!ent->parsed->n_intro_points) { log_fn(LOG_INFO,"No more intro points remain for %s. Re-fetching descriptor.", info(LD_REND,"No more intro points remain for %s. Re-fetching descriptor.", safe_str(query)); rend_client_refetch_renddesc(query); Loading @@ -318,7 +320,7 @@ rend_client_remove_intro_point(extend_info_t *failed_intro, const char *query) return 0; } log_fn(LOG_INFO,"%d options left for %s.", info(LD_REND,"%d options left for %s.", ent->parsed->n_intro_points, safe_str(query)); return 1; } Loading @@ -331,11 +333,11 @@ rend_client_rendezvous_acked(circuit_t *circ, const char *request, size_t reques { /* we just got an ack for our establish-rendezvous. switch purposes. */ if (circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) { log_fn(LOG_WARN,"Got a rendezvous ack when we weren't expecting one. Closing circ."); warn(LD_PROTOCOL,"Got a rendezvous ack when we weren't expecting one. Closing circ."); circuit_mark_for_close(circ); return -1; } log_fn(LOG_INFO,"Got rendezvous ack. This circuit is now ready for rendezvous."); info(LD_REND,"Got rendezvous ack. This circuit is now ready for rendezvous."); circ->purpose = CIRCUIT_PURPOSE_C_REND_READY; return 0; } Loading @@ -350,13 +352,13 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t requ if ((circ->purpose != CIRCUIT_PURPOSE_C_REND_READY && circ->purpose != CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) || !circ->build_state->pending_final_cpath) { log_fn(LOG_WARN,"Got rendezvous2 cell from hidden service, but not expecting it. Closing."); warn(LD_PROTOCOL,"Got rendezvous2 cell from hidden service, but not expecting it. Closing."); circuit_mark_for_close(circ); return -1; } if (request_len != DH_KEY_LEN+DIGEST_LEN) { log_fn(LOG_WARN,"Incorrect length (%d) on RENDEZVOUS2 cell.",(int)request_len); warn(LD_PROTOCOL,"Incorrect length (%d) on RENDEZVOUS2 cell.",(int)request_len); goto err; } Loading @@ -367,7 +369,7 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t requ tor_assert(hop->dh_handshake_state); if (crypto_dh_compute_secret(hop->dh_handshake_state, request, DH_KEY_LEN, keys, DIGEST_LEN+CPATH_KEY_MATERIAL_LEN)<0) { log_fn(LOG_WARN, "Couldn't complete DH handshake."); warn(LD_GENERAL, "Couldn't complete DH handshake."); goto err; } /* ... and set up cpath. */ Loading @@ -376,7 +378,7 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t requ /* Check whether the digest is right... */ if (memcmp(keys, request+DH_KEY_LEN, DIGEST_LEN)) { log_fn(LOG_WARN, "Incorrect digest of key material."); warn(LD_PROTOCOL, "Incorrect digest of key material."); goto err; } Loading Loading @@ -418,7 +420,7 @@ rend_client_desc_here(const char *query) entry->parsed->n_intro_points > 0) { /* either this fetch worked, or it failed but there was a * valid entry from before which we should reuse */ log_fn(LOG_INFO,"Rend desc is usable. Launching circuits."); info(LD_REND,"Rend desc is usable. Launching circuits."); conn->state = AP_CONN_STATE_CIRCUIT_WAIT; /* restart their timeout values, so they get a fair shake at Loading @@ -429,12 +431,12 @@ rend_client_desc_here(const char *query) if (connection_ap_handshake_attach_circuit(conn) < 0) { /* it will never work */ log_fn(LOG_WARN,"Rendezvous attempt failed. Closing."); warn(LD_REND,"Rendezvous attempt failed. Closing."); connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_ATTACH); } tor_assert(conn->state != AP_CONN_STATE_RENDDESC_WAIT); /* avoid loop */ } else { /* 404, or fetch didn't get that far */ log_fn(LOG_NOTICE,"Closing stream for '%s.onion': hidden service is unavailable (try again later).", safe_str(query)); notice(LD_REND,"Closing stream for '%s.onion': hidden service is unavailable (try again later).", safe_str(query)); connection_mark_unattached_ap(conn, END_STREAM_REASON_TIMEOUT); } } Loading @@ -451,7 +453,7 @@ rend_client_get_random_intro(const char *query) rend_cache_entry_t *entry; if (rend_cache_lookup_entry(query, -1, &entry) < 1) { log_fn(LOG_WARN,"Query '%s' didn't have valid rend desc in cache. Failing.", warn(LD_REND,"Query '%s' didn't have valid rend desc in cache. Failing.", safe_str(query)); return NULL; } Loading @@ -469,7 +471,7 @@ rend_client_get_random_intro(const char *query) char *choice = entry->parsed->intro_points[i]; routerinfo_t *router = router_get_by_nickname(choice, 0); if (!router) { log_fn(LOG_INFO, "Unknown router with nickname '%s'; trying another.",choice); info(LD_REND, "Unknown router with nickname '%s'; trying another.",choice); tor_free(choice); entry->parsed->intro_points[i] = entry->parsed->intro_points[--entry->parsed->n_intro_points]; Loading
src/or/rendcommon.c +12 −11 Changes for src/or/rendcommon.c: 12 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ const char rendcommon_c_id[] = "$Id$"; * introducers, services, clients, and rendezvous points. **/ #define NEW_LOG_INTERFACE #include "or.h" /** Return 0 if one and two are the same service ids, else -1 or 1 */ Loading Loading @@ -178,7 +179,7 @@ rend_parse_service_descriptor(const char *str, size_t len) cp += 8+DIGEST_LEN; if (end-cp < klen) goto truncated; if (!(info->onion_key = crypto_pk_asn1_decode(cp,klen))) { log_fn(LOG_WARN, "Internal error decoding onion key for intro point."); warn(LD_PROTOCOL, "Internal error decoding onion key for intro point."); goto error; } cp += klen; Loading @@ -188,7 +189,7 @@ rend_parse_service_descriptor(const char *str, size_t len) tor_assert(end-cp >= 0); if ((size_t)(end-cp) < keylen) goto truncated; if ((size_t)(end-cp) > keylen) { log_fn(LOG_WARN, "Signature is %d bytes too long on service descriptor.", warn(LD_PROTOCOL, "Signature is %d bytes too long on service descriptor.", (int)((size_t)(end-cp) - keylen)); goto error; } Loading @@ -196,13 +197,13 @@ rend_parse_service_descriptor(const char *str, size_t len) (char*)str,cp-str, /* data */ (char*)cp,end-cp /* signature*/ )<0) { log_fn(LOG_WARN, "Bad signature on service descriptor."); warn(LD_PROTOCOL, "Bad signature on service descriptor."); goto error; } return result; truncated: log_fn(LOG_WARN, "Truncated service descriptor."); warn(LD_PROTOCOL, "Truncated service descriptor."); error: rend_service_descriptor_free(result); return NULL; Loading Loading @@ -361,35 +362,35 @@ rend_cache_store(const char *desc, size_t desc_len) tor_assert(rend_cache); parsed = rend_parse_service_descriptor(desc,desc_len); if (!parsed) { log_fn(LOG_WARN,"Couldn't parse service descriptor."); warn(LD_PROTOCOL,"Couldn't parse service descriptor."); return -1; } if (rend_get_service_id(parsed->pk, query)<0) { log_fn(LOG_WARN,"Couldn't compute service ID."); warn(LD_GENERAL,"Couldn't compute service ID."); rend_service_descriptor_free(parsed); return -1; } tor_snprintf(key, sizeof(key), "%c%s", parsed->version?'1':'0', query); now = time(NULL); if (parsed->timestamp < now-REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) { log_fn(LOG_WARN,"Service descriptor %s is too old.", safe_str(query)); warn(LD_REND,"Service descriptor %s is too old.", safe_str(query)); rend_service_descriptor_free(parsed); return -1; } if (parsed->timestamp > now+REND_CACHE_MAX_SKEW) { log_fn(LOG_WARN,"Service descriptor %s is too far in the future.", warn(LD_REND,"Service descriptor %s is too far in the future.", safe_str(query)); rend_service_descriptor_free(parsed); return -1; } e = (rend_cache_entry_t*) strmap_get_lc(rend_cache, key); if (e && e->parsed->timestamp > parsed->timestamp) { log_fn(LOG_INFO,"We already have a newer service descriptor %s with the same ID and version.", safe_str(query)); info(LD_REND,"We already have a newer service descriptor %s with the same ID and version.", safe_str(query)); rend_service_descriptor_free(parsed); return 0; } if (e && e->len == desc_len && !memcmp(desc,e->desc,desc_len)) { log_fn(LOG_INFO,"We already have this service descriptor %s.", safe_str(query)); info(LD_REND,"We already have this service descriptor %s.", safe_str(query)); e->received = time(NULL); rend_service_descriptor_free(parsed); return 0; Loading @@ -407,7 +408,7 @@ rend_cache_store(const char *desc, size_t desc_len) e->desc = tor_malloc(desc_len); memcpy(e->desc, desc, desc_len); log_fn(LOG_DEBUG,"Successfully stored rend desc '%s', len %d.", debug(LD_REND,"Successfully stored rend desc '%s', len %d.", safe_str(query), (int)desc_len); return 1; } Loading