mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Emit and parse protocol lists in router descriptors
This commit is contained in:
parent
b2b2e1c7f2
commit
4df12239f6
@ -2073,6 +2073,9 @@ typedef struct {
|
||||
|
||||
char *platform; /**< What software/operating system is this OR using? */
|
||||
|
||||
char *protocol_list; /**< Encoded list of subprotocol versions supported
|
||||
* by this OR */
|
||||
|
||||
/* link info */
|
||||
uint32_t bandwidthrate; /**< How many bytes does this OR add to its token
|
||||
* bucket per second? */
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "networkstatus.h"
|
||||
#include "nodelist.h"
|
||||
#include "policies.h"
|
||||
#include "protover.h"
|
||||
#include "relay.h"
|
||||
#include "rephist.h"
|
||||
#include "router.h"
|
||||
@ -2124,6 +2125,8 @@ router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e)
|
||||
get_platform_str(platform, sizeof(platform));
|
||||
ri->platform = tor_strdup(platform);
|
||||
|
||||
ri->protocol_list = tor_strdup(get_supported_protocols());
|
||||
|
||||
/* compute ri->bandwidthrate as the min of various options */
|
||||
ri->bandwidthrate = get_effective_bwrate(options);
|
||||
|
||||
@ -2616,6 +2619,7 @@ router_dump_router_to_string(routerinfo_t *router,
|
||||
char *ed_cert_line = NULL;
|
||||
char *rsa_tap_cc_line = NULL;
|
||||
char *ntor_cc_line = NULL;
|
||||
char *proto_line = NULL;
|
||||
|
||||
/* Make sure the identity key matches the one in the routerinfo. */
|
||||
if (!crypto_pk_eq_keys(ident_key, router->identity_pkey)) {
|
||||
@ -2780,6 +2784,12 @@ router_dump_router_to_string(routerinfo_t *router,
|
||||
}
|
||||
}
|
||||
|
||||
if (router->protocol_list) {
|
||||
tor_asprintf(&proto_line, "proto %s\n", router->protocol_list);
|
||||
} else {
|
||||
proto_line = tor_strdup("");
|
||||
}
|
||||
|
||||
address = tor_dup_ip(router->addr);
|
||||
chunks = smartlist_new();
|
||||
|
||||
@ -2789,7 +2799,7 @@ router_dump_router_to_string(routerinfo_t *router,
|
||||
"%s"
|
||||
"%s"
|
||||
"platform %s\n"
|
||||
"protocols Link 1 2 Circuit 1\n"
|
||||
"%s"
|
||||
"published %s\n"
|
||||
"fingerprint %s\n"
|
||||
"uptime %ld\n"
|
||||
@ -2806,6 +2816,7 @@ router_dump_router_to_string(routerinfo_t *router,
|
||||
ed_cert_line ? ed_cert_line : "",
|
||||
extra_or_address ? extra_or_address : "",
|
||||
router->platform,
|
||||
proto_line,
|
||||
published,
|
||||
fingerprint,
|
||||
stats_n_seconds_working,
|
||||
|
@ -3102,6 +3102,7 @@ routerinfo_free(routerinfo_t *router)
|
||||
tor_free(router->cache_info.signed_descriptor_body);
|
||||
tor_free(router->nickname);
|
||||
tor_free(router->platform);
|
||||
tor_free(router->protocol_list);
|
||||
tor_free(router->contact_info);
|
||||
if (router->onion_pkey)
|
||||
crypto_pk_free(router->onion_pkey);
|
||||
|
@ -58,6 +58,7 @@ typedef enum {
|
||||
K_RUNNING_ROUTERS,
|
||||
K_ROUTER_STATUS,
|
||||
K_PLATFORM,
|
||||
K_PROTO,
|
||||
K_OPT,
|
||||
K_BANDWIDTH,
|
||||
K_CONTACT,
|
||||
@ -306,6 +307,7 @@ static token_rule_t routerdesc_token_table[] = {
|
||||
T01("fingerprint", K_FINGERPRINT, CONCAT_ARGS, NO_OBJ ),
|
||||
T01("hibernating", K_HIBERNATING, GE(1), NO_OBJ ),
|
||||
T01("platform", K_PLATFORM, CONCAT_ARGS, NO_OBJ ),
|
||||
T01("proto", K_PROTO, CONCAT_ARGS, NO_OBJ ),
|
||||
T01("contact", K_CONTACT, CONCAT_ARGS, NO_OBJ ),
|
||||
T01("read-history", K_READ_HISTORY, ARGS, NO_OBJ ),
|
||||
T01("write-history", K_WRITE_HISTORY, ARGS, NO_OBJ ),
|
||||
@ -2092,6 +2094,10 @@ router_parse_entry_from_string(const char *s, const char *end,
|
||||
router->platform = tor_strdup(tok->args[0]);
|
||||
}
|
||||
|
||||
if ((tok = find_opt_by_keyword(tokens, K_PROTO))) {
|
||||
router->protocol_list = tor_strdup(tok->args[0]);
|
||||
}
|
||||
|
||||
if ((tok = find_opt_by_keyword(tokens, K_CONTACT))) {
|
||||
router->contact_info = tor_strdup(tok->args[0]);
|
||||
}
|
||||
|
@ -231,7 +231,6 @@ test_dir_formats(void *arg)
|
||||
"platform Tor "VERSION" on ", sizeof(buf2));
|
||||
strlcat(buf2, get_uname(), sizeof(buf2));
|
||||
strlcat(buf2, "\n"
|
||||
"protocols Link 1 2 Circuit 1\n"
|
||||
"published 1970-01-01 00:00:00\n"
|
||||
"fingerprint ", sizeof(buf2));
|
||||
tt_assert(!crypto_pk_get_fingerprint(pk2, fingerprint, 1));
|
||||
@ -300,7 +299,6 @@ test_dir_formats(void *arg)
|
||||
strlcat(buf2, "platform Tor "VERSION" on ", sizeof(buf2));
|
||||
strlcat(buf2, get_uname(), sizeof(buf2));
|
||||
strlcat(buf2, "\n"
|
||||
"protocols Link 1 2 Circuit 1\n"
|
||||
"published 1970-01-01 00:00:05\n"
|
||||
"fingerprint ", sizeof(buf2));
|
||||
tt_assert(!crypto_pk_get_fingerprint(pk1, fingerprint, 1));
|
||||
|
Loading…
Reference in New Issue
Block a user