Commit b36f27e2 authored by Andrew Price's avatar Andrew Price

Timestamp fixes

Assign a timestamp to messages on creation and apply a timestamp to each
incoming message as we don't trust the client's timestamp anyway. This
avoids playing whack-a-mole trying to propagate the correct timestamp in
different situations.

Fixes #33
parent 9b6dd8b5
......@@ -198,7 +198,7 @@ void accept_action(ipc_connection_t *conn, ipc_message_t *msg)
ipcmsg_destroy(update);
ipc_message_t *gm = ipcmsg_create(IPC_EVENT, msg->head.src);
update->head.when = msg->head.when;
gm->head.when = msg->head.when;
json_t * gj = json_init(NULL);
json_addstring(gj, "target", victim_name);
json_addint(gj, "success", success);
......@@ -246,7 +246,7 @@ void accept_action(ipc_connection_t *conn, ipc_message_t *msg)
ipcmsg_destroy(update);
ipc_message_t *gm = ipcmsg_create(IPC_EVENT, msg->head.src);
update->head.when = msg->head.when;
gm->head.when = msg->head.when;
json_t * gj = json_init(NULL);
json_addstring(gj, "target", victim_name);
json_addint(gj, "success", success);
......
......@@ -130,12 +130,10 @@ void store_message(ipc_message_t *msg)
/* assign a unique serial number to each message
* thus giving a definitive replay ordering
* also attach timestamp for human friendliness
*/
void assign_serial( ipc_message_t *msg )
{
msg->head.serial = serial++;
msg->head.when = time(NULL);
}
void replay(ipc_connection_t *conn, ipc_message_t *msg)
......
......@@ -158,6 +158,7 @@ static int mainsock_event_cb(poll_event_t *events, int nmemb, void *data)
if (ev->is_read) {
ipc_message_t *msg = read_socket(c, 1);
while (msg != NULL) {
msg->head.when = time(NULL);
process_msg(c, msg);
msg=read_socket(c,0);
}
......
......@@ -19,6 +19,7 @@ ipc_message_t * ipcmsg_create(uint32_t type, uint32_t src)
ipc_message_t *new = calloc(1, sizeof(ipc_message_t));
new->head.src = src;
new->head.type = type;
new->head.when = time(NULL);
return new;
}
......@@ -37,9 +38,13 @@ void ipcmsg_summary(const char *intro, ipc_message_t *msg)
{
if (intro != NULL) printf("%s: ", intro);
if (msg->head.type < 255)
printf("src: %X, dst: %X, Type: %s, len=%d\n", msg->head.src, msg->head.dst, ipc_nametype(msg->head.type), msg->head.len);
printf("src: %X, dst: %X, Type: %s, len=%d, when=%ld\n",
msg->head.src, msg->head.dst, ipc_nametype(msg->head.type),
msg->head.len, msg->head.when);
else
printf("src: %X, dst: %X, Type: '%4.4s', len=%d\n", msg->head.src, msg->head.dst, (char *)&msg->head.type, msg->head.len);
printf("src: %X, dst: %X, Type: '%4.4s', len=%d, when=%ld\n",
msg->head.src, msg->head.dst, (char *)&msg->head.type,
msg->head.len, msg->head.when);
}
/* set the destination (PID) of a message */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment