[mw-devel] [Git][milliways/mw][master] 2 commits: Timestamp fixes
Andrew Price
welshbyte at sucs.org
Tue Apr 9 21:11:56 BST 2019
Andrew Price pushed to branch master at milliways / mw
Commits:
b36f27e2 by Andrew Price at 2019-04-09T20:02:23Z
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
- - - - -
02023ddd by Andrew Price at 2019-04-09T20:11:22Z
Remove some obsolete timestamp assignments
- - - - -
5 changed files:
- src/client/onoff.c
- src/server/actions.c
- src/server/replay.c
- src/server/servsock.c
- src/socket.c
Changes:
=====================================
src/client/onoff.c
=====================================
@@ -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;
}
=====================================
src/server/actions.c
=====================================
@@ -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);
=====================================
src/server/replay.c
=====================================
@@ -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)
=====================================
src/server/servsock.c
=====================================
@@ -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);
}
=====================================
src/socket.c
=====================================
@@ -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 */
View it on GitLab: https://projects.sucs.org/milliways/mw/compare/9b6dd8b5f57edf9b78767aeadb4939a9d8b3f366...02023ddd68d0cbbdf9d39c1cb0d7c40bbee50a0d
--
View it on GitLab: https://projects.sucs.org/milliways/mw/compare/9b6dd8b5f57edf9b78767aeadb4939a9d8b3f366...02023ddd68d0cbbdf9d39c1cb0d7c40bbee50a0d
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20190409/d52e5d34/attachment-0001.html>
More information about the mw-devel
mailing list