router->is_trusted_dir implies router->dir_port>0

and add some infrastructure for fetching running-routers list


svn:r1973
This commit is contained in:
Roger Dingledine
2004-06-16 21:08:29 +00:00
parent c9ebd47633
commit ba5d48e852
5 changed files with 59 additions and 13 deletions
+33 -3
View File
@@ -66,7 +66,7 @@ directory_post_to_dirservers(uint8_t purpose, const char *payload,
for(i=0; i < smartlist_len(rl->routers); i++) {
router = smartlist_get(rl->routers, i);
if(router->dir_port > 0)
if(router->is_trusted_dir)
directory_initiate_command(router, purpose, payload, payload_len);
}
}
@@ -123,6 +123,8 @@ directory_initiate_command(routerinfo_t *router, uint8_t purpose,
return;
}
tor_assert(router->dir_port);
conn = connection_new(CONN_TYPE_DIR);
/* set up conn so it's got all the data we need to remember */
@@ -183,7 +185,8 @@ directory_initiate_command(routerinfo_t *router, uint8_t purpose,
*/
static void directory_send_command(connection_t *conn, int purpose,
const char *payload, int payload_len) {
char fetchstring[] = "GET / HTTP/1.0\r\n\r\n";
char fetchwholedir[] = "GET / HTTP/1.0\r\n\r\n";
char fetchrunninglist[] = "GET /running-routers HTTP/1.0\r\n\r\n";
char tmp[8192];
tor_assert(conn && conn->type == CONN_TYPE_DIR);
@@ -191,7 +194,11 @@ static void directory_send_command(connection_t *conn, int purpose,
switch(purpose) {
case DIR_PURPOSE_FETCH_DIR:
tor_assert(payload == NULL);
connection_write_to_buf(fetchstring, strlen(fetchstring), conn);
connection_write_to_buf(fetchwholedir, strlen(fetchwholedir), conn);
break;
case DIR_PURPOSE_FETCH_RUNNING_LIST:
tor_assert(payload == NULL);
connection_write_to_buf(fetchrunninglist, strlen(fetchrunninglist), conn);
break;
case DIR_PURPOSE_UPLOAD_DIR:
tor_assert(payload);
@@ -344,6 +351,19 @@ int connection_dir_process_inbuf(connection_t *conn) {
directory_has_arrived(); /* do things we've been waiting to do */
}
if(conn->purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) {
/* just update our list of running routers, if this list is new info */
log_fn(LOG_INFO,"Received running-routers list (size %d):\n%s", body_len, body);
if(status_code != 200) {
log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.",
status_code);
free(body); free(headers);
connection_mark_for_close(conn);
return -1;
}
/* XXX008 hand 'body' to something that parses a running-routers list. */
}
if(conn->purpose == DIR_PURPOSE_UPLOAD_DIR) {
switch(status_code) {
case 200:
@@ -466,6 +486,16 @@ directory_handle_command_get(connection_t *conn, char *headers,
return 0;
}
if(!strcmp(url,"/running-routers")) { /* running-routers fetch */
dlen = dirserv_get_runningrouters(&cp);
snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nContent-Length: %d\r\nContent-Type: text/plain\r\n\r\n",
(int)dlen);
connection_write_to_buf(tmp, strlen(tmp), conn);
connection_write_to_buf(cp, strlen(cp), conn);
return 0;
}
if(!strncmp(url,rend_fetch_url,strlen(rend_fetch_url))) {
/* rendezvous descriptor fetch */
const char *descp;
+8
View File
@@ -618,6 +618,14 @@ size_t dirserv_get_directory(const char **directory)
return the_directory_len;
}
/** Set *<b>rr</b> to the most recently generated encoded signed
* running-routers list, generating a new one as necessary. */
size_t dirserv_get_runningrouters(const char **rr)
{
/* XXX008 fill in this function */
return 0;
}
/*
Local Variables:
mode:c
+11 -7
View File
@@ -241,20 +241,23 @@
#define _DIR_PURPOSE_MIN 1
/** Purpose for connection to directory server: download a directory. */
#define DIR_PURPOSE_FETCH_DIR 1
/** Purpose for connection to directory server: download just the list
* of running routers. */
#define DIR_PURPOSE_FETCH_RUNNING_LIST 2
/** Purpose for connection to directory server: download a rendezvous
* descriptor. */
#define DIR_PURPOSE_FETCH_RENDDESC 2
#define DIR_PURPOSE_FETCH_RENDDESC 3
/** Purpose for connection to directory server: set after a rendezvous
* descriptor is downloaded. */
#define DIR_PURPOSE_HAS_FETCHED_RENDDESC 3
#define DIR_PURPOSE_HAS_FETCHED_RENDDESC 4
/** Purpose for connection to directory server: upload a server descriptor. */
#define DIR_PURPOSE_UPLOAD_DIR 4
#define DIR_PURPOSE_UPLOAD_DIR 5
/** Purpose for connection to directory server: upload a rendezvous
* descriptor. */
#define DIR_PURPOSE_UPLOAD_RENDDESC 5
#define DIR_PURPOSE_UPLOAD_RENDDESC 6
/** Purpose for connection at a directory server. */
#define DIR_PURPOSE_SERVER 6
#define _DIR_PURPOSE_MAX 6
#define DIR_PURPOSE_SERVER 7
#define _DIR_PURPOSE_MAX 7
/** Circuit state: I'm the OP, still haven't done all my handshakes. */
#define CIRCUIT_STATE_BUILDING 0
@@ -1107,11 +1110,12 @@ void dirserv_free_fingerprint_list();
int dirserv_add_descriptor(const char **desc);
int dirserv_init_from_directory_string(const char *dir);
void dirserv_free_descriptors();
void dirserv_remove_old_servers(void);
int dirserv_dump_directory_to_string(char *s, unsigned int maxlen,
crypto_pk_env_t *private_key);
void directory_set_dirty(void);
size_t dirserv_get_directory(const char **cp);
void dirserv_remove_old_servers(void);
size_t dirserv_get_runningrouters(const char **rr);
/********************************* dns.c ***************************/
+1
View File
@@ -533,6 +533,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
router->or_port,
router->socks_port,
router->dir_port,
/* XXX008 only use dir_port here if authoritative server, else use opt line below */
router->platform,
published,
(int) router->bandwidthrate,
+6 -3
View File
@@ -58,7 +58,7 @@ routerinfo_t *router_pick_directory_server(void) {
return choice;
}
/** Pick a random running router with a positive dir_port from our
/** Pick a random running router that's a trusted dirserver from our
* routerlist. */
static routerinfo_t *router_pick_directory_server_impl(void) {
int i;
@@ -72,8 +72,10 @@ static routerinfo_t *router_pick_directory_server_impl(void) {
sl = smartlist_create();
for(i=0;i< smartlist_len(routerlist->routers); i++) {
router = smartlist_get(routerlist->routers, i);
if(router->dir_port > 0 && router->is_running && router->is_trusted_dir)
if(router->is_running && router->is_trusted_dir) {
tor_assert(router->dir_port > 0);
smartlist_add(sl, router);
}
}
router = smartlist_choose(sl);
@@ -87,7 +89,8 @@ static routerinfo_t *router_pick_directory_server_impl(void) {
* so we cycle through the list again. */
for(i=0; i < smartlist_len(routerlist->routers); i++) {
router = smartlist_get(routerlist->routers, i);
if(router->dir_port > 0 && router->is_trusted_dir) {
if(router->is_trusted_dir) {
tor_assert(router->dir_port > 0);
router->is_running = 1;
dirserver = router;
}