diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/or/config.c | 7 | ||||
-rw-r--r-- | src/or/connection_edge.c | 3 | ||||
-rw-r--r-- | src/or/control.c | 8 | ||||
-rw-r--r-- | src/or/directory.c | 10 | ||||
-rw-r--r-- | src/or/dirserv.c | 6 | ||||
-rw-r--r-- | src/or/eventdns.c | 2 | ||||
-rw-r--r-- | src/or/main.c | 9 | ||||
-rw-r--r-- | src/or/or.h | 5 | ||||
-rw-r--r-- | src/or/rendclient.c | 20 | ||||
-rw-r--r-- | src/or/rephist.c | 20 | ||||
-rw-r--r-- | src/or/router.c | 6 | ||||
-rw-r--r-- | src/or/routerlist.c | 57 | ||||
-rw-r--r-- | src/win32/orconfig.h | 2 |
13 files changed, 100 insertions, 55 deletions
diff --git a/src/or/config.c b/src/or/config.c index 81999516dd..b744f8faf4 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -1381,6 +1381,13 @@ options_act(or_options_t *old_options) geoip_load_file(actual_fname, options); tor_free(actual_fname); } +#ifdef ENABLE_GEOIP_STATS + log_warn(LD_CONFIG, "We are configured to measure GeoIP statistics, but " + "the way these statistics are measured has changed " + "significantly in later versions of Tor. The results may not be " + "as expected if you are used to later versions. Be sure you " + "know what you are doing."); +#endif /* Check if we need to parse and add the EntryNodes config option. */ if (options->EntryNodes && (!old_options || diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 1ef87dbffa..d699591cdc 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1484,7 +1484,8 @@ connection_ap_handshake_rewrite_and_attach(edge_connection_t *conn, addresstype = parse_extended_hostname(socks->address); if (addresstype == BAD_HOSTNAME) { - log_warn(LD_APP, "Invalid hostname %s; rejecting", socks->address); + log_warn(LD_APP, "Invalid onion hostname %s; rejecting", + safe_str(socks->address)); control_event_client_status(LOG_WARN, "SOCKS_BAD_HOSTNAME HOSTNAME=%s", escaped(socks->address)); connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL); diff --git a/src/or/control.c b/src/or/control.c index 486ccc4c75..90c99fd51a 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -2888,10 +2888,16 @@ connection_control_process_inbuf(control_connection_t *conn) --data_len; } - /* Quit is always valid. */ + /* If the connection is already closing, ignore further commands */ + if (TO_CONN(conn)->marked_for_close) { + return 0; + } + + /* Otherwise, Quit is always valid. */ if (!strcasecmp(conn->incoming_cmd, "QUIT")) { connection_write_str_to_buf("250 closing connection\r\n", conn); connection_mark_for_close(TO_CONN(conn)); + conn->_base.hold_open_until_flushed = 1; return 0; } diff --git a/src/or/directory.c b/src/or/directory.c index d783772eac..4ab2633022 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -2428,13 +2428,9 @@ directory_handle_command_get(dir_connection_t *conn, const char *headers, dlen = strlen(frontpage); /* Let's return a disclaimer page (users shouldn't use V1 anymore, and caches don't fetch '/', so this is safe). */ - if (global_write_bucket_low(TO_CONN(conn), dlen, 1)) { - log_info(LD_DIRSERV, - "Client asked for DirPortFrontPage content, but we've been " - "writing too many bytes lately. Sending 503 Dir busy."); - write_http_status_line(conn, 503, "Directory busy, try again later"); - goto done; - } + + /* [We don't check for write_bucket_low here, since we want to serve + * this page no matter what.] */ note_request(url, dlen); write_http_response_header_impl(conn, dlen, "text/html", "identity", NULL, DIRPORTFRONTPAGE_CACHE_LIFETIME); diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 88afe9fccc..a64a01bb80 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -797,7 +797,7 @@ directory_remove_invalid(void) if (r & FP_REJECT) { log_info(LD_DIRSERV, "Router '%s' is now rejected: %s", ent->nickname, msg?msg:""); - routerlist_remove(rl, ent, 0); + routerlist_remove(rl, ent, 0, time(NULL)); i--; changed = 1; continue; @@ -951,8 +951,8 @@ dirserv_set_router_is_running(routerinfo_t *router, time_t now) answer = get_options()->AssumeReachable || now < router->last_reachable + REACHABLE_TIMEOUT; - if (router->is_running && !answer) { - /* it was running but now it's not. tell rephist. */ + if (!answer) { + /* not considered reachable. tell rephist. */ rep_hist_note_router_unreachable(router->cache_info.identity_digest, now); } diff --git a/src/or/eventdns.c b/src/or/eventdns.c index 4464148141..4ae17a40c3 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -1842,7 +1842,7 @@ evdns_server_request_format_response(struct server_request *req, int err) if (j > 512) { overflow: j = 512; - buf[3] |= 0x02; /* set the truncated bit. */ + buf[2] |= 0x02; /* set the truncated bit. */ } req->response_len = (size_t)j; diff --git a/src/or/main.c b/src/or/main.c index 8fc712bba3..60c42aaae3 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -903,7 +903,7 @@ run_scheduled_events(time_t now) time_to_downrate_stability = rep_hist_downrate_old_runs(now); if (authdir_mode_tests_reachability(options)) { if (time_to_save_stability < now) { - if (time_to_save_stability && rep_hist_record_mtbf_data()<0) { + if (time_to_save_stability && rep_hist_record_mtbf_data(now, 1)<0) { log_warn(LD_GENERAL, "Couldn't store mtbf data."); } #define SAVE_STABILITY_INTERVAL (30*60) @@ -1955,14 +1955,15 @@ tor_cleanup(void) /* Remove our pid file. We don't care if there was an error when we * unlink, nothing we could do about it anyways. */ if (options->command == CMD_RUN_TOR) { + time_t now = time(NULL); if (options->PidFile) unlink(options->PidFile); if (accounting_is_enabled(options)) - accounting_record_bandwidth_usage(time(NULL), get_or_state()); + accounting_record_bandwidth_usage(now, get_or_state()); or_state_mark_dirty(get_or_state(), 0); /* force an immediate save. */ - or_state_save(time(NULL)); + or_state_save(now); if (authdir_mode_tests_reachability(options)) - rep_hist_record_mtbf_data(); + rep_hist_record_mtbf_data(now, 0); } #ifdef USE_DMALLOC dmalloc_log_stats(); diff --git a/src/or/or.h b/src/or/or.h index f84485f2f4..eddeda1531 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3970,7 +3970,7 @@ void rep_history_clean(time_t before); void rep_hist_note_router_reachable(const char *id, time_t when); void rep_hist_note_router_unreachable(const char *id, time_t when); -int rep_hist_record_mtbf_data(void); +int rep_hist_record_mtbf_data(time_t now, int missing_means_down); int rep_hist_load_mtbf_data(time_t now); time_t rep_hist_downrate_old_runs(time_t now); @@ -4411,7 +4411,8 @@ void routerinfo_free(routerinfo_t *router); void extrainfo_free(extrainfo_t *extrainfo); void routerlist_free(routerlist_t *rl); void dump_routerlist_mem_usage(int severity); -void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old); +void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old, + time_t now); void routerlist_free_all(void); void routerlist_reset_warnings(void); void router_set_status(const char *digest, int up); diff --git a/src/or/rendclient.c b/src/or/rendclient.c index 5b18a519b0..a5d7c1016e 100644 --- a/src/or/rendclient.c +++ b/src/or/rendclient.c @@ -94,8 +94,24 @@ rend_client_send_introduction(origin_circuit_t *introcirc, } }); if (!intro_key) { - log_warn(LD_BUG, "Internal error: could not find intro key."); - goto err; + if (rend_cache_lookup_entry(introcirc->rend_data->onion_address, + 0, &entry) > 0) { + log_warn(LD_BUG, "We have both a v0 and a v2 rend desc for this " + "service. The v2 desc doesn't contain the introduction " + "point (and key) to send an INTRODUCE1/2 cell to this " + "introduction point. Assuming the introduction point " + "is for v0 rend clients and using the service key " + "from the v0 desc instead. (This is probably a bug, " + "because we shouldn't even have both a v0 and a v2 " + "descriptor for the same service.)"); + /* See flyspray task 1024. */ + intro_key = entry->parsed->pk; + } else { + log_warn(LD_BUG, "Internal error: could not find intro key; we " + "only have a v2 rend desc with %d intro points.", + smartlist_len(entry->parsed->intro_nodes)); + goto err; + } } } if (crypto_pk_get_digest(intro_key, payload)<0) { diff --git a/src/or/rephist.c b/src/or/rephist.c index 11e040c945..13fdb58b5e 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -683,9 +683,13 @@ rep_history_clean(time_t before) } } -/** Write MTBF data to disk. Returns 0 on success, negative on failure. */ +/** Write MTBF data to disk. Return 0 on success, negative on failure. + * + * If <b>missing_means_down</b>, then if we're about to write an entry + * that is still considered up but isn't in our routerlist, consider it + * to be down. */ int -rep_hist_record_mtbf_data(void) +rep_hist_record_mtbf_data(time_t now, int missing_means_down) { char time_buf[ISO_TIME_LEN+1]; @@ -745,6 +749,18 @@ rep_hist_record_mtbf_data(void) hist = (or_history_t*) or_history_p; base16_encode(dbuf, sizeof(dbuf), digest, DIGEST_LEN); + + if (missing_means_down && hist->start_of_run && + !router_get_by_digest(digest)) { + /* We think this relay is running, but it's not listed in our + * routerlist. Somehow it fell out without telling us it went + * down. Complain and also correct it. */ + log_info(LD_HIST, + "Relay '%s' is listed as up in rephist, but it's not in " + "our routerlist. Correcting.", dbuf); + rep_hist_note_router_unreachable(digest, now); + } + PRINTF((f, "R %s\n", dbuf)); if (hist->start_of_run > 0) { format_iso_time(time_buf, hist->start_of_run); diff --git a/src/or/router.c b/src/or/router.c index 658c567db1..93afe4fad5 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -1509,8 +1509,8 @@ log_addr_has_changed(int severity, uint32_t prev, uint32_t cur, addrbuf_prev, addrbuf_cur, source); else log_notice(LD_GENERAL, - "Guessed our IP address as %s.", - addrbuf_cur); + "Guessed our IP address as %s (source: %s).", + addrbuf_cur, source); } /** Check whether our own address as defined by the Address configuration @@ -1533,7 +1533,7 @@ check_descriptor_ipaddress_changed(time_t now) } if (prev != cur) { - log_addr_has_changed(LOG_INFO, prev, cur, "resolve"); + log_addr_has_changed(LOG_NOTICE, prev, cur, "resolve"); ip_address_changed(0); } } diff --git a/src/or/routerlist.c b/src/or/routerlist.c index d8165e63bd..42b385b101 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1523,15 +1523,12 @@ router_get_advertised_bandwidth_capped(routerinfo_t *router) return result; } -/** Eventually, the number we return will come from the directory - * consensus, so clients can dynamically update to better numbers. - * - * But for now, or in case there is no consensus available, just return - * a sufficient default. */ -static uint32_t -get_max_believable_bandwidth(void) +/** Return bw*1000, unless bw*1000 would overflow, in which case return + * INT32_MAX. */ +static INLINE int32_t +kb_to_bytes(uint32_t bw) { - return DEFAULT_MAX_BELIEVABLE_BANDWIDTH; + return (bw > (INT32_MAX/1000)) ? INT32_MAX : bw*1000; } /** Helper function: @@ -1568,7 +1565,6 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule, int n_unknown = 0; bitarray_t *exit_bits; bitarray_t *guard_bits; - uint32_t max_believable_bw = get_max_believable_bandwidth(); int me_idx = -1; /* Can't choose exit and guard at same time */ @@ -1591,48 +1587,50 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule, int32_t flags = 0; uint32_t this_bw = 0; if (statuses) { - /* need to extract router info */ status = smartlist_get(sl, i); if (router_digest_is_me(status->identity_digest)) me_idx = i; router = router_get_by_digest(status->identity_digest); is_exit = status->is_exit; is_guard = status->is_possible_guard; - if (router) { - this_bw = router_get_advertised_bandwidth(router); + if (status->has_bandwidth) { + this_bw = kb_to_bytes(status->bandwidth); } else { /* guess */ + /* XXX022 once consensuses always list bandwidths, we can take + * this guessing business out. -RD */ is_known = 0; flags = status->is_fast ? 1 : 0; flags |= is_exit ? 2 : 0; flags |= is_guard ? 4 : 0; } } else { + routerstatus_t *rs; router = smartlist_get(sl, i); + rs = router_get_consensus_status_by_id( + router->cache_info.identity_digest); if (router_digest_is_me(router->cache_info.identity_digest)) me_idx = i; is_exit = router->is_exit; is_guard = router->is_possible_guard; - this_bw = router_get_advertised_bandwidth(router); + if (rs && rs->has_bandwidth) { + this_bw = kb_to_bytes(rs->bandwidth); + } else if (rs) { /* guess; don't trust the descriptor */ + /* XXX022 once consensuses always list bandwidths, we can take + * this guessing business out. -RD */ + is_known = 0; + flags = router->is_fast ? 1 : 0; + flags |= is_exit ? 2 : 0; + flags |= is_guard ? 4 : 0; + } else /* bridge or other descriptor not in our consensus */ + this_bw = router_get_advertised_bandwidth_capped(router); } if (is_exit) bitarray_set(exit_bits, i); if (is_guard) bitarray_set(guard_bits, i); - /* if they claim something huge, don't believe it */ - if (this_bw > max_believable_bw) { - char fp[HEX_DIGEST_LEN+1]; - base16_encode(fp, sizeof(fp), statuses ? - status->identity_digest : - router->cache_info.identity_digest, - DIGEST_LEN); - log_fn(LOG_PROTOCOL_WARN, LD_DIR, - "Bandwidth %d for router %s (%s) exceeds allowed max %d, capping", - this_bw, router ? router->nickname : "(null)", - fp, max_believable_bw); - this_bw = max_believable_bw; - } if (is_known) { bandwidths[i] = (int32_t) this_bw; // safe since MAX_BELIEVABLE<INT32_MAX + tor_assert(bandwidths[i] >= 0); if (is_guard) total_guard_bw += this_bw; else @@ -2631,7 +2629,7 @@ routerlist_insert_old(routerlist_t *rl, routerinfo_t *ri) * If <b>make_old</b> is true, instead of deleting the router, we try adding * it to rl->old_routers. */ void -routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old) +routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old, time_t now) { routerinfo_t *ri_tmp; extrainfo_t *ei_tmp; @@ -2639,6 +2637,9 @@ routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old) tor_assert(0 <= idx && idx < smartlist_len(rl->routers)); tor_assert(smartlist_get(rl->routers, idx) == ri); + /* make sure the rephist module knows that it's not running */ + rep_hist_note_router_unreachable(ri->cache_info.identity_digest, now); + ri->cache_info.routerlist_index = -1; smartlist_del(rl->routers, idx); if (idx < smartlist_len(rl->routers)) { @@ -3330,7 +3331,7 @@ routerlist_remove_old_routers(void) log_info(LD_DIR, "Forgetting obsolete (too old) routerinfo for router '%s'", router->nickname); - routerlist_remove(routerlist, router, 1); + routerlist_remove(routerlist, router, 1, now); i--; } } diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h index 037e869029..a13b4139c3 100644 --- a/src/win32/orconfig.h +++ b/src/win32/orconfig.h @@ -226,6 +226,6 @@ #define USING_TWOS_COMPLEMENT /* Version number of package */ -#define VERSION "0.2.1.16-rc" +#define VERSION "0.2.1.17-rc" |