Macros | Functions | Variables
unparseable.c File Reference

Dump unparseable objects to disk. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "feature/dirparse/unparseable.h"
#include "lib/sandbox/sandbox.h"

Go to the source code of this file.


#define DESC_DUMP_DATADIR_SUBDIR   "unparseable-descs"
#define DESC_DUMP_BASE_FILENAME   "unparseable-desc"


void dump_desc_init (void)
static void dump_desc_create_dir (void)
static void dump_desc_fifo_add_and_clean (char *filename, const uint8_t *digest_sha256, size_t len)
static int dump_desc_fifo_bump_hash (const uint8_t *digest_sha256)
void dump_desc_fifo_cleanup (void)
STATIC dumped_desc_t * dump_desc_populate_one_file (const char *dirname, const char *f)
static int dump_desc_compare_fifo_entries (const void **a_v, const void **b_v)
STATIC void dump_desc_populate_fifo_from_directory (const char *dirname)
void dump_desc (const char *desc, const char *type)


STATIC smartlist_tdescs_dumped = NULL
STATIC uint64_t len_descs_dumped = 0
static int have_dump_desc_dir = 0
static int problem_with_dump_desc_dir = 0

Detailed Description

Dump unparseable objects to disk.

Definition in file unparseable.c.

Macro Definition Documentation


#define DESC_DUMP_BASE_FILENAME   "unparseable-desc"

Definition at line 34 of file unparseable.c.


#define DESC_DUMP_DATADIR_SUBDIR   "unparseable-descs"

Definition at line 33 of file unparseable.c.



Definition at line 12 of file unparseable.c.

Function Documentation

◆ dump_desc()

void dump_desc ( const char *  desc,
const char *  type 

For debugging purposes, dump unparseable descriptor *desc of type *type to file $DATADIR/unparseable-desc. Do not write more than one descriptor to disk per minute. If there is already such a file in the data directory, overwrite it.

Definition at line 496 of file unparseable.c.

◆ dump_desc_compare_fifo_entries()

static int dump_desc_compare_fifo_entries ( const void **  a_v,
const void **  b_v 

Sort helper for dump_desc_populate_fifo_from_directory(); compares the when field of dumped_desc_ts in a smartlist to put the FIFO in the correct order after reconstructing it from the directory.

Definition at line 389 of file unparseable.c.

◆ dump_desc_create_dir()

static void dump_desc_create_dir ( void  )

Create the dump directory if needed and possible

Definition at line 97 of file unparseable.c.

◆ dump_desc_fifo_add_and_clean()

static void dump_desc_fifo_add_and_clean ( char *  filename,
const uint8_t *  digest_sha256,
size_t  len 

Dump desc FIFO/cleanup; take ownership of the given filename, add it to the FIFO, and clean up the oldest entries to the extent they exceed the configured cap. If any old entries with a matching hash existed, they just got overwritten right before this was called and we should adjust the total size counter without deleting them.

Definition at line 130 of file unparseable.c.

◆ dump_desc_fifo_bump_hash()

static int dump_desc_fifo_bump_hash ( const uint8_t *  digest_sha256)

Check if we already have a descriptor for this hash and move it to the head of the queue if so. Return 1 if one existed and 0 otherwise.

Definition at line 201 of file unparseable.c.

◆ dump_desc_fifo_cleanup()

void dump_desc_fifo_cleanup ( void  )

Clean up on exit; just memory, leave the dumps behind

Definition at line 239 of file unparseable.c.

Referenced by routerparse_free_all().

◆ dump_desc_init()

void dump_desc_init ( void  )

Find the dump directory and check if we'll be able to create it

Definition at line 38 of file unparseable.c.

Referenced by routerparse_init().

◆ dump_desc_populate_fifo_from_directory()

STATIC void dump_desc_populate_fifo_from_directory ( const char *  dirname)

Scan the contents of the directory, and update FIFO/counters; this will consistency-check descriptor dump filenames against hashes of descriptor dump file content, and remove any inconsistent/unreadable dumps, and then reconstruct the dump FIFO as closely as possible for the last time the tor process shut down. If a previous dump was repeated more than once and moved ahead in the FIFO, the mtime will not have been updated and the reconstructed order will be wrong, but will always be a permutation of the original.

Definition at line 426 of file unparseable.c.

◆ dump_desc_populate_one_file()

STATIC dumped_desc_t * dump_desc_populate_one_file ( const char *  dirname,
const char *  f 

Handle one file for dump_desc_populate_fifo_from_directory(); make sure the filename is sensibly formed and matches the file content, and either return a dumped_desc_t for it or remove the file and return NULL.

Definition at line 260 of file unparseable.c.

Variable Documentation

◆ descs_dumped

STATIC smartlist_t* descs_dumped = NULL

List of dumped descriptors for FIFO cleanup purposes

Definition at line 26 of file unparseable.c.

Referenced by dump_desc_fifo_add_and_clean(), dump_desc_fifo_bump_hash(), and dump_desc_fifo_cleanup().

◆ have_dump_desc_dir

int have_dump_desc_dir = 0

Directory to stash dumps in

Definition at line 30 of file unparseable.c.

◆ len_descs_dumped

STATIC uint64_t len_descs_dumped = 0

Total size of dumped descriptors for FIFO cleanup

Definition at line 28 of file unparseable.c.

Referenced by dump_desc_fifo_add_and_clean().

◆ problem_with_dump_desc_dir

int problem_with_dump_desc_dir = 0

Definition at line 31 of file unparseable.c.