From: Jennifer Richards Date: Thu, 3 May 2018 20:50:54 +0000 (-0400) Subject: Merge branch 'milestone/monitoring' into jennifer/request_id X-Git-Tag: 3.4.0~1^2~38^2~1 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=trust_router.git;a=commitdiff_plain;h=3c5fb17459ff56d5e23cea059503f46a42150a1e Merge branch 'milestone/monitoring' into jennifer/request_id # Conflicts: # include/trust_router/tid.h # tid/tidc.c # tr/tr_tid.c --- 3c5fb17459ff56d5e23cea059503f46a42150a1e diff --cc Makefile.am index fbc763c,1c933d6..1231793 --- a/Makefile.am +++ b/Makefile.am @@@ -84,9 -132,19 +134,20 @@@ $(common_srcs tr_trpc_LDADD = gsscon/libgsscon.la $(GLIB_LIBS) tr_trpc_LDFLAGS = $(AM_LDFLAGS) -pthread + tr_trmon_SOURCES = tr/trmon_main.c \ + common/tr_gss.c \ + common/tr_gss_client.c \ + $(tid_srcs) \ + $(trp_srcs) \ + $(common_srcs) \ + mon/monc.c + + tr_trmon_LDADD = gsscon/libgsscon.la $(GLIB_LIBS) + tr_trmon_LDFLAGS = $(AM_LDFLAGS) -pthread + trp_msgtst_SOURCES = trp/msgtst.c \ $(common_srcs) \ +common/tr_rand_id.c \ trp/trp_req.c \ trp/trp_upd.c \ tid/tid_resp.c \ diff --cc include/trust_router/tid.h index 42b97f3,35ec577..38833f1 --- a/include/trust_router/tid.h +++ b/include/trust_router/tid.h @@@ -94,9 -95,7 +95,9 @@@ void tid_req_set_realm(TID_REQ *req, TR TR_EXPORT TR_NAME *tid_req_get_comm(TID_REQ *req); void tid_req_set_comm(TID_REQ *req, TR_NAME *comm); TR_EXPORT TR_NAME *tid_req_get_orig_coi(TID_REQ *req); - void tid_req_set_rp_orig_coi(TID_REQ *req, TR_NAME *orig_coi); + void tid_req_set_orig_coi(TID_REQ *req, TR_NAME *orig_coi); +TR_EXPORT TR_NAME *tid_req_get_request_id(TID_REQ *req); +void tid_req_set_request_id(TID_REQ *req, TR_NAME *request_id); TR_EXPORT TIDC_RESP_FUNC *tid_req_get_resp_func(TID_REQ *req); void tid_req_set_resp_func(TID_REQ *req, TIDC_RESP_FUNC *resp_func); TR_EXPORT void *tid_req_get_cookie(TID_REQ *req); diff --cc tid/tidc.c index 320ded6,94cd98d..90335f0 --- a/tid/tidc.c +++ b/tid/tidc.c @@@ -39,9 -40,7 +40,8 @@@ #include #include #include - #include #include +#include int tmp_len = 32; @@@ -96,17 -87,31 +88,32 @@@ int tidc_open_connection (TIDC_INSTANC } int tidc_send_request (TIDC_INSTANCE *tidc, - int conn, - gss_ctx_id_t gssctx, - const char *rp_realm, - const char *realm, - const char *comm, - TIDC_RESP_FUNC *resp_handler, - void *cookie) + int conn, + gss_ctx_id_t gssctx, + const char *rp_realm, + const char *realm, + const char *comm, + TIDC_RESP_FUNC *resp_handler, + void *cookie) { TID_REQ *tid_req = NULL; + char *request_id = NULL; int rc; + int orig_conn = 0; + gss_ctx_id_t *orig_gss_ctx = NULL; + + /* For ABI compatibility, replace the generic GSS client parameters + * with the arguments we were passed. */ + orig_conn = tidc->gssc->conn; /* save to restore later */ + if (conn != tidc->gssc->conn) { + tr_warning("tidc_send_request: WARNING: socket connection FD does not match FD opened by tidc_open_connection()"); + tidc->gssc->conn = conn; + } + orig_gss_ctx = tidc->gssc->gss_ctx; /* save to restore later */ + if (gssctx != *(tidc->gssc->gss_ctx)) { + tr_warning("tidc_send_request: WARNING: sending request with different GSS context than used for tidc_open_connection()"); + *tidc->gssc->gss_ctx = gssctx; + } /* Create and populate a TID req structure */ if (!(tid_req = tid_req_new())) @@@ -122,19 -127,8 +129,19 @@@ goto error; } - tid_req->tidc_dh = tr_dh_dup(tidc->client_dh); + tid_req->tidc_dh = tr_dh_dup(tidc->gssc->client_dh); + /* generate an ID */ + request_id = tr_random_id(NULL); + if (request_id) { + if (tid_req->request_id = tr_new_name(request_id)) + tr_debug("tidc_send_request: Created TID request ID: %s", request_id); + else + tr_debug("tidc_send_request: Unable to set request ID, proceeding without one"); + talloc_free(request_id); + } else + tr_debug("tidc_send_request: Failed to generate a TID request ID, proceeding without one"); + rc = tidc_fwd_request(tidc, tid_req, resp_handler, cookie); goto cleanup; error: @@@ -149,13 -147,9 +160,10 @@@ int tidc_fwd_request(TIDC_INSTANCE *tid TIDC_RESP_FUNC *resp_handler, void *cookie) { - char *req_buf = NULL; - char *resp_buf = NULL; - size_t resp_buflen = 0; + TALLOC_CTX *tmp_ctx = talloc_new(NULL); TR_MSG *msg = NULL; TR_MSG *resp_msg = NULL; + TID_RESP *tid_resp = NULL; - int err; int rc = 0; /* Create and populate a TID msg structure */ @@@ -165,48 -159,16 +173,17 @@@ msg->msg_type = TID_REQUEST; tr_msg_set_req(msg, tid_req); - /* store the response function and cookie */ - // tid_req->resp_func = resp_handler; - // tid_req->cookie = cookie; - - /* Encode the request into a json string */ - if (!(req_buf = tr_msg_encode(msg))) { - tr_err("tidc_fwd_request: Error encoding TID request.\n"); - goto error; - } - - tr_debug( "tidc_fwd_request: Sending TID request:\n"); - tr_debug( "%s\n", req_buf); + tr_debug( "tidc_fwd_request: Sending TID request\n"); /* Send the request over the connection */ - if (err = gsscon_write_encrypted_token (tid_req->conn, tid_req->gssctx, req_buf, - strlen(req_buf))) { - tr_err( "tidc_fwd_request: Error sending request over connection.\n"); + resp_msg = tr_gssc_exchange_msgs(tmp_ctx, tidc->gssc, msg); + if (resp_msg == NULL) goto error; - } - - /* TBD -- queue request on instance, read resps in separate thread */ - - /* Read the response from the connection */ - /* TBD -- timeout? */ - if (err = gsscon_read_encrypted_token(tid_req->conn, tid_req->gssctx, &resp_buf, &resp_buflen)) { - if (resp_buf) - free(resp_buf); - goto error; - } - - tr_debug( "tidc_fwd_request: Response Received (%u bytes).\n", (unsigned) resp_buflen); - tr_debug( "%s\n", resp_buf); - - if (NULL == (resp_msg = tr_msg_decode(resp_buf, resp_buflen))) { - tr_err( "tidc_fwd_request: Error decoding response.\n"); - goto error; - } /* TBD -- Check if this is actually a valid response */ - if (TID_RESPONSE != tr_msg_get_msg_type(resp_msg)) { + tid_resp = tr_msg_get_resp(resp_msg); + if (tid_resp == NULL) { tr_err( "tidc_fwd_request: Error, no response in the response!\n"); goto error; } diff --cc tr/tr_tid.c index c4ac9fb,038cc3c..62722e8 --- a/tr/tr_tid.c +++ b/tr/tr_tid.c @@@ -273,14 -344,8 +344,14 @@@ static int tr_tids_req_handler(TIDS_INS goto cleanup; } - tr_debug("tr_tids_req_handler: Request received (conn = %d)! Realm = %s, Comm = %s", orig_req->conn, + tr_debug("tr_tids_req_handler: Request received (conn = %d)! Realm = %s, Comm = %s", orig_req->conn, orig_req->realm->buf, orig_req->comm->buf); + if (orig_req->request_id) + tr_debug("tr_tids_req_handler: TID request ID: %.*s", orig_req->request_id->len, orig_req->request_id->buf); + else + tr_debug("tr_tids_req_handler: TID request ID: none"); + + tids->req_count++; /* Duplicate the request, so we can modify and forward it */ if (NULL == (fwd_req=tid_dup_req(orig_req))) {