tor  0.4.2.1-alpha-dev
Macros | Functions
pubsub_check.c File Reference
#include "lib/dispatch/dispatch_naming.h"
#include "lib/dispatch/msgtypes.h"
#include "lib/pubsub/pubsub_flags.h"
#include "lib/pubsub/pubsub_builder_st.h"
#include "lib/pubsub/pubsub_build.h"
#include "lib/container/bitarray.h"
#include "lib/container/smartlist.h"
#include "lib/log/util_bug.h"
#include "lib/malloc/malloc.h"
#include "lib/string/compat_string.h"
#include <string.h>

Go to the source code of this file.

Macros

#define PUBSUB_PRIVATE
 
#define pubsub_adjmap_free(m)   FREE_AND_NULL(pubsub_adjmap_t, pubsub_adjmap_free_, m)
 

Functions

static void pubsub_adjmap_add (pubsub_adjmap_t *map, const pubsub_cfg_t *item)
 
static pubsub_adjmap_t * pubsub_build_adjacency_map (const pubsub_items_t *cfg)
 
static void pubsub_adjmap_free_helper (smartlist_t **lsts, size_t n)
 
static void pubsub_adjmap_free_ (pubsub_adjmap_t *map)
 
static int smartlist_len_opt (const smartlist_t *sl)
 
static const char * format_flags (unsigned flags)
 
static void pubsub_cfg_dump (const pubsub_cfg_t *cfg, int severity, const char *prefix)
 
static void get_message_bitarray (const pubsub_adjmap_t *map, const smartlist_t *items, bitarray_t **out)
 
static int lint_message_graph (const pubsub_adjmap_t *map, message_id_t msg, const smartlist_t *pub, const smartlist_t *sub)
 
static int lint_message_consistency (message_id_t msg, const smartlist_t *pub, const smartlist_t *sub)
 
static int lint_message (const pubsub_adjmap_t *map, message_id_t msg)
 
static int pubsub_adjmap_check (const pubsub_adjmap_t *map)
 
int pubsub_builder_check (pubsub_builder_t *builder)
 

Detailed Description

Enforce various requirements on a pubsub_builder.

Definition in file pubsub_check.c.

Macro Definition Documentation

◆ pubsub_adjmap_free

#define pubsub_adjmap_free (   m)    FREE_AND_NULL(pubsub_adjmap_t, pubsub_adjmap_free_, m)

Release all storage held by m and set m to NULL.

Definition at line 89 of file pubsub_check.c.

Function Documentation

◆ format_flags()

static const char* format_flags ( unsigned  flags)
static

Return a pointer to a statically allocated string encoding the dispatcher flags in flags.

Definition at line 138 of file pubsub_check.c.

References DISP_FLAG_EXCL.

Referenced by pubsub_cfg_dump().

◆ get_message_bitarray()

static void get_message_bitarray ( const pubsub_adjmap_t *  map,
const smartlist_t items,
bitarray_t **  out 
)
static

Helper: fill a bitarray out with entries corresponding to the subsystems listed in items.

Definition at line 178 of file pubsub_check.c.

References bitarray_init_zero(), bitarray_set(), and SMARTLIST_FOREACH_BEGIN.

Referenced by lint_message_graph().

◆ lint_message()

static int lint_message ( const pubsub_adjmap_t *  map,
message_id_t  msg 
)
static

Check whether there are any errors or inconsistencies for the message described by msg in map. If there are problems, log about them, and return -1. Otherwise return 0.

Definition at line 316 of file pubsub_check.c.

Referenced by pubsub_adjmap_check().

◆ lint_message_consistency()

static int lint_message_consistency ( message_id_t  msg,
const smartlist_t pub,
const smartlist_t sub 
)
static

Helper for lint_message: check that all the pubsub_cfg_t items in the two respective smartlists have compatible flags, channels, and types.

Definition at line 240 of file pubsub_check.c.

References smartlist_add_all(), and smartlist_len_opt().

◆ lint_message_graph()

static int lint_message_graph ( const pubsub_adjmap_t *  map,
message_id_t  msg,
const smartlist_t pub,
const smartlist_t sub 
)
static

Helper for lint_message: check that all the pubsub_cfg_t items in the two respective smartlists obey our local graph topology rules.

(Right now this is just a matter of "each subsystem only publishes/subscribes once; no subsystem is a publisher and subscriber for the same message.")

Return 0 on success, -1 on failure.

Definition at line 202 of file pubsub_check.c.

References bitarray_is_set(), and get_message_bitarray().

◆ pubsub_adjmap_add()

static void pubsub_adjmap_add ( pubsub_adjmap_t *  map,
const pubsub_cfg_t *  item 
)
static

Helper: add a single pubsub_cfg_t to an adjacency map.

Definition at line 61 of file pubsub_check.c.

References smartlist_add(), and tor_assert().

◆ pubsub_adjmap_check()

static int pubsub_adjmap_check ( const pubsub_adjmap_t *  map)
static

Check all the messages in map for consistency. Return 0 on success, -1 on problems.

Definition at line 381 of file pubsub_check.c.

References lint_message().

Referenced by pubsub_builder_check().

◆ pubsub_adjmap_free_()

static void pubsub_adjmap_free_ ( pubsub_adjmap_t *  map)
static

Release all storage held by map.

Definition at line 112 of file pubsub_check.c.

References pubsub_adjmap_free_helper(), and tor_free.

◆ pubsub_adjmap_free_helper()

static void pubsub_adjmap_free_helper ( smartlist_t **  lsts,
size_t  n 
)
static

Free every element of an n-element array of smartlists, then free the array itself.

Definition at line 97 of file pubsub_check.c.

Referenced by pubsub_adjmap_free_().

◆ pubsub_build_adjacency_map()

static pubsub_adjmap_t* pubsub_build_adjacency_map ( const pubsub_items_t cfg)
static

Helper: contruct and return a new pubsub_adjacency_map from cfg. Return NULL on error.

Definition at line 36 of file pubsub_check.c.

Referenced by pubsub_builder_check().

◆ pubsub_builder_check()

int pubsub_builder_check ( pubsub_builder_t builder)

Check builder for consistency and various constraints. Return 0 on success, -1 on failure.

Definition at line 397 of file pubsub_check.c.

References pubsub_adjmap_check(), pubsub_adjmap_free, and pubsub_build_adjacency_map().

◆ pubsub_cfg_dump()

static void pubsub_cfg_dump ( const pubsub_cfg_t *  cfg,
int  severity,
const char *  prefix 
)
static

Log a message containing a description of cfg at severity, prefixed by the string prefix.

Definition at line 156 of file pubsub_check.c.

References format_flags(), LD_MESG, tor_assert(), and tor_log().

◆ smartlist_len_opt()

static int smartlist_len_opt ( const smartlist_t sl)
static

Helper: return the length of sl, or 0 if sl is NULL.

Definition at line 127 of file pubsub_check.c.

Referenced by lint_message_consistency().