checking only 0.0.7 and 0.0.8 didn't work, because some dirservers

files have really old descriptors for the authdirservers, so we're
asking them in the new format because they're too old.

now we actually compare the version to a cutoff version, and act
appropriately.

also take this chance to use only >=0.0.8 servers for dns resolves,
because of the recent bugs. we'll bump to >=0.0.9pre1 once there are
some servers running that.


svn:r2380
This commit is contained in:
Roger Dingledine 2004-09-27 06:00:43 +00:00
parent a64d093339
commit a2517b4f07
8 changed files with 57 additions and 16 deletions

View File

@ -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)) {

View File

@ -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,

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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()