[or-cvs] when we think a router is unreachable, pass the message bac...
arma at seul.org
arma at seul.org
Wed Aug 31 06:14:39 UTC 2005
Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or
Modified Files:
directory.c dirserv.c or.h router.c routerlist.c test.c
Log Message:
when we think a router is unreachable, pass the message back to the
server's logs, and make it a 'warn'.
also, fix a memory leak for rejected router descriptors.
Index: directory.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.251
retrieving revision 1.252
diff -u -d -r1.251 -r1.252
--- directory.c 30 Aug 2005 07:01:30 -0000 1.251
+++ directory.c 31 Aug 2005 06:14:37 -0000 1.252
@@ -1188,19 +1188,21 @@
if (!strcmp(url,"/tor/")) { /* server descriptor post */
const char *msg;
- switch (dirserv_add_descriptor(body, &msg)) {
+ int r = dirserv_add_descriptor(body, &msg);
+ tor_assert(msg);
+ if (r > 0)
+ dirserv_get_directory(&cp, 0); /* rebuild and write to disk */
+ switch (r) {
case -2:
case -1:
- /* malformed descriptor, or something wrong */
- write_http_status_line(conn, 400, msg?msg:"Malformed or unacceptable server descriptor");
+ case 1:
log_fn(LOG_NOTICE,"Rejected descriptor published by %s.", origin);
+ /* malformed descriptor, or something wrong */
+ write_http_status_line(conn, 400, msg);
break;
- case 0:
- write_http_status_line(conn, 200, msg?msg:"Server descriptor okay, but not accepted.");
- break;
- case 1:
- dirserv_get_directory(&cp, 0); /* rebuild and write to disk */
- write_http_status_line(conn, 200, msg?msg:"Server descriptor accepted");
+ case 0: /* accepted but discarded */
+ case 2: /* accepted */
+ write_http_status_line(conn, 200, msg);
break;
}
goto done;
Index: dirserv.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.201
retrieving revision 1.202
diff -u -d -r1.201 -r1.202
--- dirserv.c 30 Aug 2005 06:48:24 -0000 1.201
+++ dirserv.c 31 Aug 2005 06:14:37 -0000 1.202
@@ -319,18 +319,19 @@
*msg = "Rejected: Address is not an IP, or IP is a private address.";
return -1;
}
-
return 0;
}
-/** Parse the server descriptor at desc and maybe insert it into the list of
- * server descriptors. Set msg to a message that should be passed back to the
- * origin of this descriptor, or to NULL.
+/** Parse the server descriptor at <b>desc</b> and maybe insert it into
+ * the list of server descriptors. Set *<b>msg</b> to a message that
+ * should be passed back to the origin of this descriptor.
*
- * Return 1 if descriptor is well-formed and accepted;
+ * Return 2 if descriptor is well-formed and accepted;
+ * 1 if well-formed and accepted but origin should hear *msg;
* 0 if well-formed but redundant with one we already have;
* -1 if it looks vaguely like a router descriptor but rejected;
- * -2 if we can't find a router descriptor in *desc.
+ * -2 if we can't find a router descriptor in <b>desc</b>.
+ *
*/
int
dirserv_add_descriptor(const char *desc, const char **msg)
@@ -345,7 +346,7 @@
if (!ri) {
log(LOG_WARN, "Couldn't parse descriptor");
*msg = "Rejected: Couldn't parse server descriptor.";
- return -1;
+ return -2;
}
if ((r = router_add_to_routerlist(ri, msg))<0) {
return r == -1 ? 0 : -1;
@@ -358,7 +359,7 @@
*msg = ri->is_verified ? "Verified server descriptor accepted" :
"Unverified server descriptor accepted";
}
- return 1;
+ return r == 0 ? 2 : 1;
}
}
@@ -504,7 +505,7 @@
/** Return 1 if we're confident that there's a problem with
* <b>router</b>'s reachability and its operator should be notified.
*/
-static int
+int
dirserv_thinks_router_is_blatantly_unreachable(routerinfo_t *router, time_t now)
{
connection_t *conn;
Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.661
retrieving revision 1.662
diff -u -d -r1.661 -r1.662
--- or.h 30 Aug 2005 06:48:24 -0000 1.661
+++ or.h 31 Aug 2005 06:14:37 -0000 1.662
@@ -1632,6 +1632,8 @@
int dirserv_add_descriptor(const char *desc, const char **msg);
char *dirserver_getinfo_unregistered(const char *question);
void dirserv_free_descriptors(void);
+int dirserv_thinks_router_is_blatantly_unreachable(routerinfo_t *router,
+ time_t now);
int list_server_status(smartlist_t *routers, char **router_status_out);
void dirserv_log_unreachable_servers(time_t now);
int dirserv_dump_directory_to_string(char **dir_out,
Index: router.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- router.c 30 Aug 2005 06:43:07 -0000 1.199
+++ router.c 31 Aug 2005 06:14:37 -0000 1.200
@@ -329,7 +329,7 @@
log_fn(LOG_ERR, "Error adding own fingerprint to approved set");
return -1;
}
- if (dirserv_add_descriptor(tmp, &m) != 1) {
+ if (dirserv_add_descriptor(tmp, &m) < 0) {
log(LOG_ERR, "Unable to add own descriptor to directory: %s",
m?m:"<unknown error>");
return -1;
Index: routerlist.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.261
retrieving revision 1.262
diff -u -d -r1.261 -r1.262
--- routerlist.c 26 Aug 2005 23:12:13 -0000 1.261
+++ routerlist.c 31 Aug 2005 06:14:37 -0000 1.262
@@ -854,15 +854,18 @@
/** Add <b>router</b> to the routerlist, if we don't already have it. Replace
* older entries (if any) with the same name. Note: Callers should not hold
* their pointers to <b>router</b> if this function fails; <b>router</b>
- * will either be inserted into the routerlist or freed. Returns 0 if the
- * router was added; less than 0 if it was not.
+ * will either be inserted into the routerlist or freed.
*
- * If we're returning an error, then assign to *<b>msg</b> a static string
- * describing the reason for refusing the routerinfo.
+ * Returns >= 0 if the router was added; less than 0 if it was not.
+ *
+ * If we're returning non-zero, then assign to *<b>msg</b> a static string
+ * describing the reason for not liking the routerinfo.
*
* If the return value is less than -1, there was a problem with the
- * routerinfo. If the return value is equal to -1, then the routerinfo was
- * fine, but out-of-date.
+ * routerinfo. If the return value is equal to -1, then the routerinfo was
+ * fine, but out-of-date. If the return value is equal to 1, the
+ * routerinfo was accepted, but we should notify the generator of the
+ * descriptor using the message *<b>msg</b>.
*/
int
router_add_to_routerlist(routerinfo_t *router, const char **msg)
@@ -882,8 +885,11 @@
crypto_pk_get_digest(router->identity_pkey, id_digest);
if (authdir) {
- if (dirserv_wants_to_reject_router(router, &authdir_verified, msg))
+ if (dirserv_wants_to_reject_router(router, &authdir_verified, msg)) {
+ tor_assert(*msg);
+ routerinfo_free(router);
return -2;
+ }
router->is_verified = authdir_verified;
if (tor_version_as_new_as(router->platform,"0.1.0.2-rc"))
router->is_verified = 1;
@@ -903,9 +909,10 @@
old_router->is_running = router->is_running;
}
routerinfo_free(router);
- if (msg) *msg = "Router descriptor was not new.";
+ *msg = "Router descriptor was not new.";
return -1;
} else {
+ int unreachable;
log_fn(LOG_DEBUG, "Replacing entry for router '%s/%s' [%s]",
router->nickname, old_router->nickname,
hex_str(id_digest,DIGEST_LEN));
@@ -915,13 +922,15 @@
router->last_reachable = old_router->last_reachable;
router->testing_since = old_router->testing_since;
}
- if (msg)
- *msg = authdir_verified ? "Verified server updated":
- "Unverified server updated. (Have you sent us your key finerprint?)";
+ unreachable = authdir &&
+ dirserv_thinks_router_is_blatantly_unreachable(router, time(NULL));
routerinfo_free(old_router);
smartlist_set(routerlist->routers, i, router);
directory_set_dirty();
- return 0;
+ *msg = unreachable ? "Dirserver believes your ORPort is unreachable" :
+ authdir_verified ? "Verified server updated" :
+ "Unverified server updated. (Have you sent us your key fingerprint?)";
+ return unreachable ? 1 : 0;
}
} else if (!strcasecmp(router->nickname, old_router->nickname)) {
/* nicknames match, keys don't. */
@@ -947,7 +956,7 @@
log_fn(LOG_DEBUG, "Skipping unverified entry for verified router '%s'",
router->nickname);
routerinfo_free(router);
- if (msg) *msg = "Already have verified router with same nickname and different key.";
+ *msg = "Already have verified router with same nickname and different key.";
return -2;
}
}
@@ -1066,7 +1075,7 @@
SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
{
const char *msg;
- if (router_add_to_routerlist(r,&msg)==0)
+ if (router_add_to_routerlist(r,&msg)>=0)
smartlist_add(changed, r);
});
smartlist_clear(new_list->routers);
@@ -1082,13 +1091,6 @@
control_event_descriptors_changed(routerlist->routers);
}
router_normalize_routerlist(routerlist);
-#if 0
- if (get_options()->AuthoritativeDir) {
- /* Learn about the descriptors in the directory. */
- dirserv_load_from_directory_string(s);
-//XXXRD
- }
-#endif
return 0;
}
Index: test.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.197
retrieving revision 1.198
diff -u -d -r1.197 -r1.198
--- test.c 29 Aug 2005 18:01:38 -0000 1.197
+++ test.c 31 Aug 2005 06:14:37 -0000 1.198
@@ -1294,9 +1294,9 @@
r1.published_on = time(NULL);
r2.published_on = time(NULL)-3*60*60;
test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
- test_eq(dirserv_add_descriptor(buf,&m), 1);
+ test_eq(dirserv_add_descriptor(buf,&m), 2);
test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0);
- test_eq(dirserv_add_descriptor(buf,&m), 1);
+ test_eq(dirserv_add_descriptor(buf,&m), 2);
get_options()->Nickname = tor_strdup("DirServer");
test_assert(!dirserv_dump_directory_to_string(&cp,pk3));
test_assert(!router_parse_routerlist_from_directory(cp, &dir1, pk3, 1, 0));
More information about the tor-commits
mailing list