mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
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:
parent
15dbe02c04
commit
2b720b5746
@ -755,6 +755,8 @@ typedef struct signed_descriptor_t {
|
||||
char signed_descriptor_digest[DIGEST_LEN];
|
||||
char identity_digest[DIGEST_LEN];
|
||||
time_t published_on;
|
||||
enum { SAVED_NOWHERE=0, SAVED_IN_CACHE, SAVED_IN_JOURNAL } saved_location;
|
||||
off_t saved_offset;
|
||||
} signed_descriptor_t;
|
||||
|
||||
/** 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,
|
||||
crypto_pk_env_t *private_key);
|
||||
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,
|
||||
routerlist_t **dest,
|
||||
crypto_pk_env_t *pkey,
|
||||
|
@ -186,6 +186,8 @@ router_append_to_journal(signed_descriptor_t *desc)
|
||||
tor_free(fname);
|
||||
return -1;
|
||||
}
|
||||
desc->saved_location = SAVED_IN_JOURNAL;
|
||||
desc->saved_offset = router_journal_len;
|
||||
|
||||
tor_free(fname);
|
||||
router_journal_len += len;
|
||||
@ -243,6 +245,20 @@ router_rebuild_store(int force)
|
||||
log_warn(LD_FS, "Error writing router store to disk.");
|
||||
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",
|
||||
options->DataDirectory);
|
||||
@ -1920,7 +1936,7 @@ router_load_routers_from_string(const char *s, int from_cache,
|
||||
char fp[HEX_DIGEST_LEN+1];
|
||||
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);
|
||||
|
||||
|
@ -637,15 +637,17 @@ check_directory_signature(const char *digest,
|
||||
* are not complete. Returns 0 on success and -1 on failure.
|
||||
*/
|
||||
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;
|
||||
const char *end, *cp;
|
||||
const char *end, *cp, *start;
|
||||
|
||||
tor_assert(s);
|
||||
tor_assert(*s);
|
||||
tor_assert(dest);
|
||||
|
||||
start = *s;
|
||||
while (1) {
|
||||
*s = eat_whitespace(*s);
|
||||
/* 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");
|
||||
continue;
|
||||
}
|
||||
if (from_cache) {
|
||||
router->cache_info.saved_location = SAVED_IN_CACHE;
|
||||
router->cache_info.saved_offset = *s - start;
|
||||
}
|
||||
smartlist_add(dest, router);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user