diff options
-rw-r--r-- | src/or/circuituse.c | 8 | ||||
-rw-r--r-- | src/or/connection_edge.c | 8 | ||||
-rw-r--r-- | src/or/connection_or.c | 2 | ||||
-rw-r--r-- | src/or/directory.c | 12 | ||||
-rw-r--r-- | src/or/or.h | 2 | ||||
-rw-r--r-- | src/or/router.c | 2 | ||||
-rw-r--r-- | src/or/routerparse.c | 31 | ||||
-rw-r--r-- | src/or/test.c | 8 |
8 files changed, 57 insertions, 16 deletions
diff --git a/src/or/circuituse.c b/src/or/circuituse.c index 549993a7c..19b9213ee 100644 --- a/src/or/circuituse.c +++ b/src/or/circuituse.c @@ -76,10 +76,10 @@ static int circuit_is_acceptable(circuit_t *circ, if (conn->socks_request && conn->socks_request->command == SOCKS_COMMAND_RESOLVE) { - /* 0.0.7 servers and earlier don't support DNS resolution. There are no - * ORs running code before 0.0.7, so we only worry about 0.0.7. Once all - * servers are running 0.0.8, remove this check. */ - if (!strcmpstart(exitrouter->platform, "Tor 0.0.7")) + /* 0.0.7 servers and earlier don't support DNS resolution. 0.0.8 servers + * have buggy resolve support. Once there are more 0.0.9 servers, change + * this to 0.0.9pre1. XXX */ + if (!tor_version_as_new_as(exitrouter->platform, "0.0.8")) return 0; } else if(purpose == CIRCUIT_PURPOSE_C_GENERAL) { if(!connection_ap_can_use_exit(conn, exitrouter)) { diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 1b2279c93..7aee5fa63 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -954,10 +954,10 @@ int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit) exit->nickname, conn->socks_request->address, conn->socks_request->port); if (conn->socks_request->command == SOCKS_COMMAND_RESOLVE) { - /* 0.0.7 servers and earlier don't support DNS resolution. There are no - * ORs running code before 0.0.7, so we only worry about 0.0.7. Once all - * servers are running 0.0.8, remove this check. XXX */ - return strcmpstart(exit->platform, "Tor 0.0.7") ? 1 : 0; + /* 0.0.7 servers and earlier don't support DNS resolution. 0.0.8 servers + * have buggy resolve support. Once there are more 0.0.9 servers, change + * this to 0.0.9pre1. XXX */ + return tor_version_as_new_as(exit->platform, "0.0.8"); } addr = client_dns_lookup_entry(conn->socks_request->address); if(router_compare_addr_to_exit_policy(addr, diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 5272b4a6c..3f7da9654 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -218,7 +218,7 @@ int connection_tls_start_handshake(connection_t *conn, int receiving) { him = router_get_by_digest(conn->identity_digest); me = router_get_my_routerinfo(); - if(him && !strcmpstart(him->platform, "Tor 0.0.7") && + if(him && !tor_version_as_new_as(him->platform, "0.0.8pre1") && (!me || !me->is_verified)) { log_fn(LOG_INFO,"He's running 0.0.7, and I'm unverified. Acting like OP."); use_no_cert = 1; diff --git a/src/or/directory.c b/src/or/directory.c index 278b042df..d7b47c73e 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -214,20 +214,22 @@ static void directory_send_command(connection_t *conn, int purpose, char fetchrunninglist[] = "GET /tor/running-routers HTTP/1.0\r\n\r\n"; char tmp[8192]; routerinfo_t *router; + int use_newer = 0; tor_assert(conn && conn->type == CONN_TYPE_DIR); router = router_get_by_digest(conn->identity_digest); tor_assert(router); /* the func that calls us found it, so we should too */ + use_newer = tor_version_as_new_as(router->platform, "0.0.9pre1"); + switch(purpose) { case DIR_PURPOSE_FETCH_DIR: tor_assert(payload == NULL); - if (!strcmpstart(router->platform, "Tor 0.0.7") || - !strcmpstart(router->platform, "Tor 0.0.8")) - connection_write_to_buf(fetchwholedir, strlen(fetchwholedir), conn); - else + if(use_newer) connection_write_to_buf(fetchwholedir_z, strlen(fetchwholedir_z), conn); + else + connection_write_to_buf(fetchwholedir, strlen(fetchwholedir), conn); break; case DIR_PURPOSE_FETCH_RUNNING_LIST: tor_assert(payload == NULL); @@ -236,7 +238,7 @@ static void directory_send_command(connection_t *conn, int purpose, case DIR_PURPOSE_UPLOAD_DIR: tor_assert(payload); snprintf(tmp, sizeof(tmp), "POST %s/ HTTP/1.0\r\nContent-Length: %d\r\n\r\n", - strcmpstart(router->platform, "Tor 0.0.8") ? "/tor" : "", + use_newer ? "/tor" : "", payload_len); connection_write_to_buf(tmp, strlen(tmp), conn); connection_write_to_buf(payload, payload_len, conn); diff --git a/src/or/or.h b/src/or/or.h index 04f02aba2..c1d00d3f0 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1461,8 +1461,8 @@ struct exit_policy_t *router_parse_exit_policy_from_string(const char *s); int check_software_version_against_directory(const char *directory, int ignoreversion); int tor_version_parse(const char *s, tor_version_t *out); +int tor_version_as_new_as(const char *platform, const char *cutoff); int tor_version_compare(tor_version_t *a, tor_version_t *b); -int tor_version_compare_to_mine(const char *s); #endif diff --git a/src/or/router.c b/src/or/router.c index ce564ff97..38e741e30 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -397,7 +397,7 @@ void router_retry_connections(void) { int router_is_clique_mode(routerinfo_t *router) { if(router->is_trusted_dir) return 1; - if(!strcmpstart(router->platform, "Tor 0.0.7")) + if(!tor_version_as_new_as(router->platform, "0.0.8pre1")) return 1; return 0; } diff --git a/src/or/routerparse.c b/src/or/routerparse.c index fdc34f205..2b2c6dfce 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -1335,6 +1335,37 @@ static int router_get_hash_impl(const char *s, char *digest, return 0; } +/** Parse the Tor version of the platform string <b>platform</b>, + * and compare it to the version in <b>cutoff</b>. Return 1 if + * the router is at least as new as the cutoff, else return 0. + */ +int tor_version_as_new_as(const char *platform, const char *cutoff) { + tor_version_t cutoff_version, router_version; + char *s, *start; + char tmp[128]; + + if(tor_version_parse(cutoff, &cutoff_version)<0) { + log_fn(LOG_WARN,"Bug: cutoff version '%s' unparsable.",cutoff); + return 0; + } + if(strcmpstart(platform,"Tor ")) /* nonstandard Tor; be safe and say yes */ + return 1; + + start = (char *)eat_whitespace(platform+3); + if (!*start) return 0; + s = (char *)find_whitespace(start); /* also finds '\0', which is fine */ + if(s-start+1 >= sizeof(tmp)) /* too big, no */ + return 0; + strlcpy(tmp, start, s-start+1); + + if(tor_version_parse(tmp, &router_version)<0) { + log_fn(LOG_INFO,"Router version '%s' unparsable.",tmp); + return 1; /* be safe and say yes */ + } + + return tor_version_compare(&router_version, &cutoff_version) >= 0; +} + int tor_version_parse(const char *s, tor_version_t *out) { char *eos=NULL, *cp=NULL; diff --git a/src/or/test.c b/src/or/test.c index 3546cbc2a..0ee815227 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -1022,6 +1022,14 @@ test_dir_format() test_eq(0, is_obsolete_version("0.0.7rc2", "0.0.7,Tor 0.0.7rc2,Tor 0.0.8")); test_eq(0, is_obsolete_version("0.0.5", "0.0.5-cvs")); test_eq(0, is_obsolete_version("0.0.5.1-cvs", "0.0.5")); + + test_eq(0, tor_version_as_new_as("Tor 0.0.5", "0.0.9pre1-cvs")); + test_eq(0, tor_version_as_new_as("Tor 0.0.5", "0.0.9pre1-cvs")); + test_eq(1, tor_version_as_new_as( + "Tor 0.0.8 on Darwin 64-121-192-100.c3-0.sfpo-ubr1.sfrn-sfpo.ca.cable.rcn.com Power Macintosh", "0.0.8rc2")); + test_eq(0, tor_version_as_new_as( + "Tor 0.0.8 on Darwin 64-121-192-100.c3-0.sfpo-ubr1.sfrn-sfpo.ca.cable.rcn.com Power Macintosh", "0.0.8.2")); + } void test_rend_fns() |