Start remembering *where* we are storing routerdescs. This will make us easier to move from a RAM-mirrors-disk model to a RAM-caches-disk model, and save maybe around 10MB on a directory server.

svn:r6427
This commit is contained in:
Nick Mathewson 2006-04-29 18:42:26 +00:00
parent 15dbe02c04
commit 2b720b5746
3 changed files with 29 additions and 4 deletions

View File

@ -755,6 +755,8 @@ typedef struct signed_descriptor_t {
char signed_descriptor_digest[DIGEST_LEN]; char signed_descriptor_digest[DIGEST_LEN];
char identity_digest[DIGEST_LEN]; char identity_digest[DIGEST_LEN];
time_t published_on; time_t published_on;
enum { SAVED_NOWHERE=0, SAVED_IN_CACHE, SAVED_IN_JOURNAL } saved_location;
off_t saved_offset;
} signed_descriptor_t; } signed_descriptor_t;
/** Information about another onion router in the network. */ /** Information about another onion router in the network. */
@ -2402,7 +2404,8 @@ int router_append_dirobj_signature(char *buf, size_t buf_len,
const char *digest, const char *digest,
crypto_pk_env_t *private_key); crypto_pk_env_t *private_key);
int router_parse_list_from_string(const char **s, int router_parse_list_from_string(const char **s,
smartlist_t *dest); smartlist_t *dest,
int from_cache);
int router_parse_routerlist_from_directory(const char *s, int router_parse_routerlist_from_directory(const char *s,
routerlist_t **dest, routerlist_t **dest,
crypto_pk_env_t *pkey, crypto_pk_env_t *pkey,

View File

@ -186,6 +186,8 @@ router_append_to_journal(signed_descriptor_t *desc)
tor_free(fname); tor_free(fname);
return -1; return -1;
} }
desc->saved_location = SAVED_IN_JOURNAL;
desc->saved_offset = router_journal_len;
tor_free(fname); tor_free(fname);
router_journal_len += len; router_journal_len += len;
@ -243,6 +245,20 @@ router_rebuild_store(int force)
log_warn(LD_FS, "Error writing router store to disk."); log_warn(LD_FS, "Error writing router store to disk.");
goto done; goto done;
} }
for (i = 0; i < 2; ++i) {
smartlist_t *lst = (i == 0) ? routerlist->old_routers :
routerlist->routers;
off_t offset = 0;
SMARTLIST_FOREACH(lst, void *, ptr,
{
signed_descriptor_t *sd = (i==0) ?
((signed_descriptor_t*)ptr): &((routerinfo_t*)ptr)->cache_info;
sd->saved_location = SAVED_IN_CACHE;
sd->saved_offset = offset;
offset += sd->signed_descriptor_len;
});
}
tor_snprintf(fname, fname_len, "%s/cached-routers.new", tor_snprintf(fname, fname_len, "%s/cached-routers.new",
options->DataDirectory); options->DataDirectory);
@ -1920,7 +1936,7 @@ router_load_routers_from_string(const char *s, int from_cache,
char fp[HEX_DIGEST_LEN+1]; char fp[HEX_DIGEST_LEN+1];
const char *msg; const char *msg;
router_parse_list_from_string(&s, routers); router_parse_list_from_string(&s, routers, from_cache);
routers_update_status_from_networkstatus(routers, !from_cache); routers_update_status_from_networkstatus(routers, !from_cache);

View File

@ -637,15 +637,17 @@ check_directory_signature(const char *digest,
* are not complete. Returns 0 on success and -1 on failure. * are not complete. Returns 0 on success and -1 on failure.
*/ */
int int
router_parse_list_from_string(const char **s, smartlist_t *dest) router_parse_list_from_string(const char **s, smartlist_t *dest,
int from_cache)
{ {
routerinfo_t *router; routerinfo_t *router;
const char *end, *cp; const char *end, *cp, *start;
tor_assert(s); tor_assert(s);
tor_assert(*s); tor_assert(*s);
tor_assert(dest); tor_assert(dest);
start = *s;
while (1) { while (1) {
*s = eat_whitespace(*s); *s = eat_whitespace(*s);
/* Don't start parsing the rest of *s unless it contains a router. */ /* Don't start parsing the rest of *s unless it contains a router. */
@ -683,6 +685,10 @@ router_parse_list_from_string(const char **s, smartlist_t *dest)
log_warn(LD_DIR, "Error reading router; skipping"); log_warn(LD_DIR, "Error reading router; skipping");
continue; continue;
} }
if (from_cache) {
router->cache_info.saved_location = SAVED_IN_CACHE;
router->cache_info.saved_offset = *s - start;
}
smartlist_add(dest, router); smartlist_add(dest, router);
} }