Tor  0.4.7.0-alpha-dev
Macros | Functions
pubsub_check.c File Reference

Enforce various requirements on a pubsub_builder. More...

#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_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 91 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 140 of file pubsub_check.c.

◆ 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 180 of file pubsub_check.c.

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 318 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 242 of file pubsub_check.c.

◆ 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 204 of file pubsub_check.c.

◆ 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 63 of file pubsub_check.c.

◆ 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 383 of file pubsub_check.c.

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 114 of file pubsub_check.c.

◆ 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 99 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: construct and return a new pubsub_adjacency_map from cfg. Return NULL on error.

Definition at line 38 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 399 of file pubsub_check.c.

◆ 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 158 of file pubsub_check.c.

◆ 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 129 of file pubsub_check.c.

Referenced by lint_message_consistency().