diff options
author | Peter Palfrader <peter@palfrader.org> | 2009-09-21 13:14:39 +0200 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2009-09-21 13:14:39 +0200 |
commit | a9c45754e0e587dda4e16f888a1662eddf90b1f5 (patch) | |
tree | cc5b7aa467419ae63f394e9e3929c38eac316915 /src/common | |
parent | b440a4d9369c4a6c4501b289f2e6ff089ba9a519 (diff) | |
parent | 54ba86d9d0cff2ceef75d564ece3d7d2ea26af26 (diff) | |
download | tor-a9c45754e0e587dda4e16f888a1662eddf90b1f5.tar tor-a9c45754e0e587dda4e16f888a1662eddf90b1f5.tar.gz |
Merge commit 'tor-0.2.2.2-alpha' into debian-merge
* commit 'tor-0.2.2.2-alpha': (94 commits)
downgrade a log severity, since this event has been known
Update to the "September 4 2009" ip-to-country file.
bump to 0.2.2.2-alpha
Revert "Teach connection_ap_can_use_exit about Exclude*Nodes"
fix grammar / add changelog for the torify commit
Fix compile on Snow Leopard
Fix build warnings on OSX 10.5.8
Change the condition on the nonlive timeout counting.
Add a couple of time helper functions.
Fix typos and comments, plus two bugs
Implement and document new network liveness algorithm.
Fix some precision-related asserts in unit tests.
replace contrib/auto-naming with a readme saying where it went
clarify our rules for assigning the Named flag
disable the end of circuitbuildtimeout units tests
draw in a lot of 0.2.1.20 changelog items into 0.2.2.2-alpha
Fix compile on freebsd
Let our config abbreviations rewrite more than once
a mish-mash of stuff in my sandbox
give proposal 151 a changelog and other touchups
...
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/address.c | 9 | ||||
-rw-r--r-- | src/common/compat.c | 4 | ||||
-rw-r--r-- | src/common/container.c | 1 | ||||
-rw-r--r-- | src/common/container.h | 6 | ||||
-rw-r--r-- | src/common/log.c | 22 | ||||
-rw-r--r-- | src/common/torint.h | 3 | ||||
-rw-r--r-- | src/common/tortls.c | 13 | ||||
-rw-r--r-- | src/common/tortls.h | 4 | ||||
-rw-r--r-- | src/common/util.c | 60 | ||||
-rw-r--r-- | src/common/util.h | 5 |
10 files changed, 103 insertions, 24 deletions
diff --git a/src/common/address.c b/src/common/address.c index fac9d50e1..2fe013a2c 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -373,10 +373,11 @@ tor_addr_parse_reverse_lookup_name(tor_addr_t *result, const char *address, return -1; /* malformed. */ /* reverse the bytes */ - inaddr.s_addr = (((inaddr.s_addr & 0x000000fful) << 24) - |((inaddr.s_addr & 0x0000ff00ul) << 8) - |((inaddr.s_addr & 0x00ff0000ul) >> 8) - |((inaddr.s_addr & 0xff000000ul) >> 24)); + inaddr.s_addr = (uint32_t) + (((inaddr.s_addr & 0x000000ff) << 24) + |((inaddr.s_addr & 0x0000ff00) << 8) + |((inaddr.s_addr & 0x00ff0000) >> 8) + |((inaddr.s_addr & 0xff000000) >> 24)); if (result) { tor_addr_from_in(result, &inaddr); diff --git a/src/common/compat.c b/src/common/compat.c index 29425c249..e1a275de1 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -480,8 +480,8 @@ get_uint32(const char *cp) return v; } /** - * Read a 32-bit value beginning at <b>cp</b>. Equivalent to - * *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid + * Read a 64-bit value beginning at <b>cp</b>. Equivalent to + * *(uint64_t*)(cp), but will not cause segfaults on platforms that forbid * unaligned memory access. */ uint64_t diff --git a/src/common/container.c b/src/common/container.c index c649787c0..12ac2527e 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -1220,6 +1220,7 @@ IMPLEMENT_ORDER_FUNC(find_nth_int, int) IMPLEMENT_ORDER_FUNC(find_nth_time, time_t) IMPLEMENT_ORDER_FUNC(find_nth_double, double) IMPLEMENT_ORDER_FUNC(find_nth_uint32, uint32_t) +IMPLEMENT_ORDER_FUNC(find_nth_int32, int32_t) IMPLEMENT_ORDER_FUNC(find_nth_long, long) /** Return a newly allocated digestset_t, optimized to hold a total of diff --git a/src/common/container.h b/src/common/container.h index e62655246..4495a7a27 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -627,6 +627,7 @@ void digestset_free(digestset_t* set); int find_nth_int(int *array, int n_elements, int nth); time_t find_nth_time(time_t *array, int n_elements, int nth); double find_nth_double(double *array, int n_elements, int nth); +int32_t find_nth_int32(int32_t *array, int n_elements, int nth); uint32_t find_nth_uint32(uint32_t *array, int n_elements, int nth); long find_nth_long(long *array, int n_elements, int nth); static INLINE int @@ -649,6 +650,11 @@ median_uint32(uint32_t *array, int n_elements) { return find_nth_uint32(array, n_elements, (n_elements-1)/2); } +static INLINE int32_t +median_int32(int32_t *array, int n_elements) +{ + return find_nth_int32(array, n_elements, (n_elements-1)/2); +} static INLINE long median_long(long *array, int n_elements) { diff --git a/src/common/log.c b/src/common/log.c index b12462a42..09efa014c 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -92,7 +92,8 @@ should_log_function_name(log_domain_mask_t domain, int severity) } /** A mutex to guard changes to logfiles and logging. */ -static tor_mutex_t *log_mutex = NULL; +static tor_mutex_t log_mutex; +static int log_mutex_initialized = 0; /** Linked list of logfile_t. */ static logfile_t *logfiles = NULL; @@ -103,9 +104,9 @@ static int syslog_count = 0; #endif #define LOCK_LOGS() STMT_BEGIN \ - tor_mutex_acquire(log_mutex); \ + tor_mutex_acquire(&log_mutex); \ STMT_END -#define UNLOCK_LOGS() STMT_BEGIN tor_mutex_release(log_mutex); STMT_END +#define UNLOCK_LOGS() STMT_BEGIN tor_mutex_release(&log_mutex); STMT_END /** What's the lowest log level anybody cares about? Checking this lets us * bail out early from log_debug if we aren't debugging. */ @@ -146,8 +147,8 @@ _log_prefix(char *buf, size_t buf_len, int severity) t = (time_t)now.tv_sec; n = strftime(buf, buf_len, "%b %d %H:%M:%S", tor_localtime_r(&t, &tm)); - r = tor_snprintf(buf+n, buf_len-n, ".%.3ld [%s] ", - (long)now.tv_usec / 1000, sev_to_string(severity)); + r = tor_snprintf(buf+n, buf_len-n, ".%.3i [%s] ", + (int)now.tv_usec / 1000, sev_to_string(severity)); if (r<0) return buf_len-1; else @@ -446,8 +447,9 @@ logs_free_all(void) log_free(victim); } tor_free(appname); - tor_mutex_free(log_mutex); - log_mutex = NULL; + + /* We _could_ destroy the log mutex here, but that would screw up any logs + * that happened between here and the end of execution. */ } /** Remove and free the log entry <b>victim</b> from the linked-list @@ -543,8 +545,10 @@ add_stream_log(const log_severity_list_t *severity, void init_logging(void) { - if (!log_mutex) - log_mutex = tor_mutex_new(); + if (!log_mutex_initialized) { + tor_mutex_init(&log_mutex); + log_mutex_initialized = 1; + } } /** Add a log handler to receive messages during startup (before the real diff --git a/src/common/torint.h b/src/common/torint.h index 1f7421174..be624e04c 100644 --- a/src/common/torint.h +++ b/src/common/torint.h @@ -117,6 +117,9 @@ typedef unsigned int uint32_t; #ifndef INT32_MAX #define INT32_MAX 0x7fffffffu #endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif #endif #if (SIZEOF_LONG == 4) diff --git a/src/common/tortls.c b/src/common/tortls.c index a518e83d2..a43c4ea0a 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -828,6 +828,9 @@ tor_tls_new(int sock, int isServer) if (!SSL_set_cipher_list(result->ssl, isServer ? SERVER_CIPHER_LIST : CLIENT_CIPHER_LIST)) { tls_log_errors(NULL, LOG_WARN, "setting ciphers"); +#ifdef SSL_set_tlsext_host_name + SSL_set_tlsext_host_name(result->ssl, NULL); +#endif SSL_free(result->ssl); tor_free(result); return NULL; @@ -838,6 +841,9 @@ tor_tls_new(int sock, int isServer) bio = BIO_new_socket(sock, BIO_NOCLOSE); if (! bio) { tls_log_errors(NULL, LOG_WARN, "opening BIO"); +#ifdef SSL_set_tlsext_host_name + SSL_set_tlsext_host_name(result->ssl, NULL); +#endif SSL_free(result->ssl); tor_free(result); return NULL; @@ -918,6 +924,9 @@ tor_tls_free(tor_tls_t *tls) if (!removed) { log_warn(LD_BUG, "Freeing a TLS that was not in the ssl->tls map."); } +#ifdef SSL_set_tlsext_host_name + SSL_set_tlsext_host_name(tls->ssl, NULL); +#endif SSL_free(tls->ssl); tls->ssl = NULL; tls->negotiated_callback = NULL; @@ -1442,8 +1451,8 @@ tor_tls_used_v1_handshake(tor_tls_t *tls) * buffer and *<b>wbuf_bytes</b> to the amount actually used. */ void tor_tls_get_buffer_sizes(tor_tls_t *tls, - int *rbuf_capacity, int *rbuf_bytes, - int *wbuf_capacity, int *wbuf_bytes) + size_t *rbuf_capacity, size_t *rbuf_bytes, + size_t *wbuf_capacity, size_t *wbuf_bytes) { if (tls->ssl->s3->rbuf.buf) *rbuf_capacity = tls->ssl->s3->rbuf.len; diff --git a/src/common/tortls.h b/src/common/tortls.h index 44e3b499e..d00690911 100644 --- a/src/common/tortls.h +++ b/src/common/tortls.h @@ -73,8 +73,8 @@ void tor_tls_get_n_raw_bytes(tor_tls_t *tls, size_t *n_read, size_t *n_written); void tor_tls_get_buffer_sizes(tor_tls_t *tls, - int *rbuf_capacity, int *rbuf_bytes, - int *wbuf_capacity, int *wbuf_bytes); + size_t *rbuf_capacity, size_t *rbuf_bytes, + size_t *wbuf_capacity, size_t *wbuf_bytes); int tor_tls_used_v1_handshake(tor_tls_t *tls); diff --git a/src/common/util.c b/src/common/util.c index 234180c4d..d05c308fe 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -735,7 +735,18 @@ tor_parse_ulong(const char *s, int base, unsigned long min, CHECK_STRTOX_RESULT(); } -/** As tor_parse_log, but return a unit64_t. Only base 10 is guaranteed to +/** As tor_parse_long(), but return a double. */ +double +tor_parse_double(const char *s, double min, double max, int *ok, char **next) +{ + char *endptr; + double r; + + r = strtod(s, &endptr); + CHECK_STRTOX_RESULT(); +} + +/** As tor_parse_long, but return a uint64_t. Only base 10 is guaranteed to * work for now. */ uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, @@ -1023,6 +1034,42 @@ wrap_string(smartlist_t *out, const char *string, size_t width, * Time * ===== */ +/** + * Converts struct timeval to a double value. + * Preserves microsecond precision, but just barely. + * Error is approx +/- 0.1 usec when dealing with epoch values. + */ +double +tv_to_double(const struct timeval *tv) +{ + double conv = tv->tv_sec; + conv += tv->tv_usec/1000000.0; + return conv; +} + +/** + * Converts timeval to milliseconds. + */ +int64_t +tv_to_msec(const struct timeval *tv) +{ + int64_t conv = ((int64_t)tv->tv_sec)*1000L; + /* Round ghetto-style */ + conv += ((int64_t)tv->tv_usec+500)/1000L; + return conv; +} + +/** + * Converts timeval to microseconds. + */ +int64_t +tv_to_usec(const struct timeval *tv) +{ + int64_t conv = ((int64_t)tv->tv_sec)*1000000L; + conv += tv->tv_usec; + return conv; +} + /** Return the number of microseconds elapsed between *start and *end. */ long @@ -1055,7 +1102,9 @@ tv_mdiff(const struct timeval *start, const struct timeval *end) return LONG_MAX; } - mdiff = secdiff*1000L + (end->tv_usec - start->tv_usec) / 1000L; + /* Subtract and round */ + mdiff = secdiff*1000L + + ((long)end->tv_usec - (long)start->tv_usec + 500L) / 1000L; return mdiff; } @@ -1865,7 +1914,8 @@ write_chunks_to_file_impl(const char *fname, const smartlist_t *chunks, int open_flags) { open_file_t *file = NULL; - int fd, result; + int fd; + ssize_t result; fd = start_writing_to_file(fname, open_flags, 0600, &file); if (fd<0) return -1; @@ -1950,7 +2000,7 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out) int fd; /* router file */ struct stat statbuf; char *string; - int r; + ssize_t r; int bin = flags & RFTS_BIN; tor_assert(filename); @@ -2009,7 +2059,7 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out) * match for size. */ int save_errno = errno; log_warn(LD_FS,"Could read only %d of %ld bytes of file \"%s\".", - r, (long)statbuf.st_size,filename); + (int)r, (long)statbuf.st_size,filename); tor_free(string); close(fd); errno = save_errno; diff --git a/src/common/util.h b/src/common/util.h index c7741a64a..28ea8a048 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -182,6 +182,8 @@ long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next); unsigned long tor_parse_ulong(const char *s, int base, unsigned long min, unsigned long max, int *ok, char **next); +double tor_parse_double(const char *s, double min, double max, int *ok, + char **next); uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next); const char *hex_str(const char *from, size_t fromlen) ATTR_NONNULL((1)); @@ -210,6 +212,9 @@ void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen); int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen); /* Time helpers */ +double tv_to_double(const struct timeval *tv); +int64_t tv_to_msec(const struct timeval *tv); +int64_t tv_to_usec(const struct timeval *tv); long tv_udiff(const struct timeval *start, const struct timeval *end); long tv_mdiff(const struct timeval *start, const struct timeval *end); time_t tor_timegm(struct tm *tm); |