cleanup: don't use size_t when you mean int

size_t is what you get back from sizeof(). no more, no less.


svn:r80
This commit is contained in:
Roger Dingledine 2002-08-24 04:59:21 +00:00
parent d8c0d21b49
commit 3a7f3ba348
6 changed files with 128 additions and 132 deletions

View File

@ -8,7 +8,7 @@
extern or_options_t options; /* command-line and config-file options */ extern or_options_t options; /* command-line and config-file options */
int buf_new(char **buf, size_t *buflen, size_t *buf_datalen) { int buf_new(char **buf, int *buflen, int *buf_datalen) {
assert(buf && buflen && buf_datalen); assert(buf && buflen && buf_datalen);
@ -26,7 +26,7 @@ void buf_free(char *buf) {
free(buf); free(buf);
} }
int read_to_buf(int s, int at_most, char **buf, size_t *buflen, size_t *buf_datalen, int *reached_eof) { int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof) {
/* read from socket s, writing onto buf+buf_datalen. If at_most is >= 0 then /* read from socket s, writing onto buf+buf_datalen. If at_most is >= 0 then
* read at most 'at_most' bytes, and in any case don't read more than will fit based on buflen. * read at most 'at_most' bytes, and in any case don't read more than will fit based on buflen.
@ -48,8 +48,8 @@ int read_to_buf(int s, int at_most, char **buf, size_t *buflen, size_t *buf_data
return 0; /* we shouldn't read anything */ return 0; /* we shouldn't read anything */
if(!options.LinkPadding && at_most > 10*sizeof(cell_t)) { if(!options.LinkPadding && at_most > 10*sizeof(cell_t)) {
/* if no linkpadding. do a rudimentary round-robin so one /* if no linkpadding: do a rudimentary round-robin so one
* connection can't hog our receiver bucket * connection can't hog an outgoing connection
*/ */
at_most = 10*sizeof(cell_t); at_most = 10*sizeof(cell_t);
} }
@ -73,7 +73,7 @@ int read_to_buf(int s, int at_most, char **buf, size_t *buflen, size_t *buf_data
} }
int flush_buf(int s, char **buf, size_t *buflen, size_t *buf_flushlen, size_t *buf_datalen) { int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen) {
/* push from buf onto s /* push from buf onto s
* then memmove to front of buf * then memmove to front of buf
@ -105,8 +105,8 @@ int flush_buf(int s, char **buf, size_t *buflen, size_t *buf_flushlen, size_t *b
} }
} }
int write_to_buf(char *string, size_t string_len, int write_to_buf(char *string, int string_len,
char **buf, size_t *buflen, size_t *buf_datalen) { char **buf, int *buflen, int *buf_datalen) {
/* append string to buf (growing as needed, return -1 if "too big") /* append string to buf (growing as needed, return -1 if "too big")
* return total number of bytes on the buf * return total number of bytes on the buf
@ -128,8 +128,8 @@ int write_to_buf(char *string, size_t string_len,
} }
int fetch_from_buf(char *string, size_t string_len, int fetch_from_buf(char *string, int string_len,
char **buf, size_t *buflen, size_t *buf_datalen) { char **buf, int *buflen, int *buf_datalen) {
/* if there is string_len bytes in buf, write them onto string, /* if there is 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) */

View File

@ -80,7 +80,7 @@ void circuit_free(circuit_t *circ) {
free(circ); free(circ);
} }
void circuit_free_cpath(crypt_path_t **cpath, size_t cpathlen) { void circuit_free_cpath(crypt_path_t **cpath, int cpathlen) {
int i; int i;
for(i=0;i<cpathlen;i++) for(i=0;i<cpathlen;i++)
@ -296,7 +296,7 @@ int circuit_deliver_data_cell(cell_t *cell, circuit_t *circ, connection_t *conn,
return connection_write_cell_to_buf(cell, conn); return connection_write_cell_to_buf(cell, conn);
} }
int circuit_crypt(circuit_t *circ, char *in, size_t inlen, char crypt_type) { int circuit_crypt(circuit_t *circ, char *in, int inlen, char crypt_type) {
char *out; char *out;
int i; int i;
crypt_path_t *thishop; crypt_path_t *thishop;

View File

@ -182,18 +182,18 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) {
return NULL; return NULL;
} }
routerinfo_t *router_get_first_in_route(unsigned int *route, size_t routelen) { routerinfo_t *router_get_first_in_route(unsigned int *route, int routelen) {
return router_array[route[routelen-1]]; return router_array[route[routelen-1]];
} }
/* a wrapper around new_route. put all these in routers.c perhaps? */ /* a wrapper around new_route. put all these in routers.c perhaps? */
unsigned int *router_new_route(size_t *rlen) { unsigned int *router_new_route(int *routelen) {
return new_route(options.CoinWeight, router_array,rarray_len, rlen); return new_route(options.CoinWeight, router_array, rarray_len, routelen);
} }
/* a wrapper around create_onion */ /* a wrapper around create_onion */
unsigned char *router_create_onion(unsigned int *route, size_t routelen, size_t *lenp, crypt_path_t **cpathp) { unsigned char *router_create_onion(unsigned int *route, int routelen, int *len, crypt_path_t **cpath) {
return create_onion(router_array,rarray_len,route,routelen,lenp,cpathp); return create_onion(router_array,rarray_len,route,routelen,len,cpath);
} }

View File

@ -92,23 +92,21 @@ int chooselen(double cw)
* int cw is the coin weight to use when choosing the route * int cw is the coin weight to use when choosing the route
* order of routers is from last to first * order of routers is from last to first
*/ */
unsigned int *new_route(double cw, routerinfo_t **rarray, size_t rarray_len, size_t *rlen) unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *routelen)
{ {
int routelen = 0;
int i, j; int i, j;
int num_acceptable_routers = 0; int num_acceptable_routers = 0;
int retval = 0;
unsigned int *route = NULL; unsigned int *route = NULL;
unsigned int oldchoice, choice; unsigned int oldchoice, choice;
assert((cw >= 0) && (cw < 1) && (rarray) && (rlen) ); /* valid parameters */ assert((cw >= 0) && (cw < 1) && (rarray) && (routelen) ); /* valid parameters */
routelen = chooselen(cw); *routelen = chooselen(cw);
if (routelen == -1) { if (*routelen == -1) {
log(LOG_ERR,"Choosing route length failed."); log(LOG_ERR,"Choosing route length failed.");
return NULL; return NULL;
} }
log(LOG_DEBUG,"new_route(): Chosen route length %d.",routelen); log(LOG_DEBUG,"new_route(): Chosen route length %d.",*routelen);
for(i=0;i<rarray_len;i++) { for(i=0;i<rarray_len;i++) {
log(LOG_DEBUG,"Contemplating whether router %d is any good...",i); log(LOG_DEBUG,"Contemplating whether router %d is any good...",i);
@ -128,28 +126,27 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, size_t rarray_len, siz
next_i_loop: next_i_loop:
} }
if(num_acceptable_routers < routelen) { if(num_acceptable_routers < *routelen) {
log(LOG_DEBUG,"new_route(): Cutting routelen from %d to %d.",routelen, num_acceptable_routers); log(LOG_DEBUG,"new_route(): Cutting routelen from %d to %d.",*routelen, num_acceptable_routers);
routelen = num_acceptable_routers; *routelen = num_acceptable_routers;
} }
if(routelen < 1) { if(*routelen < 1) {
log(LOG_ERR,"new_route(): Didn't find any acceptable routers. Failing."); log(LOG_ERR,"new_route(): Didn't find any acceptable routers. Failing.");
return NULL; return NULL;
} }
/* allocate memory for the new route */ /* allocate memory for the new route */
route = (unsigned int *)malloc(routelen * sizeof(unsigned int)); route = (unsigned int *)malloc(*routelen * sizeof(unsigned int));
if (!route) { if (!route) {
log(LOG_ERR,"Memory allocation failed."); log(LOG_ERR,"Memory allocation failed.");
return NULL; return NULL;
} }
oldchoice = rarray_len; oldchoice = rarray_len;
for(i=0;i<routelen;i++) { for(i=0;i<*routelen;i++) {
log(LOG_DEBUG,"new_route(): Choosing hop %u.",i); log(LOG_DEBUG,"new_route(): Choosing hop %u.",i);
retval = crypto_pseudo_rand(sizeof(unsigned int),(unsigned char *)&choice); if(crypto_pseudo_rand(sizeof(unsigned int),(unsigned char *)&choice)) {
if (retval) {
free((void *)route); free((void *)route);
return NULL; return NULL;
} }
@ -171,31 +168,30 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, size_t rarray_len, siz
route[i] = choice; route[i] = choice;
} }
*rlen = routelen;
return route; return route;
} }
/* creates a new onion from route, stores it and its length into bufp and lenp respectively */ /* creates a new onion from route, stores it and its length into buf and len respectively */
unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned int *route, size_t routelen, size_t *lenp, crypt_path_t **cpathp) unsigned char *create_onion(routerinfo_t **rarray, int rarray_len, unsigned int *route, int routelen, int *len, crypt_path_t **cpath)
{ {
int i,j; int i,j;
int retval = 0; int retval = 0;
onion_layer_t *layer = NULL; onion_layer_t *layer = NULL;
crypt_path_t *hop = NULL; crypt_path_t *hop = NULL;
unsigned char *retbuf = NULL; unsigned char *retbuf = NULL;
unsigned char *bufp; unsigned char *buf;
routerinfo_t *router; routerinfo_t *router;
unsigned char iv[16]; unsigned char iv[16];
assert(rarray && route && lenp && routelen); assert(rarray && route && len && routelen);
/* calculate the size of the onion */ /* calculate the size of the onion */
*lenp = routelen * 28 + 100; /* 28 bytes per layer + 100 bytes padding for the innermost layer */ *len = routelen * 28 + 100; /* 28 bytes per layer + 100 bytes padding for the innermost layer */
log(LOG_DEBUG,"create_onion() : Size of the onion is %u.",*lenp); log(LOG_DEBUG,"create_onion() : Size of the onion is %u.",*len);
/* allocate memory for the onion */ /* allocate memory for the onion */
bufp = (unsigned char *)malloc(*lenp); buf = (unsigned char *)malloc(*len);
if (!bufp) if (!buf)
{ {
log(LOG_ERR,"Error allocating memory."); log(LOG_ERR,"Error allocating memory.");
return NULL; return NULL;
@ -207,7 +203,7 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
log(LOG_DEBUG,"create_onion() : %u : %s:%u, %u/%u",routelen-retval,inet_ntoa(*((struct in_addr *)&((rarray[route[retval]])->addr))),ntohs((rarray[route[retval]])->or_port),(rarray[route[retval]])->pkey,crypto_pk_keysize((rarray[route[retval]])->pkey)); log(LOG_DEBUG,"create_onion() : %u : %s:%u, %u/%u",routelen-retval,inet_ntoa(*((struct in_addr *)&((rarray[route[retval]])->addr))),ntohs((rarray[route[retval]])->or_port),(rarray[route[retval]])->pkey,crypto_pk_keysize((rarray[route[retval]])->pkey));
} }
layer = (onion_layer_t *)(bufp + *lenp - 128); /* pointer to innermost layer */ layer = (onion_layer_t *)(buf + *len - 128); /* pointer to innermost layer */
/* create the onion layer by layer, starting with the innermost */ /* create the onion layer by layer, starting with the innermost */
for (i=0;i<routelen;i++) for (i=0;i<routelen;i++)
{ {
@ -242,16 +238,16 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
if (retval) /* error */ if (retval) /* error */
{ {
log(LOG_ERR,"Error generating random data."); log(LOG_ERR,"Error generating random data.");
free((void *)bufp); free((void *)buf);
if (cpathp) if (cpath)
{ {
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
} }
return NULL; return NULL;
@ -259,25 +255,25 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
log(LOG_DEBUG,"create_onion() : Onion layer %u built : %u, %u, %u, %s, %u.",i+1,layer->zero,layer->backf,layer->forwf,inet_ntoa(*((struct in_addr *)&layer->addr)),ntohs(layer->port)); log(LOG_DEBUG,"create_onion() : Onion layer %u built : %u, %u, %u, %s, %u.",i+1,layer->zero,layer->backf,layer->forwf,inet_ntoa(*((struct in_addr *)&layer->addr)),ntohs(layer->port));
/* build up the crypt_path */ /* build up the crypt_path */
if (cpathp) if (cpath)
{ {
cpathp[i] = (crypt_path_t *)malloc(sizeof(crypt_path_t)); cpath[i] = (crypt_path_t *)malloc(sizeof(crypt_path_t));
if (!cpathp[i]) if (!cpath[i])
{ {
log(LOG_ERR,"Error allocating memory."); log(LOG_ERR,"Error allocating memory.");
free((void *)bufp); free((void *)buf);
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
} }
log(LOG_DEBUG,"create_onion() : Building hop %u of crypt path.",i+1); log(LOG_DEBUG,"create_onion() : Building hop %u of crypt path.",i+1);
hop = cpathp[i]; hop = cpath[i];
/* set crypto functions */ /* set crypto functions */
hop->backf = layer->backf; hop->backf = layer->backf;
hop->forwf = layer->forwf; hop->forwf = layer->forwf;
@ -309,13 +305,13 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
if (!hop->f_crypto) /* cipher initialization failed */ if (!hop->f_crypto) /* cipher initialization failed */
{ {
log(LOG_ERR,"Could not create a crypto environment."); log(LOG_ERR,"Could not create a crypto environment.");
free((void *)bufp); free((void *)buf);
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
return NULL; return NULL;
} }
@ -323,13 +319,13 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
if (crypto_cipher_set_key(hop->f_crypto, hop->digest3) || if (crypto_cipher_set_key(hop->f_crypto, hop->digest3) ||
crypto_cipher_set_iv(hop->f_crypto, iv)) { crypto_cipher_set_iv(hop->f_crypto, iv)) {
log(LOG_ERR,"Could not initialize the crypto engine."); log(LOG_ERR,"Could not initialize the crypto engine.");
free((void *)bufp); free((void *)buf);
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
return NULL; return NULL;
} }
@ -349,13 +345,13 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
if (!hop->b_crypto) /* cipher initialization failed */ if (!hop->b_crypto) /* cipher initialization failed */
{ {
log(LOG_ERR,"Could not create a crypto environment."); log(LOG_ERR,"Could not create a crypto environment.");
free((void *)bufp); free((void *)buf);
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
return NULL; return NULL;
} }
@ -363,13 +359,13 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
if (crypto_cipher_set_key(hop->b_crypto, hop->digest2) || if (crypto_cipher_set_key(hop->b_crypto, hop->digest2) ||
crypto_cipher_set_iv(hop->b_crypto, iv)) { crypto_cipher_set_iv(hop->b_crypto, iv)) {
log(LOG_ERR,"Could not initialize the crypto engine."); log(LOG_ERR,"Could not initialize the crypto engine.");
free((void *)bufp); free((void *)buf);
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
return NULL; return NULL;
} }
@ -377,13 +373,13 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
/* initialize */ /* initialize */
if (crypto_cipher_encrypt_init_cipher(hop->f_crypto) || crypto_cipher_decrypt_init_cipher(hop->b_crypto)) { if (crypto_cipher_encrypt_init_cipher(hop->f_crypto) || crypto_cipher_decrypt_init_cipher(hop->b_crypto)) {
log(LOG_ERR,"Could not initialize the crypto engine."); log(LOG_ERR,"Could not initialize the crypto engine.");
free((void *)bufp); free((void *)buf);
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
return NULL; return NULL;
} }
@ -398,15 +394,15 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
if (retval) /* error */ if (retval) /* error */
{ {
log(LOG_ERR,"Error generating pseudo-random data."); log(LOG_ERR,"Error generating pseudo-random data.");
free((void *)bufp); free((void *)buf);
if (cpathp) if (cpath)
{ {
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
} }
return NULL; return NULL;
@ -419,15 +415,15 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
if (!retbuf) if (!retbuf)
{ {
log(LOG_ERR,"Error encrypting onion layer."); log(LOG_ERR,"Error encrypting onion layer.");
free((void *)bufp); free((void *)buf);
if (cpathp) if (cpath)
{ {
for (j=0;j<i;j++) { for (j=0;j<i;j++) {
if (cpathp[i]->f_crypto) if (cpath[i]->f_crypto)
crypto_free_cipher_env(cpathp[i]->f_crypto); crypto_free_cipher_env(cpath[i]->f_crypto);
if (cpathp[i]->b_crypto) if (cpath[i]->b_crypto)
crypto_free_cipher_env(cpathp[i]->b_crypto); crypto_free_cipher_env(cpath[i]->b_crypto);
free((void *)cpathp[i]); free((void *)cpath[i]);
} }
} }
return NULL; return NULL;
@ -435,10 +431,10 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
log(LOG_DEBUG,"create_onion() : Encrypted layer."); log(LOG_DEBUG,"create_onion() : Encrypted layer.");
/* calculate pointer to next layer */ /* calculate pointer to next layer */
layer = (onion_layer_t *)(bufp + (routelen-i-2)*sizeof(onion_layer_t)); layer = (onion_layer_t *)(buf + (routelen-i-2)*sizeof(onion_layer_t));
} }
return bufp; return buf;
} }
/* encrypts 128 bytes of the onion with the specified public key, the rest with /* encrypts 128 bytes of the onion with the specified public key, the rest with
@ -624,7 +620,7 @@ unsigned char *decrypt_onion(onion_layer_t *onion, uint32_t onionlen, crypto_pk_
} }
/* delete first n bytes of the onion and pads the end with n bytes of random data */ /* delete first n bytes of the onion and pads the end with n bytes of random data */
void pad_onion(unsigned char *onion, uint32_t onionlen, size_t n) void pad_onion(unsigned char *onion, uint32_t onionlen, int n)
{ {
if (onion) /* valid parameter */ if (onion) /* valid parameter */
{ {

View File

@ -144,14 +144,14 @@ typedef struct
int marked_for_close; int marked_for_close;
char *inbuf; char *inbuf;
size_t inbuflen; int inbuflen;
size_t inbuf_datalen; int inbuf_datalen;
int inbuf_reached_eof; int inbuf_reached_eof;
char *outbuf; char *outbuf;
size_t outbuflen; /* how many bytes are allocated for the outbuf? */ int outbuflen; /* how many bytes are allocated for the outbuf? */
size_t outbuf_flushlen; /* how much data should we try to flush from the outbuf? */ int outbuf_flushlen; /* how much data should we try to flush from the outbuf? */
size_t outbuf_datalen; /* how much data is there total on the outbuf? */ int outbuf_datalen; /* how much data is there total on the outbuf? */
// uint16_t aci; /* anonymous connection identifier */ // uint16_t aci; /* anonymous connection identifier */
@ -263,7 +263,7 @@ typedef struct
crypto_cipher_env_t *n_crypto; crypto_cipher_env_t *n_crypto;
crypt_path_t **cpath; crypt_path_t **cpath;
size_t cpathlen; int cpathlen;
uint32_t expire; /* expiration time for the corresponding onion */ uint32_t expire; /* expiration time for the corresponding onion */
@ -318,26 +318,26 @@ typedef struct
/********************************* buffers.c ***************************/ /********************************* buffers.c ***************************/
int buf_new(char **buf, size_t *buflen, size_t *buf_datalen); int buf_new(char **buf, int *buflen, int *buf_datalen);
void buf_free(char *buf); void buf_free(char *buf);
int read_to_buf(int s, int at_most, char **buf, size_t *buflen, size_t *buf_datalen, int *reached_eof); int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof);
/* grab from s, put onto buf, return how many bytes read */ /* grab from s, put onto buf, return how many bytes read */
int flush_buf(int s, char **buf, size_t *buflen, size_t *buf_flushlen, size_t *buf_datalen); int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen);
/* push from buf onto s /* push from buf onto s
* then memmove to front of buf * then memmove to front of buf
* return -1 or how many bytes remain on the buf */ * return -1 or how many bytes remain on the buf */
int write_to_buf(char *string, size_t string_len, int write_to_buf(char *string, int string_len,
char **buf, size_t *buflen, size_t *buf_datalen); char **buf, int *buflen, int *buf_datalen);
/* append string to buf (growing as needed, return -1 if "too big") /* append string to buf (growing as needed, return -1 if "too big")
* return total number of bytes on the buf * return total number of bytes on the buf
*/ */
int fetch_from_buf(char *string, size_t string_len, int fetch_from_buf(char *string, int string_len,
char **buf, size_t *buflen, size_t *buf_datalen); char **buf, int *buflen, int *buf_datalen);
/* if there is string_len bytes in buf, write them onto string, /* if there is 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) */
@ -360,11 +360,11 @@ circuit_t *circuit_get_by_conn(connection_t *conn);
circuit_t *circuit_get_by_naddr_nport(uint32_t naddr, uint16_t nport); circuit_t *circuit_get_by_naddr_nport(uint32_t naddr, uint16_t nport);
int circuit_deliver_data_cell(cell_t *cell, circuit_t *circ, connection_t *conn, int crypt_type); int circuit_deliver_data_cell(cell_t *cell, circuit_t *circ, connection_t *conn, int crypt_type);
int circuit_crypt(circuit_t *circ, char *in, size_t inlen, char crypt_type); int circuit_crypt(circuit_t *circ, char *in, int inlen, char crypt_type);
int circuit_init(circuit_t *circ, int aci_type); int circuit_init(circuit_t *circ, int aci_type);
void circuit_free(circuit_t *circ); void circuit_free(circuit_t *circ);
void circuit_free_cpath(crypt_path_t **cpath, size_t cpathlen); void circuit_free_cpath(crypt_path_t **cpath, int cpathlen);
void circuit_close(circuit_t *circ); void circuit_close(circuit_t *circ);
@ -517,9 +517,9 @@ connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
connection_t *connection_get_by_type(int type); connection_t *connection_get_by_type(int type);
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);
unsigned int *router_new_route(size_t *rlen); unsigned int *router_new_route(int *routelen);
unsigned char *router_create_onion(unsigned int *route, size_t routelen, size_t *lenp, crypt_path_t **cpathp); unsigned char *router_create_onion(unsigned int *route, int routelen, int *len, crypt_path_t **cpath);
routerinfo_t *router_get_first_in_route(unsigned int *route, size_t routelen); routerinfo_t *router_get_first_in_route(unsigned int *route, int routelen);
connection_t *connect_to_router_as_op(routerinfo_t *router); connection_t *connect_to_router_as_op(routerinfo_t *router);
void connection_watch_events(connection_t *conn, short events); void connection_watch_events(connection_t *conn, short events);
@ -552,10 +552,10 @@ int chooselen(double cw);
* int cw is the coin weight to use when choosing the route * int cw is the coin weight to use when choosing the route
* order of routers is from last to first * order of routers is from last to first
*/ */
unsigned int *new_route(double cw, routerinfo_t **rarray, size_t rarray_len, size_t *rlen); unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *routelen);
/* creates a new onion from route, stores it and its length into bufp and lenp respectively */ /* creates a new onion from route, stores it and its length into bufp and lenp respectively */
unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned int *route, size_t routelen, size_t *lenp, crypt_path_t **cpathp); unsigned char *create_onion(routerinfo_t **rarray, int rarray_len, unsigned int *route, int routelen, int *len, crypt_path_t **cpath);
/* encrypts 128 bytes of the onion with the specified public key, the rest with /* encrypts 128 bytes of the onion with the specified public key, the rest with
* DES OFB with the key as defined in the outter layer */ * DES OFB with the key as defined in the outter layer */
@ -565,7 +565,7 @@ unsigned char *encrypt_onion(onion_layer_t *onion, uint32_t onionlen, crypto_pk_
unsigned char *decrypt_onion(onion_layer_t *onion, uint32_t onionlen, crypto_pk_env_t *prkey); unsigned char *decrypt_onion(onion_layer_t *onion, uint32_t onionlen, crypto_pk_env_t *prkey);
/* delete first n bytes of the onion and pads the end with n bytes of random data */ /* delete first n bytes of the onion and pads the end with n bytes of random data */
void pad_onion(unsigned char *onion, uint32_t onionlen, size_t n); void pad_onion(unsigned char *onion, uint32_t onionlen, int n);
/* create a new tracked_onion entry */ /* create a new tracked_onion entry */
tracked_onion_t *new_tracked_onion(unsigned char *onion, uint32_t onionlen, tracked_onion_t **tracked_onions, tracked_onion_t **last_tracked_onion); tracked_onion_t *new_tracked_onion(unsigned char *onion, uint32_t onionlen, tracked_onion_t **tracked_onions, tracked_onion_t **last_tracked_onion);
@ -578,10 +578,10 @@ tracked_onion_t *id_tracked_onion(unsigned char *onion, uint32_t onionlen, track
/********************************* routers.c ***************************/ /********************************* routers.c ***************************/
routerinfo_t **getrouters(char *routerfile, size_t *listlenp, uint16_t or_listenport); routerinfo_t **getrouters(char *routerfile, int *listlenp, uint16_t or_listenport);
void delete_routerlist(routerinfo_t *list); void delete_routerlist(routerinfo_t *list);
/* create an NULL-terminated array of pointers pointing to elements of a router list */ /* create an NULL-terminated array of pointers pointing to elements of a router list */
routerinfo_t **make_rarray(routerinfo_t* list, size_t *listlenp); routerinfo_t **make_rarray(routerinfo_t* list, int *len);
#endif #endif

View File

@ -74,7 +74,7 @@ void delete_routerlist(routerinfo_t *list)
/* create a NULL-terminated array of pointers pointing to elements of a router list */ /* create a NULL-terminated array of pointers pointing to elements of a router list */
/* this is done in two passes through the list - inefficient but irrelevant as this is /* this is done in two passes through the list - inefficient but irrelevant as this is
* only done once when op/or start up */ * only done once when op/or start up */
routerinfo_t **make_rarray(routerinfo_t* list, size_t *len) routerinfo_t **make_rarray(routerinfo_t* list, int *len)
{ {
routerinfo_t *tmp=NULL; routerinfo_t *tmp=NULL;
int listlen = 0; int listlen = 0;
@ -116,7 +116,7 @@ routerinfo_t **make_rarray(routerinfo_t* list, size_t *len)
} }
/* load the router list */ /* load the router list */
routerinfo_t **getrouters(char *routerfile, size_t *lenp, uint16_t or_listenport) routerinfo_t **getrouters(char *routerfile, int *len, uint16_t or_listenport)
{ {
int retval = 0; int retval = 0;
char *retp = NULL; char *retp = NULL;
@ -128,7 +128,7 @@ routerinfo_t **getrouters(char *routerfile, size_t *lenp, uint16_t or_listenport
char *errtest; /* detecting errors in strtoul() calls */ char *errtest; /* detecting errors in strtoul() calls */
struct hostent *rent; struct hostent *rent;
assert(routerfile && lenp); assert(routerfile && len);
if (strcspn(routerfile,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) { if (strcspn(routerfile,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) {
log(LOG_ERR,"Filename %s contains illegal characters.",routerfile); log(LOG_ERR,"Filename %s contains illegal characters.",routerfile);
@ -414,6 +414,6 @@ routerinfo_t **getrouters(char *routerfile, size_t *lenp, uint16_t or_listenport
} }
fclose(rf); fclose(rf);
return make_rarray(routerlist, lenp); return make_rarray(routerlist, len);
} }