Add 'debug.subscriber' config option

Add debug logging to find_subscriber() function
This commit is contained in:
Andrew Bettison 2013-11-25 22:40:14 +10:30
parent 59a6ded10c
commit 851dbb4d64
4 changed files with 68 additions and 40 deletions

View File

@ -270,6 +270,7 @@ ATOM(bool_t, rhizome_rx, 0, boolean,, "")
ATOM(bool_t, rhizome_ads, 0, boolean,, "") ATOM(bool_t, rhizome_ads, 0, boolean,, "")
ATOM(bool_t, rhizome_nohttptx, 0, boolean,, "") ATOM(bool_t, rhizome_nohttptx, 0, boolean,, "")
ATOM(bool_t, rhizome_mdp_rx, 0, boolean,, "") ATOM(bool_t, rhizome_mdp_rx, 0, boolean,, "")
ATOM(bool_t, subscriber, 0, boolean,, "")
ATOM(bool_t, throttling, 0, boolean,, "") ATOM(bool_t, throttling, 0, boolean,, "")
ATOM(bool_t, meshms, 0, boolean,, "") ATOM(bool_t, meshms, 0, boolean,, "")
ATOM(bool_t, manifests, 0, boolean,, "") ATOM(bool_t, manifests, 0, boolean,, "")

View File

@ -104,57 +104,69 @@ void free_subscribers()
} }
// find a subscriber struct from a whole or abbreviated subscriber id // find a subscriber struct from a whole or abbreviated subscriber id
struct subscriber *find_subscriber(const unsigned char *sidp, int len, int create) struct subscriber *_find_subscriber(struct __sourceloc __whence, const unsigned char *sidp, int len, int create)
{ {
IN();
if (config.debug.subscriber)
DEBUGF("find_subscriber(sid=%s, create=%d)", alloca_tohex(sidp, len), create);
struct tree_node *ptr = &root; struct tree_node *ptr = &root;
int pos=0; int pos=0;
if (len!=SID_SIZE) if (len!=SID_SIZE)
create =0; create =0;
struct subscriber *ret = NULL;
do{ do {
unsigned char nibble = get_nibble(sidp, pos++); unsigned char nibble = get_nibble(sidp, pos++);
if (ptr->is_tree & (1<<nibble)){ if (ptr->is_tree & (1<<nibble)){
ptr = ptr->tree_nodes[nibble]; ptr = ptr->tree_nodes[nibble];
}else if(!ptr->subscribers[nibble]){ }else if(!ptr->subscribers[nibble]){
// subscriber is not yet known // subscriber is not yet known
if (create && (ret = (struct subscriber *) emalloc_zero(sizeof(struct subscriber)))) {
if (create){ ptr->subscribers[nibble] = ret;
struct subscriber *ret=(struct subscriber *)malloc(sizeof(struct subscriber));
memset(ret,0,sizeof(struct subscriber));
ptr->subscribers[nibble]=ret;
ret->sid = *(const sid_t *)sidp; ret->sid = *(const sid_t *)sidp;
ret->abbreviate_len=pos; ret->abbreviate_len = pos;
if (config.debug.subscriber)
DEBUGF("set node[%.*s].subscribers[%c]=%p (sid=%s, abbrev_len=%d)",
pos - 1, alloca_tohex(sidp, len), hexdigit_upper[nibble],
ret, alloca_tohex_sid_t(ret->sid), ret->abbreviate_len
);
} }
return ptr->subscribers[nibble]; goto done;
}else{ }else{
// there's a subscriber in this slot, does it match the rest of the sid we've been given? // there's a subscriber in this slot, does it match the rest of the sid we've been given?
struct subscriber *ret = ptr->subscribers[nibble]; ret = ptr->subscribers[nibble];
if (memcmp(ret->sid.binary, sidp, len) == 0) if (memcmp(ret->sid.binary, sidp, len) == 0)
return ret; goto done;
// if we need to insert this subscriber, we have to make a new tree node first // if we need to insert this subscriber, we have to make a new tree node first
if (!create) if (!create) {
return NULL; ret = NULL;
goto done;
}
// create a new tree node and move the existing subscriber into it // create a new tree node and move the existing subscriber into it
struct tree_node *new=(struct tree_node *)malloc(sizeof(struct tree_node)); struct tree_node *new = (struct tree_node *) emalloc_zero(sizeof(struct tree_node));
memset(new,0,sizeof(struct tree_node)); if (new == NULL) {
ptr->tree_nodes[nibble]=new; ret = NULL;
goto done;
}
if (config.debug.subscriber)
DEBUGF("create node[%.*s]", pos, alloca_tohex(sidp, len));
ptr->tree_nodes[nibble] = new;
ptr->is_tree |= (1<<nibble); ptr->is_tree |= (1<<nibble);
ptr = new;
ptr=new; nibble = get_nibble(ret->sid.binary, pos);
nibble=get_nibble(ret->sid.binary, pos); ptr->subscribers[nibble] = ret;
ptr->subscribers[nibble]=ret; ret->abbreviate_len = pos + 1;
ret->abbreviate_len=pos+1; if (config.debug.subscriber)
DEBUGF("set node[%.*s].subscribers[%c]=%p(sid=%s, abbrev_len=%d)",
pos, alloca_tohex(sidp, len), hexdigit_upper[nibble],
ret, alloca_tohex_sid_t(ret->sid), ret->abbreviate_len
);
// then go around the loop again to compare the next nibble against the sid until we find an empty slot. // then go around the loop again to compare the next nibble against the sid until we find an empty slot.
} }
}while(pos < len*2); } while(pos < len*2);
done:
// abbreviation is not unique if (config.debug.subscriber)
return NULL; DEBUGF("find_subscriber() return %p", ret);
RETURN(ret);
} }
/* /*
@ -298,6 +310,8 @@ static int add_explain_response(struct subscriber *subscriber, void *context)
// the header of this packet must include our full sid. // the header of this packet must include our full sid.
if (subscriber->reachable==REACHABLE_SELF){ if (subscriber->reachable==REACHABLE_SELF){
if (subscriber==my_subscriber){ if (subscriber==my_subscriber){
if (config.debug.subscriber)
DEBUGF("Explaining SELF sid=%s", alloca_tohex_sid_t(subscriber->sid));
response->please_explain->source_full=1; response->please_explain->source_full=1;
return 0; return 0;
} }
@ -305,17 +319,22 @@ static int add_explain_response(struct subscriber *subscriber, void *context)
} }
// add the whole subscriber id to the payload, stop if we run out of space // add the whole subscriber id to the payload, stop if we run out of space
DEBUGF("Adding full sid by way of explanation %s", alloca_tohex_sid_t(subscriber->sid)); if (config.debug.subscriber)
DEBUGF("Explaining sid=%s", alloca_tohex_sid_t(subscriber->sid));
ob_checkpoint(response->please_explain->payload);
ob_append_byte(response->please_explain->payload, SID_SIZE); ob_append_byte(response->please_explain->payload, SID_SIZE);
ob_append_bytes(response->please_explain->payload, subscriber->sid.binary, SID_SIZE); ob_append_bytes(response->please_explain->payload, subscriber->sid.binary, SID_SIZE);
if (ob_overrun(response->please_explain->payload)) if (ob_overrun(response->please_explain->payload)) {
ob_rewind(response->please_explain->payload);
return 1; return 1;
}
// let the routing engine know that we had to explain this sid, we probably need to re-send routing info // let the routing engine know that we had to explain this sid, we probably need to re-send routing info
link_explained(subscriber); link_explained(subscriber);
return 0; return 0;
} }
static int find_subscr_buffer(struct decode_context *context, struct overlay_buffer *b, int len, struct subscriber **subscriber){ static int find_subscr_buffer(struct decode_context *context, struct overlay_buffer *b, int len, struct subscriber **subscriber)
{
if (len<=0 || len>SID_SIZE){ if (len<=0 || len>SID_SIZE){
return WHYF("Invalid abbreviation length %d", len); return WHYF("Invalid abbreviation length %d", len);
} }
@ -428,7 +447,8 @@ int overlay_address_parse(struct decode_context *context, struct overlay_buffer
} }
// once we've finished parsing a packet, complete and send a please explain if required. // once we've finished parsing a packet, complete and send a please explain if required.
int send_please_explain(struct decode_context *context, struct subscriber *source, struct subscriber *destination){ int send_please_explain(struct decode_context *context, struct subscriber *source, struct subscriber *destination)
{
IN(); IN();
struct overlay_frame *frame=context->please_explain; struct overlay_frame *frame=context->please_explain;
if (frame == NULL) if (frame == NULL)
@ -473,7 +493,8 @@ int send_please_explain(struct decode_context *context, struct subscriber *sourc
} }
// process an incoming request for explanation of subscriber abbreviations // process an incoming request for explanation of subscriber abbreviations
int process_explain(struct overlay_frame *frame){ int process_explain(struct overlay_frame *frame)
{
struct overlay_buffer *b=frame->payload; struct overlay_buffer *b=frame->payload;
struct decode_context context; struct decode_context context;
@ -498,14 +519,17 @@ int process_explain(struct overlay_frame *frame){
if (len==SID_SIZE){ if (len==SID_SIZE){
// This message is also used to inform people of previously unknown subscribers // This message is also used to inform people of previously unknown subscribers
// make sure we know this one // make sure we know this one
INFOF("Storing explain response for %s", alloca_tohex(sid, len));
find_subscriber(sid,len,1); find_subscriber(sid,len,1);
}else{ }else{
// reply to the sender with all subscribers that match this abbreviation // reply to the sender with all subscribers that match this abbreviation
INFOF("Sending responses for %s", alloca_tohex(sid, len)); INFOF("Sending explain responses for %s", alloca_tohex(sid, len));
walk_tree(&root, 0, sid, len, sid, len, add_explain_response, &context); walk_tree(&root, 0, sid, len, sid, len, add_explain_response, &context);
} }
} }
if (context.please_explain)
send_please_explain(&context, frame->destination, frame->source); send_please_explain(&context, frame->destination, frame->source);
else if (config.debug.subscriber)
DEBUG("No explain responses");
return 0; return 0;
} }

View File

@ -110,7 +110,9 @@ struct decode_context{
extern struct subscriber *my_subscriber; extern struct subscriber *my_subscriber;
extern struct subscriber *directory_service; extern struct subscriber *directory_service;
struct subscriber *find_subscriber(const unsigned char *sid, int len, int create); struct subscriber *_find_subscriber(struct __sourceloc, const unsigned char *sid, int len, int create);
#define find_subscriber(sid, len, create) _find_subscriber(__WHENCE__, sid, len, create)
void enum_subscribers(struct subscriber *start, int(*callback)(struct subscriber *, void *), void *context); void enum_subscribers(struct subscriber *start, int(*callback)(struct subscriber *, void *), void *context);
int set_reachable(struct subscriber *subscriber, struct network_destination *destination, struct subscriber *next_hop); int set_reachable(struct subscriber *subscriber, struct network_destination *destination, struct subscriber *next_hop);
int load_subscriber_address(struct subscriber *subscriber); int load_subscriber_address(struct subscriber *subscriber);

View File

@ -81,6 +81,7 @@ start_routing_instance() {
set debug.mdprequests yes \ set debug.mdprequests yes \
set debug.linkstate yes \ set debug.linkstate yes \
set debug.verbose yes \ set debug.verbose yes \
set debug.subscriber yes \
set debug.overlayrouting yes \ set debug.overlayrouting yes \
set log.console.level debug \ set log.console.level debug \
set log.console.show_pid on \ set log.console.show_pid on \