Enhanced ACLK header payload to include timestamp-offset-usec (#8499)
Enhanced the ACLK header payload to include timestamp-offset-usec
Stelios Fragkakis committed
Mar 30, 2020 at 10:33 UTC
5f891e554fb816c9225c4da2a8dd316ee924ed12
2 files changed
+17
-7
aclk/agent_cloud_link.c
+11
-5
@@ -965,17 +965,21 @@ static void aclk_main_cleanup(void *ptr)
965
// Wakeup thread to cleanup
966
QUERY_THREAD_WAKEUP;
967
// Send a graceful disconnect message
968
- time_t time_created = now_realtime_sec();
968
char *msg_id = create_uuid();
969
970
+ usec_t time_created_offset_usec = now_realtime_usec();
971
+ time_t time_created = time_created_offset_usec / USEC_PER_SEC;
972
+ time_created_offset_usec = time_created_offset_usec % USEC_PER_SEC;
973
+
974
snprintfz(
975
payload, 511,
976
"{ \"type\": \"disconnect\","
977
" \"msg-id\": \"%s\","
978
" \"timestamp\": %ld,"
979
+ " \"timestamp-offset-usec\": %llu,"
980
" \"version\": %d,"
981
" \"payload\": \"graceful\" }",
978
- msg_id, time_created, ACLK_VERSION);
982
+ msg_id, time_created, time_created_offset_usec, ACLK_VERSION);
983
984
aclk_send_message(ACLK_METADATA_TOPIC, payload, msg_id);
985
freez(msg_id);
@@ -1522,7 +1526,6 @@ void aclk_shutdown()
1526
inline void aclk_create_header(BUFFER *dest, char *type, char *msg_id)
1527
{
1528
uuid_t uuid;
1525
- time_t time_created;
1529
char uuid_str[36 + 1];
1530
1531
if (unlikely(!msg_id)) {
@@ -1531,16 +1534,19 @@ inline void aclk_create_header(BUFFER *dest, char *type, char *msg_id)
1534
msg_id = uuid_str;
1535
}
1536
1534
- time_created = now_realtime_sec();
1537
+ usec_t time_created_offset_usec = now_realtime_usec();
1538
+ time_t time_created = time_created_offset_usec / USEC_PER_SEC;
1539
+ time_created_offset_usec = time_created_offset_usec % USEC_PER_SEC;
1540
1541
buffer_sprintf(
1542
dest,
1543
"\t{\"type\": \"%s\",\n"
1544
"\t\"msg-id\": \"%s\",\n"
1545
"\t\"timestamp\": %ld,\n"
1546
+ "\t\"timestamp-offset-usec\": %llu,\n"
1547
"\t\"version\": %d,\n"
1548
"\t\"payload\": ",
1543
- type, msg_id, time_created, ACLK_VERSION);
1549
+ type, msg_id, time_created, time_created_offset_usec, ACLK_VERSION);
1550
1551
debug(D_ACLK, "Sending v%d msgid [%s] type [%s] time [%ld]", ACLK_VERSION, msg_id, type, time_created);
1552
}
aclk/mqtt.c
+6
-2
@@ -269,7 +269,10 @@ int _link_set_lwt(char *sub_topic, int qos)
269
return 1;
270
}
271
272
- time_t time_created = now_realtime_sec();
272
+ usec_t time_created_offset_usec = now_realtime_usec();
273
+ time_t time_created = time_created_offset_usec / USEC_PER_SEC;
274
+ time_created_offset_usec = time_created_offset_usec % USEC_PER_SEC;
275
+
276
char *msg_id = create_uuid();
277
278
snprintfz(
@@ -277,9 +280,10 @@ int _link_set_lwt(char *sub_topic, int qos)
280
"{ \"type\": \"disconnect\","
281
" \"msg-id\": \"%s\","
282
" \"timestamp\": %ld,"
283
+ " \"timestamp-offset-usec\": %llu,"
284
" \"version\": %d,"
285
" \"payload\": \"unexpected\" }",
282
- msg_id, time_created, ACLK_VERSION);
286
+ msg_id, time_created, time_created_offset_usec, ACLK_VERSION);
287
288
freez(msg_id);
289