Implement proposal 227-vote-on-package-fingerprints.txt

This implementation includes tests and a little documentation.
This commit is contained in:
Nick Mathewson
2015-01-09 11:36:47 -05:00
parent 33df3e37ff
commit c83d838146
12 changed files with 348 additions and 8 deletions
+51
View File
@@ -2504,6 +2504,15 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
v3_out->client_versions = client_versions;
v3_out->server_versions = server_versions;
v3_out->package_lines = smartlist_new();
{
config_line_t *cl;
for (cl = get_options()->RecommendedPackages; cl; cl = cl->next) {
if (validate_recommended_package_line(cl->value))
smartlist_add(v3_out->package_lines, tor_strdup(cl->value));
}
}
v3_out->known_flags = smartlist_new();
smartlist_split_string(v3_out->known_flags,
"Authority Exit Fast Guard Stable V2Dir Valid",
@@ -3249,6 +3258,48 @@ connection_dirserv_flushed_some(dir_connection_t *conn)
}
}
/** Return true iff <b>line</b> is a valid recommened_packages line.
*/
int
validate_recommended_package_line(const char *line)
{
const char *cp = line;
#define WORD() \
do { \
if (*cp == ' ') \
return 0; \
cp = strchr(cp, ' '); \
if (!cp) \
return 0; \
} while (0)
WORD(); /* skip packagename */
++cp;
WORD(); /* skip version */
++cp;
WORD(); /* Skip URL */
++cp;
/* Skip digestname=digestval + */
int foundeq = 0;
while (*cp) {
if (*cp == ' ') {
if (!foundeq)
return 0;
foundeq = 0;
} else if (*cp == '=') {
if (++foundeq > 1)
return 0;
}
++cp;
}
if (!foundeq)
return 0;
return 1;
}
/** Release all storage used by the directory server. */
void
dirserv_free_all(void)