[or-cvs] start honoring the recommended_versions string
Roger Dingledine
arma at seul.org
Sat Aug 23 10:09:28 UTC 2003
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
config.c cpuworker.c main.c or.h routers.c test.c
Log Message:
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).
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- config.c 14 Aug 2003 03:52:50 -0000 1.38
+++ config.c 23 Aug 2003 10:09:25 -0000 1.39
@@ -185,6 +185,7 @@
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 @@
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);
Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cpuworker.c 20 Aug 2003 23:05:22 -0000 1.1
+++ cpuworker.c 23 Aug 2003 10:09:25 -0000 1.2
@@ -39,7 +39,6 @@
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 @@
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 {
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- main.c 20 Aug 2003 23:05:22 -0000 1.84
+++ main.c 23 Aug 2003 10:09:25 -0000 1.85
@@ -765,7 +765,9 @@
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);
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- or.h 20 Aug 2003 23:05:22 -0000 1.108
+++ or.h 23 Aug 2003 10:09:25 -0000 1.109
@@ -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 @@
int OnionRouter;
int TrafficShaping;
int LinkPadding;
+ int IgnoreVersion;
int DirRebuildPeriod;
int DirFetchPeriod;
int KeepalivePeriod;
Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- routers.c 14 Aug 2003 03:52:51 -0000 1.40
+++ routers.c 23 Aug 2003 10:09:25 -0000 1.41
@@ -168,6 +168,7 @@
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 @@
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 @@
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;
}
Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- test.c 14 Aug 2003 17:13:52 -0000 1.33
+++ test.c 23 Aug 2003 10:09:25 -0000 1.34
@@ -485,6 +485,9 @@
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 @@
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
More information about the tor-commits
mailing list