diff options
author | Roger Dingledine <arma@torproject.org> | 2004-04-01 03:23:28 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-04-01 03:23:28 +0000 |
commit | d01497cf3cb6e3c890e49953d5becd745a5222e5 (patch) | |
tree | 41f3ac31f1ce1e9067ffa48f8f4171d31c070cf7 /src/or | |
parent | 35f531b94febe2a91447fefaed4ea6751d55a1cb (diff) | |
download | tor-d01497cf3cb6e3c890e49953d5becd745a5222e5.tar tor-d01497cf3cb6e3c890e49953d5becd745a5222e5.tar.gz |
outline what bob does to initialize his hidden services
let circuit_launch_new return the circ it just made
svn:r1424
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/circuit.c | 35 | ||||
-rw-r--r-- | src/or/main.c | 7 | ||||
-rw-r--r-- | src/or/or.h | 6 | ||||
-rw-r--r-- | src/or/rendservice.c | 36 | ||||
-rw-r--r-- | src/or/router.c | 22 |
5 files changed, 75 insertions, 31 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c index f53a17097..1222f4315 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -15,7 +15,7 @@ static void circuit_rep_hist_note_result(circuit_t *circ); static void circuit_is_ready(circuit_t *circ); static void circuit_failed(circuit_t *circ); -static int circuit_establish_circuit(uint8_t purpose); +static circuit_t *circuit_establish_circuit(uint8_t purpose); unsigned long stats_n_relay_cells_relayed = 0; unsigned long stats_n_relay_cells_delivered = 0; @@ -1051,21 +1051,19 @@ static void circuit_failed(circuit_t *circ) { */ static int n_circuit_failures = 0; -/* Return -1 if you aren't going to try to make a circuit, 0 if you did try. */ -int circuit_launch_new(uint8_t purpose) { +/* Launch a new circuit and return a pointer to it. Return NULL if you failed. */ +circuit_t *circuit_launch_new(uint8_t purpose) { if(!(options.SocksPort||options.RunTesting)) /* no need for circuits. */ - return -1; + return NULL; if(n_circuit_failures > 5) { /* too many failed circs in a row. don't try. */ // log_fn(LOG_INFO,"%d failures so far, not trying.",n_circuit_failures); - return -1; + return NULL; } /* try a circ. if it fails, circuit_mark_for_close will increment n_circuit_failures */ - circuit_establish_circuit(purpose); - - return 0; + return circuit_establish_circuit(purpose); } void circuit_increment_failure_count(void) { @@ -1077,7 +1075,7 @@ void circuit_reset_failure_count(void) { n_circuit_failures = 0; } -static int circuit_establish_circuit(uint8_t purpose) { +static circuit_t *circuit_establish_circuit(uint8_t purpose) { routerinfo_t *firsthop; connection_t *n_conn; circuit_t *circ; @@ -1090,14 +1088,14 @@ static int circuit_establish_circuit(uint8_t purpose) { if (! circ->build_state) { log_fn(LOG_INFO,"Generating cpath length failed."); circuit_mark_for_close(circ); - return -1; + return NULL; } onion_extend_cpath(&circ->cpath, circ->build_state, &firsthop); if(!circ->cpath) { log_fn(LOG_INFO,"Generating first cpath hop failed."); circuit_mark_for_close(circ); - return -1; + return NULL; } /* now see if we're already connected to the first OR in 'route' */ @@ -1111,7 +1109,7 @@ static int circuit_establish_circuit(uint8_t purpose) { if(options.ORPort) { /* we would be connected if he were up. and he's not. */ log_fn(LOG_INFO,"Route's firsthop isn't connected."); circuit_mark_for_close(circ); - return -1; + return NULL; } if(!n_conn) { /* launch the connection */ @@ -1119,14 +1117,15 @@ static int circuit_establish_circuit(uint8_t purpose) { if(!n_conn) { /* connect failed, forget the whole thing */ log_fn(LOG_INFO,"connect to firsthop failed. Closing."); circuit_mark_for_close(circ); - return -1; + return NULL; } } log_fn(LOG_DEBUG,"connecting in progress (or finished). Good."); - return 0; /* return success. The onion/circuit/etc will be taken care of automatically - * (may already have been) whenever n_conn reaches OR_CONN_STATE_OPEN. - */ + /* return success. The onion/circuit/etc will be taken care of automatically + * (may already have been) whenever n_conn reaches OR_CONN_STATE_OPEN. + */ + return circ; } else { /* it (or a twin) is already open. use it. */ circ->n_addr = n_conn->addr; circ->n_port = n_conn->port; @@ -1135,10 +1134,10 @@ static int circuit_establish_circuit(uint8_t purpose) { if(circuit_send_next_onion_skin(circ) < 0) { log_fn(LOG_INFO,"circuit_send_next_onion_skin failed."); circuit_mark_for_close(circ); - return -1; + return NULL; } } - return 0; + return circ; } /* find circuits that are waiting on me, if any, and get them to send the onion */ diff --git a/src/or/main.c b/src/or/main.c index e7b5d52bc..44e734f9a 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -281,9 +281,12 @@ void directory_has_arrived(void) { log_fn(LOG_INFO, "We now have a directory."); + /* just for testing */ directory_initiate_command(router_pick_directory_server(), DIR_PURPOSE_FETCH_HIDSERV, "foo", 3); + rend_services_init(); /* get bob to initialize all his hidden services */ + } /* Perform regular maintenance tasks for a single connection. This @@ -332,7 +335,7 @@ static void run_scheduled_events(time_t now) { /* it's time to fetch a new directory and/or post our descriptor */ if(options.ORPort) { router_rebuild_descriptor(); - router_upload_desc_to_dirservers(); + router_upload_dir_desc_to_dirservers(); } if(!options.DirPort) { /* NOTE directory servers do not currently fetch directories. @@ -574,7 +577,7 @@ static int do_main_loop(void) { if(options.ORPort) { cpu_init(); /* launch cpuworkers. Need to do this *after* we've read the onion key. */ - router_upload_desc_to_dirservers(); /* upload our descriptor to all dirservers */ + router_upload_dir_desc_to_dirservers(); /* upload our descriptor to all dirservers */ } /* start up the necessary connections based on which ports are diff --git a/src/or/or.h b/src/or/or.h index a54a8287c..907010ec9 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -689,7 +689,7 @@ void circuit_log_path(int severity, circuit_t *circ); void circuit_dump_by_conn(connection_t *conn, int severity); void circuit_expire_unused_circuits(void); -int circuit_launch_new(uint8_t purpose); +circuit_t *circuit_launch_new(uint8_t purpose); void circuit_increment_failure_count(void); void circuit_reset_failure_count(void); void circuit_n_conn_open(connection_t *or_conn); @@ -929,7 +929,8 @@ int init_keys(void); crypto_pk_env_t *init_key_from_file(const char *fname); void router_retry_connections(void); -void router_upload_desc_to_dirservers(void); +void router_upload_dir_desc_to_dirservers(void); +void router_post_to_dirservers(uint8_t purpose, const char *payload, int payload_len); int router_compare_to_my_exit_policy(connection_t *conn); const char *router_get_my_descriptor(void); int router_rebuild_descriptor(void); @@ -1018,6 +1019,7 @@ int rend_parse_rendezvous_address(char *address); int rend_config_services(or_options_t *options); int rend_service_init_keys(void); +int rend_services_init(void); #endif diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 83b511535..005b1070d 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -229,3 +229,39 @@ int rend_service_init_keys(void) } return 0; } + + +#define NUM_INTRO_POINTS 3 +int rend_services_init(void) { + int i; + routerinfo_t *router; + routerlist_t *rl; + circuit_t *circ; + + router_get_routerlist(&rl); + + //for each of bob's services, + + /* The directory is now here. Pick three ORs as intro points. */ + for (i=0;i<rl->n_routers;i++) { + router = rl->routers[i]; + //... + // maybe built a smartlist of all of them, then pick at random + // until you have three? or something smarter. + } + + /* build a service descriptor out of them, and tuck it away + * somewhere so we don't lose it */ + + /* post it to the dirservers */ + //call router_post_to_dirservers(DIR_PURPOSE_UPLOAD_HIDSERV, desc, desc_len); + + // for each intro point, + { + circ = circuit_launch_new(CIRCUIT_PURPOSE_S_ESTABLISH_INTRO); + // tell circ which hidden service this is about + } + + // anything else? +} + diff --git a/src/or/router.c b/src/or/router.c index 160ca128d..59b257c97 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -236,26 +236,30 @@ void router_retry_connections(void) { } } -void router_upload_desc_to_dirservers(void) { - int i; - routerinfo_t *router; - routerlist_t *rl; +void router_upload_dir_desc_to_dirservers(void) { const char *s; - router_get_routerlist(&rl); - if(!rl) - return; - s = router_get_my_descriptor(); if (!s) { log_fn(LOG_WARN, "No descriptor; skipping upload"); return; } + router_post_to_dirservers(DIR_PURPOSE_UPLOAD_DIR, s, strlen(s)); +} + +void router_post_to_dirservers(uint8_t purpose, const char *payload, int payload_len) { + int i; + routerinfo_t *router; + routerlist_t *rl; + + router_get_routerlist(&rl); + if(!rl) + return; for(i=0;i<rl->n_routers;i++) { router = rl->routers[i]; if(router->dir_port > 0) - directory_initiate_command(router, DIR_PURPOSE_UPLOAD_DIR, s, strlen(s)); + directory_initiate_command(router, purpose, payload, payload_len); } } |