summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-06-16 21:08:29 +0000
committerRoger Dingledine <arma@torproject.org>2004-06-16 21:08:29 +0000
commitba5d48e852ba8fe463a9ef98b0ca81a6f4b589d3 (patch)
tree400035260071b3d602fb581ec71aaf94ab59fe04
parentc9ebd47633b08b0b42d3a6ff85a401c56d52ef90 (diff)
downloadtor-ba5d48e852ba8fe463a9ef98b0ca81a6f4b589d3.tar.gz
tor-ba5d48e852ba8fe463a9ef98b0ca81a6f4b589d3.zip
router->is_trusted_dir implies router->dir_port>0
and add some infrastructure for fetching running-routers list svn:r1973
-rw-r--r--src/or/directory.c36
-rw-r--r--src/or/dirserv.c8
-rw-r--r--src/or/or.h18
-rw-r--r--src/or/router.c1
-rw-r--r--src/or/routerlist.c9
5 files changed, 59 insertions, 13 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 3119a3fb7b..3f8b3a94cc 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -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;
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 3ca942de09..d2d41627f2 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -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
diff --git a/src/or/or.h b/src/or/or.h
index 58ad0713fc..d2a460c8c6 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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 ***************************/
diff --git a/src/or/router.c b/src/or/router.c
index d186ce5a06..ebdea64cdf 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -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,
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index e221ec4a43..b77c796920 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -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;
}