Skip to content

Commit

Permalink
Merge pull request #260 from openziti/add-cached_last_activity_at
Browse files Browse the repository at this point in the history
add cached_last_activity_at to ziti.c and internal_model.h
  • Loading branch information
dovholuknf authored Mar 25, 2021
2 parents 6c97311 + f98b6d9 commit fbe0025
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions inc_internal/internal_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ XX(id, string, none, id, __VA_ARGS__) \
XX(token, string, none, token, __VA_ARGS__) \
XX(expires, timestamp, ptr, expiresAt, __VA_ARGS__) \
XX(updated, timestamp, ptr, updatedAt, __VA_ARGS__) \
XX(cached_last_activity_at, timestamp, ptr, cachedLastActivityAt, __VA_ARGS__) \
XX(identity, ziti_identity, ptr, identity, __VA_ARGS__) \
XX(posture_query_set, ziti_posture_query_set, array, postureQueries, __VA_ARGS__) \
XX(auth_queries, ziti_auth_query_mfa, array, authQueries, __VA_ARGS__)
Expand Down
9 changes: 8 additions & 1 deletion library/ziti.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,14 @@ static void session_post_auth_query_cb(ziti_context ztx){
uv_timeval64_t now;
uv_gettimeofday(&now);

int time_diff = (int) (now.tv_sec - session->updated->tv_sec);
int time_diff;
if (session->cached_last_activity_at) {
ZITI_LOG(TRACE, "API supports cached_last_activity_at");
time_diff = (int) (now.tv_sec - session->cached_last_activity_at->tv_sec);
} else {
ZITI_LOG(TRACE, "API doesn't support cached_last_activity_at - using updated");
time_diff = (int) (now.tv_sec - session->updated->tv_sec);
}
if (abs(time_diff) > 10) {
ZITI_LOG(ERROR, "local clock is %d seconds %s UTC (as reported by controller)", abs(time_diff),
time_diff > 0 ? "ahead" : "behind");
Expand Down

0 comments on commit fbe0025

Please sign in to comment.