aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-08-23 10:09:25 +0000
committerRoger Dingledine <arma@torproject.org>2003-08-23 10:09:25 +0000
commit36f055e7ee7975fa6982cdfef8409b7a303166c5 (patch)
tree25c71ce947f9079be7fa2c55e5d0c9eef7a7cb34 /src
parent33b0569fba5a098e3aa25c50397ca59a0d63bb4a (diff)
downloadtor-36f055e7ee7975fa6982cdfef8409b7a303166c5.tar
tor-36f055e7ee7975fa6982cdfef8409b7a303166c5.tar.gz
start honoring the recommended_versions string
your client exits if you're running a version not in the directory's list of acceptable versions (unless you have a config variable set to override). svn:r408
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c2
-rw-r--r--src/or/cpuworker.c3
-rw-r--r--src/or/main.c4
-rw-r--r--src/or/or.h3
-rw-r--r--src/or/routers.c32
-rw-r--r--src/or/test.c14
6 files changed, 53 insertions, 5 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 59113ef86..857627577 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -185,6 +185,7 @@ void config_assign(or_options_t *options, struct config_line *list) {
config_compare(list, "Daemon", CONFIG_TYPE_BOOL, &options->Daemon) ||
config_compare(list, "TrafficShaping", CONFIG_TYPE_BOOL, &options->TrafficShaping) ||
config_compare(list, "LinkPadding", CONFIG_TYPE_BOOL, &options->LinkPadding) ||
+ config_compare(list, "IgnoreVersion", CONFIG_TYPE_BOOL, &options->IgnoreVersion) ||
/* float options */
config_compare(list, "CoinWeight", CONFIG_TYPE_DOUBLE, &options->CoinWeight)
@@ -260,6 +261,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
config_free_lines(cl);
/* print config */
+/* XXX this section is rotting. Should maybe remove it sometime. */
if (options->loglevel == LOG_DEBUG) {
printf("LogLevel=%s\n",
options->LogLevel);
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index c2437e5a5..0b92733f2 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -39,7 +39,6 @@ int connection_cpu_process_inbuf(connection_t *conn) {
if(conn->inbuf_reached_eof) {
log_fn(LOG_ERR,"Read eof. Worker dying.");
if(conn->state != CPUWORKER_STATE_IDLE) {
- onion_pending_remove(conn->circ);
circuit_close(conn->circ);
conn->circ = NULL;
num_cpuworkers_busy--;
@@ -59,11 +58,9 @@ int connection_cpu_process_inbuf(connection_t *conn) {
if(*buf == 0 || conn->circ->p_conn == NULL ||
onionskin_process(conn->circ, buf+1, buf+1+DH_KEY_LEN) < 0) {
log_fn(LOG_DEBUG,"decoding onion, onionskin_process, or p_conn failed. Closing.");
-// onion_pending_remove(conn->circ);
circuit_close(conn->circ);
} else {
log_fn(LOG_DEBUG,"onionskin_process succeeded. Yay.");
-// onion_pending_remove(conn->circ);
}
conn->circ = NULL;
} else {
diff --git a/src/or/main.c b/src/or/main.c
index 0913c28ae..720be45fe 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -765,7 +765,9 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
eos = s+maxlen;
strncpy(s,
"signed-directory\n"
- "recommended-software 0.0.2pre4,0.0.2pre5,0.0.2pre6\n" /* XXX make this real */
+ "recommended-software "
+ RECOMMENDED_SOFTWARE_VERSIONS
+ "\n"
, maxlen);
i = strlen(s);
diff --git a/src/or/or.h b/src/or/or.h
index 53033f0fc..77477497a 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -93,6 +93,8 @@
#include "../common/log.h"
#include "../common/util.h"
+#define RECOMMENDED_SOFTWARE_VERSIONS "0.0.2pre6,0.0.2pre7"
+
#define MAXCONNECTIONS 1000 /* upper bound on max connections.
can be lowered by config file */
@@ -459,6 +461,7 @@ typedef struct {
int OnionRouter;
int TrafficShaping;
int LinkPadding;
+ int IgnoreVersion;
int DirRebuildPeriod;
int DirFetchPeriod;
int KeepalivePeriod;
diff --git a/src/or/routers.c b/src/or/routers.c
index 4ed858732..c6e4d1012 100644
--- a/src/or/routers.c
+++ b/src/or/routers.c
@@ -168,6 +168,7 @@ void directory_free(directory_t *directory)
for (i = 0; i < directory->n_routers; ++i)
routerinfo_free(directory->routers[i]);
free(directory->routers);
+ /* XXX are we leaking directory->software_versions here? */
free(directory);
}
@@ -506,6 +507,25 @@ static int router_get_dir_hash(char *s, char *digest)
return 0;
}
+/* return 0 if myversion is in start. Else return -1. */
+int compare_recommended_versions(char *myversion, char *start) {
+ int len_myversion = strlen(myversion);
+ char *comma;
+ char *end = start + strlen(start);
+
+ log_fn(LOG_DEBUG,"checking '%s' in '%s'.", myversion, start);
+
+ for(;;) {
+ comma = strchr(start, ',');
+ if( ((comma ? comma : end) - start == len_myversion) &&
+ !strncmp(start, myversion, len_myversion)) /* only do strncmp if the length matches */
+ return 0; /* success, it's there */
+ if(!comma)
+ return -1; /* nope */
+ start = comma+1;
+ }
+}
+
int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey)
{
if (router_get_dir_from_string_impl(s, &directory, pkey)) {
@@ -516,7 +536,17 @@ int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey)
log(LOG_ERR, "Error resolving directory");
return -1;
}
- /* XXXX Check version number */
+ if (compare_recommended_versions(VERSION, directory->software_versions) < 0) {
+ log(LOG_ERR, "You are running tor version %s, which is no longer supported.\nPlease upgrade to one of %s.", VERSION, RECOMMENDED_SOFTWARE_VERSIONS);
+ if(options.IgnoreVersion) {
+ log(LOG_WARNING, "IgnoreVersion is set. If it breaks, we told you so.");
+ } else {
+ log(LOG_ERR,"Set IgnoreVersion config variable if you want to survive this error.");
+ fflush(0);
+ exit(0);
+ }
+ }
+
return 0;
}
diff --git a/src/or/test.c b/src/or/test.c
index 3d769c39a..547f73a07 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -485,6 +485,9 @@ test_onion_handshake() {
int dump_router_to_string(char *s, int maxlen, routerinfo_t *router);
void dump_directory_to_string(char *s, int maxlen);
+/* from routers.c */
+int compare_recommended_versions(char *myversion, char *start);
+
void
test_dir_format()
{
@@ -608,6 +611,17 @@ test_dir_format()
if (rp2) routerinfo_free(rp2);
if (dir1) free(dir1); /* And more !*/
if (dir1) free(dir2); /* And more !*/
+
+ /* make sure compare_recommended_versions() works */
+ test_eq(0, compare_recommended_versions("abc", "abc"));
+ test_eq(0, compare_recommended_versions("abc", "ab,abd,abde,abc,abcde"));
+ test_eq(0, compare_recommended_versions("abc", "ab,abd,abde,abcde,abc"));
+ test_eq(0, compare_recommended_versions("abc", "abc,abd,abde,abc,abcde"));
+ test_eq(0, compare_recommended_versions("a", "a,ab,abd,abde,abc,abcde"));
+ test_eq(-1, compare_recommended_versions("a", "ab,abd,abde,abc,abcde"));
+ test_eq(-1, compare_recommended_versions("abb", "ab,abd,abde,abc,abcde"));
+ test_eq(-1, compare_recommended_versions("a", ""));
+ test_eq(0, compare_recommended_versions(VERSION, RECOMMENDED_SOFTWARE_VERSIONS));
}
int