X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=tr%2Ftr_main.c;h=3c74730f75f66ab3a1096d346e0022cf7fbed280;hb=733b18697117cbc63ab3d9e44510c9850916ec90;hp=a03ef4b12bf0e2069633ad83a08b5818c5cbba8d;hpb=196707bb546875b9c07ffd92c9b16e524b087632;p=trust_router.git diff --git a/tr/tr_main.c b/tr/tr_main.c index a03ef4b..3c74730 100644 --- a/tr/tr_main.c +++ b/tr/tr_main.c @@ -34,15 +34,15 @@ #include #include -#include #include #include #include -#include #include -#include +#include #include +#include +#include #include #include #include @@ -145,6 +145,18 @@ static void configure_signals(void) pthread_sigmask(SIG_BLOCK, &signals, NULL); } +/* TODO move this function */ +static json_t *tr_mon_handle_version(void *cookie) +{ + return json_string(PACKAGE_VERSION); +} + +static json_t *tr_mon_handle_uptime(void *cookie) +{ + time_t *start_time = cookie; + return json_integer(time(NULL) - (*start_time)); +} + int main(int argc, char *argv[]) { TALLOC_CTX *main_ctx=NULL; @@ -153,8 +165,11 @@ int main(int argc, char *argv[]) struct cmdline_args opts; struct event_base *ev_base; struct tr_socket_event tids_ev = {0}; + struct tr_socket_event mon_ev = {0}; struct event *cfgwatch_ev; + time_t start_time = time(NULL); /* TODO move this? */ + configure_signals(); /* we're going to be multithreaded, so disable null context tracking */ @@ -192,11 +207,10 @@ int main(int argc, char *argv[]) } /***** initialize the trust path query server instance *****/ - if (NULL == (tr->tids = tids_create())) { + if (NULL == (tr->tids = tids_new(tr))) { tr_crit("Error initializing Trust Path Query Server instance."); return 1; } - talloc_steal(tr, tr->tids); /***** initialize the trust router protocol server instance *****/ if (NULL == (tr->trps = trps_new(tr))) { @@ -204,6 +218,19 @@ int main(int argc, char *argv[]) return 1; } + /***** initialize the monitoring interface instance *****/ + if (NULL == (tr->mons = mons_new(tr))) { + tr_crit("Error initializing monitoring interface instance."); + return 1; + } + /* Monitor our tids/trps instances */ + tr->mons->tids = tr->tids; + tr->mons->trps = tr->trps; + + /* TODO do this more systematically */ + mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_VERSION, tr_mon_handle_version, NULL); + mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_UPTIME, tr_mon_handle_uptime, &start_time); + /***** process configuration *****/ tr->cfgwatch=tr_cfgwatch_create(tr); if (tr->cfgwatch == NULL) { @@ -232,7 +259,12 @@ int main(int argc, char *argv[]) return 1; } - /*tr_status_event_init();*/ /* install status reporting events */ + /* install monitoring interface events */ + tr_debug("Initializing monitoring interface events."); + if (0 != tr_mons_event_init(ev_base, tr->mons, tr->cfg_mgr, &mon_ev)) { + tr_crit("Error initializing monitoring interface."); + return 1; + } /* install TID server events */ tr_debug("Initializing TID server events.");