diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-08 13:21:21 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-08 13:21:50 +0200 |
commit | 777bd9688099daf5af9d0e41f2df668040e072a9 (patch) | |
tree | e21f4520d4ccb1387575cc6baeef6ff59582d57f | |
parent | 067d63d298a15810171555f7f0acf96fb1946667 (diff) | |
download | vmod-tbf-777bd9688099daf5af9d0e41f2df668040e072a9.tar.gz vmod-tbf-777bd9688099daf5af9d0e41f2df668040e072a9.tar.bz2 |
Fix debug levels. Document data structures.
-rw-r--r-- | src/tbf.c | 9 | ||||
-rw-r--r-- | src/tbf.h | 19 |
2 files changed, 15 insertions, 13 deletions
@@ -42,13 +42,13 @@ lru_link_node(struct tree *tree, struct node *node, struct node *ref) tree->head->prev = node; else tree->tail = node; tree->head = node; } else { struct node *x; - //debug(0, ("LINK %p %p %p", node, ref, ref->next)); + node->prev = ref; node->next = ref->next; if ((x = ref->next)) x->prev = node; else tree->tail = node; @@ -662,13 +662,13 @@ tree_load_nodes(struct tree *tree, struct dump_header *hdr, for (i = 0; i < hdr->count; i++) { struct node node, *np; uint32_t len; uint32_t flags; - debug(0,("Load record %lu/%lu %lu", i, hdr->count, incomplete)); + debug(3,("Load record %lu/%lu %lu", i, hdr->count, incomplete)); if (READREC(fp, len)) return -1; if (READREC(fp, flags)) return -1; if (READREC(fp, node.key)) @@ -721,13 +721,13 @@ tree_load_nodes(struct tree *tree, struct dump_header *hdr, nodes[i] = np; } np->timestamp = node.timestamp; np->tokens = node.tokens; #if DEBUG np->keystr = node.keystr; - debug(0, ("loaded %p: %s %1x (%lu,%lu): time: %"PRIu64" us, tokens: %lu", + debug(3, ("loaded %p: %s %1x (%lu,%lu): time: %"PRIu64" us, tokens: %lu", np, np->keystr, flags, ord[CHILD_LEFT], ord[CHILD_RIGHT], np->timestamp, np->tokens)); @@ -765,13 +765,12 @@ tree_load_nodes(struct tree *tree, struct dump_header *hdr, if (incomplete) { syslog(LOG_DAEMON|LOG_ERR, "tbf.%s: %lu incomplete nodes left", __FUNCTION__, incomplete); return 1; } tree->root = nodes[hdr->root]; -// debug(0,("Loaded nodes")); return 0; } struct tree * tree_load(char const *filename) { @@ -789,13 +788,13 @@ tree_load(char const *filename) if (READREC(fp, header)) rc = -1; else { struct node **nodes; - debug(0,("elements: %"PRIu32", size: %"PRIu32", root: %"PRIu32, + debug(3,("elements: %"PRIu32", size: %"PRIu32", root: %"PRIu32, header.count, header.size, header.root)); tree = tree_create(); nodes = calloc(header.count, sizeof(*nodes)); rc = tree_load_nodes(tree, &header, nodes, fp); fclose(fp); if (rc) { @@ -50,26 +50,29 @@ struct dump_header { enum { CHILD_LEFT, CHILD_RIGHT }; #define FL_CHILD_LEFT 0x1 #define FL_CHILD_RIGHT 0x2 -enum { NST_INCOMPLETE, NST_INIT }; +enum node_status { NST_INCOMPLETE, NST_INIT }; struct node { uint8_t key[SHA256_LEN]; #ifdef DEBUG char *keystr; #endif - struct node *parent; - struct node *child[2]; - struct node *prev, *next; - pthread_cond_t notbusy; - int busy:1; - int status; - uint32_t ord; + struct node *parent; /* Parent node */ + struct node *child[2]; /* Left and right child nodes */ + struct node *prev, *next; /* More (prev) and less (next) recently + updated nodes. */ + pthread_cond_t notbusy; /* Prevent simultaneous updates */ + int busy:1; /* Node is in use if 1 */ + enum node_status status; /* Node status */ + uint32_t ord; /* Used when dumping nodes and computing tree + stats */ + /* Actual TBF payload: */ uint64_t timestamp; /* microseconds since epoch */ size_t tokens; /* tokens available */ }; struct tree { |