From 823139c57f788f5da894252ae0023b904e053a1b Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Mon, 27 Jun 2016 23:58:52 -0400 Subject: [PATCH] Trust router: open TRP connection to self, send multiple msgs. --- common/tr_msg.c | 3 +-- tr/tr_main.c | 28 +++++++++++++++++++++++----- tr/tr_trp.c | 2 -- trp/trps.c | 5 ++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/common/tr_msg.c b/common/tr_msg.c index f983015..685ad46 100644 --- a/common/tr_msg.c +++ b/common/tr_msg.c @@ -788,7 +788,6 @@ static json_t *tr_msg_encode_trp_req(TRP_REQ *req) json_t *jbody=NULL; json_t *jstr=NULL; char *s=NULL; - TR_NAME *n=NULL; if (req==NULL) return NULL; @@ -803,7 +802,7 @@ static json_t *tr_msg_encode_trp_req(TRP_REQ *req) return NULL; } - s=tr_name_strdup(n); /* ensures null termination */ + s=tr_name_strdup(trp_req_get_comm(req)); /* ensures null termination */ if (s==NULL) { json_decref(jbody); return NULL; diff --git a/tr/tr_main.c b/tr/tr_main.c index f218139..f6c67d0 100644 --- a/tr/tr_main.c +++ b/tr/tr_main.c @@ -124,20 +124,33 @@ static void tr_talloc_log(const char *msg) #endif /* TALLOC_DEBUG_ENABLE */ +struct thingy { + TRPS_INSTANCE *trps; + struct event *ev; +}; + static void debug_ping(evutil_socket_t fd, short what, void *arg) { TALLOC_CTX *tmp_ctx=talloc_new(NULL); - TRPS_INSTANCE *trps=talloc_get_type_abort(arg, TRPS_INSTANCE); + struct thingy *thingy=(struct thingy *)arg; + TRPS_INSTANCE *trps=thingy->trps; TRP_REQ *req=NULL; TR_MSG msg; char *encoded=NULL; + struct timeval interval={1, 0}; + static int count=10; + TR_NAME *name=NULL; - tr_debug("debug_ping entered, trps=%p, trps->trpc=%p", trps, trps->trpc); + tr_debug("debug_ping entered"); if (trps->trpc==NULL) tr_trpc_initiate(trps, trps->hostname, trps->port); /* create a TRP route request msg */ req=trp_req_new(tmp_ctx); + name=tr_new_name("community"); + trp_req_set_comm(req, name); + name=tr_new_name("realm"); + trp_req_set_realm(req, name); tr_msg_set_trp_req(&msg, req); encoded=tr_msg_encode(&msg); if (encoded==NULL) @@ -147,6 +160,8 @@ static void debug_ping(evutil_socket_t fd, short what, void *arg) trps_send_msg(trps, NULL, encoded); tr_msg_free_encoded(encoded); } + if (count-- > 0) + evtimer_add(thingy->ev, &interval); } int main(int argc, char *argv[]) @@ -160,7 +175,8 @@ int main(int argc, char *argv[]) TR_TRPS_EVENTS *trps_ev; struct event *cfgwatch_ev; struct event *debug_ping_ev; - struct timeval debug_ping_interval={1, 0}; + struct timeval notime={0, 0}; + struct thingy thingy={NULL}; /* we're going to be multithreaded, so disable null context tracking */ talloc_set_abort_fn(tr_abort); @@ -254,8 +270,10 @@ int main(int argc, char *argv[]) } /* for debugging, send a message to peers on a timer */ - debug_ping_ev=evtimer_new(ev_base, debug_ping, (void *)(tr->trps)); - evtimer_add(debug_ping_ev, &debug_ping_interval); + debug_ping_ev=evtimer_new(ev_base, debug_ping, (void *)&thingy); + thingy.trps=tr->trps; + thingy.ev=debug_ping_ev; + evtimer_add(debug_ping_ev, ¬ime); tr_event_loop_run(ev_base); /* does not return until we are done */ diff --git a/tr/tr_trp.c b/tr/tr_trp.c index 754063f..41c5690 100644 --- a/tr/tr_trp.c +++ b/tr/tr_trp.c @@ -162,7 +162,6 @@ static void tr_trps_process_mq(int socket, short event, void *arg) const char *s=NULL; char *tmp=NULL; - tr_debug("tr_trps_process_mw: starting"); msg=trps_mq_pop(trps); while (msg!=NULL) { s=tr_mq_msg_get_message(msg); @@ -182,7 +181,6 @@ static void tr_trps_process_mq(int socket, short event, void *arg) tr_mq_msg_free(msg); msg=trps_mq_pop(trps); } - tr_debug("tr_trps_process_mw: ending"); } static int tr_trps_events_destructor(void *obj) diff --git a/trp/trps.c b/trp/trps.c index b4b7b4f..f1175e6 100644 --- a/trp/trps.c +++ b/trp/trps.c @@ -179,7 +179,10 @@ static TRP_RC trps_read_message(TRPS_INSTANCE *trps, TRP_CONNECTION *conn, TR_MS *msg=tr_msg_decode(buf, buflen); free(buf); - return TRP_SUCCESS; + if (*msg==NULL) + return TRP_NOPARSE; + else + return TRP_SUCCESS; } int trps_get_listener(TRPS_INSTANCE *trps, -- 2.1.4