Macros | Functions | Variables
microdesc_parse.c File Reference

Code to parse and validate microdescriptors. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/or/policies.h"
#include "feature/dirparse/microdesc_parse.h"
#include "feature/dirparse/parsecommon.h"
#include "feature/dirparse/routerparse.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/nickname.h"
#include "feature/nodelist/nodefamily.h"
#include "feature/relay/router.h"
#include "lib/crypt_ops/crypto_curve25519.h"
#include "lib/crypt_ops/crypto_ed25519.h"
#include "lib/crypt_ops/crypto_format.h"
#include "lib/memarea/memarea.h"
#include "feature/nodelist/microdesc_st.h"

Go to the source code of this file.


#define CHECK_LENGTH()
#define NEXT_LINE()


static const char * find_start_of_next_microdesc (const char *s, const char *eos)
static int policy_is_reject_star_or_null (struct short_policy_t *policy)
static const char * saved_location_to_string (saved_location_t where)
static int microdesc_extract_body (microdesc_t *md, const char *start, const char *s, const char *start_of_next_microdesc, saved_location_t where)
static int microdesc_parse_fields (microdesc_t *md, memarea_t *area, const char *s, const char *start_of_next_microdesc, int allow_annotations, saved_location_t where)
smartlist_tmicrodescs_parse_from_string (const char *s, const char *eos, int allow_annotations, saved_location_t where, smartlist_t *invalid_digests_out)


static token_rule_t microdesc_token_table []

Detailed Description

Code to parse and validate microdescriptors.

Definition in file microdesc_parse.c.

Macro Definition Documentation


#define CHECK_LENGTH ( )
if (eos - s < 32) \
return NULL; \


#define NEXT_LINE ( )
s = memchr(s, '\n', eos-s); \
if (!s || eos - s <= 1) \
return NULL; \
s++; \

Function Documentation

◆ find_start_of_next_microdesc()

static const char* find_start_of_next_microdesc ( const char *  s,
const char *  eos 

Assuming that s starts with a microdesc, return the start of the NEXT one. Return NULL on "not found."

Definition at line 46 of file microdesc_parse.c.

Referenced by microdescs_parse_from_string().

◆ microdesc_extract_body()

static int microdesc_extract_body ( microdesc_t md,
const char *  start,
const char *  s,
const char *  start_of_next_microdesc,
saved_location_t  where 

Given a microdescriptor stored in where which starts at s, which ends at start_of_next_microdescriptor, and which is located within a larger document beginning at start: Fill in the body, bodylen, bodylen, saved_location, off, and digest fields of md as appropriate.

The body field will be an alias within s if saved_location is SAVED_IN_CACHE, and will be copied into body and nul-terminated otherwise.

Definition at line 138 of file microdesc_parse.c.

◆ microdesc_parse_fields()

static int microdesc_parse_fields ( microdesc_t md,
memarea_t area,
const char *  s,
const char *  start_of_next_microdesc,
int  allow_annotations,
saved_location_t  where 

Parse a microdescriptor which begins at s and ends at start_of_next_microdesc. Store its fields into md. Use where for generating log information. If allow_annotations is true, then one or more annotations may precede the microdescriptor body proper. Use area for memory management, clearing it when done.

On success, return 0; otherwise return -1.

Definition at line 175 of file microdesc_parse.c.

◆ microdescs_parse_from_string()

smartlist_t* microdescs_parse_from_string ( const char *  s,
const char *  eos,
int  allow_annotations,
saved_location_t  where,
smartlist_t invalid_digests_out 

Parse as many microdescriptors as are found from the string starting at s and ending at eos. If allow_annotations is set, read any annotations we recognize and ignore ones we don't.

If saved_location isn't SAVED_IN_CACHE, make a local copy of each descriptor in the body field of each microdesc_t.

Return all newly parsed microdescriptors in a newly allocated smartlist_t. If invalid_disgests_out is provided, add a SHA256 microdesc digest to it for every microdesc that we found to be badly formed. (This may cause duplicates)

Definition at line 291 of file microdesc_parse.c.

Referenced by microdescs_add_to_cache().

◆ saved_location_to_string()

static const char* saved_location_to_string ( saved_location_t  where)

Return a human-readable description of a given saved_location_t. Never returns NULL.

Definition at line 106 of file microdesc_parse.c.

Variable Documentation

◆ microdesc_token_table

token_rule_t microdesc_token_table[]
Initial value:
= {
T1_START("onion-key", K_ONION_KEY, NO_ARGS, NEED_KEY_1024),
T01("ntor-onion-key", K_ONION_KEY_NTOR, GE(1), NO_OBJ ),
T0N("id", K_ID, GE(2), NO_OBJ ),
T0N("a", K_A, GE(1), NO_OBJ ),
T01("family", K_FAMILY, CONCAT_ARGS, NO_OBJ ),
T01("p", K_P, CONCAT_ARGS, NO_OBJ ),
T01("p6", K_P6, CONCAT_ARGS, NO_OBJ ),
A01("@last-listed", A_LAST_LISTED, CONCAT_ARGS, NO_OBJ ),
#define END_OF_TABLE
Definition: parsecommon.h:244
#define T0N(s, t, a, o)
Definition: parsecommon.h:248
#define A01(s, t, a, o)
Definition: parsecommon.h:260
#define T1_START(s, t, a, o)
Definition: parsecommon.h:252
#define NO_ARGS
Definition: parsecommon.h:265
#define GE(n)
Definition: parsecommon.h:269
Definition: parsecommon.h:267
#define T01(s, t, a, o)
Definition: parsecommon.h:258

List of tokens recognized in microdescriptors

Definition at line 31 of file microdesc_parse.c.