summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/address.c2
-rw-r--r--src/or/config.c59
-rw-r--r--src/or/dirserv.h2
-rw-r--r--src/or/dnsserv.c2
-rw-r--r--src/or/eventdns.c6
-rw-r--r--src/or/eventdns.h4
-rw-r--r--src/or/rephist.c70
-rw-r--r--src/or/routerlist.c4
-rw-r--r--src/or/routerparse.c10
-rw-r--r--src/test/test_addr.c4
10 files changed, 64 insertions, 99 deletions
diff --git a/src/common/address.c b/src/common/address.c
index adc0ef0f7c..aff517ca51 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -604,7 +604,7 @@ tor_addr_parse_mask_ports(const char *s, tor_addr_t *addr_out,
if (family == AF_INET6 && v4map) {
if (bits > 32 && bits < 96) { /* Crazy */
log_warn(LD_GENERAL,
- "Bad mask bits %i for V4-mapped V6 address; rejecting.",
+ "Bad mask bits %d for V4-mapped V6 address; rejecting.",
bits);
goto err;
}
diff --git a/src/or/config.c b/src/or/config.c
index 5000f5d60e..9675c73c99 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2500,54 +2500,6 @@ is_local_addr(const tor_addr_t *addr)
return 0;
}
-/** Called when we don't have a nickname set. Try to guess a good nickname
- * based on the hostname, and return it in a newly allocated string. If we
- * can't, return NULL and let the caller warn if it wants to. */
-static char *
-get_default_nickname(void)
-{
- static const char * const bad_default_nicknames[] = {
- "localhost",
- NULL,
- };
- char localhostname[256];
- char *cp, *out, *outp;
- int i;
-
- if (gethostname(localhostname, sizeof(localhostname)) < 0)
- return NULL;
-
- /* Put it in lowercase; stop at the first dot. */
- if ((cp = strchr(localhostname, '.')))
- *cp = '\0';
- tor_strlower(localhostname);
-
- /* Strip invalid characters. */
- cp = localhostname;
- out = outp = tor_malloc(strlen(localhostname) + 1);
- while (*cp) {
- if (strchr(LEGAL_NICKNAME_CHARACTERS, *cp))
- *outp++ = *cp++;
- else
- cp++;
- }
- *outp = '\0';
-
- /* Enforce length. */
- if (strlen(out) > MAX_NICKNAME_LEN)
- out[MAX_NICKNAME_LEN]='\0';
-
- /* Check for dumb names. */
- for (i = 0; bad_default_nicknames[i]; ++i) {
- if (!strcmp(out, bad_default_nicknames[i])) {
- tor_free(out);
- return NULL;
- }
- }
-
- return out;
-}
-
/** Release storage held by <b>options</b>. */
static void
config_free(config_format_t *fmt, void *options)
@@ -2976,14 +2928,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->Nickname == NULL) {
if (server_mode(options)) {
- if (!(options->Nickname = get_default_nickname())) {
- log_notice(LD_CONFIG, "Couldn't pick a nickname based on "
- "our hostname; using %s instead.", UNNAMED_ROUTER_NICKNAME);
options->Nickname = tor_strdup(UNNAMED_ROUTER_NICKNAME);
- } else {
- log_notice(LD_CONFIG, "Choosing default nickname '%s'",
- options->Nickname);
- }
}
} else {
if (!is_legal_nickname(options->Nickname)) {
@@ -4382,11 +4327,13 @@ options_init_logs(or_options_t *options, int validate_only)
if (smartlist_len(elts) == 2 &&
!strcasecmp(smartlist_get(elts,0), "file")) {
if (!validate_only) {
- if (add_file_log(severity, smartlist_get(elts, 1)) < 0) {
+ char *fname = expand_filename(smartlist_get(elts, 1));
+ if (add_file_log(severity, fname) < 0) {
log_warn(LD_CONFIG, "Couldn't open file for 'Log %s': %s",
opt->value, strerror(errno));
ok = 0;
}
+ tor_free(fname);
}
goto cleanup;
}
diff --git a/src/or/dirserv.h b/src/or/dirserv.h
index 569abfca2e..a8a7060a36 100644
--- a/src/or/dirserv.h
+++ b/src/or/dirserv.h
@@ -52,7 +52,7 @@
MAX_V_LINE_LEN \
)
-#define UNNAMED_ROUTER_NICKNAME "Unnamed"
+#define UNNAMED_ROUTER_NICKNAME "Unnamed"
int connection_dirserv_flushed_some(dir_connection_t *conn);
diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c
index f7a8d35f78..243b730cbf 100644
--- a/src/or/dnsserv.c
+++ b/src/or/dnsserv.c
@@ -280,7 +280,7 @@ dnsserv_resolved(edge_connection_t *conn,
conn->socks_request->command == SOCKS_COMMAND_RESOLVE) {
evdns_server_request_add_a_reply(req,
name,
- 1, (char*)answer, ttl);
+ 1, answer, ttl);
} else if (answer_type == RESOLVED_TYPE_HOSTNAME &&
answer_len < 256 &&
conn->socks_request->command == SOCKS_COMMAND_RESOLVE_PTR) {
diff --git a/src/or/eventdns.c b/src/or/eventdns.c
index 8b679f8985..cf583d0682 100644
--- a/src/or/eventdns.c
+++ b/src/or/eventdns.c
@@ -1668,7 +1668,7 @@ evdns_server_request_add_reply(struct evdns_server_request *_req, int section, c
/* exported function */
int
-evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl)
+evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl)
{
return evdns_server_request_add_reply(
req, EVDNS_ANSWER_SECTION, name, TYPE_A, CLASS_INET,
@@ -1677,7 +1677,7 @@ evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *n
/* exported function */
int
-evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl)
+evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl)
{
return evdns_server_request_add_reply(
req, EVDNS_ANSWER_SECTION, name, TYPE_AAAA, CLASS_INET,
@@ -1904,7 +1904,7 @@ server_request_free(struct server_request *req)
if (req->port) {
if (req->port->pending_replies == req) {
- if (req->next_pending)
+ if (req->next_pending && req->next_pending != req)
req->port->pending_replies = req->next_pending;
else
req->port->pending_replies = NULL;
diff --git a/src/or/eventdns.h b/src/or/eventdns.h
index bf3b64d08a..2fe4ac9371 100644
--- a/src/or/eventdns.h
+++ b/src/or/eventdns.h
@@ -323,8 +323,8 @@ struct evdns_server_port *evdns_add_server_port(int socket, int is_tcp, evdns_re
void evdns_close_server_port(struct evdns_server_port *port);
int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data);
-int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl);
-int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl);
+int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl);
+int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl);
int evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl);
int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl);
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 9b7eefecf2..5703e3edcd 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -992,10 +992,10 @@ find_next_with(smartlist_t *sl, int i, const char *prefix)
return -1;
}
-/** How many bad times has parse_possibly_bad_iso_time parsed? */
+/** How many bad times has parse_possibly_bad_iso_time() parsed? */
static int n_bogus_times = 0;
/** Parse the ISO-formatted time in <b>s</b> into *<b>time_out</b>, but
- * rounds any pre-1970 date to Jan 1, 1970. */
+ * round any pre-1970 date to Jan 1, 1970. */
static int
parse_possibly_bad_iso_time(const char *s, time_t *time_out)
{
@@ -1288,7 +1288,7 @@ commit_max(bw_array_t *b)
b->total_in_period = 0;
}
-/** Shift the current observation time of 'b' forward by one second. */
+/** Shift the current observation time of <b>b</b> forward by one second. */
static INLINE void
advance_obs(bw_array_t *b)
{
@@ -1318,16 +1318,16 @@ advance_obs(bw_array_t *b)
static INLINE void
add_obs(bw_array_t *b, time_t when, uint64_t n)
{
- /* Don't record data in the past. */
- if (when<b->cur_obs_time)
- return;
+ if (when < b->cur_obs_time)
+ return; /* Don't record data in the past. */
+
/* If we're currently adding observations for an earlier second than
* 'when', advance b->cur_obs_time and b->cur_obs_idx by an
- * appropriate number of seconds, and do all the other housekeeping */
- while (when>b->cur_obs_time) {
+ * appropriate number of seconds, and do all the other housekeeping. */
+ while (when > b->cur_obs_time) {
/* Doing this one second at a time is potentially inefficient, if we start
with a state file that is very old. Fortunately, it doesn't seem to
- show up in profiles, so we can just ignore it for now. */
+ show up in profiles, so we can just ignore it for now. */
advance_obs(b);
}
@@ -1375,7 +1375,7 @@ bw_arrays_init(void)
dir_write_array = bw_array_new();
}
-/** We read <b>num_bytes</b> more bytes in second <b>when</b>.
+/** Remember that we read <b>num_bytes</b> bytes in second <b>when</b>.
*
* Add num_bytes to the current running total for <b>when</b>.
*
@@ -1396,7 +1396,7 @@ rep_hist_note_bytes_written(size_t num_bytes, time_t when)
add_obs(write_array, when, num_bytes);
}
-/** We wrote <b>num_bytes</b> more bytes in second <b>when</b>.
+/** Remember that we wrote <b>num_bytes</b> bytes in second <b>when</b>.
* (like rep_hist_note_bytes_written() above)
*/
void
@@ -1406,8 +1406,8 @@ rep_hist_note_bytes_read(size_t num_bytes, time_t when)
add_obs(read_array, when, num_bytes);
}
-/** We wrote <b>num_bytes</b> more directory bytes in second <b>when</b>.
- * (like rep_hist_note_bytes_written() above)
+/** Remember that we wrote <b>num_bytes</b> directory bytes in second
+ * <b>when</b>. (like rep_hist_note_bytes_written() above)
*/
void
rep_hist_note_dir_bytes_written(size_t num_bytes, time_t when)
@@ -1415,8 +1415,8 @@ rep_hist_note_dir_bytes_written(size_t num_bytes, time_t when)
add_obs(dir_write_array, when, num_bytes);
}
-/** We read <b>num_bytes</b> more directory bytes in second <b>when</b>.
- * (like rep_hist_note_bytes_written() above)
+/** Remember that we read <b>num_bytes</b> directory bytes in second
+ * <b>when</b>. (like rep_hist_note_bytes_written() above)
*/
void
rep_hist_note_dir_bytes_read(size_t num_bytes, time_t when)
@@ -1511,7 +1511,8 @@ rep_hist_fill_bandwidth_history(char *buf, size_t len, const bw_array_t *b)
}
/** Allocate and return lines for representing this server's bandwidth
- * history in its descriptor.
+ * history in its descriptor. We publish these lines in our extra-info
+ * descriptor.
*/
char *
rep_hist_get_bandwidth_lines(void)
@@ -1559,7 +1560,7 @@ rep_hist_get_bandwidth_lines(void)
}
/** Write a single bw_array_t into the Values, Ends, Interval, and Maximum
- * entries of an or_state_t. */
+ * entries of an or_state_t. Done before writing out a new state file. */
static void
rep_hist_update_bwhist_state_section(or_state_t *state,
const bw_array_t *b,
@@ -1570,6 +1571,7 @@ rep_hist_update_bwhist_state_section(or_state_t *state,
{
char *cp;
int i,j;
+ uint64_t maxval;
if (*s_values) {
SMARTLIST_FOREACH(*s_values, char *, val, tor_free(val));
@@ -1603,7 +1605,6 @@ rep_hist_update_bwhist_state_section(or_state_t *state,
/* Set i to first position in circular array */
i = (b->num_maxes_set <= b->next_max_idx) ? 0 : b->next_max_idx;
for (j=0; j < b->num_maxes_set; ++j,++i) {
- uint64_t maxval;
if (i >= NUM_TOTALS)
i = 0;
tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(b->totals[i] & ~0x3ff));
@@ -1614,11 +1615,13 @@ rep_hist_update_bwhist_state_section(or_state_t *state,
}
tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(b->total_in_period & ~0x3ff));
smartlist_add(*s_values, cp);
- tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(b->max_total & ~0x3ff));
+ maxval = b->max_total / NUM_SECS_ROLLING_MEASURE;
+ tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(maxval & ~0x3ff));
smartlist_add(*s_maxima, cp);
}
-/** Update <b>state</b> with the newest bandwidth history. */
+/** Update <b>state</b> with the newest bandwidth history. Done before
+ * writing out a new state file. */
void
rep_hist_update_state(or_state_t *state)
{
@@ -1642,7 +1645,7 @@ rep_hist_update_state(or_state_t *state)
}
/** Load a single bw_array_t from its Values, Ends, Maxima, and Interval
- * entries in an or_state_t. */
+ * entries in an or_state_t. Done while reading the state file. */
static int
rep_hist_load_bwhist_state_section(bw_array_t *b,
const smartlist_t *s_values,
@@ -1673,7 +1676,7 @@ rep_hist_load_bwhist_state_section(bw_array_t *b,
mv *= NUM_SECS_ROLLING_MEASURE;
} else {
/* No maxima known; guess average rate to be conservative. */
- mv = v / s_interval;
+ mv = (v / s_interval) * NUM_SECS_ROLLING_MEASURE;
}
if (!ok) {
retval = -1;
@@ -1686,11 +1689,24 @@ rep_hist_load_bwhist_state_section(bw_array_t *b,
}
if (start < now) {
- add_obs(b, start, v);
+ time_t cur_start = start;
+ time_t actual_interval_len = s_interval;
+ uint64_t cur_val = 0;
+ /* Calculate the average per second. This is the best we can do
+ * because our state file doesn't have per-second resolution. */
+ if (start + s_interval > now)
+ actual_interval_len = now - start;
+ cur_val = v / actual_interval_len;
+ /* This is potentially inefficient, but since we don't do it very
+ * often it should be ok. */
+ while (cur_start < start + actual_interval_len) {
+ add_obs(b, cur_start, cur_val);
+ ++cur_start;
+ }
b->max_total = mv;
/* This will result in some fairly choppy history if s_interval
- * is notthe same as NUM_SECS_BW_SUM_INTERVAL. XXXX */
- start += s_interval;
+ * is not the same as NUM_SECS_BW_SUM_INTERVAL. XXXX */
+ start += actual_interval_len;
}
} SMARTLIST_FOREACH_END(cp);
}
@@ -1704,7 +1720,7 @@ rep_hist_load_bwhist_state_section(bw_array_t *b,
return retval;
}
-/** Set bandwidth history from our saved state. */
+/** Set bandwidth history from the state file we just loaded. */
int
rep_hist_load_state(or_state_t *state, char **err)
{
@@ -1752,7 +1768,7 @@ static smartlist_t *predicted_ports_times=NULL;
static void
add_predicted_port(time_t now, uint16_t port)
{
- /* XXXX we could just use uintptr_t here, I think. */
+ /* XXXX we could just use uintptr_t here, I think. -NM */
uint16_t *tmp_port = tor_malloc(sizeof(uint16_t));
time_t *tmp_time = tor_malloc(sizeof(time_t));
*tmp_port = port;
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 4deff53a3c..c02654feef 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -531,8 +531,8 @@ authority_certs_fetch_missing(networkstatus_t *status, time_t now)
if (!found &&
download_status_is_ready(&cl->dl_status, now,MAX_CERT_DL_FAILURES) &&
!digestmap_get(pending, ds->v3_identity_digest)) {
- log_notice(LD_DIR, "No current certificate known for authority %s; "
- "launching request.", ds->nickname);
+ log_info(LD_DIR, "No current certificate known for authority %s; "
+ "launching request.", ds->nickname);
smartlist_add(missing_digests, ds->v3_identity_digest);
}
} SMARTLIST_FOREACH_END(ds);
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 95e174e550..ba29f056f1 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -4638,10 +4638,12 @@ rend_parse_v2_service_descriptor(rend_service_descriptor_t **parsed_out,
else
eos = eos + 1;
/* Check length. */
- if (strlen(desc) > REND_DESC_MAX_SIZE) {
- log_warn(LD_REND, "Descriptor length is %i which exceeds "
- "maximum rendezvous descriptor size of %i kilobytes.",
- (int)strlen(desc), REND_DESC_MAX_SIZE);
+ if (eos-desc > REND_DESC_MAX_SIZE) {
+ /* XXX023 If we are parsing this descriptor as a server, this
+ * should be a protocol warning. */
+ log_warn(LD_REND, "Descriptor length is %d which exceeds "
+ "maximum rendezvous descriptor size of %d bytes.",
+ (int)(eos-desc), REND_DESC_MAX_SIZE);
goto err;
}
/* Tokenize descriptor. */
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index 20ffaa0c52..6db4ee2483 100644
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@ -477,9 +477,9 @@ test_addr_ip6_helpers(void)
i = get_interface_address6(LOG_DEBUG, AF_INET6, &t2);
#if 0
tor_inet_ntop(AF_INET, &t1.sa.sin_addr, buf, sizeof(buf));
- printf("\nv4 address: %s (family=%i)", buf, IN_FAMILY(&t1));
+ printf("\nv4 address: %s (family=%d)", buf, IN_FAMILY(&t1));
tor_inet_ntop(AF_INET6, &t2.sa6.sin6_addr, buf, sizeof(buf));
- printf("\nv6 address: %s (family=%i)", buf, IN_FAMILY(&t2));
+ printf("\nv6 address: %s (family=%d)", buf, IN_FAMILY(&t2));
#endif
done: