aboutsummaryrefslogtreecommitdiff
path: root/src/or/onion.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-04-08 06:44:38 +0000
committerRoger Dingledine <arma@torproject.org>2003-04-08 06:44:38 +0000
commitcdf6ea201fc5868fe10f095093862431fa92b03a (patch)
tree2f287973c24fddd897c9af08e2fedd1b69d6813e /src/or/onion.c
parent79b77b421d6e6b82de46cca841d30808bba89322 (diff)
downloadtor-cdf6ea201fc5868fe10f095093862431fa92b03a.tar
tor-cdf6ea201fc5868fe10f095093862431fa92b03a.tar.gz
put most of the remaining exit policy stuff in
route selection still doesn't pay attention to exit policies though svn:r227
Diffstat (limited to 'src/or/onion.c')
-rw-r--r--src/or/onion.c53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/or/onion.c b/src/or/onion.c
index e86553311..6d920052a 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -8,6 +8,7 @@ extern or_options_t options; /* command-line and config-file options */
static int onion_process(circuit_t *circ);
static int onion_deliver_to_conn(aci_t aci, unsigned char *onion, uint32_t onionlen, connection_t *conn);
+static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len);
static int find_tracked_onion(unsigned char *onion, uint32_t onionlen);
int decide_aci_type(uint32_t local_addr, uint16_t local_port,
@@ -335,7 +336,7 @@ int chooselen(double cw)
unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *routelen)
{
int i, j;
- int num_acceptable_routers = 0;
+ int num_acceptable_routers;
unsigned int *route = NULL;
unsigned int oldchoice, choice;
@@ -348,26 +349,8 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r
}
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 a new option...",i);
- if(options.ORPort &&
- !connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) {
- log(LOG_DEBUG,"Nope, %d is not connected.",i);
- goto next_i_loop;
- }
- for(j=0;j<i;j++) {
- if(!crypto_pk_cmp_keys(rarray[i]->pkey, rarray[j]->pkey)) {
- /* these guys are twins. so we've already counted him. */
- log(LOG_DEBUG,"Nope, %d is a twin of %d.",i,j);
- goto next_i_loop;
- }
- }
- num_acceptable_routers++;
- log(LOG_DEBUG,"I like %d. num_acceptable_routers now %d.",i, num_acceptable_routers);
- next_i_loop:
- ; /* our compiler may need an explicit statement after the label */
- }
-
+ num_acceptable_routers = count_acceptable_routers(rarray, rarray_len);
+
if(num_acceptable_routers < *routelen) {
log(LOG_DEBUG,"new_route(): Cutting routelen from %d to %d.",*routelen, num_acceptable_routers);
*routelen = num_acceptable_routers;
@@ -413,6 +396,34 @@ unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, int *r
return route;
}
+static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len) {
+ int i, j;
+ int num=0;
+
+ for(i=0;i<rarray_len;i++) {
+ log(LOG_DEBUG,"Contemplating whether router %d is a new option...",i);
+ if(options.ORPort &&
+ !connection_exact_get_by_addr_port(rarray[i]->addr, rarray[i]->or_port)) {
+ log(LOG_DEBUG,"Nope, %d is not connected.",i);
+ goto next_i_loop;
+ }
+ for(j=0;j<i;j++) {
+ if(!crypto_pk_cmp_keys(rarray[i]->pkey, rarray[j]->pkey)) {
+ /* these guys are twins. so we've already counted him. */
+ log(LOG_DEBUG,"Nope, %d is a twin of %d.",i,j);
+ goto next_i_loop;
+ }
+ }
+ num++;
+ log(LOG_DEBUG,"I like %d. num_acceptable_routers now %d.",i, num);
+ next_i_loop:
+ ; /* our compiler may need an explicit statement after the label */
+ }
+
+ return num;
+}
+
+
crypto_cipher_env_t *
create_onion_cipher(int cipher_type, char *key, char *iv, int encrypt_mode)
{