Docment or add DOCDOC comments to undocumented functions in src/or. Make function definition format uniform.

svn:r4411
This commit is contained in:
Nick Mathewson 2005-06-11 18:52:12 +00:00
parent df029fc9df
commit 232861ba42
29 changed files with 1421 additions and 578 deletions

View File

@ -101,7 +101,8 @@ const char compat_c_id[] = "$Id$";
* easiest to emulate "return -1" with conformant implementations than * easiest to emulate "return -1" with conformant implementations than
* it is to emulate "return number that would be written" with * it is to emulate "return number that would be written" with
* non-conformant implementations.) */ * non-conformant implementations.) */
int tor_snprintf(char *str, size_t size, const char *format, ...) int
tor_snprintf(char *str, size_t size, const char *format, ...)
{ {
va_list ap; va_list ap;
int r; int r;
@ -114,7 +115,8 @@ int tor_snprintf(char *str, size_t size, const char *format, ...)
/** Replacement for vsnprintf; behavior differs as tor_snprintf differs from /** Replacement for vsnprintf; behavior differs as tor_snprintf differs from
* snprintf. * snprintf.
*/ */
int tor_vsnprintf(char *str, size_t size, const char *format, va_list args) int
tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
{ {
int r; int r;
if (size == 0) if (size == 0)
@ -162,7 +164,8 @@ _tor_fix_source_file(const char *fname)
* *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid * *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid
* unaligned memory access. * unaligned memory access.
*/ */
uint16_t get_uint16(const char *cp) uint16_t
get_uint16(const char *cp)
{ {
uint16_t v; uint16_t v;
memcpy(&v,cp,2); memcpy(&v,cp,2);
@ -173,7 +176,8 @@ uint16_t get_uint16(const char *cp)
* *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid * *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid
* unaligned memory access. * unaligned memory access.
*/ */
uint32_t get_uint32(const char *cp) uint32_t
get_uint32(const char *cp)
{ {
uint32_t v; uint32_t v;
memcpy(&v,cp,4); memcpy(&v,cp,4);
@ -183,7 +187,8 @@ uint32_t get_uint32(const char *cp)
* Set a 16-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to * Set a 16-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
* *(uint16_t)(cp) = v, but will not cause segfaults on platforms that forbid * *(uint16_t)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */ * unaligned memory access. */
void set_uint16(char *cp, uint16_t v) void
set_uint16(char *cp, uint16_t v)
{ {
memcpy(cp,&v,2); memcpy(cp,&v,2);
} }
@ -191,7 +196,8 @@ void set_uint16(char *cp, uint16_t v)
* Set a 32-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to * Set a 32-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
* *(uint32_t)(cp) = v, but will not cause segfaults on platforms that forbid * *(uint32_t)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */ * unaligned memory access. */
void set_uint32(char *cp, uint32_t v) void
set_uint32(char *cp, uint32_t v)
{ {
memcpy(cp,&v,4); memcpy(cp,&v,4);
} }
@ -202,7 +208,8 @@ void set_uint32(char *cp, uint32_t v)
* rename(2). On windows, this removes 'to' first if it already exists. * rename(2). On windows, this removes 'to' first if it already exists.
* Returns 0 on success. Returns -1 and sets errno on failure. * Returns 0 on success. Returns -1 and sets errno on failure.
*/ */
int replace_file(const char *from, const char *to) int
replace_file(const char *from, const char *to)
{ {
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
return rename(from,to); return rename(from,to);
@ -226,7 +233,8 @@ int replace_file(const char *from, const char *to)
/** Turn <b>socket</b> into a nonblocking socket. /** Turn <b>socket</b> into a nonblocking socket.
*/ */
void set_socket_nonblocking(int socket) void
set_socket_nonblocking(int socket)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
int nonblocking = 1; int nonblocking = 1;
@ -419,7 +427,8 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap) {
/** Call setuid and setgid to run as <b>user</b>:<b>group</b>. Return 0 on /** Call setuid and setgid to run as <b>user</b>:<b>group</b>. Return 0 on
* success. On failure, log and return -1. * success. On failure, log and return -1.
*/ */
int switch_id(char *user, char *group) { int
switch_id(char *user, char *group) {
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
struct passwd *pw = NULL; struct passwd *pw = NULL;
struct group *gr = NULL; struct group *gr = NULL;
@ -490,7 +499,8 @@ get_user_homedir(const char *username)
* Return 1 on success, 0 if c is badly formatted. (Like inet_aton(c,addr), * Return 1 on success, 0 if c is badly formatted. (Like inet_aton(c,addr),
* but works on Windows and Solaris.) * but works on Windows and Solaris.)
*/ */
int tor_inet_aton(const char *c, struct in_addr* addr) int
tor_inet_aton(const char *c, struct in_addr* addr)
{ {
#ifdef HAVE_INET_ATON #ifdef HAVE_INET_ATON
return inet_aton(c, addr); return inet_aton(c, addr);
@ -517,7 +527,8 @@ int tor_inet_aton(const char *c, struct in_addr* addr)
* (This function exists because standard windows gethostbyname * (This function exists because standard windows gethostbyname
* doesn't treat raw IP addresses properly.) * doesn't treat raw IP addresses properly.)
*/ */
int tor_lookup_hostname(const char *name, uint32_t *addr) int
tor_lookup_hostname(const char *name, uint32_t *addr)
{ {
/* Perhaps eventually this should be replaced by a tor_getaddrinfo or /* Perhaps eventually this should be replaced by a tor_getaddrinfo or
* something. * something.
@ -744,7 +755,8 @@ spawn_func(int (*func)(void *), void *data)
/** End the current thread/process. /** End the current thread/process.
*/ */
void spawn_exit() void
spawn_exit()
{ {
#if defined(USE_WIN32_THREADS) #if defined(USE_WIN32_THREADS)
_endthread(); _endthread();
@ -760,7 +772,9 @@ void spawn_exit()
/** Set *timeval to the current time of day. On error, log and terminate. /** Set *timeval to the current time of day. On error, log and terminate.
* (Same as gettimeofday(timeval,NULL), but never returns -1.) * (Same as gettimeofday(timeval,NULL), but never returns -1.)
*/ */
void tor_gettimeofday(struct timeval *timeval) { void
tor_gettimeofday(struct timeval *timeval)
{
#ifdef HAVE_GETTIMEOFDAY #ifdef HAVE_GETTIMEOFDAY
if (gettimeofday(timeval, NULL)) { if (gettimeofday(timeval, NULL)) {
log_fn(LOG_ERR, "gettimeofday failed."); log_fn(LOG_ERR, "gettimeofday failed.");
@ -785,7 +799,8 @@ void tor_gettimeofday(struct timeval *timeval) {
#ifndef HAVE_LOCALTIME_R #ifndef HAVE_LOCALTIME_R
#ifdef TIME_FNS_NEED_LOCKS #ifdef TIME_FNS_NEED_LOCKS
struct tm *tor_localtime_r(const time_t *timep, struct tm *result) struct tm *
tor_localtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
static tor_mutex_t *m=NULL; static tor_mutex_t *m=NULL;
@ -798,7 +813,8 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
return result; return result;
} }
#else #else
struct tm *tor_localtime_r(const time_t *timep, struct tm *result) struct tm *
tor_localtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
tor_assert(result); tor_assert(result);
@ -811,7 +827,8 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
#ifndef HAVE_GMTIME_R #ifndef HAVE_GMTIME_R
#ifdef TIME_FNS_NEED_LOCKS #ifdef TIME_FNS_NEED_LOCKS
struct tm *tor_gmtime_r(const time_t *timep, struct tm *result) struct tm *
tor_gmtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
static tor_mutex_t *m=NULL; static tor_mutex_t *m=NULL;
@ -824,7 +841,8 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
return result; return result;
} }
#else #else
struct tm *tor_gmtime_r(const time_t *timep, struct tm *result) struct tm *
tor_gmtime_r(const time_t *timep, struct tm *result)
{ {
struct tm *r; struct tm *r;
tor_assert(result); tor_assert(result);
@ -839,7 +857,8 @@ struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
struct tor_mutex_t { struct tor_mutex_t {
HANDLE handle; HANDLE handle;
}; };
tor_mutex_t *tor_mutex_new(void) tor_mutex_t *
tor_mutex_new(void)
{ {
tor_mutex_t *m; tor_mutex_t *m;
m = tor_malloc_zero(sizeof(tor_mutex_t)); m = tor_malloc_zero(sizeof(tor_mutex_t));
@ -847,12 +866,14 @@ tor_mutex_t *tor_mutex_new(void)
tor_assert(m->handle != NULL); tor_assert(m->handle != NULL);
return m; return m;
} }
void tor_mutex_free(tor_mutex_t *m) void
tor_mutex_free(tor_mutex_t *m)
{ {
CloseHandle(m->handle); CloseHandle(m->handle);
tor_free(m); tor_free(m);
} }
void tor_mutex_acquire(tor_mutex_t *m) void
tor_mutex_acquire(tor_mutex_t *m)
{ {
DWORD r; DWORD r;
r = WaitForSingleObject(m->handle, INFINITE); r = WaitForSingleObject(m->handle, INFINITE);
@ -867,7 +888,8 @@ void tor_mutex_acquire(tor_mutex_t *m)
log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError()); log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError());
} }
} }
void tor_mutex_release(tor_mutex_t *m) void
tor_mutex_release(tor_mutex_t *m)
{ {
BOOL r; BOOL r;
r = ReleaseMutex(m->handle); r = ReleaseMutex(m->handle);
@ -884,23 +906,27 @@ tor_get_thread_id(void)
struct tor_mutex_t { struct tor_mutex_t {
pthread_mutex_t mutex; pthread_mutex_t mutex;
}; };
tor_mutex_t *tor_mutex_new(void) tor_mutex_t *
tor_mutex_new(void)
{ {
tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t)); tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t));
pthread_mutex_init(&mutex->mutex, NULL); pthread_mutex_init(&mutex->mutex, NULL);
return mutex; return mutex;
} }
void tor_mutex_acquire(tor_mutex_t *m) void
tor_mutex_acquire(tor_mutex_t *m)
{ {
tor_assert(m); tor_assert(m);
pthread_mutex_lock(&m->mutex); pthread_mutex_lock(&m->mutex);
} }
void tor_mutex_release(tor_mutex_t *m) void
tor_mutex_release(tor_mutex_t *m)
{ {
tor_assert(m); tor_assert(m);
pthread_mutex_unlock(&m->mutex); pthread_mutex_unlock(&m->mutex);
} }
void tor_mutex_free(tor_mutex_t *m) void
tor_mutex_free(tor_mutex_t *m)
{ {
tor_assert(m); tor_assert(m);
pthread_mutex_destroy(&m->mutex); pthread_mutex_destroy(&m->mutex);
@ -1007,7 +1033,8 @@ struct { int code; const char *msg; } windows_socket_errors[] = {
/** There does not seem to be a strerror equivalent for winsock errors. /** There does not seem to be a strerror equivalent for winsock errors.
* Naturally, we have to roll our own. * Naturally, we have to roll our own.
*/ */
const char *tor_socket_strerror(int e) const char *
tor_socket_strerror(int e)
{ {
int i; int i;
for (i=0; windows_socket_errors[i].code >= 0; ++i) { for (i=0; windows_socket_errors[i].code >= 0; ++i) {
@ -1021,7 +1048,8 @@ const char *tor_socket_strerror(int e)
/** Called before we make any calls to network-related functions. /** Called before we make any calls to network-related functions.
* (Some operating systems require their network libraries to be * (Some operating systems require their network libraries to be
* initialized.) */ * initialized.) */
int network_init(void) int
network_init(void)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
/* This silly exercise is necessary before windows will allow gethostbyname to work. /* This silly exercise is necessary before windows will allow gethostbyname to work.

View File

@ -76,7 +76,8 @@ static INLINE void peek_from_buf(char *string, size_t string_len, buf_t *buf);
* beginning. This operation is relatively expensive, so it shouldn't * beginning. This operation is relatively expensive, so it shouldn't
* be used e.g. for every single read or write. * be used e.g. for every single read or write.
*/ */
static void buf_normalize(buf_t *buf) static void
buf_normalize(buf_t *buf)
{ {
check(); check();
if (buf->cur + buf->datalen <= buf->mem+buf->len) { if (buf->cur + buf->datalen <= buf->mem+buf->len) {
@ -96,7 +97,8 @@ static void buf_normalize(buf_t *buf)
} }
/** Return the point in the buffer where the next byte will get stored. */ /** Return the point in the buffer where the next byte will get stored. */
static INLINE char *_buf_end(buf_t *buf) static INLINE char *
_buf_end(buf_t *buf)
{ {
char *next = buf->cur + buf->datalen; char *next = buf->cur + buf->datalen;
char *end = buf->mem + buf->len; char *end = buf->mem + buf->len;
@ -105,7 +107,8 @@ static INLINE char *_buf_end(buf_t *buf)
/** If the pointer <b>cp</b> has passed beyond the end of the buffer, wrap it /** If the pointer <b>cp</b> has passed beyond the end of the buffer, wrap it
* around. */ * around. */
static INLINE char *_wrap_ptr(buf_t *buf, char *cp) { static INLINE char *
_wrap_ptr(buf_t *buf, char *cp) {
return (cp >= buf->mem + buf->len) ? (cp - buf->len) : cp; return (cp >= buf->mem + buf->len) ? (cp - buf->len) : cp;
} }
@ -114,7 +117,8 @@ static INLINE char *_wrap_ptr(buf_t *buf, char *cp) {
* at <b>at</b>, and set *<b>more_len</b> to the number of bytes starting * at <b>at</b>, and set *<b>more_len</b> to the number of bytes starting
* at <b>buf-&gt;mem</b>. Otherwise, set *<b>more_len</b> to 0. * at <b>buf-&gt;mem</b>. Otherwise, set *<b>more_len</b> to 0.
*/ */
static INLINE void _split_range(buf_t *buf, char *at, size_t *len, static INLINE void
_split_range(buf_t *buf, char *at, size_t *len,
size_t *more_len) size_t *more_len)
{ {
char *eos = at + *len; char *eos = at + *len;
@ -128,7 +132,8 @@ static INLINE void _split_range(buf_t *buf, char *at, size_t *len,
} }
/** Change a buffer's capacity. <b>new_capacity</b> must be \>= buf->datalen. */ /** Change a buffer's capacity. <b>new_capacity</b> must be \>= buf->datalen. */
static void buf_resize(buf_t *buf, size_t new_capacity) static void
buf_resize(buf_t *buf, size_t new_capacity)
{ {
off_t offset; off_t offset;
#ifdef CHECK_AFTER_RESIZE #ifdef CHECK_AFTER_RESIZE
@ -225,7 +230,8 @@ static void buf_resize(buf_t *buf, size_t new_capacity)
* it so that it can. (The new size will be a power of 2 times the old * it so that it can. (The new size will be a power of 2 times the old
* size.) * size.)
*/ */
static INLINE int buf_ensure_capacity(buf_t *buf, size_t capacity) static INLINE int
buf_ensure_capacity(buf_t *buf, size_t capacity)
{ {
size_t new_len; size_t new_len;
if (buf->len >= capacity) /* Don't grow if we're already big enough. */ if (buf->len >= capacity) /* Don't grow if we're already big enough. */
@ -251,7 +257,8 @@ static INLINE int buf_ensure_capacity(buf_t *buf, size_t capacity)
* one of the above no longer holds. (We shrink the buffer by * one of the above no longer holds. (We shrink the buffer by
* dividing by powers of 2.) * dividing by powers of 2.)
*/ */
static INLINE void buf_shrink_if_underfull(buf_t *buf) { static INLINE void
buf_shrink_if_underfull(buf_t *buf) {
size_t new_len; size_t new_len;
/* If the buffer is at least 1/8 full, or if shrinking the buffer would /* If the buffer is at least 1/8 full, or if shrinking the buffer would
* put it under MIN_GREEDY_SHRINK_SIZE, don't do it. */ * put it under MIN_GREEDY_SHRINK_SIZE, don't do it. */
@ -298,7 +305,8 @@ buf_shrink(buf_t *buf)
/** Remove the first <b>n</b> bytes from buf. /** Remove the first <b>n</b> bytes from buf.
*/ */
static INLINE void buf_remove_from_front(buf_t *buf, size_t n) { static INLINE void
buf_remove_from_front(buf_t *buf, size_t n) {
tor_assert(buf->datalen >= n); tor_assert(buf->datalen >= n);
buf->datalen -= n; buf->datalen -= n;
buf_total_used -= n; buf_total_used -= n;
@ -312,7 +320,8 @@ static INLINE void buf_remove_from_front(buf_t *buf, size_t n) {
} }
/** Make sure that the memory in buf ends with a zero byte. */ /** Make sure that the memory in buf ends with a zero byte. */
static INLINE int buf_nul_terminate(buf_t *buf) static INLINE int
buf_nul_terminate(buf_t *buf)
{ {
if (buf_ensure_capacity(buf,buf->datalen+1)<0) if (buf_ensure_capacity(buf,buf->datalen+1)<0)
return -1; return -1;
@ -322,7 +331,8 @@ static INLINE int buf_nul_terminate(buf_t *buf)
/** Create and return a new buf with capacity <b>size</b>. /** Create and return a new buf with capacity <b>size</b>.
*/ */
buf_t *buf_new_with_capacity(size_t size) { buf_t *
buf_new_with_capacity(size_t size) {
buf_t *buf; buf_t *buf;
buf = tor_malloc_zero(sizeof(buf_t)); buf = tor_malloc_zero(sizeof(buf_t));
buf->magic = BUFFER_MAGIC; buf->magic = BUFFER_MAGIC;
@ -336,13 +346,15 @@ buf_t *buf_new_with_capacity(size_t size) {
} }
/** Allocate and return a new buffer with default capacity. */ /** Allocate and return a new buffer with default capacity. */
buf_t *buf_new() buf_t *
buf_new(void)
{ {
return buf_new_with_capacity(INITIAL_BUF_SIZE); return buf_new_with_capacity(INITIAL_BUF_SIZE);
} }
/** Remove all data from <b>buf</b> */ /** Remove all data from <b>buf</b> */
void buf_clear(buf_t *buf) void
buf_clear(buf_t *buf)
{ {
buf_total_used -= buf->datalen; buf_total_used -= buf->datalen;
buf->datalen = 0; buf->datalen = 0;
@ -350,28 +362,33 @@ void buf_clear(buf_t *buf)
} }
/** Return the number of bytes stored in <b>buf</b> */ /** Return the number of bytes stored in <b>buf</b> */
size_t buf_datalen(const buf_t *buf) size_t
buf_datalen(const buf_t *buf)
{ {
return buf->datalen; return buf->datalen;
} }
/** Return the maximum bytes that can be stored in <b>buf</b> before buf /** Return the maximum bytes that can be stored in <b>buf</b> before buf
* needs to resize. */ * needs to resize. */
size_t buf_capacity(const buf_t *buf) size_t
buf_capacity(const buf_t *buf)
{ {
return buf->len; return buf->len;
} }
/** For testing only: Return a pointer to the raw memory stored in <b>buf</b>. /** For testing only: Return a pointer to the raw memory stored in <b>buf</b>.
*/ */
const char *_buf_peek_raw_buffer(const buf_t *buf) const char *
_buf_peek_raw_buffer(const buf_t *buf)
{ {
return buf->cur; return buf->cur;
} }
/** Release storage held by <b>buf</b>. /** Release storage held by <b>buf</b>.
*/ */
void buf_free(buf_t *buf) { void
buf_free(buf_t *buf)
{
assert_buf_ok(buf); assert_buf_ok(buf);
buf->magic = 0xDEADBEEF; buf->magic = 0xDEADBEEF;
free(RAW_MEM(buf->mem)); free(RAW_MEM(buf->mem));
@ -380,7 +397,14 @@ void buf_free(buf_t *buf) {
tor_free(buf); tor_free(buf);
} }
static INLINE int read_to_buf_impl(int s, size_t at_most, buf_t *buf, /** Helper for read_to_buf: read no more than at_most bytes from
* socket s into buffer buf, starting at the position pos. (Does not
* check for overflow.) Set *reached_eof to true on EOF. Return
* number of bytes read on success, 0 if the read would block, -1 on
* failure.
*/
static INLINE int
read_to_buf_impl(int s, size_t at_most, buf_t *buf,
char *pos, int *reached_eof) char *pos, int *reached_eof)
{ {
int read_result; int read_result;
@ -414,7 +438,8 @@ static INLINE int read_to_buf_impl(int s, size_t at_most, buf_t *buf,
* else return the number of bytes read. Return 0 if recv() would * else return the number of bytes read. Return 0 if recv() would
* block. * block.
*/ */
int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) int
read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
{ {
int r; int r;
char *next; char *next;
@ -456,6 +481,11 @@ int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof)
return r; return r;
} }
/** Helper for read_to_buf_tls: read no more than at_most bytes from
* the TLS connection tlsinto buffer buf, starting at the position
* next. (Does not check for overflow.) Return number of bytes read
* on success, 0 if the read would block, -1 on failure.
*/
static INLINE int static INLINE int
read_to_buf_tls_impl(tor_tls *tls, size_t at_most, buf_t *buf, char *next) read_to_buf_tls_impl(tor_tls *tls, size_t at_most, buf_t *buf, char *next)
{ {
@ -495,7 +525,9 @@ read_to_buf_tls_impl(tor_tls *tls, size_t at_most, buf_t *buf, char *next)
* events: sometimes, before a TLS stream can read, the network must be * events: sometimes, before a TLS stream can read, the network must be
* ready to write -- or vice versa. * ready to write -- or vice versa.
*/ */
int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf) { int
read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf)
{
int r; int r;
char *next; char *next;
size_t at_start; size_t at_start;
@ -537,6 +569,10 @@ int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf) {
return r; return r;
} }
/** Helper for flush_buf: try to write sz bytes from buffer buf onto
* socket s. On success, deduct the bytes written from *buf_flushlen.
* Return the number of bytes written on success, -1 on failure.
*/
static INLINE int static INLINE int
flush_buf_impl(int s, buf_t *buf, size_t sz, size_t *buf_flushlen) flush_buf_impl(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
{ {
@ -565,7 +601,8 @@ flush_buf_impl(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
* from the buffer. Return the number of bytes written on success, * from the buffer. Return the number of bytes written on success,
* -1 on failure. Return 0 if write() would block. * -1 on failure. Return 0 if write() would block.
*/ */
int flush_buf(int s, buf_t *buf, size_t *buf_flushlen) int
flush_buf(int s, buf_t *buf, size_t *buf_flushlen)
{ {
int r; int r;
size_t flushed = 0; size_t flushed = 0;
@ -604,6 +641,10 @@ int flush_buf(int s, buf_t *buf, size_t *buf_flushlen)
return flushed; return flushed;
} }
/** Helper for flush_buf_tls: try to write sz bytes from buffer buf onto
* TLS object tls. On success, deduct the bytes written from *buf_flushlen.
* Return the number of bytes written on success, -1 on failure.
*/
static INLINE int static INLINE int
flush_buf_tls_impl(tor_tls *tls, buf_t *buf, size_t sz, size_t *buf_flushlen) flush_buf_tls_impl(tor_tls *tls, buf_t *buf, size_t sz, size_t *buf_flushlen)
{ {
@ -699,7 +740,10 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf)
return buf->datalen; return buf->datalen;
} }
static INLINE void peek_from_buf(char *string, size_t string_len, buf_t *buf) /** Helper: copy the first string_len bytes from buf onto string.
*/
static INLINE void
peek_from_buf(char *string, size_t string_len, buf_t *buf)
{ {
size_t len2; size_t len2;
@ -724,7 +768,8 @@ static INLINE void peek_from_buf(char *string, size_t string_len, buf_t *buf)
* into <b>string</b>. Return the new buffer size. <b>string_len</b> must be \<= * into <b>string</b>. Return the new buffer size. <b>string_len</b> must be \<=
* the number of bytes on the buffer. * the number of bytes on the buffer.
*/ */
int fetch_from_buf(char *string, size_t string_len, buf_t *buf) int
fetch_from_buf(char *string, size_t string_len, buf_t *buf)
{ {
/* There must be string_len bytes in buf; write them onto string, /* There must be string_len bytes in buf; write them onto string,
* then memmove buf back (that is, remove them from buf). * then memmove buf back (that is, remove them from buf).
@ -755,9 +800,11 @@ int fetch_from_buf(char *string, size_t string_len, buf_t *buf)
* *
* Else, change nothing and return 0. * Else, change nothing and return 0.
*/ */
int fetch_from_buf_http(buf_t *buf, int
fetch_from_buf_http(buf_t *buf,
char **headers_out, size_t max_headerlen, char **headers_out, size_t max_headerlen,
char **body_out, size_t *body_used, size_t max_bodylen) { char **body_out, size_t *body_used, size_t max_bodylen)
{
char *headers, *body, *p; char *headers, *body, *p;
size_t headerlen, bodylen, contentlen; size_t headerlen, bodylen, contentlen;
@ -846,7 +893,9 @@ int fetch_from_buf_http(buf_t *buf,
* *
* If returning 0 or -1, <b>req->address</b> and <b>req->port</b> are undefined. * If returning 0 or -1, <b>req->address</b> and <b>req->port</b> are undefined.
*/ */
int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { int
fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
{
unsigned char len; unsigned char len;
char tmpbuf[INET_NTOA_BUF_LEN]; char tmpbuf[INET_NTOA_BUF_LEN];
uint32_t destip; uint32_t destip;
@ -1059,7 +1108,8 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) {
* *
* Return -1 on error. * Return -1 on error.
*/ */
int fetch_from_buf_control(buf_t *buf, uint32_t *len_out, uint16_t *type_out, int
fetch_from_buf_control(buf_t *buf, uint32_t *len_out, uint16_t *type_out,
char **body_out) char **body_out)
{ {
uint32_t msglen; uint32_t msglen;

View File

@ -36,7 +36,9 @@ static int onion_append_hop(crypt_path_t **head_ptr, routerinfo_t *choice);
* *
* Return it, or 0 if can't get a unique circ_id. * Return it, or 0 if can't get a unique circ_id.
*/ */
static uint16_t get_unique_circ_id_by_conn(connection_t *conn) { static uint16_t
get_unique_circ_id_by_conn(connection_t *conn)
{
uint16_t test_circ_id; uint16_t test_circ_id;
int attempts=0; int attempts=0;
uint16_t high_bit; uint16_t high_bit;
@ -130,7 +132,9 @@ circuit_list_path(circuit_t *circ, int verbose)
* circ's cpath. Also log the length of the cpath, and the intended * circ's cpath. Also log the length of the cpath, and the intended
* exit point. * exit point.
*/ */
void circuit_log_path(int severity, circuit_t *circ) { void
circuit_log_path(int severity, circuit_t *circ)
{
char *s = circuit_list_path(circ,1); char *s = circuit_list_path(circ,1);
log_fn(severity,"%s",s); log_fn(severity,"%s",s);
tor_free(s); tor_free(s);
@ -141,7 +145,9 @@ void circuit_log_path(int severity, circuit_t *circ) {
* extended; the _first_ hop that isn't open (if any) is marked as * extended; the _first_ hop that isn't open (if any) is marked as
* unable to extend. * unable to extend.
*/ */
void circuit_rep_hist_note_result(circuit_t *circ) { void
circuit_rep_hist_note_result(circuit_t *circ)
{
struct crypt_path_t *hop; struct crypt_path_t *hop;
char *prev_digest = NULL; char *prev_digest = NULL;
routerinfo_t *router; routerinfo_t *router;
@ -183,7 +189,8 @@ void circuit_rep_hist_note_result(circuit_t *circ) {
*/ */
static void static void
circuit_dump_details(int severity, circuit_t *circ, int poll_index, circuit_dump_details(int severity, circuit_t *circ, int poll_index,
const char *type, int this_circid, int other_circid) { const char *type, int this_circid, int other_circid)
{
log(severity,"Conn %d has %s circuit: circID %d (other side %d), state %d (%s), born %d:", log(severity,"Conn %d has %s circuit: circID %d (other side %d), state %d (%s), born %d:",
poll_index, type, this_circid, other_circid, circ->state, poll_index, type, this_circid, other_circid, circ->state,
circuit_state_to_string(circ->state), (int)circ->timestamp_created); circuit_state_to_string(circ->state), (int)circ->timestamp_created);
@ -195,7 +202,9 @@ circuit_dump_details(int severity, circuit_t *circ, int poll_index,
/** Log, at severity <b>severity</b>, information about each circuit /** Log, at severity <b>severity</b>, information about each circuit
* that is connected to <b>conn</b>. * that is connected to <b>conn</b>.
*/ */
void circuit_dump_by_conn(connection_t *conn, int severity) { void
circuit_dump_by_conn(connection_t *conn, int severity)
{
circuit_t *circ; circuit_t *circ;
connection_t *tmpconn; connection_t *tmpconn;
@ -233,7 +242,8 @@ void circuit_dump_by_conn(connection_t *conn, int severity) {
/** Pick all the entries in our cpath. Stop and return 0 when we're /** Pick all the entries in our cpath. Stop and return 0 when we're
* happy, or return -1 if an error occurs. */ * happy, or return -1 if an error occurs. */
static int static int
onion_populate_cpath(circuit_t *circ) { onion_populate_cpath(circuit_t *circ)
{
int r; int r;
again: again:
r = onion_extend_cpath(circ->purpose, &circ->cpath, circ->build_state); r = onion_extend_cpath(circ->purpose, &circ->cpath, circ->build_state);
@ -250,7 +260,8 @@ again:
/** Create and return a new circuit. Initialize its purpose and /** Create and return a new circuit. Initialize its purpose and
* build-state based on our arguments. */ * build-state based on our arguments. */
circuit_t * circuit_t *
circuit_init(uint8_t purpose, int need_uptime, int need_capacity, int internal) { circuit_init(uint8_t purpose, int need_uptime, int need_capacity, int internal)
{
circuit_t *circ = circuit_new(0, NULL); /* sets circ->p_circ_id and circ->p_conn */ circuit_t *circ = circuit_new(0, NULL); /* sets circ->p_circ_id and circ->p_conn */
circ->state = CIRCUIT_STATE_OR_WAIT; circ->state = CIRCUIT_STATE_OR_WAIT;
circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t)); circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t));
@ -270,7 +281,8 @@ circuit_init(uint8_t purpose, int need_uptime, int need_capacity, int internal)
*/ */
circuit_t * circuit_t *
circuit_establish_circuit(uint8_t purpose, routerinfo_t *exit, circuit_establish_circuit(uint8_t purpose, routerinfo_t *exit,
int need_uptime, int need_capacity, int internal) { int need_uptime, int need_capacity, int internal)
{
circuit_t *circ; circuit_t *circ;
circ = circuit_init(purpose, need_uptime, need_capacity, internal); circ = circuit_init(purpose, need_uptime, need_capacity, internal);
@ -294,7 +306,9 @@ circuit_establish_circuit(uint8_t purpose, routerinfo_t *exit,
* OR we should connect to, and if necessary start the connection to * OR we should connect to, and if necessary start the connection to
* it. If we're already connected, then send the 'create' cell. * it. If we're already connected, then send the 'create' cell.
* Return 0 for ok, -1 if circ should be marked-for-close. */ * Return 0 for ok, -1 if circ should be marked-for-close. */
int circuit_handle_first_hop(circuit_t *circ) { int
circuit_handle_first_hop(circuit_t *circ)
{
routerinfo_t *firsthop; routerinfo_t *firsthop;
connection_t *n_conn; connection_t *n_conn;
@ -344,7 +358,9 @@ int circuit_handle_first_hop(circuit_t *circ) {
* *
* Status is 1 if connect succeeded, or 0 if connect failed. * Status is 1 if connect succeeded, or 0 if connect failed.
*/ */
void circuit_n_conn_done(connection_t *or_conn, int status) { void
circuit_n_conn_done(connection_t *or_conn, int status)
{
circuit_t *circ; circuit_t *circ;
log_fn(LOG_DEBUG,"or_conn to %s, status=%d", log_fn(LOG_DEBUG,"or_conn to %s, status=%d",
@ -384,8 +400,10 @@ void circuit_n_conn_done(connection_t *or_conn, int status) {
} }
} }
/** DOCDOC */
static int static int
circuit_deliver_create_cell(circuit_t *circ, uint8_t cell_type, char *payload) { circuit_deliver_create_cell(circuit_t *circ, uint8_t cell_type, char *payload)
{
cell_t cell; cell_t cell;
uint16_t id; uint16_t id;
@ -424,7 +442,9 @@ extern int has_completed_circuit;
* *
* Return -1 if we want to tear down circ, else return 0. * Return -1 if we want to tear down circ, else return 0.
*/ */
int circuit_send_next_onion_skin(circuit_t *circ) { int
circuit_send_next_onion_skin(circuit_t *circ)
{
crypt_path_t *hop; crypt_path_t *hop;
routerinfo_t *router; routerinfo_t *router;
int r; int r;
@ -531,7 +551,9 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
/** Our clock just jumped forward by <b>seconds_elapsed</b>. Assume /** Our clock just jumped forward by <b>seconds_elapsed</b>. Assume
* something has also gone wrong with our network: notify the user, * something has also gone wrong with our network: notify the user,
* and abandon all not-yet-used circuits. */ * and abandon all not-yet-used circuits. */
void circuit_note_clock_jumped(int seconds_elapsed) { void
circuit_note_clock_jumped(int seconds_elapsed)
{
log(LOG_NOTICE,"Your clock just jumped %d seconds forward; assuming established circuits no longer work.", seconds_elapsed); log(LOG_NOTICE,"Your clock just jumped %d seconds forward; assuming established circuits no longer work.", seconds_elapsed);
has_completed_circuit=0; /* so it'll log when it works again */ has_completed_circuit=0; /* so it'll log when it works again */
circuit_mark_all_unused_circs(); circuit_mark_all_unused_circs();
@ -541,7 +563,9 @@ void circuit_note_clock_jumped(int seconds_elapsed) {
* sure we're connected to the next hop, and pass it the onion skin in * sure we're connected to the next hop, and pass it the onion skin in
* a create cell. * a create cell.
*/ */
int circuit_extend(cell_t *cell, circuit_t *circ) { int
circuit_extend(cell_t *cell, circuit_t *circ)
{
connection_t *n_conn; connection_t *n_conn;
relay_header_t rh; relay_header_t rh;
char *onionskin; char *onionskin;
@ -624,7 +648,8 @@ int circuit_extend(cell_t *cell, circuit_t *circ) {
* *
* (If 'reverse' is true, then f_XX and b_XX are swapped.) * (If 'reverse' is true, then f_XX and b_XX are swapped.)
*/ */
int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse) int
circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse)
{ {
crypto_digest_env_t *tmp_digest; crypto_digest_env_t *tmp_digest;
crypto_cipher_env_t *tmp_crypto; crypto_cipher_env_t *tmp_crypto;
@ -675,7 +700,9 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse)
* *
* Return -1 if we want to mark circ for close, else return 0. * Return -1 if we want to mark circ for close, else return 0.
*/ */
int circuit_finish_handshake(circuit_t *circ, uint8_t reply_type, char *reply) { int
circuit_finish_handshake(circuit_t *circ, uint8_t reply_type, char *reply)
{
char keys[CPATH_KEY_MATERIAL_LEN]; char keys[CPATH_KEY_MATERIAL_LEN];
crypt_path_t *hop; crypt_path_t *hop;
@ -735,7 +762,9 @@ int circuit_finish_handshake(circuit_t *circ, uint8_t reply_type, char *reply) {
* means that a connection broke or an extend failed. For now, * means that a connection broke or an extend failed. For now,
* just give up: for circ to close, and return 0. * just give up: for circ to close, and return 0.
*/ */
int circuit_truncated(circuit_t *circ, crypt_path_t *layer) { int
circuit_truncated(circuit_t *circ, crypt_path_t *layer)
{
// crypt_path_t *victim; // crypt_path_t *victim;
// connection_t *stream; // connection_t *stream;
@ -778,7 +807,9 @@ int circuit_truncated(circuit_t *circ, crypt_path_t *layer) {
/** Given a response payload and keys, initialize, then send a created /** Given a response payload and keys, initialize, then send a created
* cell back. * cell back.
*/ */
int onionskin_answer(circuit_t *circ, uint8_t cell_type, char *payload, char *keys) { int
onionskin_answer(circuit_t *circ, uint8_t cell_type, char *payload, char *keys)
{
cell_t cell; cell_t cell;
crypt_path_t *tmp_cpath; crypt_path_t *tmp_cpath;
@ -833,7 +864,9 @@ int onionskin_answer(circuit_t *circ, uint8_t cell_type, char *payload, char *ke
* to handle the desired path length, return as large a path length as * to handle the desired path length, return as large a path length as
* is feasible, except if it's less than 2, in which case return -1. * is feasible, except if it's less than 2, in which case return -1.
*/ */
static int new_route_len(double cw, uint8_t purpose, smartlist_t *routers) { static int
new_route_len(double cw, uint8_t purpose, smartlist_t *routers)
{
int num_acceptable_routers; int num_acceptable_routers;
int routelen; int routelen;
@ -893,7 +926,8 @@ static int new_route_len(double cw, uint8_t purpose, smartlist_t *routers) {
* existing circuit, and return it. * existing circuit, and return it.
*/ */
static smartlist_t * static smartlist_t *
circuit_get_unhandled_ports(time_t now) { circuit_get_unhandled_ports(time_t now)
{
smartlist_t *source = rep_hist_get_predicted_ports(now); smartlist_t *source = rep_hist_get_predicted_ports(now);
smartlist_t *dest = smartlist_create(); smartlist_t *dest = smartlist_create();
uint16_t *tmp; uint16_t *tmp;
@ -917,7 +951,8 @@ circuit_get_unhandled_ports(time_t now) {
*/ */
int int
circuit_all_predicted_ports_handled(time_t now, int *need_uptime, circuit_all_predicted_ports_handled(time_t now, int *need_uptime,
int *need_capacity) { int *need_capacity)
{
int i, enough; int i, enough;
uint16_t *port; uint16_t *port;
smartlist_t *sl = circuit_get_unhandled_ports(now); smartlist_t *sl = circuit_get_unhandled_ports(now);
@ -937,7 +972,8 @@ circuit_all_predicted_ports_handled(time_t now, int *need_uptime,
* <b>needed_ports</b>, else return 0. * <b>needed_ports</b>, else return 0.
*/ */
static int static int
router_handles_some_port(routerinfo_t *router, smartlist_t *needed_ports) { router_handles_some_port(routerinfo_t *router, smartlist_t *needed_ports)
{
int i; int i;
uint16_t port; uint16_t port;
@ -958,7 +994,8 @@ router_handles_some_port(routerinfo_t *router, smartlist_t *needed_ports) {
#define MIN_CIRCUITS_HANDLING_STREAM 2 #define MIN_CIRCUITS_HANDLING_STREAM 2
static int static int
ap_stream_wants_exit_attention(connection_t *conn) { ap_stream_wants_exit_attention(connection_t *conn)
{
if (conn->type == CONN_TYPE_AP && if (conn->type == CONN_TYPE_AP &&
conn->state == AP_CONN_STATE_CIRCUIT_WAIT && conn->state == AP_CONN_STATE_CIRCUIT_WAIT &&
!conn->marked_for_close && !conn->marked_for_close &&
@ -1182,7 +1219,8 @@ choose_good_exit_server(uint8_t purpose, routerlist_t *dir,
* router (or use <b>exit</b> if provided). Store these in the * router (or use <b>exit</b> if provided). Store these in the
* cpath. Return 0 if ok, -1 if circuit should be closed. */ * cpath. Return 0 if ok, -1 if circuit should be closed. */
static int static int
onion_pick_cpath_exit(circuit_t *circ, routerinfo_t *exit) { onion_pick_cpath_exit(circuit_t *circ, routerinfo_t *exit)
{
cpath_build_state_t *state = circ->build_state; cpath_build_state_t *state = circ->build_state;
routerlist_t *rl; routerlist_t *rl;
@ -1218,7 +1256,8 @@ onion_pick_cpath_exit(circuit_t *circ, routerinfo_t *exit) {
* the caller will do this if it wants to. * the caller will do this if it wants to.
*/ */
int int
circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit) { circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit)
{
tor_assert(exit); tor_assert(exit);
tor_assert(circ && CIRCUIT_IS_ORIGIN(circ)); tor_assert(circ && CIRCUIT_IS_ORIGIN(circ));
tor_free(circ->build_state->chosen_exit_name); tor_free(circ->build_state->chosen_exit_name);
@ -1233,7 +1272,9 @@ circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit) {
* to <b>exit</b>, and get it to send the next extend cell. If you can't * to <b>exit</b>, and get it to send the next extend cell. If you can't
* send the extend cell, mark the circuit for close and return -1, else * send the extend cell, mark the circuit for close and return -1, else
* return 0. */ * return 0. */
int circuit_extend_to_new_exit(circuit_t *circ, routerinfo_t *exit) { int
circuit_extend_to_new_exit(circuit_t *circ, routerinfo_t *exit)
{
circuit_append_new_exit(circ, exit); circuit_append_new_exit(circ, exit);
circ->state = CIRCUIT_STATE_BUILDING; circ->state = CIRCUIT_STATE_BUILDING;
if (circuit_send_next_onion_skin(circ)<0) { if (circuit_send_next_onion_skin(circ)<0) {
@ -1248,7 +1289,9 @@ int circuit_extend_to_new_exit(circuit_t *circ, routerinfo_t *exit) {
/** Return the number of routers in <b>routers</b> that are currently up /** Return the number of routers in <b>routers</b> that are currently up
* and available for building circuits through. * and available for building circuits through.
*/ */
static int count_acceptable_routers(smartlist_t *routers) { static int
count_acceptable_routers(smartlist_t *routers)
{
int i, n; int i, n;
int num=0; int num=0;
routerinfo_t *r; routerinfo_t *r;
@ -1280,7 +1323,8 @@ static int count_acceptable_routers(smartlist_t *routers) {
* *
* This function is used to extend cpath by another hop. * This function is used to extend cpath by another hop.
*/ */
void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop) void
onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop)
{ {
if (*head_ptr) { if (*head_ptr) {
new_hop->next = (*head_ptr); new_hop->next = (*head_ptr);
@ -1293,7 +1337,9 @@ void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop)
} }
} }
static routerinfo_t *choose_good_middle_server(uint8_t purpose, /** DOCDOC */
static routerinfo_t *
choose_good_middle_server(uint8_t purpose,
cpath_build_state_t *state, cpath_build_state_t *state,
crypt_path_t *head, crypt_path_t *head,
int cur_len) int cur_len)
@ -1326,7 +1372,9 @@ static routerinfo_t *choose_good_middle_server(uint8_t purpose,
return choice; return choice;
} }
static routerinfo_t *choose_good_entry_server(cpath_build_state_t *state) /** DOCDOC */
static routerinfo_t *
choose_good_entry_server(cpath_build_state_t *state)
{ {
routerinfo_t *r, *choice; routerinfo_t *r, *choice;
smartlist_t *excluded = smartlist_create(); smartlist_t *excluded = smartlist_create();
@ -1366,7 +1414,8 @@ static routerinfo_t *choose_good_entry_server(cpath_build_state_t *state)
/** Return the first non-open hop in cpath, or return NULL if all /** Return the first non-open hop in cpath, or return NULL if all
* hops are open. */ * hops are open. */
static crypt_path_t * static crypt_path_t *
onion_next_hop_in_cpath(crypt_path_t *cpath) { onion_next_hop_in_cpath(crypt_path_t *cpath)
{
crypt_path_t *hop = cpath; crypt_path_t *hop = cpath;
do { do {
if (hop->state != CPATH_STATE_OPEN) if (hop->state != CPATH_STATE_OPEN)
@ -1457,7 +1506,8 @@ onion_extend_cpath(uint8_t purpose, crypt_path_t **head_ptr,
* corresponding router <b>choice</b>, and append it to the * corresponding router <b>choice</b>, and append it to the
* end of the cpath <b>head_ptr</b>. */ * end of the cpath <b>head_ptr</b>. */
static int static int
onion_append_hop(crypt_path_t **head_ptr, routerinfo_t *choice) { onion_append_hop(crypt_path_t **head_ptr, routerinfo_t *choice)
{
crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t)); crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t));
/* link hop into the cpath, at the end. */ /* link hop into the cpath, at the end. */

View File

@ -32,8 +32,9 @@ struct orconn_circid_circuit_map_t {
circuit_t *circuit; circuit_t *circuit;
}; };
static INLINE int compare_orconn_circid_entries( /** DOCDOC */
struct orconn_circid_circuit_map_t *a, static INLINE int
compare_orconn_circid_entries(struct orconn_circid_circuit_map_t *a,
struct orconn_circid_circuit_map_t *b) struct orconn_circid_circuit_map_t *b)
{ {
if (a->or_conn < b->or_conn) if (a->or_conn < b->or_conn)
@ -43,12 +44,14 @@ static INLINE int compare_orconn_circid_entries(
else else
return ((int)b->circ_id) - ((int)a->circ_id); return ((int)b->circ_id) - ((int)a->circ_id);
}; };
static RB_HEAD(orconn_circid_tree, orconn_circid_circuit_map_t) orconn_circid_circuit_map = RB_INITIALIZER(orconn_circid_circuit_map); static RB_HEAD(orconn_circid_tree, orconn_circid_circuit_map_t) orconn_circid_circuit_map = RB_INITIALIZER(orconn_circid_circuit_map);
RB_PROTOTYPE(orconn_circid_tree, orconn_circid_circuit_map_t, node, compare_orconn_circid_entries); RB_PROTOTYPE(orconn_circid_tree, orconn_circid_circuit_map_t, node, compare_orconn_circid_entries);
RB_GENERATE(orconn_circid_tree, orconn_circid_circuit_map_t, node, compare_orconn_circid_entries); RB_GENERATE(orconn_circid_tree, orconn_circid_circuit_map_t, node, compare_orconn_circid_entries);
struct orconn_circid_circuit_map_t *_last_circid_orconn_ent = NULL; struct orconn_circid_circuit_map_t *_last_circid_orconn_ent = NULL;
/** DOCDOC */
void void
circuit_set_circid_orconn(circuit_t *circ, uint16_t id, circuit_set_circid_orconn(circuit_t *circ, uint16_t id,
connection_t *conn, connection_t *conn,
@ -111,7 +114,9 @@ circuit_set_circid_orconn(circuit_t *circ, uint16_t id,
/** Add <b>circ</b> to the global list of circuits. This is called only from /** Add <b>circ</b> to the global list of circuits. This is called only from
* within circuit_new. * within circuit_new.
*/ */
static void circuit_add(circuit_t *circ) { static void
circuit_add(circuit_t *circ)
{
if (!global_circuitlist) { /* first one */ if (!global_circuitlist) { /* first one */
global_circuitlist = circ; global_circuitlist = circ;
circ->next = NULL; circ->next = NULL;
@ -124,7 +129,8 @@ static void circuit_add(circuit_t *circ) {
/** Detach from the global circuit list, and deallocate, all /** Detach from the global circuit list, and deallocate, all
* circuits that have been marked for close. * circuits that have been marked for close.
*/ */
void circuit_close_all_marked(void) void
circuit_close_all_marked(void)
{ {
circuit_t *tmp,*m; circuit_t *tmp,*m;
@ -167,7 +173,9 @@ circuit_state_to_string(int state) {
/** Allocate space for a new circuit, initializing with <b>p_circ_id</b> /** Allocate space for a new circuit, initializing with <b>p_circ_id</b>
* and <b>p_conn</b>. Add it to the global circuit list. * and <b>p_conn</b>. Add it to the global circuit list.
*/ */
circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) { circuit_t *
circuit_new(uint16_t p_circ_id, connection_t *p_conn)
{
circuit_t *circ; circuit_t *circ;
static uint32_t n_circuits_allocated = 1; static uint32_t n_circuits_allocated = 1;
/* never zero, since a global ID of 0 is treated specially by the controller */ /* never zero, since a global ID of 0 is treated specially by the controller */
@ -198,7 +206,9 @@ circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) {
/** Deallocate space associated with circ. /** Deallocate space associated with circ.
*/ */
static void circuit_free(circuit_t *circ) { static void
circuit_free(circuit_t *circ)
{
tor_assert(circ); tor_assert(circ);
tor_assert(circ->magic == CIRCUIT_MAGIC); tor_assert(circ->magic == CIRCUIT_MAGIC);
if (circ->n_crypto) if (circ->n_crypto)
@ -228,7 +238,9 @@ static void circuit_free(circuit_t *circ) {
} }
/** Deallocate space associated with the linked list <b>cpath</b>. */ /** Deallocate space associated with the linked list <b>cpath</b>. */
static void circuit_free_cpath(crypt_path_t *cpath) { static void
circuit_free_cpath(crypt_path_t *cpath)
{
crypt_path_t *victim, *head=cpath; crypt_path_t *victim, *head=cpath;
if (!cpath) if (!cpath)
@ -265,7 +277,8 @@ circuit_free_all(void)
/** Deallocate space associated with the cpath node <b>victim</b>. */ /** Deallocate space associated with the cpath node <b>victim</b>. */
static void static void
circuit_free_cpath_node(crypt_path_t *victim) { circuit_free_cpath_node(crypt_path_t *victim)
{
if (victim->f_crypto) if (victim->f_crypto)
crypto_free_cipher_env(victim->f_crypto); crypto_free_cipher_env(victim->f_crypto);
if (victim->b_crypto) if (victim->b_crypto)
@ -303,7 +316,9 @@ circuit_get_by_global_id(uint32_t id)
* in p_streams or n_streams. * in p_streams or n_streams.
* Return NULL if no such circuit exists. * Return NULL if no such circuit exists.
*/ */
circuit_t *circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn) { circuit_t *
circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn)
{
struct orconn_circid_circuit_map_t search; struct orconn_circid_circuit_map_t search;
struct orconn_circid_circuit_map_t *found; struct orconn_circid_circuit_map_t *found;
@ -346,7 +361,8 @@ circuit_t *circuit_get_by_circid_orconn(uint16_t circ_id, connection_t *conn) {
} }
/** DOCDOC */ /** DOCDOC */
circuit_t *circuit_get_by_edge_conn(connection_t *conn) circuit_t *
circuit_get_by_edge_conn(connection_t *conn)
{ {
circuit_t *circ; circuit_t *circ;
connection_t *tmpconn; connection_t *tmpconn;
@ -382,7 +398,9 @@ circuit_t *circuit_get_by_edge_conn(connection_t *conn)
* *
* Return NULL if no such circuit exists. * Return NULL if no such circuit exists.
*/ */
circuit_t *circuit_get_by_conn(connection_t *conn) { circuit_t *
circuit_get_by_conn(connection_t *conn)
{
circuit_t *circ; circuit_t *circ;
connection_t *tmpconn; connection_t *tmpconn;
@ -413,7 +431,9 @@ circuit_t *circuit_get_by_conn(connection_t *conn) {
* *
* Return NULL if no such circuit exists. * Return NULL if no such circuit exists.
*/ */
circuit_t *circuit_get_by_rend_query_and_purpose(const char *rend_query, uint8_t purpose) { circuit_t *
circuit_get_by_rend_query_and_purpose(const char *rend_query, uint8_t purpose)
{
circuit_t *circ; circuit_t *circ;
for (circ = global_circuitlist; circ; circ = circ->next) { for (circ = global_circuitlist; circ; circ = circ->next) {
@ -454,7 +474,8 @@ circuit_get_next_by_pk_and_purpose(circuit_t *start,
/** Return the circuit waiting for a rendezvous with the provided cookie. /** Return the circuit waiting for a rendezvous with the provided cookie.
* Return NULL if no such circuit is found. * Return NULL if no such circuit is found.
*/ */
circuit_t *circuit_get_rendezvous(const char *cookie) circuit_t *
circuit_get_rendezvous(const char *cookie)
{ {
circuit_t *circ; circuit_t *circ;
for (circ = global_circuitlist; circ; circ = circ->next) { for (circ = global_circuitlist; circ; circ = circ->next) {
@ -476,7 +497,8 @@ circuit_t *circuit_get_rendezvous(const char *cookie)
*/ */
circuit_t * circuit_t *
circuit_get_clean_open(uint8_t purpose, int need_uptime, circuit_get_clean_open(uint8_t purpose, int need_uptime,
int need_capacity, int internal) { int need_capacity, int internal)
{
circuit_t *circ; circuit_t *circ;
circuit_t *best=NULL; circuit_t *best=NULL;
@ -500,7 +522,9 @@ circuit_get_clean_open(uint8_t purpose, int need_uptime,
/** Go through the circuitlist; mark-for-close each circuit that starts /** Go through the circuitlist; mark-for-close each circuit that starts
* at us but has not yet been used. */ * at us but has not yet been used. */
void circuit_mark_all_unused_circs(void) { void
circuit_mark_all_unused_circs(void)
{
circuit_t *circ; circuit_t *circ;
for (circ=global_circuitlist; circ; circ = circ->next) { for (circ=global_circuitlist; circ; circ = circ->next) {
@ -526,7 +550,8 @@ void circuit_mark_all_unused_circs(void) {
* - If circ->rend_splice is set (we are the midpoint of a joined * - If circ->rend_splice is set (we are the midpoint of a joined
* rendezvous stream), then mark the other circuit to close as well. * rendezvous stream), then mark the other circuit to close as well.
*/ */
void _circuit_mark_for_close(circuit_t *circ, int line, const char *file) void
_circuit_mark_for_close(circuit_t *circ, int line, const char *file)
{ {
connection_t *conn; connection_t *conn;
@ -600,7 +625,8 @@ void _circuit_mark_for_close(circuit_t *circ, int line, const char *file)
/** Verify that cpath layer <b>cp</b> has all of its invariants /** Verify that cpath layer <b>cp</b> has all of its invariants
* correct. Trigger an assert if anything is invalid. * correct. Trigger an assert if anything is invalid.
*/ */
void assert_cpath_layer_ok(const crypt_path_t *cp) void
assert_cpath_layer_ok(const crypt_path_t *cp)
{ {
// tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */ // tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */
// tor_assert(cp->port); // tor_assert(cp->port);
@ -652,7 +678,8 @@ assert_cpath_ok(const crypt_path_t *cp)
/** Verify that circuit <b>c</b> has all of its invariants /** Verify that circuit <b>c</b> has all of its invariants
* correct. Trigger an assert if anything is invalid. * correct. Trigger an assert if anything is invalid.
*/ */
void assert_circuit_ok(const circuit_t *c) void
assert_circuit_ok(const circuit_t *c)
{ {
connection_t *conn; connection_t *conn;

View File

@ -28,7 +28,8 @@ static void circuit_increment_failure_count(void);
/* Return 1 if <b>circ</b> could be returned by circuit_get_best(). /* Return 1 if <b>circ</b> could be returned by circuit_get_best().
* Else return 0. * Else return 0.
*/ */
static int circuit_is_acceptable(circuit_t *circ, static int
circuit_is_acceptable(circuit_t *circ,
connection_t *conn, connection_t *conn,
int must_be_open, int must_be_open,
uint8_t purpose, uint8_t purpose,
@ -102,7 +103,8 @@ static int circuit_is_acceptable(circuit_t *circ,
/* Return 1 if circuit <b>a</b> is better than circuit <b>b</b> for /* Return 1 if circuit <b>a</b> is better than circuit <b>b</b> for
* <b>purpose</b>, and return 0 otherwise. Used by circuit_get_best. * <b>purpose</b>, and return 0 otherwise. Used by circuit_get_best.
*/ */
static int circuit_is_better(circuit_t *a, circuit_t *b, uint8_t purpose) static int
circuit_is_better(circuit_t *a, circuit_t *b, uint8_t purpose)
{ {
switch (purpose) { switch (purpose) {
case CIRCUIT_PURPOSE_C_GENERAL: case CIRCUIT_PURPOSE_C_GENERAL:
@ -184,7 +186,9 @@ circuit_get_best(connection_t *conn, int must_be_open, uint8_t purpose)
/** Close all circuits that start at us, aren't open, and were born /** Close all circuits that start at us, aren't open, and were born
* at least MIN_SECONDS_BEFORE_EXPIRING_CIRC seconds ago. * at least MIN_SECONDS_BEFORE_EXPIRING_CIRC seconds ago.
*/ */
void circuit_expire_building(time_t now) { void
circuit_expire_building(time_t now)
{
circuit_t *victim, *circ = global_circuitlist; circuit_t *victim, *circ = global_circuitlist;
while (circ) { while (circ) {
@ -254,7 +258,8 @@ void circuit_expire_building(time_t now) {
* open or in-progress circuit. * open or in-progress circuit.
*/ */
void void
circuit_remove_handled_ports(smartlist_t *needed_ports) { circuit_remove_handled_ports(smartlist_t *needed_ports)
{
int i; int i;
uint16_t *port; uint16_t *port;
@ -275,7 +280,9 @@ circuit_remove_handled_ports(smartlist_t *needed_ports) {
* an acceptable exit node for conn if conn is defined, else for "*:port". * an acceptable exit node for conn if conn is defined, else for "*:port".
* Else return 0. * Else return 0.
*/ */
int circuit_stream_is_being_handled(connection_t *conn, uint16_t port, int min) { int
circuit_stream_is_being_handled(connection_t *conn, uint16_t port, int min)
{
circuit_t *circ; circuit_t *circ;
routerinfo_t *exitrouter; routerinfo_t *exitrouter;
int num=0; int num=0;
@ -377,7 +384,9 @@ circuit_predict_and_launch_new(void)
* services just want enough circuits for current tasks, whereas * services just want enough circuits for current tasks, whereas
* others want a minimum set of idle circuits hanging around. * others want a minimum set of idle circuits hanging around.
*/ */
void circuit_build_needed_circs(time_t now) { void
circuit_build_needed_circs(time_t now)
{
static long time_to_new_circuit = 0; static long time_to_new_circuit = 0;
/* launch a new circ for any pending streams that need one */ /* launch a new circ for any pending streams that need one */
@ -410,7 +419,9 @@ void circuit_build_needed_circs(time_t now) {
/** If the stream <b>conn</b> is a member of any of the linked /** If the stream <b>conn</b> is a member of any of the linked
* lists of <b>circ</b>, then remove it from the list. * lists of <b>circ</b>, then remove it from the list.
*/ */
void circuit_detach_stream(circuit_t *circ, connection_t *conn) { void
circuit_detach_stream(circuit_t *circ, connection_t *conn)
{
connection_t *prevconn; connection_t *prevconn;
tor_assert(circ); tor_assert(circ);
@ -472,7 +483,9 @@ void circuit_detach_stream(circuit_t *circ, connection_t *conn) {
* If it's an edge conn, then detach it from its circ, so we don't * If it's an edge conn, then detach it from its circ, so we don't
* try to reference it later. * try to reference it later.
*/ */
void circuit_about_to_close_connection(connection_t *conn) { void
circuit_about_to_close_connection(connection_t *conn)
{
/* currently, we assume it's too late to flush conn's buf here. /* currently, we assume it's too late to flush conn's buf here.
* down the road, maybe we'll consider that eof doesn't mean can't-write * down the road, maybe we'll consider that eof doesn't mean can't-write
*/ */
@ -550,7 +563,8 @@ circuit_expire_old_circuits(void)
/** A testing circuit has completed. Take whatever stats we want. */ /** A testing circuit has completed. Take whatever stats we want. */
static void static void
circuit_testing_opened(circuit_t *circ) { circuit_testing_opened(circuit_t *circ)
{
/* For now, we only use testing circuits to see if our ORPort is /* For now, we only use testing circuits to see if our ORPort is
reachable. But we remember reachability in onionskin_answer(), reachable. But we remember reachability in onionskin_answer(),
so there's no need to record anything here. Just close the circ. */ so there's no need to record anything here. Just close the circ. */
@ -576,8 +590,9 @@ circuit_testing_failed(circuit_t *circ, int at_last_hop) {
* call connection_ap_attach_pending, which looks for pending streams * call connection_ap_attach_pending, which looks for pending streams
* that could use circ. * that could use circ.
*/ */
void circuit_has_opened(circuit_t *circ) { void
circuit_has_opened(circuit_t *circ)
{
control_event_circuit_status(circ, CIRC_EVENT_BUILT); control_event_circuit_status(circ, CIRC_EVENT_BUILT);
switch (circ->purpose) { switch (circ->purpose) {
@ -610,10 +625,11 @@ void circuit_has_opened(circuit_t *circ) {
} }
} }
/*~ Called whenever a circuit could not be successfully built. /** Called whenever a circuit could not be successfully built.
*/ */
void circuit_build_failed(circuit_t *circ) { void
circuit_build_failed(circuit_t *circ)
{
/* we should examine circ and see if it failed because of /* we should examine circ and see if it failed because of
* the last hop or an earlier hop. then use this info below. * the last hop or an earlier hop. then use this info below.
*/ */
@ -771,7 +787,9 @@ circuit_launch_by_nickname(uint8_t purpose, const char *exit_nickname,
/** Record another failure at opening a general circuit. When we have /** Record another failure at opening a general circuit. When we have
* too many, we'll stop trying for the remainder of this minute. * too many, we'll stop trying for the remainder of this minute.
*/ */
static void circuit_increment_failure_count(void) { static void
circuit_increment_failure_count(void)
{
++n_circuit_failures; ++n_circuit_failures;
log_fn(LOG_DEBUG,"n_circuit_failures now %d.",n_circuit_failures); log_fn(LOG_DEBUG,"n_circuit_failures now %d.",n_circuit_failures);
} }
@ -780,7 +798,9 @@ static void circuit_increment_failure_count(void) {
* we will try MAX_CIRCUIT_FAILURES times more (if necessary) before * we will try MAX_CIRCUIT_FAILURES times more (if necessary) before
* stopping again. * stopping again.
*/ */
void circuit_reset_failure_count(int timeout) { void
circuit_reset_failure_count(int timeout)
{
if (timeout && n_circuit_failures > MAX_CIRCUIT_FAILURES) if (timeout && n_circuit_failures > MAX_CIRCUIT_FAILURES)
did_circs_fail_last_period = 1; did_circs_fail_last_period = 1;
else else
@ -797,7 +817,8 @@ void circuit_reset_failure_count(int timeout) {
static int static int
circuit_get_open_circ_or_launch(connection_t *conn, circuit_get_open_circ_or_launch(connection_t *conn,
uint8_t desired_circuit_purpose, uint8_t desired_circuit_purpose,
circuit_t **circp) { circuit_t **circp)
{
circuit_t *circ; circuit_t *circ;
int is_resolve; int is_resolve;
int need_uptime; int need_uptime;
@ -919,7 +940,9 @@ try_an_intro_point:
* p_streams. Also set apconn's cpath_layer to the last hop in * p_streams. Also set apconn's cpath_layer to the last hop in
* circ's cpath. * circ's cpath.
*/ */
static void link_apconn_to_circ(connection_t *apconn, circuit_t *circ) { static void
link_apconn_to_circ(connection_t *apconn, circuit_t *circ)
{
/* add it into the linked list of streams on this circuit */ /* add it into the linked list of streams on this circuit */
log_fn(LOG_DEBUG,"attaching new conn to circ. n_circ_id %d.", circ->n_circ_id); log_fn(LOG_DEBUG,"attaching new conn to circ. n_circ_id %d.", circ->n_circ_id);
apconn->timestamp_lastread = time(NULL); /* reset it, so we can measure circ timeouts */ apconn->timestamp_lastread = time(NULL); /* reset it, so we can measure circ timeouts */
@ -938,7 +961,8 @@ static void link_apconn_to_circ(connection_t *apconn, circuit_t *circ) {
/** If an exit wasn't specifically chosen, save the history for future /** If an exit wasn't specifically chosen, save the history for future
* use */ * use */
static void static void
consider_recording_trackhost(connection_t *conn, circuit_t *circ) { consider_recording_trackhost(connection_t *conn, circuit_t *circ)
{
int found_needle = 0; int found_needle = 0;
char *str; char *str;
or_options_t *options = get_options(); or_options_t *options = get_options();
@ -1023,7 +1047,9 @@ connection_ap_handshake_attach_chosen_circuit(connection_t *conn,
* Otherwise, associate conn with a safe live circuit, do the * Otherwise, associate conn with a safe live circuit, do the
* right next step, and return 1. * right next step, and return 1.
*/ */
int connection_ap_handshake_attach_circuit(connection_t *conn) { int
connection_ap_handshake_attach_circuit(connection_t *conn)
{
int retval; int retval;
int conn_age; int conn_age;

View File

@ -36,8 +36,10 @@ static void command_process_destroy_cell(cell_t *cell, connection_t *conn);
* <b>cell</b> that just arrived on <b>conn</b>. Increment <b>*time</b> * <b>cell</b> that just arrived on <b>conn</b>. Increment <b>*time</b>
* by the number of microseconds used by the call to <b>*func(cell, conn)</b>. * by the number of microseconds used by the call to <b>*func(cell, conn)</b>.
*/ */
static void command_time_process_cell(cell_t *cell, connection_t *conn, int *time, static void
void (*func)(cell_t *, connection_t *)) { command_time_process_cell(cell_t *cell, connection_t *conn, int *time,
void (*func)(cell_t *, connection_t *))
{
struct timeval start, end; struct timeval start, end;
long time_passed; long time_passed;
@ -64,7 +66,9 @@ static void command_time_process_cell(cell_t *cell, connection_t *conn, int *tim
* this second, and the total number of microseconds it took to * this second, and the total number of microseconds it took to
* process each type of cell. * process each type of cell.
*/ */
void command_process_cell(cell_t *cell, connection_t *conn) { void
command_process_cell(cell_t *cell, connection_t *conn)
{
#ifdef KEEP_TIMING_STATS #ifdef KEEP_TIMING_STATS
/* how many of each cell have we seen so far this second? needs better /* how many of each cell have we seen so far this second? needs better
* name. */ * name. */
@ -150,7 +154,9 @@ void command_process_cell(cell_t *cell, connection_t *conn) {
* onionskin_pending, and pass the onionskin to the cpuworker. Circ will * onionskin_pending, and pass the onionskin to the cpuworker. Circ will
* get picked up again when the cpuworker finishes decrypting it. * get picked up again when the cpuworker finishes decrypting it.
*/ */
static void command_process_create_cell(cell_t *cell, connection_t *conn) { static void
command_process_create_cell(cell_t *cell, connection_t *conn)
{
circuit_t *circ; circuit_t *circ;
if (we_are_hibernating()) { if (we_are_hibernating()) {
@ -219,7 +225,9 @@ static void command_process_create_cell(cell_t *cell, connection_t *conn) {
* finish processing keys, and then call circuit_send_next_onion_skin() to * finish processing keys, and then call circuit_send_next_onion_skin() to
* extend to the next hop in the circuit if necessary. * extend to the next hop in the circuit if necessary.
*/ */
static void command_process_created_cell(cell_t *cell, connection_t *conn) { static void
command_process_created_cell(cell_t *cell, connection_t *conn)
{
circuit_t *circ; circuit_t *circ;
circ = circuit_get_by_circid_orconn(cell->circ_id, conn); circ = circuit_get_by_circid_orconn(cell->circ_id, conn);
@ -259,7 +267,9 @@ static void command_process_created_cell(cell_t *cell, connection_t *conn) {
* it came in with a recognized circ_id. Pass it on to * it came in with a recognized circ_id. Pass it on to
* circuit_receive_relay_cell() for actual processing. * circuit_receive_relay_cell() for actual processing.
*/ */
static void command_process_relay_cell(cell_t *cell, connection_t *conn) { static void
command_process_relay_cell(cell_t *cell, connection_t *conn)
{
circuit_t *circ; circuit_t *circ;
circ = circuit_get_by_circid_orconn(cell->circ_id, conn); circ = circuit_get_by_circid_orconn(cell->circ_id, conn);
@ -304,7 +314,9 @@ static void command_process_relay_cell(cell_t *cell, connection_t *conn) {
* Then mark the circuit for close (which marks all edges for close, * Then mark the circuit for close (which marks all edges for close,
* and passes the destroy cell onward if necessary). * and passes the destroy cell onward if necessary).
*/ */
static void command_process_destroy_cell(cell_t *cell, connection_t *conn) { static void
command_process_destroy_cell(cell_t *cell, connection_t *conn)
{
circuit_t *circ; circuit_t *circ;
circ = circuit_get_by_circid_orconn(cell->circ_id, conn); circ = circuit_get_by_circid_orconn(cell->circ_id, conn);

View File

@ -232,7 +232,8 @@ static char *config_fname = NULL;
/** Return the currently configured options. */ /** Return the currently configured options. */
or_options_t * or_options_t *
get_options(void) { get_options(void)
{
tor_assert(global_options); tor_assert(global_options);
return global_options; return global_options;
} }
@ -241,7 +242,8 @@ get_options(void) {
* of their current value; free the old value as necessary. * of their current value; free the old value as necessary.
*/ */
void void
set_options(or_options_t *new_val) { set_options(or_options_t *new_val)
{
if (global_options) if (global_options)
options_free(global_options); options_free(global_options);
global_options = new_val; global_options = new_val;
@ -258,7 +260,8 @@ config_free_all(void)
* else return address. * else return address.
*/ */
const char * const char *
safe_str(const char *address) { safe_str(const char *address)
{
if (get_options()->SafeLogging) if (get_options()->SafeLogging)
return "[scrubbed]"; return "[scrubbed]";
else else
@ -276,7 +279,8 @@ safe_str(const char *address) {
* here yet. Some is still in do_hup() and other places. * here yet. Some is still in do_hup() and other places.
*/ */
int int
options_act(void) { options_act(void)
{
struct config_line_t *cl; struct config_line_t *cl;
or_options_t *options = get_options(); or_options_t *options = get_options();
static int libevent_initialized = 0; static int libevent_initialized = 0;
@ -549,7 +553,8 @@ config_free_lines(struct config_line_t *front)
* config_var_t. Otherwise, if <b>key</b> is a non-standard abbreviation, * config_var_t. Otherwise, if <b>key</b> is a non-standard abbreviation,
* warn, and return the corresponding config_var_t. Otherwise return NULL. * warn, and return the corresponding config_var_t. Otherwise return NULL.
*/ */
static config_var_t *config_find_option(const char *key) static config_var_t *
config_find_option(const char *key)
{ {
int i; int i;
size_t keylen = strlen(key); size_t keylen = strlen(key);
@ -1225,7 +1230,8 @@ config_dump_options(or_options_t *options, int minimal)
} }
static int static int
validate_ports_csv(smartlist_t *sl, const char *name) { validate_ports_csv(smartlist_t *sl, const char *name)
{
int i; int i;
int result = 0; int result = 0;
tor_assert(name); tor_assert(name);
@ -1641,8 +1647,8 @@ opt_streq(const char *s1, const char *s2)
/** Check if any of the previous options have changed but aren't allowed to. */ /** Check if any of the previous options have changed but aren't allowed to. */
static int static int
options_transition_allowed(or_options_t *old, or_options_t *new_val) { options_transition_allowed(or_options_t *old, or_options_t *new_val)
{
if (!old) if (!old)
return 0; return 0;
@ -1682,7 +1688,8 @@ options_transition_allowed(or_options_t *old, or_options_t *new_val) {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
/** Return the directory on windows where we expect to find our application /** Return the directory on windows where we expect to find our application
* data. */ * data. */
static char *get_windows_conf_root(void) static char *
get_windows_conf_root(void)
{ {
static int is_set = 0; static int is_set = 0;
static char path[MAX_PATH+1]; static char path[MAX_PATH+1];
@ -1738,7 +1745,8 @@ get_default_conf_file(void)
/** Verify whether lst is a string containing valid-looking space-separated /** Verify whether lst is a string containing valid-looking space-separated
* nicknames, or NULL. Return 0 on success. Warn and return -1 on failure. * nicknames, or NULL. Return 0 on success. Warn and return -1 on failure.
*/ */
static int check_nickname_list(const char *lst, const char *name) static int
check_nickname_list(const char *lst, const char *name)
{ {
int r = 0; int r = 0;
smartlist_t *sl; smartlist_t *sl;
@ -1897,8 +1905,12 @@ init_from_config(int argc, char **argv)
return -1; return -1;
} }
/** Adjust the address map mased on the MapAddress elements in the
* configuration <b>options</b>
*/
static void static void
config_register_addressmaps(or_options_t *options) { config_register_addressmaps(or_options_t *options)
{
smartlist_t *elts; smartlist_t *elts;
struct config_line_t *opt; struct config_line_t *opt;
char *from, *to; char *from, *to;
@ -2180,6 +2192,8 @@ normalize_log_options(or_options_t *options)
#define DEFAULT_EXIT_POLICY "reject 0.0.0.0/8,reject 169.254.0.0/16,reject 127.0.0.0/8,reject 192.168.0.0/16,reject 10.0.0.0/8,reject 172.16.0.0/12,reject *:25,reject *:119,reject *:135-139,reject *:445,reject *:1214,reject *:4661-4666,reject *:6346-6429,reject *:6699,reject *:6881-6999,accept *:*" #define DEFAULT_EXIT_POLICY "reject 0.0.0.0/8,reject 169.254.0.0/16,reject 127.0.0.0/8,reject 192.168.0.0/16,reject 10.0.0.0/8,reject 172.16.0.0/12,reject *:25,reject *:119,reject *:135-139,reject *:445,reject *:1214,reject *:4661-4666,reject *:6346-6429,reject *:6699,reject *:6881-6999,accept *:*"
/** Add the default exit policy entries to <b>policy</b>
*/
void void
config_append_default_exit_policy(addr_policy_t **policy) config_append_default_exit_policy(addr_policy_t **policy)
{ {
@ -2247,7 +2261,8 @@ config_parse_addr_policy(struct config_line_t *cfg,
/** Release all storage held by <b>p</b> */ /** Release all storage held by <b>p</b> */
void void
addr_policy_free(addr_policy_t *p) { addr_policy_free(addr_policy_t *p)
{
addr_policy_t *e; addr_policy_t *e;
while (p) { while (p) {
@ -2374,7 +2389,8 @@ parse_dir_server_line(const char *line, int validate_only)
/** Adjust the value of options->DataDirectory, or fill it in if it's /** Adjust the value of options->DataDirectory, or fill it in if it's
* absent. Return 0 on success, -1 on failure. */ * absent. Return 0 on success, -1 on failure. */
static int static int
normalize_data_directory(or_options_t *options) { normalize_data_directory(or_options_t *options)
{
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
char *p; char *p;
if (options->DataDirectory) if (options->DataDirectory)
@ -2412,7 +2428,8 @@ normalize_data_directory(or_options_t *options) {
/** Check and normalize the value of options->DataDirectory; return 0 if it /** Check and normalize the value of options->DataDirectory; return 0 if it
* sane, -1 otherwise. */ * sane, -1 otherwise. */
static int static int
validate_data_directory(or_options_t *options) { validate_data_directory(or_options_t *options)
{
if (normalize_data_directory(options) < 0) if (normalize_data_directory(options) < 0)
return -1; return -1;
tor_assert(options->DataDirectory); tor_assert(options->DataDirectory);
@ -2676,7 +2693,7 @@ check_libevent_version(const char *m, const char *v, int server)
} else if (!strcmp(m, "poll")) { } else if (!strcmp(m, "poll")) {
if (!strcmp(v, "1.0c") || !strcmp(v, "1.0d")) if (!strcmp(v, "1.0c") || !strcmp(v, "1.0d"))
buggy = 1; buggy = 1;
else if (!strcmp(v, "1.0e")) T else if (!strcmp(v, "1.0e"))
slow = 1; slow = 1;
} else if (!strcmp(m, "poll")) { } else if (!strcmp(m, "poll")) {
if (!strcmp(v, "1.0c") || !strcmp(v, "1.0d") || !strcmp(v, "1.0e")) if (!strcmp(v, "1.0c") || !strcmp(v, "1.0d") || !strcmp(v, "1.0e"))
@ -2700,6 +2717,7 @@ check_libevent_version(const char *m, const char *v, int server)
} }
#endif #endif
/** Dump the version of every file to the log. */
static void static void
print_cvs_version(void) print_cvs_version(void)
{ {

View File

@ -27,6 +27,9 @@ static int connection_bucket_read_limit(connection_t *conn);
/**************************************************************/ /**************************************************************/
/**
* Return the human-readable name for the connection type <b>type</b>
*/
const char * const char *
conn_type_to_string(int type) conn_type_to_string(int type)
{ {
@ -50,8 +53,13 @@ conn_type_to_string(int type)
} }
} }
/**
* Return the human-readable name for the connection state <b>state</b>
* for the connection type <b>type</b>
*/
const char * const char *
conn_state_to_string(int type, int state) { conn_state_to_string(int type, int state)
{
static char buf[96]; static char buf[96];
switch (type) { switch (type) {
case CONN_TYPE_OR_LISTENER: case CONN_TYPE_OR_LISTENER:
@ -138,7 +146,9 @@ conn_state_to_string(int type, int state) {
* *
* Initialize conn's timestamps to now. * Initialize conn's timestamps to now.
*/ */
connection_t *connection_new(int type) { connection_t *
connection_new(int type)
{
static uint32_t n_connections_allocated = 0; static uint32_t n_connections_allocated = 0;
connection_t *conn; connection_t *conn;
time_t now = time(NULL); time_t now = time(NULL);
@ -188,7 +198,8 @@ connection_unregister(connection_t *conn)
* is an OR or OP connection. * is an OR or OP connection.
*/ */
static void static void
_connection_free(connection_t *conn) { _connection_free(connection_t *conn)
{
tor_assert(conn->magic == CONNECTION_MAGIC); tor_assert(conn->magic == CONNECTION_MAGIC);
if (!connection_is_listener(conn)) { if (!connection_is_listener(conn)) {
@ -224,7 +235,9 @@ _connection_free(connection_t *conn) {
/** Make sure <b>conn</b> isn't in any of the global conn lists; then free it. /** Make sure <b>conn</b> isn't in any of the global conn lists; then free it.
*/ */
void connection_free(connection_t *conn) { void
connection_free(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(!connection_is_on_closeable_list(conn)); tor_assert(!connection_is_on_closeable_list(conn));
tor_assert(!connection_in_array(conn)); tor_assert(!connection_in_array(conn));
@ -243,7 +256,9 @@ void connection_free(connection_t *conn) {
* Don't do the checks in connection_free(), because they will * Don't do the checks in connection_free(), because they will
* fail. * fail.
*/ */
void connection_free_all(void) { void
connection_free_all(void)
{
int i, n; int i, n;
connection_t **carray; connection_t **carray;
@ -261,7 +276,8 @@ void connection_free_all(void) {
* - AP and Exit conns need to send an end cell if they can. * - AP and Exit conns need to send an end cell if they can.
* - DNS conns need to fail any resolves that are pending on them. * - DNS conns need to fail any resolves that are pending on them.
*/ */
void connection_about_to_close_connection(connection_t *conn) void
connection_about_to_close_connection(connection_t *conn)
{ {
circuit_t *circ; circuit_t *circ;
@ -338,7 +354,8 @@ void connection_about_to_close_connection(connection_t *conn)
* flush it. Must be used in conjunction with (right before) * flush it. Must be used in conjunction with (right before)
* connection_mark_for_close(). * connection_mark_for_close().
*/ */
void connection_close_immediate(connection_t *conn) void
connection_close_immediate(connection_t *conn)
{ {
assert_connection_ok(conn,0); assert_connection_ok(conn,0);
if (conn->s < 0) { if (conn->s < 0) {
@ -395,7 +412,8 @@ _connection_mark_for_close(connection_t *conn, int line, const char *file)
* hold_open_until_flushed to 0. This means it will get cleaned * hold_open_until_flushed to 0. This means it will get cleaned
* up in the next loop through close_if_marked() in main.c. * up in the next loop through close_if_marked() in main.c.
*/ */
void connection_expire_held_open(void) void
connection_expire_held_open(void)
{ {
connection_t **carray, *conn; connection_t **carray, *conn;
int n, i; int n, i;
@ -428,7 +446,9 @@ void connection_expire_held_open(void)
* If <b>bindaddress</b> includes a port, we bind on that port; otherwise, we * If <b>bindaddress</b> includes a port, we bind on that port; otherwise, we
* use bindport. * use bindport.
*/ */
static int connection_create_listener(const char *bindaddress, uint16_t bindport, int type) { static int
connection_create_listener(const char *bindaddress, uint16_t bindport, int type)
{
struct sockaddr_in bindaddr; /* where to bind */ struct sockaddr_in bindaddr; /* where to bind */
connection_t *conn; connection_t *conn;
uint16_t usePort; uint16_t usePort;
@ -527,7 +547,9 @@ check_sockaddr_in(struct sockaddr *sa, int len, int level)
/** The listener connection <b>conn</b> told poll() it wanted to read. /** The listener connection <b>conn</b> told poll() it wanted to read.
* Call accept() on conn-\>s, and add the new connection if necessary. * Call accept() on conn-\>s, and add the new connection if necessary.
*/ */
static int connection_handle_listener_read(connection_t *conn, int new_type) { static int
connection_handle_listener_read(connection_t *conn, int new_type)
{
int news; /* the new socket */ int news; /* the new socket */
connection_t *newconn; connection_t *newconn;
/* information about the remote peer when connecting to other routers */ /* information about the remote peer when connecting to other routers */
@ -629,8 +651,9 @@ static int connection_handle_listener_read(connection_t *conn, int new_type) {
/** Initialize states for newly accepted connection <b>conn</b>. /** Initialize states for newly accepted connection <b>conn</b>.
* If conn is an OR, start the tls handshake. * If conn is an OR, start the tls handshake.
*/ */
static int connection_init_accepted_conn(connection_t *conn) { static int
connection_init_accepted_conn(connection_t *conn)
{
connection_start_reading(conn); connection_start_reading(conn);
switch (conn->type) { switch (conn->type) {
@ -658,7 +681,10 @@ static int connection_init_accepted_conn(connection_t *conn) {
* *
* On success, add conn to the list of polled connections. * On success, add conn to the list of polled connections.
*/ */
int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port) { int
connection_connect(connection_t *conn, char *address,
uint32_t addr, uint16_t port)
{
int s; int s;
struct sockaddr_in dest_addr; struct sockaddr_in dest_addr;
or_options_t *options = get_options(); or_options_t *options = get_options();
@ -732,7 +758,9 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
/** If there exist any listeners of type <b>type</b> in the connection /** If there exist any listeners of type <b>type</b> in the connection
* array, mark them for close. * array, mark them for close.
*/ */
static void listener_close_if_present(int type) { static void
listener_close_if_present(int type)
{
connection_t *conn; connection_t *conn;
connection_t **carray; connection_t **carray;
int i,n; int i,n;
@ -761,9 +789,9 @@ static void listener_close_if_present(int type) {
* Otherwise, only relaunch the listeners of this type if the number of * Otherwise, only relaunch the listeners of this type if the number of
* existing connections is not as configured (e.g., because one died). * existing connections is not as configured (e.g., because one died).
*/ */
static int retry_listeners(int type, struct config_line_t *cfg, static int
int port_option, const char *default_addr, retry_listeners(int type, struct config_line_t *cfg,
int force) int port_option, const char *default_addr, int force)
{ {
if (!force) { if (!force) {
int want, have, n_conn, i; int want, have, n_conn, i;
@ -821,7 +849,9 @@ static int retry_listeners(int type, struct config_line_t *cfg,
* is false, then only relaunch listeners when we have the wrong number of * is false, then only relaunch listeners when we have the wrong number of
* connections for a given type. * connections for a given type.
*/ */
int retry_all_listeners(int force) { int
retry_all_listeners(int force)
{
or_options_t *options = get_options(); or_options_t *options = get_options();
if (server_mode(options) && if (server_mode(options) &&
@ -844,7 +874,9 @@ int retry_all_listeners(int force) {
extern int global_read_bucket, global_write_bucket; extern int global_read_bucket, global_write_bucket;
/** How many bytes at most can we read onto this connection? */ /** How many bytes at most can we read onto this connection? */
static int connection_bucket_read_limit(connection_t *conn) { static int
connection_bucket_read_limit(connection_t *conn)
{
int at_most; int at_most;
/* do a rudimentary round-robin so one circuit can't hog a connection */ /* do a rudimentary round-robin so one circuit can't hog a connection */
@ -867,14 +899,19 @@ static int connection_bucket_read_limit(connection_t *conn) {
} }
/** We just read num_read onto conn. Decrement buckets appropriately. */ /** We just read num_read onto conn. Decrement buckets appropriately. */
static void connection_read_bucket_decrement(connection_t *conn, int num_read) { static void
connection_read_bucket_decrement(connection_t *conn, int num_read)
{
global_read_bucket -= num_read; //tor_assert(global_read_bucket >= 0); global_read_bucket -= num_read; //tor_assert(global_read_bucket >= 0);
if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) { if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) {
conn->receiver_bucket -= num_read; //tor_assert(conn->receiver_bucket >= 0); conn->receiver_bucket -= num_read; //tor_assert(conn->receiver_bucket >= 0);
} }
} }
static void connection_consider_empty_buckets(connection_t *conn) { /** DOCDOC */
static void
connection_consider_empty_buckets(connection_t *conn)
{
if (global_read_bucket <= 0) { if (global_read_bucket <= 0) {
log_fn(LOG_DEBUG,"global bucket exhausted. Pausing."); log_fn(LOG_DEBUG,"global bucket exhausted. Pausing.");
conn->wants_to_read = 1; conn->wants_to_read = 1;
@ -892,14 +929,18 @@ static void connection_consider_empty_buckets(connection_t *conn) {
/** Initialize the global read bucket to options->BandwidthBurst, /** Initialize the global read bucket to options->BandwidthBurst,
* and current_time to the current time. */ * and current_time to the current time. */
void connection_bucket_init(void) { void
connection_bucket_init(void)
{
or_options_t *options = get_options(); or_options_t *options = get_options();
global_read_bucket = (int)options->BandwidthBurst; /* start it at max traffic */ global_read_bucket = (int)options->BandwidthBurst; /* start it at max traffic */
global_write_bucket = (int)options->BandwidthBurst; /* start it at max traffic */ global_write_bucket = (int)options->BandwidthBurst; /* start it at max traffic */
} }
/** A second has rolled over; increment buckets appropriately. */ /** A second has rolled over; increment buckets appropriately. */
void connection_bucket_refill(struct timeval *now) { void
connection_bucket_refill(struct timeval *now)
{
int i, n; int i, n;
connection_t *conn; connection_t *conn;
connection_t **carray; connection_t **carray;
@ -947,7 +988,9 @@ void connection_bucket_refill(struct timeval *now) {
/** Is the receiver bucket for connection <b>conn</b> low enough that we /** Is the receiver bucket for connection <b>conn</b> low enough that we
* should add another pile of tokens to it? * should add another pile of tokens to it?
*/ */
static int connection_receiver_bucket_should_increase(connection_t *conn) { static int
connection_receiver_bucket_should_increase(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
if (!connection_speaks_cells(conn)) if (!connection_speaks_cells(conn))
@ -973,7 +1016,9 @@ static int connection_receiver_bucket_should_increase(connection_t *conn) {
* Mark the connection and return -1 if you want to close it, else * Mark the connection and return -1 if you want to close it, else
* return 0. * return 0.
*/ */
int connection_handle_read(connection_t *conn) { int
connection_handle_read(connection_t *conn)
{
int max_to_read=-1, try_to_read; int max_to_read=-1, try_to_read;
if (conn->marked_for_close) if (conn->marked_for_close)
@ -1041,7 +1086,9 @@ loop_again:
* *
* Return -1 if we want to break conn, else return 0. * Return -1 if we want to break conn, else return 0.
*/ */
static int connection_read_to_buf(connection_t *conn, int *max_to_read) { static int
connection_read_to_buf(connection_t *conn, int *max_to_read)
{
int result, at_most = *max_to_read; int result, at_most = *max_to_read;
size_t bytes_in_buf, more_to_read; size_t bytes_in_buf, more_to_read;
@ -1140,13 +1187,17 @@ static int connection_read_to_buf(connection_t *conn, int *max_to_read) {
} }
/** A pass-through to fetch_from_buf. */ /** A pass-through to fetch_from_buf. */
int connection_fetch_from_buf(char *string, size_t len, connection_t *conn) { int
connection_fetch_from_buf(char *string, size_t len, connection_t *conn)
{
return fetch_from_buf(string, len, conn->inbuf); return fetch_from_buf(string, len, conn->inbuf);
} }
/** Return conn-\>outbuf_flushlen: how many bytes conn wants to flush /** Return conn-\>outbuf_flushlen: how many bytes conn wants to flush
* from its outbuf. */ * from its outbuf. */
int connection_wants_to_flush(connection_t *conn) { int
connection_wants_to_flush(connection_t *conn)
{
return conn->outbuf_flushlen; return conn->outbuf_flushlen;
} }
@ -1154,7 +1205,9 @@ int connection_wants_to_flush(connection_t *conn) {
* send back a relay-level sendme yet? Return 1 if so, 0 if not. Used by * send back a relay-level sendme yet? Return 1 if so, 0 if not. Used by
* connection_edge_consider_sending_sendme(). * connection_edge_consider_sending_sendme().
*/ */
int connection_outbuf_too_full(connection_t *conn) { int
connection_outbuf_too_full(connection_t *conn)
{
return (conn->outbuf_flushlen > 10*CELL_PAYLOAD_SIZE); return (conn->outbuf_flushlen > 10*CELL_PAYLOAD_SIZE);
} }
@ -1172,7 +1225,9 @@ int connection_outbuf_too_full(connection_t *conn) {
* Mark the connection and return -1 if you want to close it, else * Mark the connection and return -1 if you want to close it, else
* return 0. * return 0.
*/ */
int connection_handle_write(connection_t *conn) { int
connection_handle_write(connection_t *conn)
{
int e; int e;
socklen_t len=sizeof(e); socklen_t len=sizeof(e);
int result; int result;
@ -1288,7 +1343,8 @@ int connection_handle_write(connection_t *conn) {
} }
/* DOCDOC */ /* DOCDOC */
void _connection_controller_force_write(connection_t *conn) void
_connection_controller_force_write(connection_t *conn)
{ {
/* XXX This is hideous code duplication, but raising it seems a little /* XXX This is hideous code duplication, but raising it seems a little
* tricky for now. Think more about this one. We only call it for * tricky for now. Think more about this one. We only call it for
@ -1324,8 +1380,9 @@ void _connection_controller_force_write(connection_t *conn)
/** Append <b>len</b> bytes of <b>string</b> onto <b>conn</b>'s /** Append <b>len</b> bytes of <b>string</b> onto <b>conn</b>'s
* outbuf, and ask it to start writing. * outbuf, and ask it to start writing.
*/ */
void connection_write_to_buf(const char *string, size_t len, connection_t *conn) { void
connection_write_to_buf(const char *string, size_t len, connection_t *conn)
{
if (!len) if (!len)
return; return;
/* if it's marked for close, only allow write if we mean to flush it */ /* if it's marked for close, only allow write if we mean to flush it */
@ -1351,7 +1408,9 @@ void connection_write_to_buf(const char *string, size_t len, connection_t *conn)
/** Return the conn to addr/port that has the most recent /** Return the conn to addr/port that has the most recent
* timestamp_created, or NULL if no such conn exists. */ * timestamp_created, or NULL if no such conn exists. */
connection_t *connection_or_exact_get_by_addr_port(uint32_t addr, uint16_t port) { connection_t *
connection_or_exact_get_by_addr_port(uint32_t addr, uint16_t port)
{
int i, n; int i, n;
connection_t *conn, *best=NULL; connection_t *conn, *best=NULL;
connection_t **carray; connection_t **carray;
@ -1369,7 +1428,8 @@ connection_t *connection_or_exact_get_by_addr_port(uint32_t addr, uint16_t port)
return best; return best;
} }
connection_t *connection_get_by_identity_digest(const char *digest, int type) connection_t *
connection_get_by_identity_digest(const char *digest, int type)
{ {
int i, n; int i, n;
connection_t *conn, *best=NULL; connection_t *conn, *best=NULL;
@ -1392,7 +1452,8 @@ connection_t *connection_get_by_identity_digest(const char *digest, int type)
* marked for close. * marked for close.
*/ */
connection_t * connection_t *
connection_get_by_global_id(uint32_t id) { connection_get_by_global_id(uint32_t id)
{
int i, n; int i, n;
connection_t *conn; connection_t *conn;
connection_t **carray; connection_t **carray;
@ -1413,7 +1474,9 @@ connection_get_by_global_id(uint32_t id) {
/** Return a connection of type <b>type</b> that is not marked for /** Return a connection of type <b>type</b> that is not marked for
* close. * close.
*/ */
connection_t *connection_get_by_type(int type) { connection_t *
connection_get_by_type(int type)
{
int i, n; int i, n;
connection_t *conn; connection_t *conn;
connection_t **carray; connection_t **carray;
@ -1430,7 +1493,9 @@ connection_t *connection_get_by_type(int type) {
/** Return a connection of type <b>type</b> that is in state <b>state</b>, /** Return a connection of type <b>type</b> that is in state <b>state</b>,
* and that is not marked for close. * and that is not marked for close.
*/ */
connection_t *connection_get_by_type_state(int type, int state) { connection_t *
connection_get_by_type_state(int type, int state)
{
int i, n; int i, n;
connection_t *conn; connection_t *conn;
connection_t **carray; connection_t **carray;
@ -1448,7 +1513,9 @@ connection_t *connection_get_by_type_state(int type, int state) {
* <b>state</b>, that was written to least recently, and that is not * <b>state</b>, that was written to least recently, and that is not
* marked for close. * marked for close.
*/ */
connection_t *connection_get_by_type_state_lastwritten(int type, int state) { connection_t *
connection_get_by_type_state_lastwritten(int type, int state)
{
int i, n; int i, n;
connection_t *conn, *best=NULL; connection_t *conn, *best=NULL;
connection_t **carray; connection_t **carray;
@ -1486,7 +1553,9 @@ connection_get_by_type_state_rendquery(int type, int state, const char *rendquer
} }
/** Return 1 if <b>conn</b> is a listener conn, else return 0. */ /** Return 1 if <b>conn</b> is a listener conn, else return 0. */
int connection_is_listener(connection_t *conn) { int
connection_is_listener(connection_t *conn)
{
if (conn->type == CONN_TYPE_OR_LISTENER || if (conn->type == CONN_TYPE_OR_LISTENER ||
conn->type == CONN_TYPE_AP_LISTENER || conn->type == CONN_TYPE_AP_LISTENER ||
conn->type == CONN_TYPE_DIR_LISTENER || conn->type == CONN_TYPE_DIR_LISTENER ||
@ -1498,7 +1567,9 @@ int connection_is_listener(connection_t *conn) {
/** Return 1 if <b>conn</b> is in state "open" and is not marked /** Return 1 if <b>conn</b> is in state "open" and is not marked
* for close, else return 0. * for close, else return 0.
*/ */
int connection_state_is_open(connection_t *conn) { int
connection_state_is_open(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
if (conn->marked_for_close) if (conn->marked_for_close)
@ -1514,7 +1585,9 @@ int connection_state_is_open(connection_t *conn) {
} }
/** Return 1 if conn is in 'connecting' state, else return 0. */ /** Return 1 if conn is in 'connecting' state, else return 0. */
int connection_state_is_connecting(connection_t *conn) { int
connection_state_is_connecting(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
if (conn->marked_for_close) if (conn->marked_for_close)
@ -1537,7 +1610,9 @@ int connection_state_is_connecting(connection_t *conn) {
* *
* Return 0. * Return 0.
*/ */
int connection_send_destroy(uint16_t circ_id, connection_t *conn) { int
connection_send_destroy(uint16_t circ_id, connection_t *conn)
{
cell_t cell; cell_t cell;
tor_assert(conn); tor_assert(conn);
@ -1555,7 +1630,8 @@ int connection_send_destroy(uint16_t circ_id, connection_t *conn) {
* auth, based on the input string <b>authenticator</b>. Returns it * auth, based on the input string <b>authenticator</b>. Returns it
* if success, else returns NULL. */ * if success, else returns NULL. */
char * char *
alloc_http_authenticator(const char *authenticator) { alloc_http_authenticator(const char *authenticator)
{
/* an authenticator in Basic authentication /* an authenticator in Basic authentication
* is just the string "username:password" */ * is just the string "username:password" */
const int authenticator_length = strlen(authenticator); const int authenticator_length = strlen(authenticator);
@ -1579,8 +1655,9 @@ alloc_http_authenticator(const char *authenticator) {
* connection_*_process_inbuf() function. It also passes in * connection_*_process_inbuf() function. It also passes in
* package_partial if wanted. * package_partial if wanted.
*/ */
static int connection_process_inbuf(connection_t *conn, int package_partial) { static int
connection_process_inbuf(connection_t *conn, int package_partial)
{
tor_assert(conn); tor_assert(conn);
switch (conn->type) { switch (conn->type) {
@ -1610,8 +1687,9 @@ static int connection_process_inbuf(connection_t *conn, int package_partial) {
* This function just passes conn to the connection-specific * This function just passes conn to the connection-specific
* connection_*_finished_flushing() function. * connection_*_finished_flushing() function.
*/ */
static int connection_finished_flushing(connection_t *conn) { static int
connection_finished_flushing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
// log_fn(LOG_DEBUG,"entered. Socket %u.", conn->s); // log_fn(LOG_DEBUG,"entered. Socket %u.", conn->s);
@ -1643,7 +1721,8 @@ static int connection_finished_flushing(connection_t *conn) {
* This function just passes conn to the connection-specific * This function just passes conn to the connection-specific
* connection_*_finished_connecting() function. * connection_*_finished_connecting() function.
*/ */
static int connection_finished_connecting(connection_t *conn) static int
connection_finished_connecting(connection_t *conn)
{ {
tor_assert(conn); tor_assert(conn);
switch (conn->type) switch (conn->type)
@ -1661,7 +1740,9 @@ static int connection_finished_connecting(connection_t *conn)
} }
} }
static int connection_reached_eof(connection_t *conn) /** Callback: invoked when a connection reaches an EOF event. */
static int
connection_reached_eof(connection_t *conn)
{ {
switch (conn->type) { switch (conn->type) {
case CONN_TYPE_OR: case CONN_TYPE_OR:
@ -1687,7 +1768,8 @@ static int connection_reached_eof(connection_t *conn)
/** Verify that connection <b>conn</b> has all of its invariants /** Verify that connection <b>conn</b> has all of its invariants
* correct. Trigger an assert if anything is invalid. * correct. Trigger an assert if anything is invalid.
*/ */
void assert_connection_ok(connection_t *conn, time_t now) void
assert_connection_ok(connection_t *conn, time_t now)
{ {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->magic == CONNECTION_MAGIC); tor_assert(conn->magic == CONNECTION_MAGIC);

View File

@ -26,8 +26,8 @@ static int address_is_in_virtual_range(const char *addr);
*/ */
void void
_connection_mark_unattached_ap(connection_t *conn, int endreason, _connection_mark_unattached_ap(connection_t *conn, int endreason,
int line, const char *file) { int line, const char *file)
{
tor_assert(conn->type == CONN_TYPE_AP); tor_assert(conn->type == CONN_TYPE_AP);
conn->has_sent_end = 1; /* no circ yet */ conn->has_sent_end = 1; /* no circ yet */
@ -57,7 +57,9 @@ _connection_mark_unattached_ap(connection_t *conn, int endreason,
/** There was an EOF. Send an end and mark the connection for close. /** There was an EOF. Send an end and mark the connection for close.
*/ */
int connection_edge_reached_eof(connection_t *conn) { int
connection_edge_reached_eof(connection_t *conn)
{
#ifdef HALF_OPEN #ifdef HALF_OPEN
/* eof reached; we're done reading, but we might want to write more. */ /* eof reached; we're done reading, but we might want to write more. */
conn->done_receiving = 1; conn->done_receiving = 1;
@ -98,8 +100,9 @@ int connection_edge_reached_eof(connection_t *conn) {
* Mark and return -1 if there was an unexpected error with the conn, * Mark and return -1 if there was an unexpected error with the conn,
* else return 0. * else return 0.
*/ */
int connection_edge_process_inbuf(connection_t *conn, int package_partial) { int
connection_edge_process_inbuf(connection_t *conn, int package_partial)
{
tor_assert(conn); tor_assert(conn);
tor_assert(CONN_IS_EDGE(conn)); tor_assert(CONN_IS_EDGE(conn));
@ -138,7 +141,9 @@ int connection_edge_process_inbuf(connection_t *conn, int package_partial) {
/** This edge needs to be closed, because its circuit has closed. /** This edge needs to be closed, because its circuit has closed.
* Mark it for close and return 0. * Mark it for close and return 0.
*/ */
int connection_edge_destroy(uint16_t circ_id, connection_t *conn) { int
connection_edge_destroy(uint16_t circ_id, connection_t *conn)
{
tor_assert(CONN_IS_EDGE(conn)); tor_assert(CONN_IS_EDGE(conn));
if (!conn->marked_for_close) { if (!conn->marked_for_close) {
@ -228,7 +233,9 @@ connection_edge_end_errno(connection_t *conn, crypt_path_t *cpath_layer)
* If <b>conn</b> is broken, mark it for close and return -1, else * If <b>conn</b> is broken, mark it for close and return -1, else
* return 0. * return 0.
*/ */
int connection_edge_finished_flushing(connection_t *conn) { int
connection_edge_finished_flushing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(CONN_IS_EDGE(conn)); tor_assert(CONN_IS_EDGE(conn));
@ -256,7 +263,8 @@ int connection_edge_finished_flushing(connection_t *conn) {
/** Connected handler for exit connections: start writing pending /** Connected handler for exit connections: start writing pending
* data, deliver 'CONNECTED' relay cells as appropriate, and check * data, deliver 'CONNECTED' relay cells as appropriate, and check
* any pending data that may have been received. */ * any pending data that may have been received. */
int connection_edge_finished_connecting(connection_t *conn) int
connection_edge_finished_connecting(connection_t *conn)
{ {
char connected_payload[4]; char connected_payload[4];
@ -296,7 +304,9 @@ int connection_edge_finished_connecting(connection_t *conn)
* For rendezvous streams, simply give up after 45 seconds (with no * For rendezvous streams, simply give up after 45 seconds (with no
* retry attempt). * retry attempt).
*/ */
void connection_ap_expire_beginning(void) { void
connection_ap_expire_beginning(void)
{
connection_t **carray; connection_t **carray;
connection_t *conn; connection_t *conn;
circuit_t *circ; circuit_t *circ;
@ -366,7 +376,8 @@ void connection_ap_expire_beginning(void) {
/** Tell any AP streams that are waiting for a new circuit that one is /** Tell any AP streams that are waiting for a new circuit that one is
* available. * available.
*/ */
void connection_ap_attach_pending(void) void
connection_ap_attach_pending(void)
{ {
connection_t **carray; connection_t **carray;
connection_t *conn; connection_t *conn;
@ -455,27 +466,33 @@ static strmap_t *addressmap=NULL;
static strmap_t *virtaddress_reversemap=NULL; static strmap_t *virtaddress_reversemap=NULL;
/** Initialize addressmap. */ /** Initialize addressmap. */
void addressmap_init(void) { void
addressmap_init(void)
{
addressmap = strmap_new(); addressmap = strmap_new();
virtaddress_reversemap = strmap_new(); virtaddress_reversemap = strmap_new();
} }
/** Free the memory associated with the addressmap entry <b>_ent</b>. */ /** Free the memory associated with the addressmap entry <b>_ent</b>. */
static void static void
addressmap_ent_free(void *_ent) { addressmap_ent_free(void *_ent)
{
addressmap_entry_t *ent = _ent; addressmap_entry_t *ent = _ent;
tor_free(ent->new_address); tor_free(ent->new_address);
tor_free(ent); tor_free(ent);
} }
/** Free storage held by a virtaddress_entry_t* entry in <b>ent</b> */
static void static void
addressmap_virtaddress_ent_free(void *_ent) { addressmap_virtaddress_ent_free(void *_ent)
{
virtaddress_entry_t *ent = _ent; virtaddress_entry_t *ent = _ent;
tor_free(ent->ipv4_address); tor_free(ent->ipv4_address);
tor_free(ent->hostname_address); tor_free(ent->hostname_address);
tor_free(ent); tor_free(ent);
} }
/** Free storage held by a virtaddress_entry_t* entry in <b>ent</b> */
static void static void
addressmap_virtaddress_remove(const char *addr, addressmap_entry_t *ent) addressmap_virtaddress_remove(const char *addr, addressmap_entry_t *ent)
{ {
@ -521,13 +538,17 @@ addressmap_clear_transient(void)
/** Clean out entries from the addressmap cache that were /** Clean out entries from the addressmap cache that were
* added long enough ago that they are no longer valid. * added long enough ago that they are no longer valid.
*/ */
void addressmap_clean(time_t now) { void
addressmap_clean(time_t now)
{
addressmap_get_mappings(NULL, 2, now); addressmap_get_mappings(NULL, 2, now);
} }
/** Free all the elements in the addressmap, and free the addressmap /** Free all the elements in the addressmap, and free the addressmap
* itself. */ * itself. */
void addressmap_free_all(void) { void
addressmap_free_all(void)
{
strmap_free(addressmap, addressmap_ent_free); strmap_free(addressmap, addressmap_ent_free);
addressmap = NULL; addressmap = NULL;
strmap_free(virtaddress_reversemap, addressmap_virtaddress_ent_free); strmap_free(virtaddress_reversemap, addressmap_virtaddress_ent_free);
@ -537,7 +558,9 @@ void addressmap_free_all(void) {
* more rewrites; but don't get into an infinite loop. * more rewrites; but don't get into an infinite loop.
* Don't write more than maxlen chars into address. * Don't write more than maxlen chars into address.
*/ */
void addressmap_rewrite(char *address, size_t maxlen) { void
addressmap_rewrite(char *address, size_t maxlen)
{
addressmap_entry_t *ent; addressmap_entry_t *ent;
int rewrites; int rewrites;
@ -557,7 +580,9 @@ void addressmap_rewrite(char *address, size_t maxlen) {
} }
/** Return 1 if <b>address</b> is already registered, else return 0 */ /** Return 1 if <b>address</b> is already registered, else return 0 */
int addressmap_already_mapped(const char *address) { int
addressmap_already_mapped(const char *address)
{
return strmap_get(addressmap, address) ? 1 : 0; return strmap_get(addressmap, address) ? 1 : 0;
} }
@ -572,7 +597,9 @@ int addressmap_already_mapped(const char *address) {
* If <b>new_address</b> is NULL, or equal to <b>address</b>, remove * If <b>new_address</b> is NULL, or equal to <b>address</b>, remove
* any mappings that exist from <b>address</b>. * any mappings that exist from <b>address</b>.
*/ */
void addressmap_register(const char *address, char *new_address, time_t expires) { void
addressmap_register(const char *address, char *new_address, time_t expires)
{
addressmap_entry_t *ent; addressmap_entry_t *ent;
ent = strmap_get(addressmap, address); ent = strmap_get(addressmap, address);
@ -616,7 +643,8 @@ void addressmap_register(const char *address, char *new_address, time_t expires)
* Increment the number of resolve failures we have on record * Increment the number of resolve failures we have on record
* for it, and then return that number. * for it, and then return that number.
*/ */
int client_dns_incr_failures(const char *address) int
client_dns_incr_failures(const char *address)
{ {
addressmap_entry_t *ent; addressmap_entry_t *ent;
ent = strmap_get(addressmap,address); ent = strmap_get(addressmap,address);
@ -638,7 +666,8 @@ int client_dns_incr_failures(const char *address)
* If <b>exitname</b> is defined, then append the addresses with * If <b>exitname</b> is defined, then append the addresses with
* ".exitname.exit" before registering the mapping. * ".exitname.exit" before registering the mapping.
*/ */
void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname) void
client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname)
{ {
struct in_addr in; struct in_addr in;
char extendedaddress[MAX_SOCKS_ADDR_LEN+MAX_HEX_NICKNAME_LEN+10]; char extendedaddress[MAX_SOCKS_ADDR_LEN+MAX_HEX_NICKNAME_LEN+10];
@ -802,7 +831,8 @@ addressmap_register_virtual_address(int type, char *new_address)
* colons. Return 0 if it's fine. * colons. Return 0 if it's fine.
*/ */
static int static int
address_is_invalid_destination(const char *address) { address_is_invalid_destination(const char *address)
{
/* FFFF should flesh this out */ /* FFFF should flesh this out */
if (strchr(address,':')) if (strchr(address,':'))
return 1; return 1;
@ -854,7 +884,9 @@ addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
* Return -1 if an unexpected error with conn (and it should be marked * Return -1 if an unexpected error with conn (and it should be marked
* for close), else return 0. * for close), else return 0.
*/ */
static int connection_ap_handshake_process_socks(connection_t *conn) { static int
connection_ap_handshake_process_socks(connection_t *conn)
{
socks_request_t *socks; socks_request_t *socks;
int sockshere; int sockshere;
hostname_type_t addresstype; hostname_type_t addresstype;
@ -1055,7 +1087,9 @@ static int connection_ap_handshake_process_socks(connection_t *conn) {
/** Iterate over the two bytes of stream_id until we get one that is not /** Iterate over the two bytes of stream_id until we get one that is not
* already in use; return it. Return 0 if can't get a unique stream_id. * already in use; return it. Return 0 if can't get a unique stream_id.
*/ */
static uint16_t get_unique_stream_id_by_circ(circuit_t *circ) { static uint16_t
get_unique_stream_id_by_circ(circuit_t *circ)
{
connection_t *tmpconn; connection_t *tmpconn;
uint16_t test_stream_id; uint16_t test_stream_id;
uint32_t attempts=0; uint32_t attempts=0;
@ -1080,7 +1114,8 @@ again:
* *
* If ap_conn is broken, mark it for close and return -1. Else return 0. * If ap_conn is broken, mark it for close and return -1. Else return 0.
*/ */
int connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ) int
connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ)
{ {
char payload[CELL_PAYLOAD_SIZE]; char payload[CELL_PAYLOAD_SIZE];
int payload_len; int payload_len;
@ -1122,7 +1157,8 @@ int connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ)
* *
* If ap_conn is broken, mark it for close and return -1. Else return 0. * If ap_conn is broken, mark it for close and return -1. Else return 0.
*/ */
int connection_ap_handshake_send_resolve(connection_t *ap_conn, circuit_t *circ) int
connection_ap_handshake_send_resolve(connection_t *ap_conn, circuit_t *circ)
{ {
int payload_len; int payload_len;
const char *string_addr; const char *string_addr;
@ -1163,7 +1199,9 @@ int connection_ap_handshake_send_resolve(connection_t *ap_conn, circuit_t *circ)
* *
* Return the other end of the socketpair, or -1 if error. * Return the other end of the socketpair, or -1 if error.
*/ */
int connection_ap_make_bridge(char *address, uint16_t port) { int
connection_ap_make_bridge(char *address, uint16_t port)
{
int fd[2]; int fd[2];
connection_t *conn; connection_t *conn;
@ -1220,7 +1258,8 @@ int connection_ap_make_bridge(char *address, uint16_t port) {
* -1 for unreachable; the answer should be in the format specified * -1 for unreachable; the answer should be in the format specified
* in the socks extensions document. * in the socks extensions document.
**/ **/
void connection_ap_handshake_socks_resolved(connection_t *conn, void
connection_ap_handshake_socks_resolved(connection_t *conn,
int answer_type, int answer_type,
size_t answer_len, size_t answer_len,
const char *answer) const char *answer)
@ -1285,7 +1324,8 @@ void connection_ap_handshake_socks_resolved(connection_t *conn,
* *
* If <b>reply</b> is undefined, <b>status</b> can't be 0. * If <b>reply</b> is undefined, <b>status</b> can't be 0.
*/ */
void connection_ap_handshake_socks_reply(connection_t *conn, char *reply, void
connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
size_t replylen, size_t replylen,
socks5_reply_status_t status) { socks5_reply_status_t status) {
char buf[256]; char buf[256];
@ -1341,7 +1381,9 @@ void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
* *
* Return -1 if we want to tear down <b>circ</b>. Else return 0. * Return -1 if we want to tear down <b>circ</b>. Else return 0.
*/ */
int connection_exit_begin_conn(cell_t *cell, circuit_t *circ) { int
connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
{
connection_t *n_stream; connection_t *n_stream;
relay_header_t rh; relay_header_t rh;
char *address=NULL; char *address=NULL;
@ -1449,7 +1491,9 @@ int connection_exit_begin_conn(cell_t *cell, circuit_t *circ) {
* Called when we receive a RELAY_RESOLVE cell 'cell' along the circuit 'circ'; * Called when we receive a RELAY_RESOLVE cell 'cell' along the circuit 'circ';
* begin resolving the hostname, and (eventually) reply with a RESOLVED cell. * begin resolving the hostname, and (eventually) reply with a RESOLVED cell.
*/ */
int connection_exit_begin_resolve(cell_t *cell, circuit_t *circ) { int
connection_exit_begin_resolve(cell_t *cell, circuit_t *circ)
{
connection_t *dummy_conn; connection_t *dummy_conn;
relay_header_t rh; relay_header_t rh;
@ -1498,7 +1542,8 @@ int connection_exit_begin_resolve(cell_t *cell, circuit_t *circ) {
* streams must not reveal what IP they connected to.) * streams must not reveal what IP they connected to.)
*/ */
void void
connection_exit_connect(connection_t *conn) { connection_exit_connect(connection_t *conn)
{
char connected_payload[4]; char connected_payload[4];
uint32_t addr; uint32_t addr;
uint16_t port; uint16_t port;
@ -1577,7 +1622,9 @@ connection_exit_connect(connection_t *conn) {
/** Return 1 if <b>conn</b> is a rendezvous stream, or 0 if /** Return 1 if <b>conn</b> is a rendezvous stream, or 0 if
* it is a general stream. * it is a general stream.
*/ */
int connection_edge_is_rendezvous_stream(connection_t *conn) { int
connection_edge_is_rendezvous_stream(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
if (*conn->rend_query) /* XXX */ if (*conn->rend_query) /* XXX */
return 1; return 1;
@ -1589,7 +1636,8 @@ int connection_edge_is_rendezvous_stream(connection_t *conn) {
* (We might be uncertain if conn's destination address has not yet been * (We might be uncertain if conn's destination address has not yet been
* resolved.) * resolved.)
*/ */
int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit) int
connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit)
{ {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_AP); tor_assert(conn->type == CONN_TYPE_AP);
@ -1648,6 +1696,8 @@ parse_socks_policy(void)
} }
} }
/** Free all storage held by our SOCKS allow policy
*/
void void
free_socks_policy(void) free_socks_policy(void)
{ {
@ -1658,7 +1708,8 @@ free_socks_policy(void)
/** Return 1 if <b>addr</b> is permitted to connect to our socks port, /** Return 1 if <b>addr</b> is permitted to connect to our socks port,
* based on <b>socks_policy</b>. Else return 0. * based on <b>socks_policy</b>. Else return 0.
*/ */
int socks_policy_permits_address(uint32_t addr) int
socks_policy_permits_address(uint32_t addr)
{ {
int a; int a;
@ -1695,7 +1746,8 @@ set_exit_redirects(smartlist_t *lst)
* Return NORMAL_HOSTNAME and change nothing. * Return NORMAL_HOSTNAME and change nothing.
*/ */
hostname_type_t hostname_type_t
parse_extended_hostname(char *address) { parse_extended_hostname(char *address)
{
char *s; char *s;
char query[REND_SERVICE_ID_LEN+1]; char query[REND_SERVICE_ID_LEN+1];

View File

@ -26,7 +26,9 @@ static int connection_or_process_cells_from_inbuf(connection_t *conn);
* in the buffer <b>dest</b>. See tor-spec.txt for details about the * in the buffer <b>dest</b>. See tor-spec.txt for details about the
* wire format. * wire format.
*/ */
static void cell_pack(char *dest, const cell_t *src) { static void
cell_pack(char *dest, const cell_t *src)
{
*(uint16_t*)dest = htons(src->circ_id); *(uint16_t*)dest = htons(src->circ_id);
*(uint8_t*)(dest+2) = src->command; *(uint8_t*)(dest+2) = src->command;
memcpy(dest+3, src->payload, CELL_PAYLOAD_SIZE); memcpy(dest+3, src->payload, CELL_PAYLOAD_SIZE);
@ -35,13 +37,17 @@ static void cell_pack(char *dest, const cell_t *src) {
/** Unpack the network-order buffer <b>src</b> into a host-order /** Unpack the network-order buffer <b>src</b> into a host-order
* cell_t structure <b>dest</b>. * cell_t structure <b>dest</b>.
*/ */
static void cell_unpack(cell_t *dest, const char *src) { static void
cell_unpack(cell_t *dest, const char *src)
{
dest->circ_id = ntohs(*(uint16_t*)(src)); dest->circ_id = ntohs(*(uint16_t*)(src));
dest->command = *(uint8_t*)(src+2); dest->command = *(uint8_t*)(src+2);
memcpy(dest->payload, src+3, CELL_PAYLOAD_SIZE); memcpy(dest->payload, src+3, CELL_PAYLOAD_SIZE);
} }
int connection_or_reached_eof(connection_t *conn) { int
connection_or_reached_eof(connection_t *conn)
{
log_fn(LOG_INFO,"OR connection reached EOF. Closing."); log_fn(LOG_INFO,"OR connection reached EOF. Closing.");
connection_mark_for_close(conn); connection_mark_for_close(conn);
return 0; return 0;
@ -53,8 +59,8 @@ int connection_or_reached_eof(connection_t *conn) {
* and hope for better luck next time. * and hope for better luck next time.
*/ */
static int static int
connection_or_read_proxy_response(connection_t *conn) { connection_or_read_proxy_response(connection_t *conn)
{
char *headers; char *headers;
char *reason=NULL; char *reason=NULL;
int status_code; int status_code;
@ -108,8 +114,9 @@ connection_or_read_proxy_response(connection_t *conn) {
* connection_or_process_cells_from_inbuf() * connection_or_process_cells_from_inbuf()
* (else do nothing). * (else do nothing).
*/ */
int connection_or_process_inbuf(connection_t *conn) { int
connection_or_process_inbuf(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_OR); tor_assert(conn->type == CONN_TYPE_OR);
@ -131,7 +138,9 @@ int connection_or_process_inbuf(connection_t *conn) {
* If <b>conn</b> is broken, mark it for close and return -1, else * If <b>conn</b> is broken, mark it for close and return -1, else
* return 0. * return 0.
*/ */
int connection_or_finished_flushing(connection_t *conn) { int
connection_or_finished_flushing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_OR); tor_assert(conn->type == CONN_TYPE_OR);
@ -156,7 +165,8 @@ int connection_or_finished_flushing(connection_t *conn) {
/** Connected handler for OR connections: begin the TLS handshake. /** Connected handler for OR connections: begin the TLS handshake.
*/ */
int connection_or_finished_connecting(connection_t *conn) int
connection_or_finished_connecting(connection_t *conn)
{ {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_OR); tor_assert(conn->type == CONN_TYPE_OR);
@ -208,7 +218,8 @@ int connection_or_finished_connecting(connection_t *conn)
* if the other side initiated it. * if the other side initiated it.
*/ */
static void static void
connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) { connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router)
{
or_options_t *options = get_options(); or_options_t *options = get_options();
conn->addr = router->addr; conn->addr = router->addr;
@ -221,6 +232,7 @@ connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) {
conn->address = tor_strdup(router->address); conn->address = tor_strdup(router->address);
} }
/** DOCDOC */
static void static void
connection_or_init_conn_from_address(connection_t *conn, connection_or_init_conn_from_address(connection_t *conn,
uint32_t addr, uint16_t port, uint32_t addr, uint16_t port,
@ -257,6 +269,7 @@ connection_or_init_conn_from_address(connection_t *conn,
tor_inet_ntoa(&in,conn->address,INET_NTOA_BUF_LEN); tor_inet_ntoa(&in,conn->address,INET_NTOA_BUF_LEN);
} }
/** DOCDOC */
void void
connection_or_update_nickname(connection_t *conn) connection_or_update_nickname(connection_t *conn)
{ {
@ -303,8 +316,9 @@ connection_or_update_nickname(connection_t *conn)
* *
* Return the launched conn, or NULL if it failed. * Return the launched conn, or NULL if it failed.
*/ */
connection_t *connection_or_connect(uint32_t addr, uint16_t port, connection_t *
const char *id_digest) { connection_or_connect(uint32_t addr, uint16_t port, const char *id_digest)
{
connection_t *conn; connection_t *conn;
routerinfo_t *me; routerinfo_t *me;
or_options_t *options = get_options(); or_options_t *options = get_options();
@ -370,7 +384,9 @@ connection_t *connection_or_connect(uint32_t addr, uint16_t port,
* *
* Return -1 if <b>conn</b> is broken, else return 0. * Return -1 if <b>conn</b> is broken, else return 0.
*/ */
int connection_tls_start_handshake(connection_t *conn, int receiving) { int
connection_tls_start_handshake(connection_t *conn, int receiving)
{
conn->state = OR_CONN_STATE_HANDSHAKING; conn->state = OR_CONN_STATE_HANDSHAKING;
conn->tls = tor_tls_new(conn->s, receiving, 0); conn->tls = tor_tls_new(conn->s, receiving, 0);
if (!conn->tls) { if (!conn->tls) {
@ -390,7 +406,9 @@ int connection_tls_start_handshake(connection_t *conn, int receiving) {
* *
* Return -1 if <b>conn</b> is broken, else return 0. * Return -1 if <b>conn</b> is broken, else return 0.
*/ */
int connection_tls_continue_handshake(connection_t *conn) { int
connection_tls_continue_handshake(connection_t *conn)
{
check_no_tls_errors(); check_no_tls_errors();
switch (tor_tls_handshake(conn->tls)) { switch (tor_tls_handshake(conn->tls)) {
case TOR_TLS_ERROR: case TOR_TLS_ERROR:
@ -412,7 +430,9 @@ int connection_tls_continue_handshake(connection_t *conn) {
static char ZERO_DIGEST[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; static char ZERO_DIGEST[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
int connection_or_nonopen_was_started_here(connection_t *conn) /** DOCDOC */
int
connection_or_nonopen_was_started_here(connection_t *conn)
{ {
tor_assert(sizeof(ZERO_DIGEST) == DIGEST_LEN); tor_assert(sizeof(ZERO_DIGEST) == DIGEST_LEN);
tor_assert(conn->type == CONN_TYPE_OR); tor_assert(conn->type == CONN_TYPE_OR);
@ -443,7 +463,8 @@ int connection_or_nonopen_was_started_here(connection_t *conn)
* an authdirserver). * an authdirserver).
*/ */
static int static int
connection_tls_finish_handshake(connection_t *conn) { connection_tls_finish_handshake(connection_t *conn)
{
routerinfo_t *router; routerinfo_t *router;
char nickname[MAX_NICKNAME_LEN+1]; char nickname[MAX_NICKNAME_LEN+1];
connection_t *c; connection_t *c;
@ -567,7 +588,9 @@ connection_tls_finish_handshake(connection_t *conn) {
* (Commented out) If it's an OR conn, and an entire TLS record is * (Commented out) If it's an OR conn, and an entire TLS record is
* ready, then try to flush the record now. * ready, then try to flush the record now.
*/ */
void connection_or_write_cell_to_buf(const cell_t *cell, connection_t *conn) { void
connection_or_write_cell_to_buf(const cell_t *cell, connection_t *conn)
{
char networkcell[CELL_NETWORK_SIZE]; char networkcell[CELL_NETWORK_SIZE];
char *n = networkcell; char *n = networkcell;
@ -615,7 +638,9 @@ void connection_or_write_cell_to_buf(const cell_t *cell, connection_t *conn) {
* *
* Always return 0. * Always return 0.
*/ */
static int connection_or_process_cells_from_inbuf(connection_t *conn) { static int
connection_or_process_cells_from_inbuf(connection_t *conn)
{
char buf[CELL_NETWORK_SIZE]; char buf[CELL_NETWORK_SIZE];
cell_t cell; cell_t cell;

View File

@ -184,6 +184,7 @@ event_to_log_severity(int event)
} }
} }
/** DOCDOC */
static INLINE int static INLINE int
log_severity_to_event(int severity) log_severity_to_event(int severity)
{ {
@ -199,7 +200,8 @@ log_severity_to_event(int severity)
/** Set <b>global_event_mask</b> to the bitwise OR of each live control /** Set <b>global_event_mask</b> to the bitwise OR of each live control
* connection's event_mask field. */ * connection's event_mask field. */
static void update_global_event_mask(void) static void
update_global_event_mask(void)
{ {
connection_t **conns; connection_t **conns;
int n_conns, i; int n_conns, i;
@ -215,7 +217,10 @@ static void update_global_event_mask(void)
adjust_event_log_severity(); adjust_event_log_severity();
} }
void adjust_event_log_severity(void) { /** DOCDOC */
void
adjust_event_log_severity(void)
{
int i; int i;
int min_log_event=EVENT_ERR_MSG, max_log_event=EVENT_DEBUG_MSG; int min_log_event=EVENT_ERR_MSG, max_log_event=EVENT_DEBUG_MSG;
@ -286,7 +291,9 @@ send_control_done(connection_t *conn)
send_control_message(conn, CONTROL_CMD_DONE, 0, NULL); send_control_message(conn, CONTROL_CMD_DONE, 0, NULL);
} }
static void send_control_done2(connection_t *conn, const char *msg, size_t len) /** DOCDOC */
static void
send_control_done2(connection_t *conn, const char *msg, size_t len)
{ {
if (len==0) if (len==0)
len = strlen(msg); len = strlen(msg);
@ -527,6 +534,7 @@ handle_control_authenticate(connection_t *conn, uint32_t len, const char *body)
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_saveconf(connection_t *conn, uint32_t len, handle_control_saveconf(connection_t *conn, uint32_t len,
const char *body) const char *body)
@ -540,6 +548,7 @@ handle_control_saveconf(connection_t *conn, uint32_t len,
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_signal(connection_t *conn, uint32_t len, handle_control_signal(connection_t *conn, uint32_t len,
const char *body) const char *body)
@ -555,6 +564,7 @@ handle_control_signal(connection_t *conn, uint32_t len,
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body) handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
{ {
@ -663,6 +673,7 @@ handle_getinfo_helper(const char *question, char **answer)
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_getinfo(connection_t *conn, uint32_t len, const char *body) handle_control_getinfo(connection_t *conn, uint32_t len, const char *body)
{ {
@ -702,6 +713,8 @@ handle_control_getinfo(connection_t *conn, uint32_t len, const char *body)
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_extendcircuit(connection_t *conn, uint32_t len, handle_control_extendcircuit(connection_t *conn, uint32_t len,
const char *body) const char *body)
@ -779,7 +792,10 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
smartlist_free(routers); smartlist_free(routers);
return 0; return 0;
} }
static int handle_control_attachstream(connection_t *conn, uint32_t len,
/** DOCDOC */
static int
handle_control_attachstream(connection_t *conn, uint32_t len,
const char *body) const char *body)
{ {
uint32_t conn_id; uint32_t conn_id;
@ -829,6 +845,8 @@ static int handle_control_attachstream(connection_t *conn, uint32_t len,
send_control_done(conn); send_control_done(conn);
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_postdescriptor(connection_t *conn, uint32_t len, handle_control_postdescriptor(connection_t *conn, uint32_t len,
const char *body) const char *body)
@ -848,6 +866,8 @@ handle_control_postdescriptor(connection_t *conn, uint32_t len,
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_redirectstream(connection_t *conn, uint32_t len, handle_control_redirectstream(connection_t *conn, uint32_t len,
const char *body) const char *body)
@ -873,6 +893,8 @@ handle_control_redirectstream(connection_t *conn, uint32_t len,
send_control_done(conn); send_control_done(conn);
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_closestream(connection_t *conn, uint32_t len, handle_control_closestream(connection_t *conn, uint32_t len,
const char *body) const char *body)
@ -901,6 +923,7 @@ handle_control_closestream(connection_t *conn, uint32_t len,
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_closecircuit(connection_t *conn, uint32_t len, handle_control_closecircuit(connection_t *conn, uint32_t len,
const char *body) const char *body)
@ -930,6 +953,7 @@ handle_control_closecircuit(connection_t *conn, uint32_t len,
return 0; return 0;
} }
/** DOCDOC */
static int static int
handle_control_fragments(connection_t *conn, uint16_t command_type, handle_control_fragments(connection_t *conn, uint16_t command_type,
uint32_t body_len, char *body) uint32_t body_len, char *body)
@ -972,7 +996,8 @@ handle_control_fragments(connection_t *conn, uint16_t command_type,
/** Called when <b>conn</b> has no more bytes left on its outbuf. */ /** Called when <b>conn</b> has no more bytes left on its outbuf. */
int int
connection_control_finished_flushing(connection_t *conn) { connection_control_finished_flushing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_CONTROL); tor_assert(conn->type == CONN_TYPE_CONTROL);
@ -981,7 +1006,9 @@ connection_control_finished_flushing(connection_t *conn) {
} }
/** Called when <b>conn</b> has gotten its socket closed. */ /** Called when <b>conn</b> has gotten its socket closed. */
int connection_control_reached_eof(connection_t *conn) { int
connection_control_reached_eof(connection_t *conn)
{
log_fn(LOG_INFO,"Control connection reached EOF. Closing."); log_fn(LOG_INFO,"Control connection reached EOF. Closing.");
connection_mark_for_close(conn); connection_mark_for_close(conn);
return 0; return 0;
@ -990,7 +1017,8 @@ int connection_control_reached_eof(connection_t *conn) {
/** Called when <b>conn</b> has received more bytes on its inbuf. /** Called when <b>conn</b> has received more bytes on its inbuf.
*/ */
int int
connection_control_process_inbuf(connection_t *conn) { connection_control_process_inbuf(connection_t *conn)
{
uint32_t body_len; uint32_t body_len;
uint16_t command_type; uint16_t command_type;
char *body; char *body;
@ -1253,7 +1281,8 @@ control_event_logmsg(int severity, const char *msg)
* interested control connections. <b>routers</b> is a list of * interested control connections. <b>routers</b> is a list of
* DIGEST_LEN-byte identity digests. * DIGEST_LEN-byte identity digests.
*/ */
int control_event_descriptors_changed(smartlist_t *routers) int
control_event_descriptors_changed(smartlist_t *routers)
{ {
size_t len; size_t len;
char *msg; char *msg;
@ -1302,4 +1331,3 @@ init_cookie_authentication(int enabled)
return 0; return 0;
} }

View File

@ -43,13 +43,17 @@ static void process_pending_task(connection_t *cpuworker);
/** Initialize the cpuworker subsystem. /** Initialize the cpuworker subsystem.
*/ */
void cpu_init(void) { void
cpu_init(void)
{
last_rotation_time=time(NULL); last_rotation_time=time(NULL);
spawn_enough_cpuworkers(); spawn_enough_cpuworkers();
} }
/** Called when we're done sending a request to a cpuworker. */ /** Called when we're done sending a request to a cpuworker. */
int connection_cpu_finished_flushing(connection_t *conn) { int
connection_cpu_finished_flushing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_CPUWORKER); tor_assert(conn->type == CONN_TYPE_CPUWORKER);
connection_stop_writing(conn); connection_stop_writing(conn);
@ -58,7 +62,9 @@ int connection_cpu_finished_flushing(connection_t *conn) {
/** Pack addr,port,and circ_id; set *tag to the result. (See note on /** Pack addr,port,and circ_id; set *tag to the result. (See note on
* cpuworker_main for wire format.) */ * cpuworker_main for wire format.) */
static void tag_pack(char *tag, uint32_t addr, uint16_t port, uint16_t circ_id) { static void
tag_pack(char *tag, uint32_t addr, uint16_t port, uint16_t circ_id)
{
*(uint32_t *)tag = addr; *(uint32_t *)tag = addr;
*(uint16_t *)(tag+4) = port; *(uint16_t *)(tag+4) = port;
*(uint16_t *)(tag+6) = circ_id; *(uint16_t *)(tag+6) = circ_id;
@ -66,7 +72,9 @@ static void tag_pack(char *tag, uint32_t addr, uint16_t port, uint16_t circ_id)
/** Unpack <b>tag</b> into addr, port, and circ_id. /** Unpack <b>tag</b> into addr, port, and circ_id.
*/ */
static void tag_unpack(const char *tag, uint32_t *addr, uint16_t *port, uint16_t *circ_id) { static void
tag_unpack(const char *tag, uint32_t *addr, uint16_t *port, uint16_t *circ_id)
{
struct in_addr in; struct in_addr in;
char addrbuf[INET_NTOA_BUF_LEN]; char addrbuf[INET_NTOA_BUF_LEN];
@ -83,7 +91,8 @@ static void tag_unpack(const char *tag, uint32_t *addr, uint16_t *port, uint16_t
* cpuworkers. Close all currently idle cpuworkers, and mark the last * cpuworkers. Close all currently idle cpuworkers, and mark the last
* rotation time as now. * rotation time as now.
*/ */
void cpuworkers_rotate(void) void
cpuworkers_rotate(void)
{ {
connection_t *cpuworker; connection_t *cpuworker;
while ((cpuworker = connection_get_by_type_state(CONN_TYPE_CPUWORKER, while ((cpuworker = connection_get_by_type_state(CONN_TYPE_CPUWORKER,
@ -97,7 +106,9 @@ void cpuworkers_rotate(void)
/** If the cpuworker closes the connection, /** If the cpuworker closes the connection,
* mark it as closed and spawn a new one as needed. */ * mark it as closed and spawn a new one as needed. */
int connection_cpu_reached_eof(connection_t *conn) { int
connection_cpu_reached_eof(connection_t *conn)
{
log_fn(LOG_WARN,"Read eof. Worker died unexpectedly."); log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
if (conn->state != CPUWORKER_STATE_IDLE) { if (conn->state != CPUWORKER_STATE_IDLE) {
/* the circ associated with this cpuworker will have to wait until /* the circ associated with this cpuworker will have to wait until
@ -116,7 +127,9 @@ int connection_cpu_reached_eof(connection_t *conn) {
* wait for a complete answer. If the answer is complete, * wait for a complete answer. If the answer is complete,
* process it as appropriate. * process it as appropriate.
*/ */
int connection_cpu_process_inbuf(connection_t *conn) { int
connection_cpu_process_inbuf(connection_t *conn)
{
char success; char success;
char buf[LEN_ONION_RESPONSE]; char buf[LEN_ONION_RESPONSE];
uint32_t addr; uint32_t addr;
@ -199,7 +212,9 @@ done_processing:
* (Note: this _should_ be by addr/port, since we're concerned with specific * (Note: this _should_ be by addr/port, since we're concerned with specific
* connections, not with routers (where we'd use identity).) * connections, not with routers (where we'd use identity).)
*/ */
static int cpuworker_main(void *data) { static int
cpuworker_main(void *data)
{
char question[ONIONSKIN_CHALLENGE_LEN]; char question[ONIONSKIN_CHALLENGE_LEN];
uint8_t question_type; uint8_t question_type;
int *fdarray = data; int *fdarray = data;
@ -280,7 +295,9 @@ static int cpuworker_main(void *data) {
/** Launch a new cpuworker. /** Launch a new cpuworker.
*/ */
static int spawn_cpuworker(void) { static int
spawn_cpuworker(void)
{
int *fdarray; int *fdarray;
int fd; int fd;
connection_t *conn; connection_t *conn;
@ -325,7 +342,9 @@ static int spawn_cpuworker(void) {
/** If we have too few or too many active cpuworkers, try to spawn new ones /** If we have too few or too many active cpuworkers, try to spawn new ones
* or kill idle ones. * or kill idle ones.
*/ */
static void spawn_enough_cpuworkers(void) { static void
spawn_enough_cpuworkers(void)
{
int num_cpuworkers_needed = get_options()->NumCpus; int num_cpuworkers_needed = get_options()->NumCpus;
if (num_cpuworkers_needed < MIN_CPUWORKERS) if (num_cpuworkers_needed < MIN_CPUWORKERS)
@ -343,7 +362,9 @@ static void spawn_enough_cpuworkers(void) {
} }
/** Take a pending task from the queue and assign it to 'cpuworker'. */ /** Take a pending task from the queue and assign it to 'cpuworker'. */
static void process_pending_task(connection_t *cpuworker) { static void
process_pending_task(connection_t *cpuworker)
{
circuit_t *circ; circuit_t *circ;
tor_assert(cpuworker); tor_assert(cpuworker);
@ -364,7 +385,8 @@ static void process_pending_task(connection_t *cpuworker) {
* thinks of itself as idle. I don't know why. But here's a workaround * thinks of itself as idle. I don't know why. But here's a workaround
* to kill any cpuworker that's been busy for more than 3600 seconds. */ * to kill any cpuworker that's been busy for more than 3600 seconds. */
static void static void
cull_wedged_cpuworkers(void) { cull_wedged_cpuworkers(void)
{
connection_t **carray; connection_t **carray;
connection_t *conn; connection_t *conn;
int n_conns, i; int n_conns, i;
@ -391,8 +413,10 @@ cull_wedged_cpuworkers(void) {
* If question_type is CPUWORKER_TASK_ONION then task is a circ. * If question_type is CPUWORKER_TASK_ONION then task is a circ.
* No other question_types are allowed. * No other question_types are allowed.
*/ */
int assign_to_cpuworker(connection_t *cpuworker, uint8_t question_type, int
void *task) { assign_to_cpuworker(connection_t *cpuworker, uint8_t question_type,
void *task)
{
circuit_t *circ; circuit_t *circ;
char tag[TAG_LEN]; char tag[TAG_LEN];

View File

@ -85,6 +85,7 @@ parse_dir_policy(void)
} }
} }
/** Free storage used to hold parsed directory policy */
void void
free_dir_policy(void) free_dir_policy(void)
{ {
@ -95,7 +96,8 @@ free_dir_policy(void)
/** Return 1 if <b>addr</b> is permitted to connect to our dir port, /** Return 1 if <b>addr</b> is permitted to connect to our dir port,
* based on <b>dir_policy</b>. Else return 0. * based on <b>dir_policy</b>. Else return 0.
*/ */
int dir_policy_permits_address(uint32_t addr) int
dir_policy_permits_address(uint32_t addr)
{ {
int a; int a;
@ -110,8 +112,11 @@ int dir_policy_permits_address(uint32_t addr)
return 0; return 0;
} }
/** Return true iff the directory purpose 'purpose' must use an
* anonymous connection to a directory. */
static int static int
purpose_is_private(uint8_t purpose) { purpose_is_private(uint8_t purpose)
{
if (purpose == DIR_PURPOSE_FETCH_DIR || if (purpose == DIR_PURPOSE_FETCH_DIR ||
purpose == DIR_PURPOSE_UPLOAD_DIR || purpose == DIR_PURPOSE_UPLOAD_DIR ||
purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) purpose == DIR_PURPOSE_FETCH_RUNNING_LIST)
@ -363,7 +368,8 @@ directory_initiate_command(const char *address, uint32_t addr,
static void static void
directory_send_command(connection_t *conn, const char *platform, directory_send_command(connection_t *conn, const char *platform,
int purpose, const char *resource, int purpose, const char *resource,
const char *payload, size_t payload_len) { const char *payload, size_t payload_len)
{
char tmp[8192]; char tmp[8192];
char proxystring[256]; char proxystring[256];
char proxyauthstring[256]; char proxyauthstring[256];
@ -846,7 +852,10 @@ connection_dir_client_reached_eof(connection_t *conn)
return 0; return 0;
} }
int connection_dir_reached_eof(connection_t *conn) { /** Called when a directory connection reaches EOF */
int
connection_dir_reached_eof(connection_t *conn)
{
int retval; int retval;
if (conn->state != DIR_CONN_STATE_CLIENT_READING) { if (conn->state != DIR_CONN_STATE_CLIENT_READING) {
log_fn(LOG_INFO,"conn reached eof, not reading. Closing."); log_fn(LOG_INFO,"conn reached eof, not reading. Closing.");
@ -863,8 +872,8 @@ int connection_dir_reached_eof(connection_t *conn) {
/** Read handler for directory connections. (That's connections <em>to</em> /** Read handler for directory connections. (That's connections <em>to</em>
* directory servers and connections <em>at</em> directory servers.) * directory servers and connections <em>at</em> directory servers.)
*/ */
int connection_dir_process_inbuf(connection_t *conn) { int connection_dir_process_inbuf(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_DIR); tor_assert(conn->type == CONN_TYPE_DIR);
@ -910,7 +919,8 @@ write_http_status_line(connection_t *conn, int status,
* Else return 0. * Else return 0.
*/ */
static int static int
already_fetching_directory(int purpose) { already_fetching_directory(int purpose)
{
int i, n; int i, n;
connection_t *conn; connection_t *conn;
connection_t **carray; connection_t **carray;
@ -1116,7 +1126,9 @@ directory_handle_command_post(connection_t *conn, char *headers,
* from the inbuf, try to process it; otherwise, leave it on the * from the inbuf, try to process it; otherwise, leave it on the
* buffer. Return a 0 on success, or -1 on error. * buffer. Return a 0 on success, or -1 on error.
*/ */
static int directory_handle_command(connection_t *conn) { static int
directory_handle_command(connection_t *conn)
{
char *headers=NULL, *body=NULL; char *headers=NULL, *body=NULL;
size_t body_len=0; size_t body_len=0;
int r; int r;
@ -1155,8 +1167,9 @@ static int directory_handle_command(connection_t *conn) {
* been flushed. Close the connection or wait for a response as * been flushed. Close the connection or wait for a response as
* appropriate. * appropriate.
*/ */
int connection_dir_finished_flushing(connection_t *conn) { int
connection_dir_finished_flushing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_DIR); tor_assert(conn->type == CONN_TYPE_DIR);
@ -1180,7 +1193,8 @@ int connection_dir_finished_flushing(connection_t *conn) {
/** Connected handler for directory connections: begin sending data to the /** Connected handler for directory connections: begin sending data to the
* server */ * server */
int connection_dir_finished_connecting(connection_t *conn) int
connection_dir_finished_connecting(connection_t *conn)
{ {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_DIR); tor_assert(conn->type == CONN_TYPE_DIR);

View File

@ -196,7 +196,8 @@ dirserv_router_fingerprint_is_known(const routerinfo_t *router)
/** If we are an authoritative dirserver, and the list of approved /** If we are an authoritative dirserver, and the list of approved
* servers contains one whose identity key digest is <b>digest</b>, * servers contains one whose identity key digest is <b>digest</b>,
* return that router's nickname. Otherwise return NULL. */ * return that router's nickname. Otherwise return NULL. */
const char *dirserv_get_nickname_by_digest(const char *digest) const char *
dirserv_get_nickname_by_digest(const char *digest)
{ {
char hexdigest[HEX_DIGEST_LEN+1]; char hexdigest[HEX_DIGEST_LEN+1];
if (!fingerprint_list) if (!fingerprint_list)
@ -730,6 +731,7 @@ static size_t the_directory_len = 0;
static char *the_directory_z = NULL; static char *the_directory_z = NULL;
static size_t the_directory_z_len = 0; static size_t the_directory_z_len = 0;
/** DOCDOC */
typedef struct cached_dir_t { typedef struct cached_dir_t {
char *dir; char *dir;
char *dir_z; char *dir_z;
@ -745,7 +747,8 @@ static cached_dir_t cached_runningrouters = { NULL, NULL, 0, 0, 0 };
/** If we have no cached directory, or it is older than <b>when</b>, then /** If we have no cached directory, or it is older than <b>when</b>, then
* replace it with <b>directory</b>, published at <b>when</b>. * replace it with <b>directory</b>, published at <b>when</b>.
*/ */
void dirserv_set_cached_directory(const char *directory, time_t when, void
dirserv_set_cached_directory(const char *directory, time_t when,
int is_running_routers) int is_running_routers)
{ {
time_t now; time_t now;
@ -781,7 +784,8 @@ void dirserv_set_cached_directory(const char *directory, time_t when,
/** Set *<b>directory</b> to the most recently generated encoded signed /** Set *<b>directory</b> to the most recently generated encoded signed
* directory, generating a new one as necessary. If not an authoritative * directory, generating a new one as necessary. If not an authoritative
* directory may return 0 if no directory is yet cached.*/ * directory may return 0 if no directory is yet cached.*/
size_t dirserv_get_directory(const char **directory, int compress) size_t
dirserv_get_directory(const char **directory, int compress)
{ {
if (!get_options()->AuthoritativeDir) { if (!get_options()->AuthoritativeDir) {
cached_dir_t *d = &cached_directory; cached_dir_t *d = &cached_directory;
@ -807,7 +811,8 @@ size_t dirserv_get_directory(const char **directory, int compress)
/** /**
* Generate a fresh directory (authdirservers only.) * Generate a fresh directory (authdirservers only.)
*/ */
static int dirserv_regenerate_directory(void) static int
dirserv_regenerate_directory(void)
{ {
char *new_directory=NULL; char *new_directory=NULL;
@ -859,7 +864,8 @@ static char *the_runningrouters_z=NULL;
static size_t the_runningrouters_z_len=0; static size_t the_runningrouters_z_len=0;
/** Replace the current running-routers list with a newly generated one. */ /** Replace the current running-routers list with a newly generated one. */
static int generate_runningrouters(crypto_pk_env_t *private_key) static int
generate_runningrouters(crypto_pk_env_t *private_key)
{ {
char *s=NULL, *cp; char *s=NULL, *cp;
char *router_status=NULL; char *router_status=NULL;
@ -942,7 +948,8 @@ static int generate_runningrouters(crypto_pk_env_t *private_key)
/** Set *<b>rr</b> to the most recently generated encoded signed /** Set *<b>rr</b> to the most recently generated encoded signed
* running-routers list, generating a new one as necessary. Return the * running-routers list, generating a new one as necessary. Return the
* size of the directory on success, and 0 on failure. */ * size of the directory on success, and 0 on failure. */
size_t dirserv_get_runningrouters(const char **rr, int compress) size_t
dirserv_get_runningrouters(const char **rr, int compress)
{ {
if (!get_options()->AuthoritativeDir) { if (!get_options()->AuthoritativeDir) {
cached_dir_t *d = &cached_runningrouters; cached_dir_t *d = &cached_runningrouters;
@ -1012,6 +1019,7 @@ dirserv_orconn_tls_done(const char *address,
} }
} }
/** Release all storage used by the directory server. */
void void
dirserv_free_all(void) dirserv_free_all(void)
{ {

View File

@ -91,19 +91,25 @@ SPLAY_PROTOTYPE(cache_tree, cached_resolve, node, compare_cached_resolves);
SPLAY_GENERATE(cache_tree, cached_resolve, node, compare_cached_resolves); SPLAY_GENERATE(cache_tree, cached_resolve, node, compare_cached_resolves);
/** Initialize the DNS cache. */ /** Initialize the DNS cache. */
static void init_cache_tree(void) { static void
init_cache_tree(void)
{
SPLAY_INIT(&cache_root); SPLAY_INIT(&cache_root);
} }
/** Initialize the DNS subsystem; called by the OR process. */ /** Initialize the DNS subsystem; called by the OR process. */
void dns_init(void) { void
dns_init(void)
{
init_cache_tree(); init_cache_tree();
last_rotation_time=time(NULL); last_rotation_time=time(NULL);
spawn_enough_dnsworkers(); spawn_enough_dnsworkers();
} }
/** Helper: free storage held by an entry in the DNS cache. */
static void static void
_free_cached_resolve(struct cached_resolve *r) { _free_cached_resolve(struct cached_resolve *r)
{
while (r->pending_connections) { while (r->pending_connections) {
struct pending_connection_t *victim = r->pending_connections; struct pending_connection_t *victim = r->pending_connections;
r->pending_connections = victim->next; r->pending_connections = victim->next;
@ -112,6 +118,7 @@ _free_cached_resolve(struct cached_resolve *r) {
tor_free(r); tor_free(r);
} }
/** Free all storage held in the DNS cache */
void void
dns_free_all(void) dns_free_all(void)
{ {
@ -129,7 +136,9 @@ static struct cached_resolve *newest_cached_resolve = NULL;
/** Remove every cached_resolve whose <b>expire</b> time is before <b>now</b> /** Remove every cached_resolve whose <b>expire</b> time is before <b>now</b>
* from the cache. */ * from the cache. */
static void purge_expired_resolves(uint32_t now) { static void
purge_expired_resolves(uint32_t now)
{
struct cached_resolve *resolve; struct cached_resolve *resolve;
struct pending_connection_t *pend; struct pending_connection_t *pend;
connection_t *pendconn; connection_t *pendconn;
@ -169,7 +178,10 @@ static void purge_expired_resolves(uint32_t now) {
} }
} }
static void send_resolved_cell(connection_t *conn, uint8_t answer_type) /** Send a response to the RESOVLE request of a connection. answer_type must
* be one of RESOLVED_TYPE_(IPV4|ERROR|ERROR_TRANSIENT) */
static void
send_resolved_cell(connection_t *conn, uint8_t answer_type)
{ {
char buf[RELAY_PAYLOAD_SIZE]; char buf[RELAY_PAYLOAD_SIZE];
size_t buflen; size_t buflen;
@ -223,7 +235,9 @@ insert_resolve(struct cached_resolve *r)
* Else, if not seen before, add conn to pending list, hand to * Else, if not seen before, add conn to pending list, hand to
* dns farm, and return 0. * dns farm, and return 0.
*/ */
int dns_resolve(connection_t *exitconn) { int
dns_resolve(connection_t *exitconn)
{
struct cached_resolve *resolve; struct cached_resolve *resolve;
struct cached_resolve search; struct cached_resolve search;
struct pending_connection_t *pending_connection; struct pending_connection_t *pending_connection;
@ -305,7 +319,9 @@ int dns_resolve(connection_t *exitconn) {
/** Find or spawn a dns worker process to handle resolving /** Find or spawn a dns worker process to handle resolving
* <b>exitconn</b>-\>address; tell that dns worker to begin resolving. * <b>exitconn</b>-\>address; tell that dns worker to begin resolving.
*/ */
static int assign_to_dnsworker(connection_t *exitconn) { static int
assign_to_dnsworker(connection_t *exitconn)
{
connection_t *dnsconn; connection_t *dnsconn;
unsigned char len; unsigned char len;
@ -341,7 +357,8 @@ static int assign_to_dnsworker(connection_t *exitconn) {
/** Remove <b>conn</b> from the list of connections waiting for conn-\>address. /** Remove <b>conn</b> from the list of connections waiting for conn-\>address.
*/ */
void connection_dns_remove(connection_t *conn) void
connection_dns_remove(connection_t *conn)
{ {
struct pending_connection_t *pend, *victim; struct pending_connection_t *pend, *victim;
struct cached_resolve search; struct cached_resolve search;
@ -386,7 +403,9 @@ void connection_dns_remove(connection_t *conn)
/** Log an error and abort if conn is waiting for a DNS resolve. /** Log an error and abort if conn is waiting for a DNS resolve.
*/ */
void assert_connection_edge_not_dns_pending(connection_t *conn) { void
assert_connection_edge_not_dns_pending(connection_t *conn)
{
struct pending_connection_t *pend; struct pending_connection_t *pend;
struct cached_resolve *resolve; struct cached_resolve *resolve;
@ -401,7 +420,9 @@ void assert_connection_edge_not_dns_pending(connection_t *conn) {
/** Log an error and abort if any connection waiting for a DNS resolve is /** Log an error and abort if any connection waiting for a DNS resolve is
* corrupted. */ * corrupted. */
void assert_all_pending_dns_resolves_ok(void) { void
assert_all_pending_dns_resolves_ok(void)
{
struct pending_connection_t *pend; struct pending_connection_t *pend;
struct cached_resolve *resolve; struct cached_resolve *resolve;
@ -420,7 +441,9 @@ void assert_all_pending_dns_resolves_ok(void) {
* the resolve for <b>address</b> itself, and remove any cached results for * the resolve for <b>address</b> itself, and remove any cached results for
* <b>address</b> from the cache. * <b>address</b> from the cache.
*/ */
void dns_cancel_pending_resolve(char *address) { void
dns_cancel_pending_resolve(char *address)
{
struct pending_connection_t *pend; struct pending_connection_t *pend;
struct cached_resolve search; struct cached_resolve search;
struct cached_resolve *resolve; struct cached_resolve *resolve;
@ -469,7 +492,9 @@ void dns_cancel_pending_resolve(char *address) {
/** Remove <b>resolve</b> from the cache. /** Remove <b>resolve</b> from the cache.
*/ */
static void dns_purge_resolve(struct cached_resolve *resolve) { static void
dns_purge_resolve(struct cached_resolve *resolve)
{
struct cached_resolve *tmp; struct cached_resolve *tmp;
/* remove resolve from the linked list */ /* remove resolve from the linked list */
@ -500,7 +525,9 @@ static void dns_purge_resolve(struct cached_resolve *resolve) {
* <b>outcome</b> is one of * <b>outcome</b> is one of
* DNS_RESOLVE_{FAILED_TRANSIENT|FAILED_PERMANENT|SUCCEEDED}. * DNS_RESOLVE_{FAILED_TRANSIENT|FAILED_PERMANENT|SUCCEEDED}.
*/ */
static void dns_found_answer(char *address, uint32_t addr, char outcome) { static void
dns_found_answer(char *address, uint32_t addr, char outcome)
{
struct pending_connection_t *pend; struct pending_connection_t *pend;
struct cached_resolve search; struct cached_resolve search;
struct cached_resolve *resolve; struct cached_resolve *resolve;
@ -604,14 +631,18 @@ static void dns_found_answer(char *address, uint32_t addr, char outcome) {
*/ */
/** Write handler: called when we've pushed a request to a dnsworker. */ /** Write handler: called when we've pushed a request to a dnsworker. */
int connection_dns_finished_flushing(connection_t *conn) { int
connection_dns_finished_flushing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_DNSWORKER); tor_assert(conn->type == CONN_TYPE_DNSWORKER);
connection_stop_writing(conn); connection_stop_writing(conn);
return 0; return 0;
} }
int connection_dns_reached_eof(connection_t *conn) { int
connection_dns_reached_eof(connection_t *conn)
{
log_fn(LOG_WARN,"Read eof. Worker died unexpectedly."); log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
if (conn->state == DNSWORKER_STATE_BUSY) { if (conn->state == DNSWORKER_STATE_BUSY) {
/* don't cancel the resolve here -- it would be cancelled in /* don't cancel the resolve here -- it would be cancelled in
@ -628,7 +659,9 @@ int connection_dns_reached_eof(connection_t *conn) {
/** Read handler: called when we get data from a dnsworker. See /** Read handler: called when we get data from a dnsworker. See
* if we have a complete answer. If so, call dns_found_answer on the * if we have a complete answer. If so, call dns_found_answer on the
* result. If not, wait. Returns 0. */ * result. If not, wait. Returns 0. */
int connection_dns_process_inbuf(connection_t *conn) { int
connection_dns_process_inbuf(connection_t *conn)
{
char success; char success;
uint32_t addr; uint32_t addr;
@ -681,7 +714,8 @@ int connection_dns_process_inbuf(connection_t *conn) {
/** Close and re-open all idle dnsworkers; schedule busy ones to be closed /** Close and re-open all idle dnsworkers; schedule busy ones to be closed
* and re-opened once they're no longer busy. * and re-opened once they're no longer busy.
**/ **/
void dnsworkers_rotate(void) void
dnsworkers_rotate(void)
{ {
connection_t *dnsconn; connection_t *dnsconn;
log_fn(LOG_INFO, "Rotating DNS workers."); log_fn(LOG_INFO, "Rotating DNS workers.");
@ -711,7 +745,9 @@ void dnsworkers_rotate(void)
* The dnsworker runs indefinitely, until its connection is closed or an error * The dnsworker runs indefinitely, until its connection is closed or an error
* occurs. * occurs.
*/ */
static int dnsworker_main(void *data) { static int
dnsworker_main(void *data)
{
char address[MAX_ADDRESSLEN]; char address[MAX_ADDRESSLEN];
unsigned char address_len; unsigned char address_len;
char answer[5]; char answer[5];
@ -782,7 +818,9 @@ static int dnsworker_main(void *data) {
/** Launch a new DNS worker; return 0 on success, -1 on failure. /** Launch a new DNS worker; return 0 on success, -1 on failure.
*/ */
static int spawn_dnsworker(void) { static int
spawn_dnsworker(void)
{
int *fdarray; int *fdarray;
int fd; int fd;
connection_t *conn; connection_t *conn;
@ -828,7 +866,9 @@ static int spawn_dnsworker(void) {
/** If we have too many or too few DNS workers, spawn or kill some. /** If we have too many or too few DNS workers, spawn or kill some.
*/ */
static void spawn_enough_dnsworkers(void) { static void
spawn_enough_dnsworkers(void)
{
int num_dnsworkers_needed; /* aim to have 1 more than needed, int num_dnsworkers_needed; /* aim to have 1 more than needed,
* but no less than min and no more than max */ * but no less than min and no more than max */
connection_t *dnsconn; connection_t *dnsconn;

View File

@ -209,7 +209,9 @@ accounting_parse_options(or_options_t *options, int validate_only)
/** If we want to manage the accounting system and potentially /** If we want to manage the accounting system and potentially
* hibernate, return 1, else return 0. * hibernate, return 1, else return 0.
*/ */
int accounting_is_enabled(or_options_t *options) { int
accounting_is_enabled(or_options_t *options)
{
if (options->AccountingMax) if (options->AccountingMax)
return 1; return 1;
return 0; return 0;
@ -366,7 +368,8 @@ update_expected_bandwidth(void)
* the start and end of the interval, and clear byte/time totals. * the start and end of the interval, and clear byte/time totals.
*/ */
static void static void
reset_accounting(time_t now) { reset_accounting(time_t now)
{
log_fn(LOG_INFO, "Starting new accounting interval."); log_fn(LOG_INFO, "Starting new accounting interval.");
update_expected_bandwidth(); update_expected_bandwidth();
interval_start_time = start_of_accounting_period_containing(now); interval_start_time = start_of_accounting_period_containing(now);
@ -400,6 +403,8 @@ time_to_record_bandwidth_usage(time_t now)
return 0; return 0;
} }
/** Invoked once per second. Checks whether it is time to hibernate,
* record bandwidth used, etc. */
void void
accounting_run_housekeeping(time_t now) accounting_run_housekeeping(time_t now)
{ {
@ -640,7 +645,8 @@ hibernate_hard_limit_reached(void)
/** Return true iff we have sent/received almost all the bytes we are willing /** Return true iff we have sent/received almost all the bytes we are willing
* to send/receive this interval. */ * to send/receive this interval. */
static int hibernate_soft_limit_reached(void) static int
hibernate_soft_limit_reached(void)
{ {
uint64_t soft_limit = (uint64_t) ((get_options()->AccountingMax) * .95); uint64_t soft_limit = (uint64_t) ((get_options()->AccountingMax) * .95);
if (!soft_limit) if (!soft_limit)
@ -652,7 +658,9 @@ static int hibernate_soft_limit_reached(void)
/** Called when we get a SIGINT, or when bandwidth soft limit is /** Called when we get a SIGINT, or when bandwidth soft limit is
* reached. Puts us into "loose hibernation": we don't accept new * reached. Puts us into "loose hibernation": we don't accept new
* connections, but we continue handling old ones. */ * connections, but we continue handling old ones. */
static void hibernate_begin(int new_state, time_t now) { static void
hibernate_begin(int new_state, time_t now)
{
connection_t *conn; connection_t *conn;
or_options_t *options = get_options(); or_options_t *options = get_options();
@ -689,8 +697,8 @@ static void hibernate_begin(int new_state, time_t now) {
/** Called when we've been hibernating and our timeout is reached. */ /** Called when we've been hibernating and our timeout is reached. */
static void static void
hibernate_end(int new_state) { hibernate_end(int new_state)
{
tor_assert(hibernate_state == HIBERNATE_STATE_LOWBANDWIDTH || tor_assert(hibernate_state == HIBERNATE_STATE_LOWBANDWIDTH ||
hibernate_state == HIBERNATE_STATE_DORMANT); hibernate_state == HIBERNATE_STATE_DORMANT);
@ -704,20 +712,23 @@ hibernate_end(int new_state) {
/** A wrapper around hibernate_begin, for when we get SIGINT. */ /** A wrapper around hibernate_begin, for when we get SIGINT. */
void void
hibernate_begin_shutdown(void) { hibernate_begin_shutdown(void)
{
hibernate_begin(HIBERNATE_STATE_EXITING, time(NULL)); hibernate_begin(HIBERNATE_STATE_EXITING, time(NULL));
} }
/** Return true iff we are currently hibernating. */ /** Return true iff we are currently hibernating. */
int int
we_are_hibernating(void) { we_are_hibernating(void)
{
return hibernate_state != HIBERNATE_STATE_LIVE; return hibernate_state != HIBERNATE_STATE_LIVE;
} }
/** If we aren't currently dormant, close all connections and become /** If we aren't currently dormant, close all connections and become
* dormant. */ * dormant. */
static void static void
hibernate_go_dormant(time_t now) { hibernate_go_dormant(time_t now)
{
connection_t *conn; connection_t *conn;
if (hibernate_state == HIBERNATE_STATE_DORMANT) if (hibernate_state == HIBERNATE_STATE_DORMANT)
@ -780,7 +791,9 @@ hibernate_end_time_elapsed(time_t now)
/** Consider our environment and decide if it's time /** Consider our environment and decide if it's time
* to start/stop hibernating. * to start/stop hibernating.
*/ */
void consider_hibernation(time_t now) { void
consider_hibernation(time_t now)
{
int accounting_enabled = get_options()->AccountingMax != 0; int accounting_enabled = get_options()->AccountingMax != 0;
char buf[ISO_TIME_LEN+1]; char buf[ISO_TIME_LEN+1];

View File

@ -121,7 +121,9 @@ static int nt_service_is_stopped(void);
* connection's socket must be set; the connection starts out * connection's socket must be set; the connection starts out
* non-reading and non-writing. * non-reading and non-writing.
*/ */
int connection_add(connection_t *conn) { int
connection_add(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->s >= 0); tor_assert(conn->s >= 0);
@ -153,7 +155,9 @@ int connection_add(connection_t *conn) {
* corresponding poll entry. Calling this function will shift the last * corresponding poll entry. Calling this function will shift the last
* connection (if any) into the position occupied by conn. * connection (if any) into the position occupied by conn.
*/ */
int connection_remove(connection_t *conn) { int
connection_remove(connection_t *conn)
{
int current_index; int current_index;
tor_assert(conn); tor_assert(conn);
@ -188,7 +192,9 @@ int connection_remove(connection_t *conn) {
* *
* Then free it. * Then free it.
*/ */
static void connection_unlink(connection_t *conn, int remove) { static void
connection_unlink(connection_t *conn, int remove)
{
circuit_about_to_close_connection(conn); circuit_about_to_close_connection(conn);
connection_about_to_close_connection(conn); connection_about_to_close_connection(conn);
if (remove) { if (remove) {
@ -212,12 +218,16 @@ add_connection_to_closeable_list(connection_t *conn)
} }
/** Return 1 if conn is on the closeable list, else return 0. */ /** Return 1 if conn is on the closeable list, else return 0. */
int connection_is_on_closeable_list(connection_t *conn) { int
connection_is_on_closeable_list(connection_t *conn)
{
return smartlist_isin(closeable_connection_lst, conn); return smartlist_isin(closeable_connection_lst, conn);
} }
/** Return true iff conn is in the current poll array. */ /** Return true iff conn is in the current poll array. */
int connection_in_array(connection_t *conn) { int
connection_in_array(connection_t *conn)
{
int i; int i;
for (i=0; i<nfds; ++i) { for (i=0; i<nfds; ++i) {
if (conn==connection_array[i]) if (conn==connection_array[i])
@ -230,7 +240,9 @@ int connection_in_array(connection_t *conn) {
* to the length of the array. <b>*array</b> and <b>*n</b> must not * to the length of the array. <b>*array</b> and <b>*n</b> must not
* be modified. * be modified.
*/ */
void get_connection_array(connection_t ***array, int *n) { void
get_connection_array(connection_t ***array, int *n)
{
*array = connection_array; *array = connection_array;
*n = nfds; *n = nfds;
} }
@ -238,7 +250,9 @@ void get_connection_array(connection_t ***array, int *n) {
/** Set the event mask on <b>conn</b> to <b>events</b>. (The event /** Set the event mask on <b>conn</b> to <b>events</b>. (The event
* mask is a bitmask whose bits are EV_READ and EV_WRITE.) * mask is a bitmask whose bits are EV_READ and EV_WRITE.)
*/ */
void connection_watch_events(connection_t *conn, short events) { void
connection_watch_events(connection_t *conn, short events)
{
int r; int r;
tor_assert(conn); tor_assert(conn);
@ -269,14 +283,18 @@ void connection_watch_events(connection_t *conn, short events) {
} }
/** Return true iff <b>conn</b> is listening for read events. */ /** Return true iff <b>conn</b> is listening for read events. */
int connection_is_reading(connection_t *conn) { int
connection_is_reading(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
return conn->read_event && event_pending(conn->read_event, EV_READ, NULL); return conn->read_event && event_pending(conn->read_event, EV_READ, NULL);
} }
/** Tell the main loop to stop notifying <b>conn</b> of any read events. */ /** Tell the main loop to stop notifying <b>conn</b> of any read events. */
void connection_stop_reading(connection_t *conn) { void
connection_stop_reading(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->read_event); tor_assert(conn->read_event);
@ -287,7 +305,9 @@ void connection_stop_reading(connection_t *conn) {
} }
/** Tell the main loop to start notifying <b>conn</b> of any read events. */ /** Tell the main loop to start notifying <b>conn</b> of any read events. */
void connection_start_reading(connection_t *conn) { void
connection_start_reading(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->read_event); tor_assert(conn->read_event);
@ -297,14 +317,18 @@ void connection_start_reading(connection_t *conn) {
} }
/** Return true iff <b>conn</b> is listening for write events. */ /** Return true iff <b>conn</b> is listening for write events. */
int connection_is_writing(connection_t *conn) { int
connection_is_writing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
return conn->write_event && event_pending(conn->write_event, EV_WRITE, NULL); return conn->write_event && event_pending(conn->write_event, EV_WRITE, NULL);
} }
/** Tell the main loop to stop notifying <b>conn</b> of any write events. */ /** Tell the main loop to stop notifying <b>conn</b> of any write events. */
void connection_stop_writing(connection_t *conn) { void
connection_stop_writing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->write_event); tor_assert(conn->write_event);
@ -315,7 +339,9 @@ void connection_stop_writing(connection_t *conn) {
} }
/** Tell the main loop to start notifying <b>conn</b> of any write events. */ /** Tell the main loop to start notifying <b>conn</b> of any write events. */
void connection_start_writing(connection_t *conn) { void
connection_start_writing(connection_t *conn)
{
tor_assert(conn); tor_assert(conn);
tor_assert(conn->write_event); tor_assert(conn->write_event);
@ -371,7 +397,8 @@ conn_read_callback(int fd, short event, void *_conn)
/** Libevent callback: this gets invoked when (connection_t*)<b>conn</b> has /** Libevent callback: this gets invoked when (connection_t*)<b>conn</b> has
* some data to write. */ * some data to write. */
static void conn_write_callback(int fd, short events, void *_conn) static void
conn_write_callback(int fd, short events, void *_conn)
{ {
connection_t *conn = _conn; connection_t *conn = _conn;
@ -404,7 +431,9 @@ static void conn_write_callback(int fd, short events, void *_conn)
* all other lists, close it, and free it. * all other lists, close it, and free it.
* Returns 1 if the connection was closed, 0 otherwise. * Returns 1 if the connection was closed, 0 otherwise.
*/ */
static int conn_close_if_marked(int i) { static int
conn_close_if_marked(int i)
{
connection_t *conn; connection_t *conn;
int retval; int retval;
@ -456,7 +485,9 @@ static int conn_close_if_marked(int i) {
* and try another directory fetch. Kill off all the circuit_wait * and try another directory fetch. Kill off all the circuit_wait
* streams that are waiting now, since they will all timeout anyway. * streams that are waiting now, since they will all timeout anyway.
*/ */
void directory_all_unreachable(time_t now) { void
directory_all_unreachable(time_t now)
{
connection_t *conn; connection_t *conn;
has_fetched_directory=0; has_fetched_directory=0;
@ -470,6 +501,9 @@ void directory_all_unreachable(time_t now) {
} }
} }
/**
* Return the interval to wait betweeen directory downloads, in seconds.
*/
static INLINE int static INLINE int
get_dir_fetch_period(or_options_t *options) get_dir_fetch_period(or_options_t *options)
{ {
@ -484,6 +518,9 @@ get_dir_fetch_period(or_options_t *options)
return 40*60; return 40*60;
} }
/**
* Return the interval to wait betweeen router status downloads, in seconds.
*/
static INLINE int static INLINE int
get_status_fetch_period(or_options_t *options) get_status_fetch_period(or_options_t *options)
{ {
@ -501,7 +538,9 @@ get_status_fetch_period(or_options_t *options)
/** This function is called whenever we successfully pull down a directory. /** This function is called whenever we successfully pull down a directory.
* If <b>identity_digest</b> is defined, it contains the digest of the * If <b>identity_digest</b> is defined, it contains the digest of the
* router that just gave us this directory. */ * router that just gave us this directory. */
void directory_has_arrived(time_t now, char *identity_digest) { void
directory_has_arrived(time_t now, char *identity_digest)
{
or_options_t *options = get_options(); or_options_t *options = get_options();
log_fn(LOG_INFO, "A directory has arrived."); log_fn(LOG_INFO, "A directory has arrived.");
@ -536,7 +575,9 @@ void directory_has_arrived(time_t now, char *identity_digest) {
/** Perform regular maintenance tasks for a single connection. This /** Perform regular maintenance tasks for a single connection. This
* function gets run once per second per connection by run_scheduled_events. * function gets run once per second per connection by run_scheduled_events.
*/ */
static void run_connection_housekeeping(int i, time_t now) { static void
run_connection_housekeeping(int i, time_t now)
{
cell_t cell; cell_t cell;
connection_t *conn = connection_array[i]; connection_t *conn = connection_array[i];
or_options_t *options = get_options(); or_options_t *options = get_options();
@ -598,7 +639,9 @@ static void run_connection_housekeeping(int i, time_t now) {
/** Perform regular maintenance tasks. This function gets run once per /** Perform regular maintenance tasks. This function gets run once per
* second by prepare_for_poll. * second by prepare_for_poll.
*/ */
static void run_scheduled_events(time_t now) { static void
run_scheduled_events(time_t now)
{
static time_t last_rotated_certificate = 0; static time_t last_rotated_certificate = 0;
static time_t time_to_check_listeners = 0; static time_t time_to_check_listeners = 0;
static time_t time_to_check_descriptor = 0; static time_t time_to_check_descriptor = 0;
@ -769,7 +812,8 @@ static void run_scheduled_events(time_t now) {
static struct event *timeout_event = NULL; static struct event *timeout_event = NULL;
/** Libevent callback: invoked once every second. */ /** Libevent callback: invoked once every second. */
static void second_elapsed_callback(int fd, short event, void *args) static void
second_elapsed_callback(int fd, short event, void *args)
{ {
static struct timeval one_second; static struct timeval one_second;
static long current_second = 0; static long current_second = 0;
@ -843,7 +887,9 @@ static void second_elapsed_callback(int fd, short event, void *args)
/** Called when we get a SIGHUP: reload configuration files and keys, /** Called when we get a SIGHUP: reload configuration files and keys,
* retry all connections, re-upload all descriptors, and so on. */ * retry all connections, re-upload all descriptors, and so on. */
static int do_hup(void) { static int
do_hup(void)
{
char keydir[512]; char keydir[512];
or_options_t *options = get_options(); or_options_t *options = get_options();
@ -894,7 +940,9 @@ static int do_hup(void) {
} }
/** Tor main loop. */ /** Tor main loop. */
static int do_main_loop(void) { static int
do_main_loop(void)
{
int loop_result; int loop_result;
/* load the private keys, if we're supposed to have them, and set up the /* load the private keys, if we're supposed to have them, and set up the
@ -1005,7 +1053,10 @@ control_signal_act(int the_signal)
return 0; return 0;
} }
static void signal_callback(int fd, short events, void *arg) /** Libevent callback: invoked when we get a signal.
*/
static void
signal_callback(int fd, short events, void *arg)
{ {
uintptr_t sig = (uintptr_t)arg; uintptr_t sig = (uintptr_t)arg;
switch (sig) switch (sig)
@ -1051,8 +1102,12 @@ static void signal_callback(int fd, short events, void *arg)
} }
} }
/**
* Write current memory uusage information to the log.
*/
static void static void
dumpmemusage(int severity) { dumpmemusage(int severity)
{
extern uint64_t buf_total_used; extern uint64_t buf_total_used;
extern uint64_t buf_total_alloc; extern uint64_t buf_total_alloc;
extern uint64_t rephist_total_alloc; extern uint64_t rephist_total_alloc;
@ -1067,7 +1122,8 @@ dumpmemusage(int severity) {
/** Write all statistics to the log, with log level 'severity'. Called /** Write all statistics to the log, with log level 'severity'. Called
* in response to a SIGUSR1. */ * in response to a SIGUSR1. */
static void static void
dumpstats(int severity) { dumpstats(int severity)
{
int i; int i;
connection_t *conn; connection_t *conn;
time_t now = time(NULL); time_t now = time(NULL);
@ -1144,7 +1200,8 @@ dumpstats(int severity) {
/** Called by exit() as we shut down the process. /** Called by exit() as we shut down the process.
*/ */
static void exit_function(void) static void
exit_function(void)
{ {
/* NOTE: If we ever daemonize, this gets called immediately. That's /* NOTE: If we ever daemonize, this gets called immediately. That's
* okay for now, because we only use this on Windows. */ * okay for now, because we only use this on Windows. */
@ -1154,7 +1211,8 @@ static void exit_function(void)
} }
/** Set up the signal handlers for either parent or child. */ /** Set up the signal handlers for either parent or child. */
void handle_signals(int is_parent) void
handle_signals(int is_parent)
{ {
#ifndef MS_WINDOWS /* do signal stuff only on unix */ #ifndef MS_WINDOWS /* do signal stuff only on unix */
int i; int i;
@ -1199,7 +1257,9 @@ void handle_signals(int is_parent)
/** Main entry point for the Tor command-line client. /** Main entry point for the Tor command-line client.
*/ */
static int tor_init(int argc, char *argv[]) { static int
tor_init(int argc, char *argv[])
{
time_of_process_start = time(NULL); time_of_process_start = time(NULL);
closeable_connection_lst = smartlist_create(); closeable_connection_lst = smartlist_create();
/* Initialize the history structures. */ /* Initialize the history structures. */
@ -1250,7 +1310,8 @@ static int tor_init(int argc, char *argv[]) {
* *
* Also valgrind should then report 0 reachable in its * Also valgrind should then report 0 reachable in its
* leak report */ * leak report */
void tor_free_all(int postfork) void
tor_free_all(int postfork)
{ {
routerlist_free_current(); routerlist_free_current();
free_trusted_dir_servers(); free_trusted_dir_servers();
@ -1281,7 +1342,8 @@ void tor_free_all(int postfork)
} }
/** Do whatever cleanup is necessary before shutting Tor down. */ /** Do whatever cleanup is necessary before shutting Tor down. */
void tor_cleanup(void) { void
tor_cleanup(void) {
or_options_t *options = get_options(); or_options_t *options = get_options();
/* Remove our pid file. We don't care if there was an error when we /* Remove our pid file. We don't care if there was an error when we
* unlink, nothing we could do about it anyways. */ * unlink, nothing we could do about it anyways. */
@ -1298,7 +1360,8 @@ void tor_cleanup(void) {
} }
/** Read/create keys as needed, and echo our fingerprint to stdout. */ /** Read/create keys as needed, and echo our fingerprint to stdout. */
static void do_list_fingerprint(void) static void
do_list_fingerprint(void)
{ {
char buf[FINGERPRINT_LEN+1]; char buf[FINGERPRINT_LEN+1];
crypto_pk_env_t *k; crypto_pk_env_t *k;
@ -1325,7 +1388,8 @@ static void do_list_fingerprint(void)
/** Entry point for password hashing: take the desired password from /** Entry point for password hashing: take the desired password from
* the command line, and print its salted hash to stdout. **/ * the command line, and print its salted hash to stdout. **/
static void do_hash_password(void) static void
do_hash_password(void)
{ {
char output[256]; char output[256];
@ -1357,7 +1421,9 @@ nt_service_is_stopped(void)
return 0; return 0;
} }
void nt_service_control(DWORD request) /** DOCDOC */
void
nt_service_control(DWORD request)
{ {
switch (request) { switch (request) {
case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_STOP:
@ -1369,7 +1435,9 @@ void nt_service_control(DWORD request)
SetServiceStatus(hStatus, &service_status); SetServiceStatus(hStatus, &service_status);
} }
void nt_service_body(int argc, char **argv) /** DOCDOC */
void
nt_service_body(int argc, char **argv)
{ {
int err; int err;
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
@ -1402,7 +1470,9 @@ void nt_service_body(int argc, char **argv)
return; return;
} }
void nt_service_main(void) /** DOCDOC */
void
nt_service_main(void)
{ {
SERVICE_TABLE_ENTRY table[2]; SERVICE_TABLE_ENTRY table[2];
DWORD result = 0; DWORD result = 0;
@ -1438,7 +1508,9 @@ void nt_service_main(void)
} }
} }
int nt_service_install() /** DOCDOC */
int
nt_service_install(void)
{ {
/* XXXX Problems with NT services: /* XXXX Problems with NT services:
* 1. The configuration file needs to be in the same directory as the .exe * 1. The configuration file needs to be in the same directory as the .exe
@ -1541,7 +1613,9 @@ int nt_service_install()
return 0; return 0;
} }
int nt_service_remove() /** DOCDOC */
int
nt_service_remove(void)
{ {
SC_HANDLE hSCManager = NULL; SC_HANDLE hSCManager = NULL;
SC_HANDLE hService = NULL; SC_HANDLE hService = NULL;
@ -1587,7 +1661,10 @@ int nt_service_remove()
} }
#endif #endif
int tor_main(int argc, char *argv[]) { /** DOCDOC */
int
tor_main(int argc, char *argv[])
{
#ifdef MS_WINDOWS_SERVICE #ifdef MS_WINDOWS_SERVICE
backup_argv = argv; backup_argv = argv;
backup_argc = argc; backup_argc = argc;

View File

@ -31,7 +31,9 @@ static int ol_length=0;
/** Add <b>circ</b> to the end of ol_list and return 0, except /** Add <b>circ</b> to the end of ol_list and return 0, except
* if ol_list is too long, in which case do nothing and return -1. * if ol_list is too long, in which case do nothing and return -1.
*/ */
int onion_pending_add(circuit_t *circ) { int
onion_pending_add(circuit_t *circ)
{
struct onion_queue_t *tmp; struct onion_queue_t *tmp;
time_t now = time(NULL); time_t now = time(NULL);
@ -73,7 +75,9 @@ int onion_pending_add(circuit_t *circ) {
/** Remove the first item from ol_list and return it, or return /** Remove the first item from ol_list and return it, or return
* NULL if the list is empty. * NULL if the list is empty.
*/ */
circuit_t *onion_next_task(void) { circuit_t *
onion_next_task(void)
{
circuit_t *circ; circuit_t *circ;
if (!ol_list) if (!ol_list)
@ -90,7 +94,9 @@ circuit_t *onion_next_task(void) {
/** Go through ol_list, find the onion_queue_t element which points to /** Go through ol_list, find the onion_queue_t element which points to
* circ, remove and free that element. Leave circ itself alone. * circ, remove and free that element. Leave circ itself alone.
*/ */
void onion_pending_remove(circuit_t *circ) { void
onion_pending_remove(circuit_t *circ)
{
struct onion_queue_t *tmpo, *victim; struct onion_queue_t *tmpo, *victim;
if (!ol_list) if (!ol_list)
@ -329,6 +335,7 @@ onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
return 0; return 0;
} }
/** DOCDOC */
int int
fast_server_handshake(const char *key_in, /* DIGEST_LEN bytes */ fast_server_handshake(const char *key_in, /* DIGEST_LEN bytes */
char *handshake_reply_out, /* DIGEST_LEN*2 bytes */ char *handshake_reply_out, /* DIGEST_LEN*2 bytes */
@ -359,6 +366,7 @@ fast_server_handshake(const char *key_in, /* DIGEST_LEN bytes */
return 0; return 0;
} }
/** DOCDOC */
int int
fast_client_handshake(const char *handshake_state, /* DIGEST_LEN bytes */ fast_client_handshake(const char *handshake_state, /* DIGEST_LEN bytes */
const char *handshake_reply_out, /* DIGEST_LEN*2 bytes */ const char *handshake_reply_out, /* DIGEST_LEN*2 bytes */

View File

@ -44,7 +44,9 @@ unsigned long stats_n_relay_cells_delivered = 0;
/** Update digest from the payload of cell. Assign integrity part to /** Update digest from the payload of cell. Assign integrity part to
* cell. * cell.
*/ */
static void relay_set_digest(crypto_digest_env_t *digest, cell_t *cell) { static void
relay_set_digest(crypto_digest_env_t *digest, cell_t *cell)
{
char integrity[4]; char integrity[4];
relay_header_t rh; relay_header_t rh;
@ -63,7 +65,9 @@ static void relay_set_digest(crypto_digest_env_t *digest, cell_t *cell) {
* to 0). If the integrity part is valid, return 1, else restore digest * to 0). If the integrity part is valid, return 1, else restore digest
* and cell to their original state and return 0. * and cell to their original state and return 0.
*/ */
static int relay_digest_matches(crypto_digest_env_t *digest, cell_t *cell) { static int
relay_digest_matches(crypto_digest_env_t *digest, cell_t *cell)
{
char received_integrity[4], calculated_integrity[4]; char received_integrity[4], calculated_integrity[4];
relay_header_t rh; relay_header_t rh;
crypto_digest_env_t *backup_digest=NULL; crypto_digest_env_t *backup_digest=NULL;
@ -104,8 +108,10 @@ static int relay_digest_matches(crypto_digest_env_t *digest, cell_t *cell) {
* *
* Return -1 if the crypto fails, else return 0. * Return -1 if the crypto fails, else return 0.
*/ */
static int relay_crypt_one_payload(crypto_cipher_env_t *cipher, char *in, static int
int encrypt_mode) { relay_crypt_one_payload(crypto_cipher_env_t *cipher, char *in,
int encrypt_mode)
{
char out[CELL_PAYLOAD_SIZE]; /* 'in' must be this size too */ char out[CELL_PAYLOAD_SIZE]; /* 'in' must be this size too */
if (( encrypt_mode && crypto_cipher_encrypt(cipher, out, in, CELL_PAYLOAD_SIZE)) || if (( encrypt_mode && crypto_cipher_encrypt(cipher, out, in, CELL_PAYLOAD_SIZE)) ||
@ -126,8 +132,9 @@ static int relay_crypt_one_payload(crypto_cipher_env_t *cipher, char *in,
* - Else connection_or_write_cell_to_buf to the conn on the other * - Else connection_or_write_cell_to_buf to the conn on the other
* side of the circuit. * side of the circuit.
*/ */
int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, int
int cell_direction) { circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, int cell_direction)
{
connection_t *conn=NULL; connection_t *conn=NULL;
crypt_path_t *layer_hint=NULL; crypt_path_t *layer_hint=NULL;
char recognized=0; char recognized=0;
@ -214,8 +221,10 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
* else return 0. * else return 0.
*/ */
/* wrap this into receive_relay_cell one day */ /* wrap this into receive_relay_cell one day */
static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction, static int
crypt_path_t **layer_hint, char *recognized) { relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction,
crypt_path_t **layer_hint, char *recognized)
{
crypt_path_t *thishop; crypt_path_t *thishop;
relay_header_t rh; relay_header_t rh;
@ -370,7 +379,9 @@ relay_lookup_conn(circuit_t *circ, cell_t *cell, int cell_direction)
* network-order in the buffer <b>dest</b>. See tor-spec.txt for details * network-order in the buffer <b>dest</b>. See tor-spec.txt for details
* about the wire format. * about the wire format.
*/ */
void relay_header_pack(char *dest, const relay_header_t *src) { void
relay_header_pack(char *dest, const relay_header_t *src)
{
*(uint8_t*)(dest) = src->command; *(uint8_t*)(dest) = src->command;
set_uint16(dest+1, htons(src->recognized)); set_uint16(dest+1, htons(src->recognized));
@ -382,7 +393,9 @@ void relay_header_pack(char *dest, const relay_header_t *src) {
/** Unpack the network-order buffer <b>src</b> into a host-order /** Unpack the network-order buffer <b>src</b> into a host-order
* relay_header_t structure <b>dest</b>. * relay_header_t structure <b>dest</b>.
*/ */
void relay_header_unpack(relay_header_t *dest, const char *src) { void
relay_header_unpack(relay_header_t *dest, const char *src)
{
dest->command = *(uint8_t*)(src); dest->command = *(uint8_t*)(src);
dest->recognized = ntohs(get_uint16(src+1)); dest->recognized = ntohs(get_uint16(src+1));
@ -400,9 +413,11 @@ void relay_header_unpack(relay_header_t *dest, const char *src) {
* If you can't send the cell, mark the circuit for close and * If you can't send the cell, mark the circuit for close and
* return -1. Else return 0. * return -1. Else return 0.
*/ */
int connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int
connection_edge_send_command(connection_t *fromconn, circuit_t *circ,
int relay_command, const char *payload, int relay_command, const char *payload,
size_t payload_len, crypt_path_t *cpath_layer) { size_t payload_len, crypt_path_t *cpath_layer)
{
cell_t cell; cell_t cell;
relay_header_t rh; relay_header_t rh;
int cell_direction; int cell_direction;
@ -462,7 +477,8 @@ int connection_edge_send_command(connection_t *fromconn, circuit_t *circ,
* <b>reason</b> is -1 if no reason was provided. * <b>reason</b> is -1 if no reason was provided.
*/ */
static const char * static const char *
connection_edge_end_reason_str(int reason) { connection_edge_end_reason_str(int reason)
{
switch (reason) { switch (reason) {
case -1: case -1:
log_fn(LOG_WARN,"End cell arrived with length 0. Should be at least 1."); log_fn(LOG_WARN,"End cell arrived with length 0. Should be at least 1.");
@ -542,6 +558,9 @@ connection_edge_end_reason_socks5_response(int reason)
#define S_CASE(s) case s #define S_CASE(s) case s
#endif #endif
/** Given an errno from a failed exit connection, return a reason code
* appropriate for use in a RELAY END cell.
*/
int int
errno_to_end_reason(int e) errno_to_end_reason(int e)
{ {
@ -585,17 +604,22 @@ errno_to_end_reason(int e)
/** Return 1 if reason is something that you should retry if you /** Return 1 if reason is something that you should retry if you
* get the end cell before you've connected; else return 0. */ * get the end cell before you've connected; else return 0. */
static int static int
edge_reason_is_retriable(int reason) { edge_reason_is_retriable(int reason)
{
return reason == END_STREAM_REASON_HIBERNATING || return reason == END_STREAM_REASON_HIBERNATING ||
reason == END_STREAM_REASON_RESOURCELIMIT || reason == END_STREAM_REASON_RESOURCELIMIT ||
reason == END_STREAM_REASON_EXITPOLICY || reason == END_STREAM_REASON_EXITPOLICY ||
reason == END_STREAM_REASON_RESOLVEFAILED; reason == END_STREAM_REASON_RESOLVEFAILED;
} }
/** Called when we receive an END cell on a stream that isn't open yet.
* Arguments are as for connection_edge_process_relay_cell().
*/
static int static int
connection_edge_process_end_not_open( connection_edge_process_end_not_open(
relay_header_t *rh, cell_t *cell, circuit_t *circ, relay_header_t *rh, cell_t *cell, circuit_t *circ,
connection_t *conn, crypt_path_t *layer_hint) { connection_t *conn, crypt_path_t *layer_hint)
{
struct in_addr in; struct in_addr in;
routerinfo_t *exitrouter; routerinfo_t *exitrouter;
int reason = *(cell->payload+RELAY_HEADER_SIZE); int reason = *(cell->payload+RELAY_HEADER_SIZE);
@ -693,8 +717,8 @@ connection_edge_process_end_not_open(
static int static int
connection_edge_process_relay_cell_not_open( connection_edge_process_relay_cell_not_open(
relay_header_t *rh, cell_t *cell, circuit_t *circ, relay_header_t *rh, cell_t *cell, circuit_t *circ,
connection_t *conn, crypt_path_t *layer_hint) { connection_t *conn, crypt_path_t *layer_hint)
{
if (rh->command == RELAY_COMMAND_END) if (rh->command == RELAY_COMMAND_END)
return connection_edge_process_end_not_open(rh, cell, circ, conn, layer_hint); return connection_edge_process_end_not_open(rh, cell, circ, conn, layer_hint);
@ -995,7 +1019,9 @@ uint64_t stats_n_data_bytes_received = 0;
* Return -1 (and send a RELAY_END cell if necessary) if conn should * Return -1 (and send a RELAY_END cell if necessary) if conn should
* be marked for close, else return 0. * be marked for close, else return 0.
*/ */
int connection_edge_package_raw_inbuf(connection_t *conn, int package_partial) { int
connection_edge_package_raw_inbuf(connection_t *conn, int package_partial)
{
size_t amount_to_process, length; size_t amount_to_process, length;
char payload[CELL_PAYLOAD_SIZE]; char payload[CELL_PAYLOAD_SIZE];
circuit_t *circ; circuit_t *circ;
@ -1077,7 +1103,9 @@ repeat_connection_edge_package_raw_inbuf:
* If conn->outbuf is not too full, and our deliver window is * If conn->outbuf is not too full, and our deliver window is
* low, send back a suitable number of stream-level sendme cells. * low, send back a suitable number of stream-level sendme cells.
*/ */
void connection_edge_consider_sending_sendme(connection_t *conn) { void
connection_edge_consider_sending_sendme(connection_t *conn)
{
circuit_t *circ; circuit_t *circ;
if (connection_outbuf_too_full(conn)) if (connection_outbuf_too_full(conn))
@ -1125,8 +1153,8 @@ circuit_resume_edge_reading(circuit_t *circ, crypt_path_t *layer_hint)
static int static int
circuit_resume_edge_reading_helper(connection_t *conn, circuit_resume_edge_reading_helper(connection_t *conn,
circuit_t *circ, circuit_t *circ,
crypt_path_t *layer_hint) { crypt_path_t *layer_hint)
{
for ( ; conn; conn=conn->next_stream) { for ( ; conn; conn=conn->next_stream) {
if (conn->marked_for_close) if (conn->marked_for_close)
continue; continue;

View File

@ -53,7 +53,8 @@ rend_client_send_establish_rendezvous(circuit_t *circ)
* down introcirc if possible. * down introcirc if possible.
*/ */
int int
rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) { rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc)
{
size_t payload_len; size_t payload_len;
int r; int r;
char payload[RELAY_PAYLOAD_SIZE]; char payload[RELAY_PAYLOAD_SIZE];
@ -383,7 +384,9 @@ rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t requ
* with at least one intro point, move them to the next state; * with at least one intro point, move them to the next state;
* else fail them. * else fail them.
*/ */
void rend_client_desc_here(char *query) { void
rend_client_desc_here(char *query)
{
connection_t *conn; connection_t *conn;
rend_cache_entry_t *entry; rend_cache_entry_t *entry;
time_t now = time(NULL); time_t now = time(NULL);
@ -419,7 +422,9 @@ void rend_client_desc_here(char *query) {
/** strdup a nickname for a random introduction /** strdup a nickname for a random introduction
* point of query. return NULL if error. * point of query. return NULL if error.
*/ */
char *rend_client_get_random_intro(char *query) { char *
rend_client_get_random_intro(char *query)
{
int i; int i;
smartlist_t *sl; smartlist_t *sl;
char *choice; char *choice;

View File

@ -85,8 +85,8 @@ rend_encode_service_descriptor(rend_service_descriptor_t *desc,
* success, return a newly alloced service_descriptor_t. On failure, * success, return a newly alloced service_descriptor_t. On failure,
* return NULL. * return NULL.
*/ */
rend_service_descriptor_t *rend_parse_service_descriptor( rend_service_descriptor_t *
const char *str, size_t len) rend_parse_service_descriptor(const char *str, size_t len)
{ {
rend_service_descriptor_t *result = NULL; rend_service_descriptor_t *result = NULL;
int i; int i;
@ -144,7 +144,8 @@ rend_service_descriptor_t *rend_parse_service_descriptor(
* base32 encoded. NUL-terminates out. (We use this string to * base32 encoded. NUL-terminates out. (We use this string to
* identify services in directory requests and .onion URLs.) * identify services in directory requests and .onion URLs.)
*/ */
int rend_get_service_id(crypto_pk_env_t *pk, char *out) int
rend_get_service_id(crypto_pk_env_t *pk, char *out)
{ {
char buf[DIGEST_LEN]; char buf[DIGEST_LEN];
tor_assert(pk); tor_assert(pk);
@ -165,11 +166,13 @@ static strmap_t *rend_cache = NULL;
/** Initializes the service descriptor cache. /** Initializes the service descriptor cache.
*/ */
void rend_cache_init(void) void
rend_cache_init(void)
{ {
rend_cache = strmap_new(); rend_cache = strmap_new();
} }
/** Helper: free storage held by a single service descriptor cache entry. */
static void static void
_rend_cache_entry_free(void *p) _rend_cache_entry_free(void *p)
{ {
@ -179,6 +182,7 @@ _rend_cache_entry_free(void *p)
tor_free(e); tor_free(e);
} }
/** Free all storage held by the service descriptor cache. */
void void
rend_cache_free_all(void) rend_cache_free_all(void)
{ {
@ -188,7 +192,8 @@ rend_cache_free_all(void)
/** Removes all old entries from the service descriptor cache. /** Removes all old entries from the service descriptor cache.
*/ */
void rend_cache_clean(void) void
rend_cache_clean(void)
{ {
strmap_iter_t *iter; strmap_iter_t *iter;
const char *key; const char *key;
@ -210,7 +215,9 @@ void rend_cache_clean(void)
/** Return true iff <b>query</b> is a syntactically valid service ID (as /** Return true iff <b>query</b> is a syntactically valid service ID (as
* generated by rend_get_service_id). */ * generated by rend_get_service_id). */
int rend_valid_service_id(const char *query) { int
rend_valid_service_id(const char *query)
{
if (strlen(query) != REND_SERVICE_ID_LEN) if (strlen(query) != REND_SERVICE_ID_LEN)
return 0; return 0;
@ -223,7 +230,8 @@ int rend_valid_service_id(const char *query) {
/** If we have a cached rend_cache_entry_t for the service ID <b>query</b>, set /** If we have a cached rend_cache_entry_t for the service ID <b>query</b>, set
* *<b>e</b> to that entry and return 1. Else return 0. * *<b>e</b> to that entry and return 1. Else return 0.
*/ */
int rend_cache_lookup_entry(const char *query, rend_cache_entry_t **e) int
rend_cache_lookup_entry(const char *query, rend_cache_entry_t **e)
{ {
tor_assert(rend_cache); tor_assert(rend_cache);
if (!rend_valid_service_id(query)) if (!rend_valid_service_id(query))
@ -242,7 +250,8 @@ int rend_cache_lookup_entry(const char *query, rend_cache_entry_t **e)
* Note: calls to rend_cache_clean or rend_cache_store may invalidate * Note: calls to rend_cache_clean or rend_cache_store may invalidate
* *desc. * *desc.
*/ */
int rend_cache_lookup_desc(const char *query, const char **desc, size_t *desc_len) int
rend_cache_lookup_desc(const char *query, const char **desc, size_t *desc_len)
{ {
rend_cache_entry_t *e; rend_cache_entry_t *e;
int r; int r;
@ -260,7 +269,8 @@ int rend_cache_lookup_desc(const char *query, const char **desc, size_t *desc_le
* it's the same or older than one we've already got; return 1 if * it's the same or older than one we've already got; return 1 if
* it's novel. * it's novel.
*/ */
int rend_cache_store(const char *desc, size_t desc_len) int
rend_cache_store(const char *desc, size_t desc_len)
{ {
rend_cache_entry_t *e; rend_cache_entry_t *e;
rend_service_descriptor_t *parsed; rend_service_descriptor_t *parsed;
@ -322,7 +332,8 @@ int rend_cache_store(const char *desc, size_t desc_len)
/** Called when we get a rendezvous-related relay cell on circuit /** Called when we get a rendezvous-related relay cell on circuit
* <b>circ</b>. Dispatch on rendezvous relay command. */ * <b>circ</b>. Dispatch on rendezvous relay command. */
void rend_process_relay_cell(circuit_t *circ, int command, size_t length, void
rend_process_relay_cell(circuit_t *circ, int command, size_t length,
const char *payload) const char *payload)
{ {
int r; int r;

View File

@ -63,7 +63,8 @@ static smartlist_t *rend_service_list = NULL;
/** Release the storage held by <b>service</b>. /** Release the storage held by <b>service</b>.
*/ */
static void rend_service_free(rend_service_t *service) static void
rend_service_free(rend_service_t *service)
{ {
if (!service) return; if (!service) return;
tor_free(service->directory); tor_free(service->directory);
@ -82,7 +83,8 @@ static void rend_service_free(rend_service_t *service)
/** Release all the storage held in rend_service_list. /** Release all the storage held in rend_service_list.
*/ */
void rend_service_free_all(void) void
rend_service_free_all(void)
{ {
if (!rend_service_list) { if (!rend_service_list) {
return; return;
@ -95,7 +97,8 @@ void rend_service_free_all(void)
/** Validate <b>service</b> and add it to rend_service_list if possible. /** Validate <b>service</b> and add it to rend_service_list if possible.
*/ */
static void add_service(rend_service_t *service) static void
add_service(rend_service_t *service)
{ {
int i; int i;
rend_service_port_config_t *p; rend_service_port_config_t *p;
@ -131,7 +134,8 @@ static void add_service(rend_service_t *service)
* *
* IP defaults to 127.0.0.1; RealPort defaults to VirtualPort. * IP defaults to 127.0.0.1; RealPort defaults to VirtualPort.
*/ */
static rend_service_port_config_t *parse_port_config(const char *string) static rend_service_port_config_t *
parse_port_config(const char *string)
{ {
int virtport; int virtport;
int realport; int realport;
@ -186,8 +190,8 @@ static rend_service_port_config_t *parse_port_config(const char *string)
* failure. (If <b>validate_only</b> is set, parse, warn and return as * failure. (If <b>validate_only</b> is set, parse, warn and return as
* normal, but don't actually change the configured services.) * normal, but don't actually change the configured services.)
*/ */
int
int rend_config_services(or_options_t *options, int validate_only) rend_config_services(or_options_t *options, int validate_only)
{ {
struct config_line_t *line; struct config_line_t *line;
rend_service_t *service = NULL; rend_service_t *service = NULL;
@ -253,7 +257,8 @@ int rend_config_services(or_options_t *options, int validate_only)
/** Replace the old value of <b>service</b>-\>desc with one that reflects /** Replace the old value of <b>service</b>-\>desc with one that reflects
* the other fields in service. * the other fields in service.
*/ */
static void rend_service_update_descriptor(rend_service_t *service) static void
rend_service_update_descriptor(rend_service_t *service)
{ {
rend_service_descriptor_t *d; rend_service_descriptor_t *d;
circuit_t *circ; circuit_t *circ;
@ -288,7 +293,8 @@ static void rend_service_update_descriptor(rend_service_t *service)
/** Load and/or generate private keys for all hidden services. Return 0 on /** Load and/or generate private keys for all hidden services. Return 0 on
* success, -1 on failure. * success, -1 on failure.
*/ */
int rend_service_load_keys(void) int
rend_service_load_keys(void)
{ {
int i; int i;
rend_service_t *s; rend_service_t *s;
@ -828,7 +834,9 @@ upload_service_descriptor(rend_service_t *service)
* - Pick new intro points as necessary. * - Pick new intro points as necessary.
* - Launch circuits to any new intro points. * - Launch circuits to any new intro points.
*/ */
void rend_services_introduce(void) { void
rend_services_introduce(void)
{
int i,j,r; int i,j,r;
routerinfo_t *router; routerinfo_t *router;
rend_service_t *service; rend_service_t *service;
@ -937,7 +945,8 @@ void rend_services_introduce(void) {
* from now, and pick it independently for each service. * from now, and pick it independently for each service.
*/ */
void void
rend_consider_services_upload(time_t now) { rend_consider_services_upload(time_t now)
{
int i; int i;
rend_service_t *service; rend_service_t *service;
int rendpostperiod = get_options()->RendPostPeriod; int rendpostperiod = get_options()->RendPostPeriod;

View File

@ -5,7 +5,9 @@ const char rephist_c_id[] = "$Id$";
/** /**
* \file rephist.c * \file rephist.c
* \brief Basic history functionality for reputation module. * \brief Basic history and "reputation" functionality to remember
* which servers have worked in the past, how much bandwidth we've
* been using, which ports we tend to want, and so on.
**/ **/
#include "or.h" #include "or.h"
@ -57,7 +59,8 @@ static strmap_t *history_map = NULL;
/** Return the or_history_t for the named OR, creating it if necessary. /** Return the or_history_t for the named OR, creating it if necessary.
*/ */
static or_history_t *get_or_history(const char* id) static or_history_t *
get_or_history(const char* id)
{ {
or_history_t *hist; or_history_t *hist;
char hexid[HEX_DIGEST_LEN+1]; char hexid[HEX_DIGEST_LEN+1];
@ -81,8 +84,8 @@ static or_history_t *get_or_history(const char* id)
* the second, creating it if necessary. (ORs are identified by * the second, creating it if necessary. (ORs are identified by
* identity digest) * identity digest)
*/ */
static link_history_t *get_link_history(const char *from_id, static link_history_t *
const char *to_id) get_link_history(const char *from_id, const char *to_id)
{ {
or_history_t *orhist; or_history_t *orhist;
link_history_t *lhist; link_history_t *lhist;
@ -103,6 +106,7 @@ static link_history_t *get_link_history(const char *from_id,
return lhist; return lhist;
} }
/** Helper: free storage held by a single link history entry */
static void static void
_free_link_history(void *val) _free_link_history(void *val)
{ {
@ -110,6 +114,7 @@ _free_link_history(void *val)
tor_free(val); tor_free(val);
} }
/** Helper: free storage held by a single OR history entry */
static void static void
free_or_history(void *_hist) free_or_history(void *_hist)
{ {
@ -122,7 +127,8 @@ free_or_history(void *_hist)
/** Update an or_history_t object <b>hist</b> so that its uptime/downtime /** Update an or_history_t object <b>hist</b> so that its uptime/downtime
* count is up-to-date as of <b>when</b>. * count is up-to-date as of <b>when</b>.
*/ */
static void update_or_history(or_history_t *hist, time_t when) static void
update_or_history(or_history_t *hist, time_t when)
{ {
tor_assert(hist); tor_assert(hist);
if (hist->up_since) { if (hist->up_since) {
@ -137,7 +143,8 @@ static void update_or_history(or_history_t *hist, time_t when)
/** Initialize the static data structures for tracking history. /** Initialize the static data structures for tracking history.
*/ */
void rep_hist_init(void) void
rep_hist_init(void)
{ {
history_map = strmap_new(); history_map = strmap_new();
bw_arrays_init(); bw_arrays_init();
@ -147,7 +154,8 @@ void rep_hist_init(void)
/** Remember that an attempt to connect to the OR with identity digest /** Remember that an attempt to connect to the OR with identity digest
* <b>id</b> failed at <b>when</b>. * <b>id</b> failed at <b>when</b>.
*/ */
void rep_hist_note_connect_failed(const char* id, time_t when) void
rep_hist_note_connect_failed(const char* id, time_t when)
{ {
or_history_t *hist; or_history_t *hist;
hist = get_or_history(id); hist = get_or_history(id);
@ -166,7 +174,8 @@ void rep_hist_note_connect_failed(const char* id, time_t when)
/** Remember that an attempt to connect to the OR with identity digest /** Remember that an attempt to connect to the OR with identity digest
* <b>id</b> succeeded at <b>when</b>. * <b>id</b> succeeded at <b>when</b>.
*/ */
void rep_hist_note_connect_succeeded(const char* id, time_t when) void
rep_hist_note_connect_succeeded(const char* id, time_t when)
{ {
or_history_t *hist; or_history_t *hist;
hist = get_or_history(id); hist = get_or_history(id);
@ -185,7 +194,8 @@ void rep_hist_note_connect_succeeded(const char* id, time_t when)
/** Remember that we intentionally closed our connection to the OR /** Remember that we intentionally closed our connection to the OR
* with identity digest <b>id</b> at <b>when</b>. * with identity digest <b>id</b> at <b>when</b>.
*/ */
void rep_hist_note_disconnect(const char* id, time_t when) void
rep_hist_note_disconnect(const char* id, time_t when)
{ {
or_history_t *hist; or_history_t *hist;
hist = get_or_history(id); hist = get_or_history(id);
@ -202,7 +212,8 @@ void rep_hist_note_disconnect(const char* id, time_t when)
/** Remember that our connection to the OR with identity digest /** Remember that our connection to the OR with identity digest
* <b>id</b> had an error and stopped working at <b>when</b>. * <b>id</b> had an error and stopped working at <b>when</b>.
*/ */
void rep_hist_note_connection_died(const char* id, time_t when) void
rep_hist_note_connection_died(const char* id, time_t when)
{ {
or_history_t *hist; or_history_t *hist;
if (!id) { if (!id) {
@ -229,8 +240,8 @@ void rep_hist_note_connection_died(const char* id, time_t when)
* digest <b>from_id</b> to the OR with identity digest * digest <b>from_id</b> to the OR with identity digest
* <b>to_name</b>. * <b>to_name</b>.
*/ */
void rep_hist_note_extend_succeeded(const char *from_id, void
const char *to_id) rep_hist_note_extend_succeeded(const char *from_id, const char *to_id)
{ {
link_history_t *hist; link_history_t *hist;
/* log_fn(LOG_WARN, "EXTEND SUCCEEDED: %s->%s",from_name,to_name); */ /* log_fn(LOG_WARN, "EXTEND SUCCEEDED: %s->%s",from_name,to_name); */
@ -245,7 +256,8 @@ void rep_hist_note_extend_succeeded(const char *from_id,
* <b>from_id</b> to the OR with identity digest <b>to_name</b>, but * <b>from_id</b> to the OR with identity digest <b>to_name</b>, but
* failed. * failed.
*/ */
void rep_hist_note_extend_failed(const char *from_id, const char *to_id) void
rep_hist_note_extend_failed(const char *from_id, const char *to_id)
{ {
link_history_t *hist; link_history_t *hist;
/* log_fn(LOG_WARN, "EXTEND FAILED: %s->%s",from_name,to_name); */ /* log_fn(LOG_WARN, "EXTEND FAILED: %s->%s",from_name,to_name); */
@ -259,7 +271,8 @@ void rep_hist_note_extend_failed(const char *from_id, const char *to_id)
/** Log all the reliability data we have remembered, with the chosen /** Log all the reliability data we have remembered, with the chosen
* severity. * severity.
*/ */
void rep_hist_dump_stats(time_t now, int severity) void
rep_hist_dump_stats(time_t now, int severity)
{ {
strmap_iter_t *lhist_it; strmap_iter_t *lhist_it;
strmap_iter_t *orhist_it; strmap_iter_t *orhist_it;
@ -331,7 +344,8 @@ void rep_hist_dump_stats(time_t now, int severity)
/** Remove history info for routers/links that haven't changed since /** Remove history info for routers/links that haven't changed since
* <b>before</b> */ * <b>before</b> */
void rep_history_clean(time_t before) void
rep_history_clean(time_t before)
{ {
or_history_t *or_history; or_history_t *or_history;
link_history_t *link_history; link_history_t *link_history;
@ -365,7 +379,8 @@ void rep_history_clean(time_t before)
} }
#if 0 #if 0
void write_rep_history(const char *filename) void
write_rep_history(const char *filename)
{ {
FILE *f = NULL; FILE *f = NULL;
char *tmpfile; char *tmpfile;
@ -439,7 +454,9 @@ typedef struct bw_array_t {
/** Shift the current period of b forward by one. /** Shift the current period of b forward by one.
*/ */
static void commit_max(bw_array_t *b) { static void
commit_max(bw_array_t *b)
{
/* Store total from current period. */ /* Store total from current period. */
b->totals[b->next_max_idx] = b->total_in_period; b->totals[b->next_max_idx] = b->total_in_period;
/* Store maximum from current period. */ /* Store maximum from current period. */
@ -458,7 +475,9 @@ static void commit_max(bw_array_t *b) {
/** Shift the current observation time of 'b' forward by one second. /** Shift the current observation time of 'b' forward by one second.
*/ */
static INLINE void advance_obs(bw_array_t *b) { static INLINE void
advance_obs(bw_array_t *b)
{
int nextidx; int nextidx;
int total; int total;
@ -482,7 +501,9 @@ static INLINE void advance_obs(bw_array_t *b) {
/** Add 'n' bytes to the number of bytes in b for second 'when'. /** Add 'n' bytes to the number of bytes in b for second 'when'.
*/ */
static INLINE void add_obs(bw_array_t *b, time_t when, int n) { static INLINE void
add_obs(bw_array_t *b, time_t when, int n)
{
/* Don't record data in the past. */ /* Don't record data in the past. */
if (when<b->cur_obs_time) if (when<b->cur_obs_time)
return; return;
@ -498,7 +519,8 @@ static INLINE void add_obs(bw_array_t *b, time_t when, int n) {
/** Allocate, initialize, and return a new bw_array. /** Allocate, initialize, and return a new bw_array.
*/ */
static bw_array_t *bw_array_new(void) { static bw_array_t *bw_array_new(void)
{
bw_array_t *b; bw_array_t *b;
time_t start; time_t start;
b = tor_malloc_zero(sizeof(bw_array_t)); b = tor_malloc_zero(sizeof(bw_array_t));
@ -514,7 +536,8 @@ static bw_array_t *write_array = NULL;
/** Set up read_array and write_array /** Set up read_array and write_array
*/ */
static void bw_arrays_init(void) static void
bw_arrays_init(void)
{ {
read_array = bw_array_new(); read_array = bw_array_new();
write_array = bw_array_new(); write_array = bw_array_new();
@ -527,7 +550,9 @@ static void bw_arrays_init(void)
* <b>when</b> can go back to time, but it's safe to ignore calls * <b>when</b> can go back to time, but it's safe to ignore calls
* earlier than the latest <b>when</b> you've heard of. * earlier than the latest <b>when</b> you've heard of.
*/ */
void rep_hist_note_bytes_written(int num_bytes, time_t when) { void
rep_hist_note_bytes_written(int num_bytes, time_t when)
{
/* Maybe a circular array for recent seconds, and step to a new point /* Maybe a circular array for recent seconds, and step to a new point
* every time a new second shows up. Or simpler is to just to have * every time a new second shows up. Or simpler is to just to have
* a normal array and push down each item every second; it's short. * a normal array and push down each item every second; it's short.
@ -542,7 +567,9 @@ void rep_hist_note_bytes_written(int num_bytes, time_t when) {
/** We wrote <b>num_bytes</b> more bytes in second <b>when</b>. /** We wrote <b>num_bytes</b> more bytes in second <b>when</b>.
* (like rep_hist_note_bytes_written() above) * (like rep_hist_note_bytes_written() above)
*/ */
void rep_hist_note_bytes_read(int num_bytes, time_t when) { void
rep_hist_note_bytes_read(int num_bytes, time_t when)
{
/* if we're smart, we can make this func and the one above share code */ /* if we're smart, we can make this func and the one above share code */
add_obs(read_array, when, num_bytes); add_obs(read_array, when, num_bytes);
} }
@ -551,7 +578,8 @@ void rep_hist_note_bytes_read(int num_bytes, time_t when) {
* most bandwidth used in any NUM_SECS_ROLLING_MEASURE period for the last * most bandwidth used in any NUM_SECS_ROLLING_MEASURE period for the last
* NUM_SECS_BW_SUM_IS_VALID seconds.) * NUM_SECS_BW_SUM_IS_VALID seconds.)
*/ */
static int find_largest_max(bw_array_t *b) static int
find_largest_max(bw_array_t *b)
{ {
int i,max; int i,max;
max=0; max=0;
@ -569,7 +597,9 @@ static int find_largest_max(bw_array_t *b)
* *
* Return the smaller of these sums, divided by NUM_SECS_ROLLING_MEASURE. * Return the smaller of these sums, divided by NUM_SECS_ROLLING_MEASURE.
*/ */
int rep_hist_bandwidth_assess(void) { int
rep_hist_bandwidth_assess(void)
{
int w,r; int w,r;
r = find_largest_max(read_array); r = find_largest_max(read_array);
w = find_largest_max(write_array); w = find_largest_max(write_array);
@ -633,7 +663,10 @@ static smartlist_t *predicted_ports_list=NULL;
/** The corresponding most recently used time for each port. */ /** The corresponding most recently used time for each port. */
static smartlist_t *predicted_ports_times=NULL; static smartlist_t *predicted_ports_times=NULL;
static void add_predicted_port(uint16_t port, time_t now) { /** DOCDOC */
static void
add_predicted_port(uint16_t port, time_t now)
{
/* XXXX we could just use uintptr_t here, I think. */ /* XXXX we could just use uintptr_t here, I think. */
uint16_t *tmp_port = tor_malloc(sizeof(uint16_t)); uint16_t *tmp_port = tor_malloc(sizeof(uint16_t));
time_t *tmp_time = tor_malloc(sizeof(time_t)); time_t *tmp_time = tor_malloc(sizeof(time_t));
@ -644,13 +677,19 @@ static void add_predicted_port(uint16_t port, time_t now) {
smartlist_add(predicted_ports_times, tmp_time); smartlist_add(predicted_ports_times, tmp_time);
} }
static void predicted_ports_init(void) { /** DOCDOC */
static void
predicted_ports_init(void)
{
predicted_ports_list = smartlist_create(); predicted_ports_list = smartlist_create();
predicted_ports_times = smartlist_create(); predicted_ports_times = smartlist_create();
add_predicted_port(80, time(NULL)); /* add one to kickstart us */ add_predicted_port(80, time(NULL)); /* add one to kickstart us */
} }
static void predicted_ports_free(void) { /** DOCDOC */
static void
predicted_ports_free(void)
{
rephist_total_alloc -= smartlist_len(predicted_ports_list)*sizeof(uint16_t); rephist_total_alloc -= smartlist_len(predicted_ports_list)*sizeof(uint16_t);
SMARTLIST_FOREACH(predicted_ports_list, char *, cp, tor_free(cp)); SMARTLIST_FOREACH(predicted_ports_list, char *, cp, tor_free(cp));
smartlist_free(predicted_ports_list); smartlist_free(predicted_ports_list);
@ -663,7 +702,9 @@ static void predicted_ports_free(void) {
* This is used for predicting what sorts of streams we'll make in the * This is used for predicting what sorts of streams we'll make in the
* future and making circuits to anticipate that. * future and making circuits to anticipate that.
*/ */
void rep_hist_note_used_port(uint16_t port, time_t now) { void
rep_hist_note_used_port(uint16_t port, time_t now)
{
int i; int i;
uint16_t *tmp_port; uint16_t *tmp_port;
time_t *tmp_time; time_t *tmp_time;
@ -693,7 +734,9 @@ void rep_hist_note_used_port(uint16_t port, time_t now) {
* *
* The caller promises not to mess with it. * The caller promises not to mess with it.
*/ */
smartlist_t *rep_hist_get_predicted_ports(time_t now) { smartlist_t *
rep_hist_get_predicted_ports(time_t now)
{
int i; int i;
uint16_t *tmp_port; uint16_t *tmp_port;
time_t *tmp_time; time_t *tmp_time;
@ -726,7 +769,9 @@ static time_t predicted_hidserv_uptime_time = 0;
static time_t predicted_hidserv_capacity_time = 0; static time_t predicted_hidserv_capacity_time = 0;
/** Remember that we used an internal circ at time <b>now</b>. */ /** Remember that we used an internal circ at time <b>now</b>. */
void rep_hist_note_used_hidserv(time_t now, int need_uptime, int need_capacity) { void
rep_hist_note_used_hidserv(time_t now, int need_uptime, int need_capacity)
{
predicted_hidserv_time = now; predicted_hidserv_time = now;
if (need_uptime) if (need_uptime)
predicted_hidserv_uptime_time = now; predicted_hidserv_uptime_time = now;
@ -735,7 +780,9 @@ void rep_hist_note_used_hidserv(time_t now, int need_uptime, int need_capacity)
} }
/** Return 1 if we've used an internal circ recently; else return 0. */ /** Return 1 if we've used an internal circ recently; else return 0. */
int rep_hist_get_predicted_hidserv(time_t now, int *need_uptime, int *need_capacity) { int
rep_hist_get_predicted_hidserv(time_t now, int *need_uptime, int *need_capacity)
{
if (!predicted_hidserv_time) /* initialize it */ if (!predicted_hidserv_time) /* initialize it */
predicted_hidserv_time = now; predicted_hidserv_time = now;
if (predicted_hidserv_time + PREDICTED_CIRCS_RELEVANCE_TIME < now) if (predicted_hidserv_time + PREDICTED_CIRCS_RELEVANCE_TIME < now)
@ -751,7 +798,10 @@ int rep_hist_get_predicted_hidserv(time_t now, int *need_uptime, int *need_capac
void rep_hist_note_used_resolve(time_t now) { } void rep_hist_note_used_resolve(time_t now) { }
int rep_hist_get_predicted_resolve(time_t now) { return 0; } int rep_hist_get_predicted_resolve(time_t now) { return 0; }
void rep_hist_free_all(void) /** Free all storage held by the OR/link history caches, by the
* bandwidth history arrays, or by the port history. */
void
rep_hist_free_all(void)
{ {
strmap_free(history_map, free_or_history); strmap_free(history_map, free_or_history);
tor_free(read_array); tor_free(read_array);

View File

@ -34,7 +34,9 @@ static crypto_pk_env_t *identitykey=NULL;
/** Replace the current onion key with <b>k</b>. Does not affect lastonionkey; /** Replace the current onion key with <b>k</b>. Does not affect lastonionkey;
* to update onionkey correctly, call rotate_onion_key(). * to update onionkey correctly, call rotate_onion_key().
*/ */
void set_onion_key(crypto_pk_env_t *k) { void
set_onion_key(crypto_pk_env_t *k)
{
tor_mutex_acquire(key_lock); tor_mutex_acquire(key_lock);
onionkey = k; onionkey = k;
onionkey_set_at = time(NULL); onionkey_set_at = time(NULL);
@ -44,7 +46,9 @@ void set_onion_key(crypto_pk_env_t *k) {
/** Return the current onion key. Requires that the onion key has been /** Return the current onion key. Requires that the onion key has been
* loaded or generated. */ * loaded or generated. */
crypto_pk_env_t *get_onion_key(void) { crypto_pk_env_t *
get_onion_key(void)
{
tor_assert(onionkey); tor_assert(onionkey);
return onionkey; return onionkey;
} }
@ -53,14 +57,17 @@ crypto_pk_env_t *get_onion_key(void) {
* key rotation. If no rotation has been performed since this process * key rotation. If no rotation has been performed since this process
* started, return NULL. * started, return NULL.
*/ */
crypto_pk_env_t *get_previous_onion_key(void) { crypto_pk_env_t *
get_previous_onion_key(void)
{
return lastonionkey; return lastonionkey;
} }
/** Store a copy of the current onion key into *<b>key</b>, and a copy /** Store a copy of the current onion key into *<b>key</b>, and a copy
* of the most recent onion key into *<b>last</b>. * of the most recent onion key into *<b>last</b>.
*/ */
void dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last) void
dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last)
{ {
tor_assert(key); tor_assert(key);
tor_assert(last); tor_assert(last);
@ -77,26 +84,34 @@ void dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last)
* when the process launched, or the time of the most recent key rotation since * when the process launched, or the time of the most recent key rotation since
* the process launched. * the process launched.
*/ */
time_t get_onion_key_set_at(void) { time_t
get_onion_key_set_at(void)
{
return onionkey_set_at; return onionkey_set_at;
} }
/** Set the current identity key to k. /** Set the current identity key to k.
*/ */
void set_identity_key(crypto_pk_env_t *k) { void
set_identity_key(crypto_pk_env_t *k)
{
identitykey = k; identitykey = k;
} }
/** Returns the current identity key; requires that the identity key has been /** Returns the current identity key; requires that the identity key has been
* set. * set.
*/ */
crypto_pk_env_t *get_identity_key(void) { crypto_pk_env_t *
get_identity_key(void)
{
tor_assert(identitykey); tor_assert(identitykey);
return identitykey; return identitykey;
} }
/** Return true iff the identity key has been set. */ /** Return true iff the identity key has been set. */
int identity_key_is_set(void) { int
identity_key_is_set(void)
{
return identitykey != NULL; return identitykey != NULL;
} }
@ -107,7 +122,8 @@ int identity_key_is_set(void) {
* pending work. (This will cause fresh cpuworkers to be generated.) * pending work. (This will cause fresh cpuworkers to be generated.)
* - generate and upload a fresh routerinfo. * - generate and upload a fresh routerinfo.
*/ */
void rotate_onion_key(void) void
rotate_onion_key(void)
{ {
char fname[512]; char fname[512];
char fname_prev[512]; char fname_prev[512];
@ -153,7 +169,6 @@ static crypto_pk_env_t *
init_key_from_file_name_changed(const char *fname_old, init_key_from_file_name_changed(const char *fname_old,
const char *fname_new) const char *fname_new)
{ {
if (file_status(fname_new) == FN_FILE || file_status(fname_old) != FN_FILE) if (file_status(fname_new) == FN_FILE || file_status(fname_old) != FN_FILE)
/* The new filename is there, or both are, or neither is. */ /* The new filename is there, or both are, or neither is. */
return init_key_from_file(fname_new); return init_key_from_file(fname_new);
@ -171,7 +186,8 @@ init_key_from_file_name_changed(const char *fname_old,
* create a new RSA key and save it in <b>fname</b>. Return the read/created * create a new RSA key and save it in <b>fname</b>. Return the read/created
* key, or NULL on error. * key, or NULL on error.
*/ */
crypto_pk_env_t *init_key_from_file(const char *fname) crypto_pk_env_t *
init_key_from_file(const char *fname)
{ {
crypto_pk_env_t *prkey = NULL; crypto_pk_env_t *prkey = NULL;
FILE *file = NULL; FILE *file = NULL;
@ -223,7 +239,9 @@ crypto_pk_env_t *init_key_from_file(const char *fname)
/** Initialize all OR private keys, and the TLS context, as necessary. /** Initialize all OR private keys, and the TLS context, as necessary.
* On OPs, this only initializes the tls context. * On OPs, this only initializes the tls context.
*/ */
int init_keys(void) { int
init_keys(void)
{
/* XXX009 Two problems with how this is called: /* XXX009 Two problems with how this is called:
* 1. It should be idempotent for servers, so we can call init_keys * 1. It should be idempotent for servers, so we can call init_keys
* as much as we need to. * as much as we need to.
@ -382,15 +400,23 @@ static int can_reach_or_port = 0;
static int can_reach_dir_port = 0; static int can_reach_dir_port = 0;
/** Return 1 if or port is known reachable; else return 0. */ /** Return 1 if or port is known reachable; else return 0. */
int check_whether_orport_reachable(void) { int
check_whether_orport_reachable(void)
{
return clique_mode(get_options()) || can_reach_or_port; return clique_mode(get_options()) || can_reach_or_port;
} }
/** Return 1 if we don't have a dirport configured, or if it's reachable. */ /** Return 1 if we don't have a dirport configured, or if it's reachable. */
int check_whether_dirport_reachable(void) { int
check_whether_dirport_reachable(void)
{
return !get_options()->DirPort || can_reach_dir_port; return !get_options()->DirPort || can_reach_dir_port;
} }
void consider_testing_reachability(void) { /**DOCDOC*/
void
consider_testing_reachability(void)
{
routerinfo_t *me = router_get_my_routerinfo(); routerinfo_t *me = router_get_my_routerinfo();
if (!me) { if (!me) {
log_fn(LOG_WARN,"Bug: router_get_my_routerinfo() did not find my routerinfo?"); log_fn(LOG_WARN,"Bug: router_get_my_routerinfo() did not find my routerinfo?");
@ -411,7 +437,9 @@ void consider_testing_reachability(void) {
} }
/** Annotate that we found our ORPort reachable. */ /** Annotate that we found our ORPort reachable. */
void router_orport_found_reachable(void) { void
router_orport_found_reachable(void)
{
if (!can_reach_or_port) { if (!can_reach_or_port) {
if (!clique_mode(get_options())) if (!clique_mode(get_options()))
log(LOG_NOTICE,"Your ORPort is reachable from the outside. Excellent.%s", log(LOG_NOTICE,"Your ORPort is reachable from the outside. Excellent.%s",
@ -422,7 +450,9 @@ void router_orport_found_reachable(void) {
} }
/** Annotate that we found our DirPort reachable. */ /** Annotate that we found our DirPort reachable. */
void router_dirport_found_reachable(void) { void
router_dirport_found_reachable(void)
{
if (!can_reach_dir_port) { if (!can_reach_dir_port) {
log(LOG_NOTICE,"Your DirPort is reachable from the outside. Excellent."); log(LOG_NOTICE,"Your DirPort is reachable from the outside. Excellent.");
can_reach_dir_port = 1; can_reach_dir_port = 1;
@ -430,7 +460,9 @@ void router_dirport_found_reachable(void) {
} }
/** Our router has just moved to a new IP. Reset stats. */ /** Our router has just moved to a new IP. Reset stats. */
void server_has_changed_ip(void) { void
server_has_changed_ip(void)
{
stats_n_seconds_working = 0; stats_n_seconds_working = 0;
can_reach_or_port = 0; can_reach_or_port = 0;
can_reach_dir_port = 0; can_reach_dir_port = 0;
@ -440,18 +472,24 @@ void server_has_changed_ip(void) {
/** Return true iff we believe ourselves to be an authoritative /** Return true iff we believe ourselves to be an authoritative
* directory server. * directory server.
*/ */
int authdir_mode(or_options_t *options) { int
authdir_mode(or_options_t *options)
{
return options->AuthoritativeDir != 0; return options->AuthoritativeDir != 0;
} }
/** Return true iff we try to stay connected to all ORs at once. /** Return true iff we try to stay connected to all ORs at once.
*/ */
int clique_mode(or_options_t *options) { int
clique_mode(or_options_t *options)
{
return authdir_mode(options); return authdir_mode(options);
} }
/** Return true iff we are trying to be a server. /** Return true iff we are trying to be a server.
*/ */
int server_mode(or_options_t *options) { int
server_mode(or_options_t *options)
{
if (options->ClientOnly) return 0; if (options->ClientOnly) return 0;
return (options->ORPort != 0 || options->ORBindAddress); return (options->ORPort != 0 || options->ORBindAddress);
} }
@ -461,16 +499,25 @@ static int server_is_advertised=0;
/** Return true iff we have published our descriptor lately. /** Return true iff we have published our descriptor lately.
*/ */
int advertised_server_mode(void) { int
advertised_server_mode(void)
{
return server_is_advertised; return server_is_advertised;
} }
static void set_server_advertised(int s) { /**
* Called with a boolean: set whether we have recently published our descriptor.
*/
static void
set_server_advertised(int s)
{
server_is_advertised = s; server_is_advertised = s;
} }
/** Return true iff we are trying to be a socks proxy. */ /** Return true iff we are trying to be a socks proxy. */
int proxy_mode(or_options_t *options) { int
proxy_mode(or_options_t *options)
{
return (options->SocksPort != 0 || options->SocksBindAddress); return (options->SocksPort != 0 || options->SocksBindAddress);
} }
@ -484,7 +531,9 @@ int proxy_mode(or_options_t *options) {
* - We believe we are reachable from the outside; or * - We believe we are reachable from the outside; or
* - We have the AuthoritativeDirectory option set. * - We have the AuthoritativeDirectory option set.
*/ */
static int decide_if_publishable_server(time_t now) { static int
decide_if_publishable_server(time_t now)
{
or_options_t *options = get_options(); or_options_t *options = get_options();
if (options->ClientOnly) if (options->ClientOnly)
@ -499,7 +548,12 @@ static int decide_if_publishable_server(time_t now) {
return check_whether_orport_reachable(); return check_whether_orport_reachable();
} }
void consider_publishable_server(time_t now, int force) { /** Initiate server descriptor upload as reasonable (if server is publishable,
* etc). <b>force</b> is as for router_upload_dir_desc_to_dirservers.
*/
void
consider_publishable_server(time_t now, int force)
{
if (decide_if_publishable_server(now)) { if (decide_if_publishable_server(now)) {
set_server_advertised(1); set_server_advertised(1);
if (router_rebuild_descriptor(force) == 0) if (router_rebuild_descriptor(force) == 0)
@ -517,7 +571,9 @@ void consider_publishable_server(time_t now, int force) {
* other ORs we know about. Otherwise, open connections to those we * other ORs we know about. Otherwise, open connections to those we
* think are in clique mode. * think are in clique mode.
*/ */
void router_retry_connections(void) { void
router_retry_connections(void)
{
int i; int i;
routerinfo_t *router; routerinfo_t *router;
routerlist_t *rl; routerlist_t *rl;
@ -544,7 +600,9 @@ void router_retry_connections(void) {
/** Return true iff this OR should try to keep connections open to all /** Return true iff this OR should try to keep connections open to all
* other ORs. */ * other ORs. */
int router_is_clique_mode(routerinfo_t *router) { int
router_is_clique_mode(routerinfo_t *router)
{
if (router_digest_is_trusted_dir(router->identity_digest)) if (router_digest_is_trusted_dir(router->identity_digest))
return 1; return 1;
return 0; return 0;
@ -565,7 +623,9 @@ static int desc_needs_upload = 0;
* descriptor successfully yet, try to upload our signed descriptor to * descriptor successfully yet, try to upload our signed descriptor to
* all the directory servers we know about. * all the directory servers we know about.
*/ */
void router_upload_dir_desc_to_dirservers(int force) { void
router_upload_dir_desc_to_dirservers(int force)
{
const char *s; const char *s;
s = router_get_my_descriptor(); s = router_get_my_descriptor();
@ -582,7 +642,8 @@ void router_upload_dir_desc_to_dirservers(int force) {
/** OR only: Check whether my exit policy says to allow connection to /** OR only: Check whether my exit policy says to allow connection to
* conn. Return false if we accept; true if we reject. * conn. Return false if we accept; true if we reject.
*/ */
int router_compare_to_my_exit_policy(connection_t *conn) int
router_compare_to_my_exit_policy(connection_t *conn)
{ {
tor_assert(desc_routerinfo); tor_assert(desc_routerinfo);
@ -597,7 +658,8 @@ int router_compare_to_my_exit_policy(connection_t *conn)
/** Return true iff I'm a server and <b>digest</b> is equal to /** Return true iff I'm a server and <b>digest</b> is equal to
* my identity digest. */ * my identity digest. */
int router_digest_is_me(const char *digest) int
router_digest_is_me(const char *digest)
{ {
routerinfo_t *me = router_get_my_routerinfo(); routerinfo_t *me = router_get_my_routerinfo();
if (!me || memcmp(me->identity_digest, digest, DIGEST_LEN)) if (!me || memcmp(me->identity_digest, digest, DIGEST_LEN))
@ -606,14 +668,16 @@ int router_digest_is_me(const char *digest)
} }
/** A wrapper around router_digest_is_me(). */ /** A wrapper around router_digest_is_me(). */
int router_is_me(routerinfo_t *router) int
router_is_me(routerinfo_t *router)
{ {
return router_digest_is_me(router->identity_digest); return router_digest_is_me(router->identity_digest);
} }
/** Return a routerinfo for this OR, rebuilding a fresh one if /** Return a routerinfo for this OR, rebuilding a fresh one if
* necessary. Return NULL on error, or if called on an OP. */ * necessary. Return NULL on error, or if called on an OP. */
routerinfo_t *router_get_my_routerinfo(void) routerinfo_t *
router_get_my_routerinfo(void)
{ {
if (!server_mode(get_options())) if (!server_mode(get_options()))
return NULL; return NULL;
@ -628,7 +692,9 @@ routerinfo_t *router_get_my_routerinfo(void)
/** OR only: Return a signed server descriptor for this OR, rebuilding a fresh /** OR only: Return a signed server descriptor for this OR, rebuilding a fresh
* one if necessary. Return NULL on error. * one if necessary. Return NULL on error.
*/ */
const char *router_get_my_descriptor(void) { const char *
router_get_my_descriptor(void)
{
if (!desc_routerinfo) { if (!desc_routerinfo) {
if (router_rebuild_descriptor(1)) if (router_rebuild_descriptor(1))
return NULL; return NULL;
@ -641,7 +707,9 @@ const char *router_get_my_descriptor(void) {
* a fresh routerinfo and signed server descriptor for this OR. * a fresh routerinfo and signed server descriptor for this OR.
* Return 0 on success, -1 on error. * Return 0 on success, -1 on error.
*/ */
int router_rebuild_descriptor(int force) { int
router_rebuild_descriptor(int force)
{
routerinfo_t *ri; routerinfo_t *ri;
uint32_t addr; uint32_t addr;
char platform[256]; char platform[256];
@ -720,7 +788,8 @@ mark_my_descriptor_dirty(void)
* string describing the version of Tor and the operating system we're * string describing the version of Tor and the operating system we're
* currently running on. * currently running on.
*/ */
void get_platform_str(char *platform, size_t len) void
get_platform_str(char *platform, size_t len)
{ {
tor_snprintf(platform, len, "Tor %s on %s", tor_snprintf(platform, len, "Tor %s on %s",
VERSION, get_uname()); VERSION, get_uname());
@ -738,8 +807,10 @@ void get_platform_str(char *platform, size_t len)
* result into <b>s</b>, using at most <b>maxlen</b> bytes. Return -1 on * result into <b>s</b>, using at most <b>maxlen</b> bytes. Return -1 on
* failure, and the number of bytes used on success. * failure, and the number of bytes used on success.
*/ */
int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, int
crypto_pk_env_t *ident_key) { router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
crypto_pk_env_t *ident_key)
{
char *onion_pkey; /* Onion key, PEM-encoded. */ char *onion_pkey; /* Onion key, PEM-encoded. */
char *identity_pkey; /* Identity key, PEM-encoded. */ char *identity_pkey; /* Identity key, PEM-encoded. */
char digest[20]; char digest[20];
@ -936,7 +1007,8 @@ int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
} }
/** Return true iff <b>s</b> is a legally valid server nickname. */ /** Return true iff <b>s</b> is a legally valid server nickname. */
int is_legal_nickname(const char *s) int
is_legal_nickname(const char *s)
{ {
size_t len; size_t len;
tor_assert(s); tor_assert(s);
@ -946,7 +1018,8 @@ int is_legal_nickname(const char *s)
} }
/** Return true iff <b>s</b> is a legally valid server nickname or /** Return true iff <b>s</b> is a legally valid server nickname or
* hex-encoded identity-key digest. */ * hex-encoded identity-key digest. */
int is_legal_nickname_or_hexdigest(const char *s) int
is_legal_nickname_or_hexdigest(const char *s)
{ {
size_t len; size_t len;
tor_assert(s); tor_assert(s);
@ -958,7 +1031,8 @@ int is_legal_nickname_or_hexdigest(const char *s)
} }
/** Release all resources held in router keys. */ /** Release all resources held in router keys. */
void router_free_all_keys(void) void
router_free_all_keys(void)
{ {
if (onionkey) if (onionkey)
crypto_free_pk_env(onionkey); crypto_free_pk_env(onionkey);

View File

@ -45,7 +45,8 @@ extern int has_fetched_directory; /**< from main.c */
* Reload the original list of trusted dirservers, and the most recent * Reload the original list of trusted dirservers, and the most recent
* cached directory (if present). * cached directory (if present).
*/ */
int router_reload_router_list(void) int
router_reload_router_list(void)
{ {
char filename[512]; char filename[512];
int is_recent; int is_recent;
@ -77,7 +78,8 @@ int router_reload_router_list(void)
* trusted_dir_server_t * for all known trusted dirservers. Callers * trusted_dir_server_t * for all known trusted dirservers. Callers
* must not modify the list or its contents. * must not modify the list or its contents.
*/ */
void router_get_trusted_dir_servers(smartlist_t **outp) void
router_get_trusted_dir_servers(smartlist_t **outp)
{ {
if (!trusted_dir_servers) if (!trusted_dir_servers)
trusted_dir_servers = smartlist_create(); trusted_dir_servers = smartlist_create();
@ -92,10 +94,12 @@ void router_get_trusted_dir_servers(smartlist_t **outp)
* true, then only pick a dirserver that can answer runningrouters queries * true, then only pick a dirserver that can answer runningrouters queries
* (that is, a trusted dirserver, or one running 0.0.9rc5-cvs or later). * (that is, a trusted dirserver, or one running 0.0.9rc5-cvs or later).
*/ */
routerinfo_t *router_pick_directory_server(int requireothers, routerinfo_t *
router_pick_directory_server(int requireothers,
int fascistfirewall, int fascistfirewall,
int for_runningrouters, int for_runningrouters,
int retry_if_no_servers) { int retry_if_no_servers)
{
routerinfo_t *choice; routerinfo_t *choice;
if (!routerlist) if (!routerlist)
@ -127,9 +131,12 @@ routerinfo_t *router_pick_directory_server(int requireothers,
return choice; return choice;
} }
trusted_dir_server_t *router_pick_trusteddirserver(int requireothers, /** DOCDOC */
trusted_dir_server_t *
router_pick_trusteddirserver(int requireothers,
int fascistfirewall, int fascistfirewall,
int retry_if_no_servers) { int retry_if_no_servers)
{
trusted_dir_server_t *choice; trusted_dir_server_t *choice;
choice = router_pick_trusteddirserver_impl(requireothers, fascistfirewall); choice = router_pick_trusteddirserver_impl(requireothers, fascistfirewall);
@ -197,6 +204,7 @@ router_pick_directory_server_impl(int requireothers, int fascistfirewall,
return router; return router;
} }
/** DOCDOC */
static trusted_dir_server_t * static trusted_dir_server_t *
router_pick_trusteddirserver_impl(int requireother, int fascistfirewall) router_pick_trusteddirserver_impl(int requireother, int fascistfirewall)
{ {
@ -231,7 +239,9 @@ router_pick_trusteddirserver_impl(int requireother, int fascistfirewall)
} }
/** Go through and mark the auth dirservers as up */ /** Go through and mark the auth dirservers as up */
static void mark_all_trusteddirservers_up(void) { static void
mark_all_trusteddirservers_up(void)
{
if (routerlist) { if (routerlist) {
SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, router, SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, router,
if (router_digest_is_trusted_dir(router->identity_digest)) { if (router_digest_is_trusted_dir(router->identity_digest)) {
@ -249,7 +259,9 @@ static void mark_all_trusteddirservers_up(void) {
/** Return 0 if \\exists an authoritative dirserver that's currently /** Return 0 if \\exists an authoritative dirserver that's currently
* thought to be running, else return 1. * thought to be running, else return 1.
*/ */
int all_trusted_directory_servers_down(void) { int
all_trusted_directory_servers_down(void)
{
if (!trusted_dir_servers) if (!trusted_dir_servers)
return 1; return 1;
SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, dir, SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, dir,
@ -259,7 +271,9 @@ int all_trusted_directory_servers_down(void) {
/** Add all the family of <b>router</b> to the smartlist <b>sl</b>. /** Add all the family of <b>router</b> to the smartlist <b>sl</b>.
*/ */
void routerlist_add_family(smartlist_t *sl, routerinfo_t *router) { void
routerlist_add_family(smartlist_t *sl, routerinfo_t *router)
{
routerinfo_t *r; routerinfo_t *r;
struct config_line_t *cl; struct config_line_t *cl;
@ -395,8 +409,10 @@ router_add_running_routers_to_smartlist(smartlist_t *sl, int allow_unverified,
} }
} }
/** DOCDOC */
routerinfo_t * routerinfo_t *
routerlist_find_my_routerinfo(void) { routerlist_find_my_routerinfo(void)
{
routerinfo_t *router; routerinfo_t *router;
int i; int i;
@ -411,6 +427,7 @@ routerlist_find_my_routerinfo(void) {
return NULL; return NULL;
} }
/** DOCDOC */
int int
router_is_unreliable(routerinfo_t *router, int need_uptime, int need_capacity) router_is_unreliable(routerinfo_t *router, int need_uptime, int need_capacity)
{ {
@ -421,6 +438,7 @@ router_is_unreliable(routerinfo_t *router, int need_uptime, int need_capacity)
return 0; return 0;
} }
/** DOCDOC */
static void static void
routerlist_sl_remove_unreliable_routers(smartlist_t *sl) routerlist_sl_remove_unreliable_routers(smartlist_t *sl)
{ {
@ -437,6 +455,7 @@ routerlist_sl_remove_unreliable_routers(smartlist_t *sl)
} }
} }
/** DOCDOC */
routerinfo_t * routerinfo_t *
routerlist_sl_choose_by_bandwidth(smartlist_t *sl) routerlist_sl_choose_by_bandwidth(smartlist_t *sl)
{ {
@ -490,7 +509,8 @@ routerlist_sl_choose_by_bandwidth(smartlist_t *sl)
* available. If <b>strict</b> is true, never pick any node besides * available. If <b>strict</b> is true, never pick any node besides
* those in <b>preferred</b>. * those in <b>preferred</b>.
*/ */
routerinfo_t *router_choose_random_node(const char *preferred, routerinfo_t *
router_choose_random_node(const char *preferred,
const char *excluded, const char *excluded,
smartlist_t *excludedsmartlist, smartlist_t *excludedsmartlist,
int need_uptime, int need_capacity, int need_uptime, int need_capacity,
@ -544,7 +564,9 @@ routerinfo_t *router_choose_random_node(const char *preferred,
/** Return the router in our routerlist whose address is <b>addr</b> and /** Return the router in our routerlist whose address is <b>addr</b> and
* whose OR port is <b>port</b>. Return NULL if no such router is known. * whose OR port is <b>port</b>. Return NULL if no such router is known.
*/ */
routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { routerinfo_t *
router_get_by_addr_port(uint32_t addr, uint16_t port)
{
int i; int i;
routerinfo_t *router; routerinfo_t *router;
@ -563,8 +585,8 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) {
* encoded in hexadecimal, matches <b>hexdigest</b> (which is * encoded in hexadecimal, matches <b>hexdigest</b> (which is
* optionally prefixed with a single dollar sign). Return false if * optionally prefixed with a single dollar sign). Return false if
* <b>hexdigest</b> is malformed, or it doesn't match. */ * <b>hexdigest</b> is malformed, or it doesn't match. */
static INLINE int router_hex_digest_matches(routerinfo_t *router, static INLINE int
const char *hexdigest) router_hex_digest_matches(routerinfo_t *router, const char *hexdigest)
{ {
char digest[DIGEST_LEN]; char digest[DIGEST_LEN];
tor_assert(hexdigest); tor_assert(hexdigest);
@ -582,7 +604,8 @@ static INLINE int router_hex_digest_matches(routerinfo_t *router,
* (case-insensitive), or if <b>router's</b> identity key digest * (case-insensitive), or if <b>router's</b> identity key digest
* matches a hexadecimal value stored in <b>nickname</b>. Return * matches a hexadecimal value stored in <b>nickname</b>. Return
* false otherwise.*/ * false otherwise.*/
int router_nickname_matches(routerinfo_t *router, const char *nickname) int
router_nickname_matches(routerinfo_t *router, const char *nickname)
{ {
if (nickname[0]!='$' && !strcasecmp(router->nickname, nickname)) if (nickname[0]!='$' && !strcasecmp(router->nickname, nickname))
return 1; return 1;
@ -594,7 +617,8 @@ int router_nickname_matches(routerinfo_t *router, const char *nickname)
* nickname or (case-sensitive) hexadecimal key digest is * nickname or (case-sensitive) hexadecimal key digest is
* <b>nickname</b>. Return NULL if no such router is known. * <b>nickname</b>. Return NULL if no such router is known.
*/ */
routerinfo_t *router_get_by_nickname(const char *nickname) routerinfo_t *
router_get_by_nickname(const char *nickname)
{ {
int i, maybedigest; int i, maybedigest;
routerinfo_t *router; routerinfo_t *router;
@ -625,7 +649,9 @@ routerinfo_t *router_get_by_nickname(const char *nickname)
/** Return true iff <b>digest</b> is the digest of the identity key of /** Return true iff <b>digest</b> is the digest of the identity key of
* a trusted directory. */ * a trusted directory. */
int router_digest_is_trusted_dir(const char *digest) { int
router_digest_is_trusted_dir(const char *digest)
{
if (!trusted_dir_servers) if (!trusted_dir_servers)
return 0; return 0;
SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ent, SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ent,
@ -635,7 +661,9 @@ int router_digest_is_trusted_dir(const char *digest) {
/** Return the router in our routerlist whose hexadecimal key digest /** Return the router in our routerlist whose hexadecimal key digest
* is <b>hexdigest</b>. Return NULL if no such router is known. */ * is <b>hexdigest</b>. Return NULL if no such router is known. */
routerinfo_t *router_get_by_hexdigest(const char *hexdigest) { routerinfo_t *
router_get_by_hexdigest(const char *hexdigest)
{
char digest[DIGEST_LEN]; char digest[DIGEST_LEN];
tor_assert(hexdigest); tor_assert(hexdigest);
@ -652,7 +680,9 @@ routerinfo_t *router_get_by_hexdigest(const char *hexdigest) {
/** Return the router in our routerlist whose 20-byte key digest /** Return the router in our routerlist whose 20-byte key digest
* is <b>digest</b>. Return NULL if no such router is known. */ * is <b>digest</b>. Return NULL if no such router is known. */
routerinfo_t *router_get_by_digest(const char *digest) { routerinfo_t *
router_get_by_digest(const char *digest)
{
int i; int i;
routerinfo_t *router; routerinfo_t *router;
@ -673,18 +703,23 @@ routerinfo_t *router_get_by_digest(const char *digest) {
} }
/** Set *<b>prouterlist</b> to the current list of all known routers. */ /** Set *<b>prouterlist</b> to the current list of all known routers. */
void router_get_routerlist(routerlist_t **prouterlist) { void
router_get_routerlist(routerlist_t **prouterlist)
{
*prouterlist = routerlist; *prouterlist = routerlist;
} }
/** Return the publication time on the current routerlist, or 0 if we have no /** Return the publication time on the current routerlist, or 0 if we have no
* routerlist. */ * routerlist. */
time_t routerlist_get_published_time(void) { time_t
routerlist_get_published_time(void)
{
return routerlist ? routerlist->published_on : 0; return routerlist ? routerlist->published_on : 0;
} }
/** Free all storage held by <b>router</b>. */ /** Free all storage held by <b>router</b>. */
void routerinfo_free(routerinfo_t *router) void
routerinfo_free(routerinfo_t *router)
{ {
if (!router) if (!router)
return; return;
@ -707,7 +742,8 @@ void routerinfo_free(routerinfo_t *router)
} }
/** Allocate a fresh copy of <b>router</b> */ /** Allocate a fresh copy of <b>router</b> */
routerinfo_t *routerinfo_copy(const routerinfo_t *router) routerinfo_t *
routerinfo_copy(const routerinfo_t *router)
{ {
routerinfo_t *r; routerinfo_t *r;
addr_policy_t **e, *tmp; addr_policy_t **e, *tmp;
@ -741,7 +777,8 @@ routerinfo_t *routerinfo_copy(const routerinfo_t *router)
} }
/** Free all storage held by a routerlist <b>rl</b> */ /** Free all storage held by a routerlist <b>rl</b> */
void routerlist_free(routerlist_t *rl) void
routerlist_free(routerlist_t *rl)
{ {
tor_assert(rl); tor_assert(rl);
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r, SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r,
@ -752,7 +789,9 @@ void routerlist_free(routerlist_t *rl)
tor_free(rl); tor_free(rl);
} }
void routerlist_free_current(void) /** Free all entries in the current router list. */
void
routerlist_free_current(void)
{ {
if (routerlist) if (routerlist)
routerlist_free(routerlist); routerlist_free(routerlist);
@ -764,7 +803,9 @@ void routerlist_free_current(void)
} }
} }
void free_trusted_dir_servers(void) /** Free all entries in the list of trusted directory servers. */
void
free_trusted_dir_servers(void)
{ {
if (trusted_dir_servers) { if (trusted_dir_servers) {
SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds, SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds,
@ -775,7 +816,9 @@ void free_trusted_dir_servers(void)
} }
/** Mark the router with ID <b>digest</b> as non-running in our routerlist. */ /** Mark the router with ID <b>digest</b> as non-running in our routerlist. */
void router_mark_as_down(const char *digest) { void
router_mark_as_down(const char *digest)
{
routerinfo_t *router; routerinfo_t *router;
tor_assert(digest); tor_assert(digest);
@ -802,7 +845,8 @@ void router_mark_as_down(const char *digest) {
* DOCDOC msg * DOCDOC msg
*/ */
static int static int
router_add_to_routerlist(routerinfo_t *router, const char **msg) { router_add_to_routerlist(routerinfo_t *router, const char **msg)
{
int i; int i;
routerinfo_t *r; routerinfo_t *r;
char id_digest[DIGEST_LEN]; char id_digest[DIGEST_LEN];
@ -958,7 +1002,8 @@ router_load_single_router(const char *s, const char **msg)
* If <b>dir_is_cached</b> is non-zero, then we're reading it * If <b>dir_is_cached</b> is non-zero, then we're reading it
* from the cache so don't bother to re-write it to the cache. * from the cache so don't bother to re-write it to the cache.
*/ */
int router_load_routerlist_from_directory(const char *s, int
router_load_routerlist_from_directory(const char *s,
crypto_pk_env_t *pkey, crypto_pk_env_t *pkey,
int dir_is_recent, int dir_is_recent,
int dir_is_cached) int dir_is_cached)
@ -1134,8 +1179,10 @@ router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
/** Return 1 if all running sufficiently-stable routers will reject /** Return 1 if all running sufficiently-stable routers will reject
* addr:port, return 0 if any might accept it. */ * addr:port, return 0 if any might accept it. */
int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port, int
int need_uptime) { router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port,
int need_uptime)
{
int i; int i;
routerinfo_t *router; routerinfo_t *router;
addr_policy_result_t r; addr_policy_result_t r;
@ -1241,13 +1288,16 @@ exit_policy_implicitly_allows_local_networks(addr_policy_t *policy,
/** Return true iff <b>router</b> does not permit exit streams. /** Return true iff <b>router</b> does not permit exit streams.
*/ */
int router_exit_policy_rejects_all(routerinfo_t *router) { int
router_exit_policy_rejects_all(routerinfo_t *router)
{
return router_compare_addr_to_addr_policy(0, 0, router->exit_policy) return router_compare_addr_to_addr_policy(0, 0, router->exit_policy)
== ADDR_POLICY_REJECTED; == ADDR_POLICY_REJECTED;
} }
/** Release all space held in <b>rr</b>. */ /** Release all space held in <b>rr</b>. */
void running_routers_free(running_routers_t *rr) void
running_routers_free(running_routers_t *rr)
{ {
if (!rr) if (!rr)
return; return;
@ -1274,7 +1324,8 @@ routerlist_set_runningrouters(routerlist_t *list, running_routers_t *rr)
* on the contents of <b>rr</b>. */ * on the contents of <b>rr</b>. */
/* Note: this function is not yet used, since nobody publishes just /* Note: this function is not yet used, since nobody publishes just
* running-router lists yet. */ * running-router lists yet. */
void routerlist_update_from_runningrouters(routerlist_t *list, void
routerlist_update_from_runningrouters(routerlist_t *list,
running_routers_t *rr) running_routers_t *rr)
{ {
routerinfo_t *me = router_get_my_routerinfo(); routerinfo_t *me = router_get_my_routerinfo();
@ -1317,7 +1368,8 @@ void routerlist_update_from_runningrouters(routerlist_t *list,
* *
* Return 1 if we found router in running_list, else return 0. * Return 1 if we found router in running_list, else return 0.
*/ */
int routers_update_status_from_entry(smartlist_t *routers, int
routers_update_status_from_entry(smartlist_t *routers,
time_t list_time, time_t list_time,
const char *s) const char *s)
{ {
@ -1448,7 +1500,8 @@ add_trusted_dir_server(const char *address, uint16_t port, const char *digest)
} }
/** Remove all members from the list of trusted dir servers. */ /** Remove all members from the list of trusted dir servers. */
void clear_trusted_dir_servers(void) void
clear_trusted_dir_servers(void)
{ {
if (trusted_dir_servers) { if (trusted_dir_servers) {
SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ent, SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ent,

View File

@ -152,7 +152,8 @@ static int tor_version_same_series(tor_version_t *a, tor_version_t *b);
/** Set <b>digest</b> to the SHA-1 digest of the hash of the directory in /** Set <b>digest</b> to the SHA-1 digest of the hash of the directory in
* <b>s</b>. Return 0 on success, nonzero on failure. * <b>s</b>. Return 0 on success, nonzero on failure.
*/ */
int router_get_dir_hash(const char *s, char *digest) int
router_get_dir_hash(const char *s, char *digest)
{ {
return router_get_hash_impl(s,digest, return router_get_hash_impl(s,digest,
"signed-directory","\ndirectory-signature"); "signed-directory","\ndirectory-signature");
@ -161,7 +162,8 @@ int router_get_dir_hash(const char *s, char *digest)
/** Set <b>digest</b> to the SHA-1 digest of the hash of the first router in /** Set <b>digest</b> to the SHA-1 digest of the hash of the first router in
* <b>s</b>. Return 0 on success, nonzero on failure. * <b>s</b>. Return 0 on success, nonzero on failure.
*/ */
int router_get_router_hash(const char *s, char *digest) int
router_get_router_hash(const char *s, char *digest)
{ {
return router_get_hash_impl(s,digest, return router_get_hash_impl(s,digest,
"router ","\nrouter-signature"); "router ","\nrouter-signature");
@ -170,7 +172,8 @@ int router_get_router_hash(const char *s, char *digest)
/** Set <b>digest</b> to the SHA-1 digest of the hash of the running-routers /** Set <b>digest</b> to the SHA-1 digest of the hash of the running-routers
* string in <b>s</b>. Return 0 on success, nonzero on failure. * string in <b>s</b>. Return 0 on success, nonzero on failure.
*/ */
int router_get_runningrouters_hash(const char *s, char *digest) int
router_get_runningrouters_hash(const char *s, char *digest)
{ {
return router_get_hash_impl(s,digest, return router_get_hash_impl(s,digest,
"network-status","\ndirectory-signature"); "network-status","\ndirectory-signature");
@ -309,7 +312,8 @@ get_recommended_software_from_directory(const char *str)
/* Return 0 if myversion is supported; else log a message and return /* Return 0 if myversion is supported; else log a message and return
* -1 (or exit if ignoreversions is false) */ * -1 (or exit if ignoreversions is false) */
int check_software_version_against_directory(const char *directory, int
check_software_version_against_directory(const char *directory,
int ignoreversion) int ignoreversion)
{ {
char *v; char *v;
@ -629,7 +633,8 @@ router_parse_runningrouters(const char *str, int write_to_cache)
/** Given a directory or running-routers string in <b>str</b>, try to /** Given a directory or running-routers string in <b>str</b>, try to
* find the its dir-signing-key token (if any). If this token is * find the its dir-signing-key token (if any). If this token is
* present, extract and return the key. Return NULL on failure. */ * present, extract and return the key. Return NULL on failure. */
static crypto_pk_env_t *find_dir_signing_key(const char *str) static crypto_pk_env_t *
find_dir_signing_key(const char *str)
{ {
const char *cp; const char *cp;
directory_token_t *tok; directory_token_t *tok;
@ -675,7 +680,8 @@ static crypto_pk_env_t *find_dir_signing_key(const char *str)
/** Return true iff <b>key</b> is allowed to sign directories. /** Return true iff <b>key</b> is allowed to sign directories.
*/ */
static int dir_signing_key_is_trusted(crypto_pk_env_t *key) static int
dir_signing_key_is_trusted(crypto_pk_env_t *key)
{ {
char digest[DIGEST_LEN]; char digest[DIGEST_LEN];
if (!key) return 0; if (!key) return 0;
@ -702,7 +708,8 @@ static int dir_signing_key_is_trusted(crypto_pk_env_t *key)
* (New callers should always use <b>declared_key</b> when possible; * (New callers should always use <b>declared_key</b> when possible;
* <b>pkey</b> is only for debugging.) * <b>pkey</b> is only for debugging.)
*/ */
static int check_directory_signature(const char *digest, static int
check_directory_signature(const char *digest,
directory_token_t *tok, directory_token_t *tok,
crypto_pk_env_t *pkey, crypto_pk_env_t *pkey,
crypto_pk_env_t *declared_key) crypto_pk_env_t *declared_key)
@ -816,8 +823,9 @@ router_parse_list_from_string(const char **s, routerlist_t **dest,
* *<b>end</b>. Mallocs a new router and returns it if all goes well, else * *<b>end</b>. Mallocs a new router and returns it if all goes well, else
* returns NULL. * returns NULL.
*/ */
routerinfo_t *router_parse_entry_from_string(const char *s, routerinfo_t *
const char *end) { router_parse_entry_from_string(const char *s, const char *end)
{
routerinfo_t *router = NULL; routerinfo_t *router = NULL;
char signed_digest[128]; char signed_digest[128];
char digest[128]; char digest[128];
@ -1014,10 +1022,6 @@ routerinfo_t *router_parse_entry_from_string(const char *s,
router->platform = tor_strdup("<unknown>"); router->platform = tor_strdup("<unknown>");
} }
// log_fn(LOG_DEBUG,"or_port %d, dir_port %d, bandwidthrate %u, bandwidthburst %u.",
// router->or_port, router->dir_port,
// (unsigned) router->bandwidthrate, (unsigned) router->bandwidthburst);
goto done; goto done;
return router; return router;
@ -1075,6 +1079,7 @@ router_parse_addr_policy_from_string(const char *s)
return r; return r;
} }
/** DOCDOC */
int int
router_add_exit_policy_from_string(routerinfo_t *router, const char *s) router_add_exit_policy_from_string(routerinfo_t *router, const char *s)
{ {
@ -1089,6 +1094,7 @@ router_add_exit_policy_from_string(routerinfo_t *router, const char *s)
return 0; return 0;
} }
/** DOCDOC */
static int static int
router_add_exit_policy(routerinfo_t *router,directory_token_t *tok) router_add_exit_policy(routerinfo_t *router,directory_token_t *tok)
{ {
@ -1106,8 +1112,8 @@ router_add_exit_policy(routerinfo_t *router,directory_token_t *tok)
/** Given a K_ACCEPT or K_REJECT token and a router, create and return /** Given a K_ACCEPT or K_REJECT token and a router, create and return
* a new exit_policy_t corresponding to the token. */ * a new exit_policy_t corresponding to the token. */
static addr_policy_t * static addr_policy_t *
router_parse_addr_policy(directory_token_t *tok) { router_parse_addr_policy(directory_token_t *tok)
{
addr_policy_t *newe; addr_policy_t *newe;
// struct in_addr in; // struct in_addr in;
char *arg; char *arg;
@ -1152,6 +1158,7 @@ policy_read_failed:
return NULL; return NULL;
} }
/** log and exit if <b>t</b> is malformed */
void void
assert_addr_policy_ok(addr_policy_t *t) assert_addr_policy_ok(addr_policy_t *t)
{ {
@ -1204,7 +1211,8 @@ token_free(directory_token_t *tok)
* or RTR_ONLY, reject all tokens of the wrong type. * or RTR_ONLY, reject all tokens of the wrong type.
*/ */
static directory_token_t * static directory_token_t *
get_next_token(const char **s, where_syntax where) { get_next_token(const char **s, where_syntax where)
{
const char *next, *obstart; const char *next, *obstart;
int i, done, allocated, is_opt; int i, done, allocated, is_opt;
directory_token_t *tok; directory_token_t *tok;
@ -1461,7 +1469,8 @@ find_all_exitpolicy(smartlist_t *s)
* *
* If no such substring exists, return -1. * If no such substring exists, return -1.
*/ */
static int router_get_hash_impl(const char *s, char *digest, static int
router_get_hash_impl(const char *s, char *digest,
const char *start_str, const char *start_str,
const char *end_str) const char *end_str)
{ {
@ -1500,7 +1509,9 @@ static int router_get_hash_impl(const char *s, char *digest,
* and compare it to the version in <b>cutoff</b>. Return 1 if * and compare it to the version in <b>cutoff</b>. Return 1 if
* the router is at least as new as the cutoff, else return 0. * the router is at least as new as the cutoff, else return 0.
*/ */
int tor_version_as_new_as(const char *platform, const char *cutoff) { int
tor_version_as_new_as(const char *platform, const char *cutoff)
{
tor_version_t cutoff_version, router_version; tor_version_t cutoff_version, router_version;
char *s, *start; char *s, *start;
char tmp[128]; char tmp[128];
@ -1529,7 +1540,8 @@ int tor_version_as_new_as(const char *platform, const char *cutoff) {
/** Parse a tor version from <b>s</b>, and store the result in <b>out</b>. /** Parse a tor version from <b>s</b>, and store the result in <b>out</b>.
* Return 0 on success, -1 on failure. */ * Return 0 on success, -1 on failure. */
int tor_version_parse(const char *s, tor_version_t *out) int
tor_version_parse(const char *s, tor_version_t *out)
{ {
char *eos=NULL, *cp=NULL; char *eos=NULL, *cp=NULL;
/* Format is: /* Format is:
@ -1598,7 +1610,8 @@ int tor_version_parse(const char *s, tor_version_t *out)
/** Compare two tor versions; Return <0 if a < b; 0 if a ==b, >0 if a > /** Compare two tor versions; Return <0 if a < b; 0 if a ==b, >0 if a >
* b. */ * b. */
int tor_version_compare(tor_version_t *a, tor_version_t *b) int
tor_version_compare(tor_version_t *a, tor_version_t *b)
{ {
int i; int i;
tor_assert(a); tor_assert(a);
@ -1621,6 +1634,8 @@ int tor_version_compare(tor_version_t *a, tor_version_t *b)
} }
} }
/** Return true iff versions <b>a</b> and <b>b</b> belong to the same series.
*/
static int static int
tor_version_same_series(tor_version_t *a, tor_version_t *b) tor_version_same_series(tor_version_t *a, tor_version_t *b)
{ {

View File

@ -122,7 +122,8 @@ remove_directory(void)
} }
static void static void
test_buffers(void) { test_buffers(void)
{
char str[256]; char str[256];
char str2[256]; char str2[256];
@ -599,7 +600,8 @@ test_crypto_s2k(void)
} }
static void static void
test_util(void) { test_util(void)
{
struct timeval start, end; struct timeval start, end;
struct tm a_time; struct tm a_time;
smartlist_t *sl; smartlist_t *sl;
@ -1428,7 +1430,8 @@ test_rend_fns(void)
} }
int int
main(int c, char**v) { main(int c, char**v)
{
or_options_t *options = tor_malloc_zero(sizeof(or_options_t)); or_options_t *options = tor_malloc_zero(sizeof(or_options_t));
network_init(); network_init();
options_init(options); options_init(options);

View File

@ -15,7 +15,8 @@ int tor_main(int argc, char *argv[]);
/** We keep main() in a separate file so that our unit tests can use /** We keep main() in a separate file so that our unit tests can use
* functions from main.c) * functions from main.c)
*/ */
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
return tor_main(argc, argv); return tor_main(argc, argv);
} }

View File

@ -44,6 +44,9 @@
do { log_fn(LOG_ERR, "Error while %s: %s", act, \ do { log_fn(LOG_ERR, "Error while %s: %s", act, \
tor_socket_strerror(tor_socket_errno(_s))); } while (0) tor_socket_strerror(tor_socket_errno(_s))); } while (0)
/** Set *out to a newly allocated SOCKS4a resolve request with
* username and hostname as provided. Return the number of bytes in
* the request. */
static int static int
build_socks4a_resolve_request(char **out, build_socks4a_resolve_request(char **out,
const char *username, const char *username,
@ -66,6 +69,9 @@ build_socks4a_resolve_request(char **out,
return len; return len;
} }
/** Given a len-byte SOCKS4a response in <b>response</b>, set *addr_out to the
* address it contains (in host order). Return 0 on success, -1 on error.
*/
static int static int
parse_socks4a_resolve_response(const char *response, size_t len, parse_socks4a_resolve_response(const char *response, size_t len,
uint32_t *addr_out) uint32_t *addr_out)
@ -96,6 +102,10 @@ parse_socks4a_resolve_response(const char *response, size_t len,
return 0; return 0;
} }
/** Send a resolve request for <b>hostname</b> to the Tor listening on
* <b>sockshost</b>:<b>socksport</b>. Store the resulting IPv4
* address (in host order) into <b>result_addr</b>.
*/
static int static int
do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport, do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
uint32_t *result_addr) uint32_t *result_addr)
@ -163,6 +173,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
return 0; return 0;
} }
/** Print a usage message and exit. */
static void static void
usage(void) usage(void)
{ {
@ -170,6 +181,7 @@ usage(void)
exit(1); exit(1);
} }
/** Entry point to tor-resolve */
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {