mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-23 20:03:31 +01:00
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:
parent
d8c0d21b49
commit
3a7f3ba348
@ -8,7 +8,7 @@
|
||||
|
||||
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);
|
||||
|
||||
@ -26,7 +26,7 @@ void buf_free(char *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 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 */
|
||||
|
||||
if(!options.LinkPadding && at_most > 10*sizeof(cell_t)) {
|
||||
/* if no linkpadding. do a rudimentary round-robin so one
|
||||
* connection can't hog our receiver bucket
|
||||
/* if no linkpadding: do a rudimentary round-robin so one
|
||||
* connection can't hog an outgoing connection
|
||||
*/
|
||||
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
|
||||
* 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,
|
||||
char **buf, size_t *buflen, size_t *buf_datalen) {
|
||||
int write_to_buf(char *string, int string_len,
|
||||
char **buf, int *buflen, int *buf_datalen) {
|
||||
|
||||
/* append string to buf (growing as needed, return -1 if "too big")
|
||||
* 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,
|
||||
char **buf, size_t *buflen, size_t *buf_datalen) {
|
||||
int fetch_from_buf(char *string, int string_len,
|
||||
char **buf, int *buflen, int *buf_datalen) {
|
||||
|
||||
/* if there is string_len bytes in buf, write them onto string,
|
||||
* then memmove buf back (that is, remove them from buf) */
|
||||
|
@ -80,7 +80,7 @@ void circuit_free(circuit_t *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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
int i;
|
||||
crypt_path_t *thishop;
|
||||
|
@ -182,18 +182,18 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) {
|
||||
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]];
|
||||
}
|
||||
|
||||
/* a wrapper around new_route. put all these in routers.c perhaps? */
|
||||
unsigned int *router_new_route(size_t *rlen) {
|
||||
return new_route(options.CoinWeight, router_array,rarray_len, rlen);
|
||||
unsigned int *router_new_route(int *routelen) {
|
||||
return new_route(options.CoinWeight, router_array, rarray_len, routelen);
|
||||
}
|
||||
|
||||
/* a wrapper around create_onion */
|
||||
unsigned char *router_create_onion(unsigned int *route, size_t routelen, size_t *lenp, crypt_path_t **cpathp) {
|
||||
return create_onion(router_array,rarray_len,route,routelen,lenp,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,len,cpath);
|
||||
}
|
||||
|
||||
|
||||
|
174
src/or/onion.c
174
src/or/onion.c
@ -92,23 +92,21 @@ int chooselen(double cw)
|
||||
* int cw is the coin weight to use when choosing the route
|
||||
* 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 num_acceptable_routers = 0;
|
||||
int retval = 0;
|
||||
unsigned int *route = NULL;
|
||||
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);
|
||||
if (routelen == -1) {
|
||||
*routelen = chooselen(cw);
|
||||
if (*routelen == -1) {
|
||||
log(LOG_ERR,"Choosing route length failed.");
|
||||
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++) {
|
||||
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:
|
||||
}
|
||||
|
||||
if(num_acceptable_routers < routelen) {
|
||||
log(LOG_DEBUG,"new_route(): Cutting routelen from %d to %d.",routelen, num_acceptable_routers);
|
||||
routelen = num_acceptable_routers;
|
||||
if(num_acceptable_routers < *routelen) {
|
||||
log(LOG_DEBUG,"new_route(): Cutting routelen from %d to %d.",*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.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* allocate memory for the new route */
|
||||
route = (unsigned int *)malloc(routelen * sizeof(unsigned int));
|
||||
route = (unsigned int *)malloc(*routelen * sizeof(unsigned int));
|
||||
if (!route) {
|
||||
log(LOG_ERR,"Memory allocation failed.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
oldchoice = rarray_len;
|
||||
for(i=0;i<routelen;i++) {
|
||||
for(i=0;i<*routelen;i++) {
|
||||
log(LOG_DEBUG,"new_route(): Choosing hop %u.",i);
|
||||
retval = crypto_pseudo_rand(sizeof(unsigned int),(unsigned char *)&choice);
|
||||
if (retval) {
|
||||
if(crypto_pseudo_rand(sizeof(unsigned int),(unsigned char *)&choice)) {
|
||||
free((void *)route);
|
||||
return NULL;
|
||||
}
|
||||
@ -171,31 +168,30 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, size_t rarray_len, siz
|
||||
route[i] = choice;
|
||||
}
|
||||
|
||||
*rlen = routelen;
|
||||
return route;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
/* creates a new onion from route, stores it and its length into buf and len respectively */
|
||||
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 retval = 0;
|
||||
onion_layer_t *layer = NULL;
|
||||
crypt_path_t *hop = NULL;
|
||||
unsigned char *retbuf = NULL;
|
||||
unsigned char *bufp;
|
||||
unsigned char *buf;
|
||||
routerinfo_t *router;
|
||||
unsigned char iv[16];
|
||||
|
||||
assert(rarray && route && lenp && routelen);
|
||||
assert(rarray && route && len && routelen);
|
||||
|
||||
/* calculate the size of the onion */
|
||||
*lenp = 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);
|
||||
*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.",*len);
|
||||
|
||||
/* allocate memory for the onion */
|
||||
bufp = (unsigned char *)malloc(*lenp);
|
||||
if (!bufp)
|
||||
buf = (unsigned char *)malloc(*len);
|
||||
if (!buf)
|
||||
{
|
||||
log(LOG_ERR,"Error allocating memory.");
|
||||
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));
|
||||
}
|
||||
|
||||
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 */
|
||||
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 */
|
||||
{
|
||||
log(LOG_ERR,"Error generating random data.");
|
||||
free((void *)bufp);
|
||||
if (cpathp)
|
||||
free((void *)buf);
|
||||
if (cpath)
|
||||
{
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
|
||||
free((void *)cpathp[i]);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
}
|
||||
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));
|
||||
|
||||
/* build up the crypt_path */
|
||||
if (cpathp)
|
||||
if (cpath)
|
||||
{
|
||||
cpathp[i] = (crypt_path_t *)malloc(sizeof(crypt_path_t));
|
||||
if (!cpathp[i])
|
||||
cpath[i] = (crypt_path_t *)malloc(sizeof(crypt_path_t));
|
||||
if (!cpath[i])
|
||||
{
|
||||
log(LOG_ERR,"Error allocating memory.");
|
||||
free((void *)bufp);
|
||||
free((void *)buf);
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[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);
|
||||
hop = cpathp[i];
|
||||
hop = cpath[i];
|
||||
/* set crypto functions */
|
||||
hop->backf = layer->backf;
|
||||
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 */
|
||||
{
|
||||
log(LOG_ERR,"Could not create a crypto environment.");
|
||||
free((void *)bufp);
|
||||
free((void *)buf);
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
free((void *)cpathp[i]);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
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) ||
|
||||
crypto_cipher_set_iv(hop->f_crypto, iv)) {
|
||||
log(LOG_ERR,"Could not initialize the crypto engine.");
|
||||
free((void *)bufp);
|
||||
free((void *)buf);
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
free((void *)cpathp[i]);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
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 */
|
||||
{
|
||||
log(LOG_ERR,"Could not create a crypto environment.");
|
||||
free((void *)bufp);
|
||||
free((void *)buf);
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
free((void *)cpathp[i]);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
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) ||
|
||||
crypto_cipher_set_iv(hop->b_crypto, iv)) {
|
||||
log(LOG_ERR,"Could not initialize the crypto engine.");
|
||||
free((void *)bufp);
|
||||
free((void *)buf);
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
free((void *)cpathp[i]);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -377,13 +373,13 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
|
||||
/* initialize */
|
||||
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.");
|
||||
free((void *)bufp);
|
||||
free((void *)buf);
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
free((void *)cpathp[i]);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -398,15 +394,15 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
|
||||
if (retval) /* error */
|
||||
{
|
||||
log(LOG_ERR,"Error generating pseudo-random data.");
|
||||
free((void *)bufp);
|
||||
if (cpathp)
|
||||
free((void *)buf);
|
||||
if (cpath)
|
||||
{
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
free((void *)cpathp[i]);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@ -419,15 +415,15 @@ unsigned char *create_onion(routerinfo_t **rarray, size_t rarray_len, unsigned i
|
||||
if (!retbuf)
|
||||
{
|
||||
log(LOG_ERR,"Error encrypting onion layer.");
|
||||
free((void *)bufp);
|
||||
if (cpathp)
|
||||
free((void *)buf);
|
||||
if (cpath)
|
||||
{
|
||||
for (j=0;j<i;j++) {
|
||||
if (cpathp[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->f_crypto);
|
||||
if (cpathp[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpathp[i]->b_crypto);
|
||||
free((void *)cpathp[i]);
|
||||
if (cpath[i]->f_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->f_crypto);
|
||||
if (cpath[i]->b_crypto)
|
||||
crypto_free_cipher_env(cpath[i]->b_crypto);
|
||||
free((void *)cpath[i]);
|
||||
}
|
||||
}
|
||||
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.");
|
||||
|
||||
/* 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
|
||||
@ -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 */
|
||||
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 */
|
||||
{
|
||||
|
46
src/or/or.h
46
src/or/or.h
@ -144,14 +144,14 @@ typedef struct
|
||||
int marked_for_close;
|
||||
|
||||
char *inbuf;
|
||||
size_t inbuflen;
|
||||
size_t inbuf_datalen;
|
||||
int inbuflen;
|
||||
int inbuf_datalen;
|
||||
int inbuf_reached_eof;
|
||||
|
||||
char *outbuf;
|
||||
size_t outbuflen; /* how many bytes are allocated for the outbuf? */
|
||||
size_t 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 outbuflen; /* how many bytes are allocated for the outbuf? */
|
||||
int outbuf_flushlen; /* how much data should we try to flush from the outbuf? */
|
||||
int outbuf_datalen; /* how much data is there total on the outbuf? */
|
||||
|
||||
// uint16_t aci; /* anonymous connection identifier */
|
||||
|
||||
@ -263,7 +263,7 @@ typedef struct
|
||||
crypto_cipher_env_t *n_crypto;
|
||||
|
||||
crypt_path_t **cpath;
|
||||
size_t cpathlen;
|
||||
int cpathlen;
|
||||
|
||||
uint32_t expire; /* expiration time for the corresponding onion */
|
||||
|
||||
@ -318,26 +318,26 @@ typedef struct
|
||||
|
||||
/********************************* 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);
|
||||
|
||||
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 */
|
||||
|
||||
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
|
||||
* then memmove to front of buf
|
||||
* return -1 or how many bytes remain on the buf */
|
||||
|
||||
int write_to_buf(char *string, size_t string_len,
|
||||
char **buf, size_t *buflen, size_t *buf_datalen);
|
||||
int write_to_buf(char *string, int string_len,
|
||||
char **buf, int *buflen, int *buf_datalen);
|
||||
/* append string to buf (growing as needed, return -1 if "too big")
|
||||
* return total number of bytes on the buf
|
||||
*/
|
||||
|
||||
int fetch_from_buf(char *string, size_t string_len,
|
||||
char **buf, size_t *buflen, size_t *buf_datalen);
|
||||
int fetch_from_buf(char *string, int string_len,
|
||||
char **buf, int *buflen, int *buf_datalen);
|
||||
/* if there is string_len bytes in buf, write them onto string,
|
||||
* * 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);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
@ -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);
|
||||
|
||||
routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
|
||||
unsigned int *router_new_route(size_t *rlen);
|
||||
unsigned char *router_create_onion(unsigned int *route, size_t routelen, size_t *lenp, crypt_path_t **cpathp);
|
||||
routerinfo_t *router_get_first_in_route(unsigned int *route, size_t routelen);
|
||||
unsigned int *router_new_route(int *routelen);
|
||||
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, int routelen);
|
||||
connection_t *connect_to_router_as_op(routerinfo_t *router);
|
||||
|
||||
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
|
||||
* 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 */
|
||||
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
|
||||
* 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);
|
||||
|
||||
/* 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 */
|
||||
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 ***************************/
|
||||
|
||||
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);
|
||||
/* 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
|
||||
|
@ -74,7 +74,7 @@ void delete_routerlist(routerinfo_t *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
|
||||
* 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;
|
||||
int listlen = 0;
|
||||
@ -116,7 +116,7 @@ routerinfo_t **make_rarray(routerinfo_t* list, size_t *len)
|
||||
}
|
||||
|
||||
/* 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;
|
||||
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 */
|
||||
struct hostent *rent;
|
||||
|
||||
assert(routerfile && lenp);
|
||||
assert(routerfile && len);
|
||||
|
||||
if (strcspn(routerfile,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) {
|
||||
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);
|
||||
return make_rarray(routerlist, lenp);
|
||||
return make_rarray(routerlist, len);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user