Skip to content
Commits on Source (2)
  • Andrew Price's avatar
    Timestamp fixes · b36f27e2
    Andrew Price authored
    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
    b36f27e2
  • Andrew Price's avatar
    Remove some obsolete timestamp assignments · 02023ddd
    Andrew Price authored
    02023ddd
......@@ -25,7 +25,6 @@ int announce_logon(const char *usr, int type, int quiet)
ipcmsg_destination(msg, SYSTEM_USER);
ipcmsg_json_encode(msg, j);
json_decref(j);
msg->head.when = time(NULL);
ipcmsg_transmit(msg);
return 0;
}
......@@ -49,7 +48,6 @@ int announce_logoff(const char *usr, int type, const char *agent, const char *re
ipcmsg_destination(msg, SYSTEM_USER);
ipcmsg_json_encode(msg, j);
json_decref(j);
msg->head.when = time(NULL);
ipcmsg_transmit(msg);
return 0;
}
......@@ -72,7 +70,6 @@ int announce_join(const char *usr, int channel, int type, const char *agent, int
ipcmsg_destination(msg, SYSTEM_USER);
ipcmsg_json_encode(msg, j);
json_decref(j);
msg->head.when = time(NULL);
ipcmsg_transmit(msg);
return 0;
}
......@@ -97,7 +94,6 @@ int announce_leave(const char *usr, int channel, int type, const char *agent, co
ipcmsg_destination(msg, SYSTEM_USER);
ipcmsg_json_encode(msg, j);
json_decref(j);
msg->head.when = time(NULL);
ipcmsg_transmit(msg);
return 0;
}
......@@ -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 */
......