Mercurial > hg > freeDiameter
diff libfdproto/messages.c @ 895:fbf77629cb7b
Added received and sent timestamps in the messages; added logs on emission and reception
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 30 Nov 2012 00:44:10 +0100 |
parents | 43fb27a9037f |
children | 4382d7420e65 |
line wrap: on
line diff
--- a/libfdproto/messages.c Thu Nov 29 22:51:49 2012 +0100 +++ b/libfdproto/messages.c Fri Nov 30 00:44:10 2012 +0100 @@ -127,7 +127,8 @@ } msg_cb; /* Callback to be called when an answer is received, if not NULL */ DiamId_t msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */ size_t msg_src_id_len; /* cached length of this string */ - struct timespec msg_ts; /* Timestamp associated with the message */ + struct timespec msg_ts_rcv; /* Timestamp when this message was received from the network */ + struct timespec msg_ts_sent; /* Timestamp when this message was sent to the network */ }; @@ -677,6 +678,9 @@ static int obj_dump_msg (struct msg * msg, int indent, char **outstr, size_t *offset, size_t *outlen ) { int ret = 0; + char buftime[256]; + size_t tsoffset = 0; + struct tm tm; CHECK_FCT( dump_add_str(outstr, offset, outlen, "%*sMSG: %p\n", INOBJHDRVAL, msg) ); @@ -685,6 +689,17 @@ return 0; } + if ((msg->msg_ts_rcv.tv_sec != 0) || (msg->msg_ts_rcv.tv_nsec != 0)) { + tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_rcv.tv_sec , &tm )); + tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_rcv.tv_nsec / 1000); + CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Received: %s\n", INOBJHDRVAL, buftime) ); + } + if ((msg->msg_ts_sent.tv_sec != 0) || (msg->msg_ts_sent.tv_nsec != 0)) { + tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_sent.tv_sec , &tm )); + tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_sent.tv_nsec / 1000); + CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Sent : %s\n", INOBJHDRVAL, buftime) ); + } + if (!msg->msg_model) { CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model)\n", INOBJHDRVAL) ); @@ -733,7 +748,7 @@ if (!avp->avp_model) { - CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model)\n", INOBJHDRVAL) ); + CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model resolved)\n", INOBJHDRVAL) ); } else { @@ -825,7 +840,7 @@ } while (ref); /* now really output this in one shot, so it is not interrupted */ - fd_log_debug_fstr(fstr, "%s", outstr); + fd_log_debug_fstr(fstr, "%s\n", outstr); free(outstr); } @@ -837,7 +852,7 @@ CHECK_FCT_DO( msg_dump_intern ( NONE, msg, 2, &outstr, &offset, &outlen ), fd_log_debug_fstr(fstr, "Error while dumping %p\n", msg) ); /* now really output this in one shot, so it is not interrupted */ - fd_log_debug_fstr(fstr, "%s", outstr); + fd_log_debug_fstr(fstr, "%s\n", outstr); free(outstr); } @@ -1152,6 +1167,55 @@ return 0; } +int fd_msg_ts_set_recv( struct msg * msg, struct timespec * ts ) +{ + TRACE_ENTRY("%p %p", msg, ts); + + /* Check we received valid parameters */ + CHECK_PARAMS( CHECK_MSG(msg) ); + CHECK_PARAMS( ts ); + + memcpy(&msg->msg_ts_rcv, ts, sizeof(struct timespec)); + return 0; +} + +int fd_msg_ts_get_recv( struct msg * msg, struct timespec * ts ) +{ + TRACE_ENTRY("%p %p", msg, ts); + + /* Check we received valid parameters */ + CHECK_PARAMS( CHECK_MSG(msg) ); + CHECK_PARAMS( ts ); + + memcpy(ts, &msg->msg_ts_rcv, sizeof(struct timespec)); + return 0; +} + +int fd_msg_ts_set_sent( struct msg * msg, struct timespec * ts ) +{ + TRACE_ENTRY("%p %p", msg, ts); + + /* Check we received valid parameters */ + CHECK_PARAMS( CHECK_MSG(msg) ); + CHECK_PARAMS( ts ); + + memcpy(&msg->msg_ts_sent, ts, sizeof(struct timespec)); + return 0; +} + +int fd_msg_ts_get_sent( struct msg * msg, struct timespec * ts ) +{ + TRACE_ENTRY("%p %p", msg, ts); + + /* Check we received valid parameters */ + CHECK_PARAMS( CHECK_MSG(msg) ); + CHECK_PARAMS( ts ); + + memcpy(ts, &msg->msg_ts_sent, sizeof(struct timespec)); + return 0; +} + + /* Retrieve the session of the message */ int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * new) {