[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Indirect access to the signed_descriptor field to make it e...
Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv617/src/or
Modified Files:
control.c directory.c dirserv.c or.h router.c routerlist.c
routerparse.c
Log Message:
Indirect access to the signed_descriptor field to make it easier to keep them lazily on disk.
Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -p -d -r1.164 -r1.165
--- control.c 10 Jan 2006 22:42:44 -0000 1.164
+++ control.c 12 Jan 2006 18:04:17 -0000 1.165
@@ -1279,20 +1279,27 @@ handle_getinfo_helper(const char *questi
*answer = list_getinfo_options();
} else if (!strcmpstart(question, "desc/id/")) {
routerinfo_t *ri = router_get_by_hexdigest(question+strlen("desc/id/"));
- if (ri && ri->cache_info.signed_descriptor)
- *answer = tor_strdup(ri->cache_info.signed_descriptor);
+ if (ri) {
+ const char *body = signed_descriptor_get_body(&ri->cache_info);
+ if (body)
+ *answer = tor_strdup(body);
+ }
} else if (!strcmpstart(question, "desc/name/")) {
routerinfo_t *ri = router_get_by_nickname(question+strlen("desc/name/"),1);
- if (ri && ri->cache_info.signed_descriptor)
- *answer = tor_strdup(ri->cache_info.signed_descriptor);
+ if (ri) {
+ const char *body = signed_descriptor_get_body(&ri->cache_info);
+ if (body)
+ *answer = tor_strdup(body);
+ }
} else if (!strcmp(question, "desc/all-recent")) {
routerlist_t *routerlist = router_get_routerlist();
smartlist_t *sl = smartlist_create();
if (routerlist && routerlist->routers) {
SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, ri,
{
- if (ri && ri->cache_info.signed_descriptor)
- smartlist_add(sl, tor_strdup(ri->cache_info.signed_descriptor));
+ const char *body = signed_descriptor_get_body(&ri->cache_info);
+ if (body)
+ smartlist_add(sl, tor_strdup(body));
});
}
*answer = smartlist_join_strings(sl, "", 0, NULL);
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.341
retrieving revision 1.342
diff -u -p -d -r1.341 -r1.342
--- directory.c 10 Jan 2006 20:50:22 -0000 1.341
+++ directory.c 12 Jan 2006 18:04:17 -0000 1.342
@@ -1516,8 +1516,8 @@ directory_handle_command_get(connection_
char *cp = inp;
SMARTLIST_FOREACH(descs, signed_descriptor_t *, ri,
{
- memcpy(cp, ri->signed_descriptor,
- ri->signed_descriptor_len);
+ const char *body = signed_descriptor_get_body(ri);
+ memcpy(cp, body, ri->signed_descriptor_len);
cp += ri->signed_descriptor_len;
*cp++ = '\n';
});
@@ -1550,9 +1550,10 @@ directory_handle_command_get(connection_
note_request(request_type, len);
connection_write_to_buf(tmp, strlen(tmp), conn);
SMARTLIST_FOREACH(descs, signed_descriptor_t *, ri,
- connection_write_to_buf(ri->signed_descriptor,
- ri->signed_descriptor_len,
- conn));
+ {
+ const char *body = signed_descriptor_get_body(ri);
+ connection_write_to_buf(body, ri->signed_descriptor_len, conn);
+ });
}
}
smartlist_free(descs);
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.291
retrieving revision 1.292
diff -u -p -d -r1.291 -r1.292
--- dirserv.c 11 Jan 2006 03:59:55 -0000 1.291
+++ dirserv.c 12 Jan 2006 18:04:17 -0000 1.292
@@ -871,9 +871,11 @@ dirserv_dump_directory_to_string(char **
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri,
{
size_t len = ri->cache_info.signed_descriptor_len;
+ const char *body;
if (cp+len+1 >= buf+buf_len)
goto truncated;
- memcpy(cp, ri->cache_info.signed_descriptor, len);
+ body = signed_descriptor_get_body(&ri->cache_info);
+ memcpy(cp, body, len);
cp += len;
*cp++ = '\n'; /* add an extra newline in case somebody was depending on
* it. */
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.779
retrieving revision 1.780
diff -u -p -d -r1.779 -r1.780
--- or.h 10 Jan 2006 22:42:44 -0000 1.779
+++ or.h 12 Jan 2006 18:04:17 -0000 1.780
@@ -762,7 +762,7 @@ typedef struct cached_dir_t {
/** Information need to cache an onion router's descriptor. */
typedef struct signed_descriptor_t {
- char *signed_descriptor;
+ char *signed_descriptor_body;
size_t signed_descriptor_len;
char signed_descriptor_digest[DIGEST_LEN];
char identity_digest[DIGEST_LEN];
@@ -2277,6 +2277,7 @@ routerinfo_t *router_get_by_nickname(con
routerinfo_t *router_get_by_hexdigest(const char *hexdigest);
routerinfo_t *router_get_by_digest(const char *digest);
signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
+const char *signed_descriptor_get_body(signed_descriptor_t *desc);
int router_digest_version_as_new_as(const char *digest, const char *cutoff);
int router_digest_is_trusted_dir(const char *digest);
routerlist_t *router_get_routerlist(void);
Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.239
retrieving revision 1.240
diff -u -p -d -r1.239 -r1.240
--- router.c 10 Jan 2006 07:21:01 -0000 1.239
+++ router.c 12 Jan 2006 18:04:17 -0000 1.240
@@ -761,13 +761,14 @@ router_get_my_routerinfo(void)
const char *
router_get_my_descriptor(void)
{
+ const char *body;
if (!desc_routerinfo) {
if (router_rebuild_descriptor(1))
return NULL;
}
- debug(LD_GENERAL,"my desc is '%s'",
- desc_routerinfo->cache_info.signed_descriptor);
- return desc_routerinfo->cache_info.signed_descriptor;
+ body = signed_descriptor_get_body(&desc_routerinfo->cache_info);
+ debug(LD_GENERAL,"my desc is '%s'", body);
+ return body;
}
/*DOCDOC*/
@@ -865,16 +866,16 @@ router_rebuild_descriptor(int force)
});
smartlist_free(family);
}
- ri->cache_info.signed_descriptor = tor_malloc(8192);
- if (router_dump_router_to_string(ri->cache_info.signed_descriptor, 8192,
+ ri->cache_info.signed_descriptor_body = tor_malloc(8192);
+ if (router_dump_router_to_string(ri->cache_info.signed_descriptor_body, 8192,
ri, get_identity_key())<0) {
warn(LD_BUG, "Couldn't allocate string for descriptor.");
return -1;
}
ri->cache_info.signed_descriptor_len =
- strlen(ri->cache_info.signed_descriptor);
+ strlen(ri->cache_info.signed_descriptor_body);
crypto_digest(ri->cache_info.signed_descriptor_digest,
- ri->cache_info.signed_descriptor,
+ ri->cache_info.signed_descriptor_body,
ri->cache_info.signed_descriptor_len);
if (desc_routerinfo)
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.424
retrieving revision 1.425
diff -u -p -d -r1.424 -r1.425
--- routerlist.c 12 Jan 2006 03:43:39 -0000 1.424
+++ routerlist.c 12 Jan 2006 18:04:17 -0000 1.425
@@ -159,19 +159,20 @@ router_should_rebuild_store(void)
/** Add the <b>len</b>-type router descriptor in <b>s</b> to the router
* journal. */
static int
-router_append_to_journal(const char *s, size_t len)
+router_append_to_journal(signed_descriptor_t *desc)
{
or_options_t *options = get_options();
size_t fname_len = strlen(options->DataDirectory)+32;
- char *fname = tor_malloc(len);
+ char *fname = tor_malloc(fname_len);
+ const char *body = signed_descriptor_get_body(desc);
+ size_t len = desc->signed_descriptor_len;
tor_snprintf(fname, fname_len, "%s/cached-routers.new",
options->DataDirectory);
- if (!len)
- len = strlen(s);
+ tor_assert(len == strlen(body));
- if (append_bytes_to_file(fname, s, len, 0)) {
+ if (append_bytes_to_file(fname, body, len, 0)) {
warn(LD_FS, "Unable to store router descriptor");
tor_free(fname);
return -1;
@@ -218,12 +219,13 @@ router_rebuild_store(int force)
signed_descriptor_t *sd = (i==0) ?
((signed_descriptor_t*)ptr): &((routerinfo_t*)ptr)->cache_info;
sized_chunk_t *c;
- if (!sd->signed_descriptor) {
- warn(LD_BUG, "Bug! No descriptor stored for router.");
+ const char *body = signed_descriptor_get_body(sd);
+ if (!body) {
+ warn(LD_BUG, "Bug! No descriptor available for router.");
goto done;
}
c = tor_malloc(sizeof(sized_chunk_t));
- c->bytes = sd->signed_descriptor;
+ c->bytes = body;
c->len = sd->signed_descriptor_len;
smartlist_add(chunk_list, c);
});
@@ -1062,6 +1064,12 @@ router_get_by_descriptor_digest(const ch
return digestmap_get(routerlist->desc_digest_map, digest);
}
+const char *
+signed_descriptor_get_body(signed_descriptor_t *desc)
+{
+ return desc->signed_descriptor_body;
+}
+
/** Return the current list of all known routers. */
routerlist_t *
router_get_routerlist(void)
@@ -1083,7 +1091,7 @@ routerinfo_free(routerinfo_t *router)
if (!router)
return;
- tor_free(router->cache_info.signed_descriptor);
+ tor_free(router->cache_info.signed_descriptor_body);
tor_free(router->address);
tor_free(router->nickname);
tor_free(router->platform);
@@ -1104,7 +1112,7 @@ routerinfo_free(routerinfo_t *router)
static void
signed_descriptor_free(signed_descriptor_t *sd)
{
- tor_free(sd->signed_descriptor);
+ tor_free(sd->signed_descriptor_body);
tor_free(sd);
}
@@ -1115,50 +1123,11 @@ signed_descriptor_from_routerinfo(router
{
signed_descriptor_t *sd = tor_malloc_zero(sizeof(signed_descriptor_t));
memcpy(sd, &(ri->cache_info), sizeof(signed_descriptor_t));
- ri->cache_info.signed_descriptor = NULL;
+ ri->cache_info.signed_descriptor_body = NULL;
routerinfo_free(ri);
return sd;
}
-#if 0
-/** Allocate a fresh copy of <b>router</b> */
-/* XXX Nobody uses this. Remove it? */
-routerinfo_t *
-routerinfo_copy(const routerinfo_t *router)
-{
- routerinfo_t *r;
- addr_policy_t **e, *tmp;
-
- r = tor_malloc(sizeof(routerinfo_t));
- memcpy(r, router, sizeof(routerinfo_t));
-
- r->address = tor_strdup(r->address);
- r->nickname = tor_strdup(r->nickname);
- r->platform = tor_strdup(r->platform);
- if (r->cache_info.signed_descriptor)
- r->cache_info.signed_descriptor =
- tor_strdup(r->cache_info.signed_descriptor);
- if (r->onion_pkey)
- r->onion_pkey = crypto_pk_dup_key(r->onion_pkey);
- if (r->identity_pkey)
- r->identity_pkey = crypto_pk_dup_key(r->identity_pkey);
- e = &r->exit_policy;
- while (*e) {
- tmp = tor_malloc(sizeof(addr_policy_t));
- memcpy(tmp,*e,sizeof(addr_policy_t));
- *e = tmp;
- (*e)->string = tor_strdup((*e)->string);
- e = & ((*e)->next);
- }
- if (r->declared_family) {
- r->declared_family = smartlist_create();
- SMARTLIST_FOREACH(router->declared_family, const char *, s,
- smartlist_add(r->declared_family, tor_strdup(s)));
- }
- return r;
-}
-#endif
-
/** Free all storage held by a routerlist <b>rl</b> */
void
routerlist_free(routerlist_t *rl)
@@ -1588,9 +1557,9 @@ router_add_to_routerlist(routerinfo_t *r
}
}
routerlist_replace(routerlist, old_router, router, i, 1);
- if (!from_cache)
- router_append_to_journal(router->cache_info.signed_descriptor,
- router->cache_info.signed_descriptor_len);
+ if (!from_cache) {
+ router_append_to_journal(&router->cache_info);
+ }
directory_set_dirty();
*msg = unreachable ? "Dirserver believes your ORPort is unreachable" :
authdir_verified ? "Verified server updated" :
@@ -1633,8 +1602,7 @@ router_add_to_routerlist(routerinfo_t *r
* the list. */
routerlist_insert(routerlist, router);
if (!from_cache)
- router_append_to_journal(router->cache_info.signed_descriptor,
- router->cache_info.signed_descriptor_len);
+ router_append_to_journal(&router->cache_info);
directory_set_dirty();
return 0;
}
Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.167
retrieving revision 1.168
diff -u -p -d -r1.167 -r1.168
--- routerparse.c 2 Jan 2006 05:11:31 -0000 1.167
+++ routerparse.c 12 Jan 2006 18:04:17 -0000 1.168
@@ -745,7 +745,7 @@ router_parse_entry_from_string(const cha
}
router = tor_malloc_zero(sizeof(routerinfo_t));
- router->cache_info.signed_descriptor = tor_strndup(s, end-s);
+ router->cache_info.signed_descriptor_body = tor_strndup(s, end-s);
router->cache_info.signed_descriptor_len = end-s;
memcpy(router->cache_info.signed_descriptor_digest, digest, DIGEST_LEN);