From a01e2068848f6988a1f32fbaa3a739d70afc156d Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Mon, 19 Dec 2016 20:23:28 -0500 Subject: [PATCH] Properly set expiry on new community inforecs. --- common/tr_comm.c | 7 +++++++ common/tr_mq.c | 3 ++- include/trp_internal.h | 4 ++++ trp/trps.c | 10 ++++++---- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/common/tr_comm.c b/common/tr_comm.c index 750651f..73c8023 100644 --- a/common/tr_comm.c +++ b/common/tr_comm.c @@ -246,6 +246,7 @@ void tr_comm_add_idp_realm(TR_COMM_TABLE *ctab, tr_comm_memb_set_comm(newmemb, comm); tr_comm_memb_set_interval(newmemb, interval); tr_comm_memb_set_provenance(newmemb, provenance); + tr_comm_memb_set_expiry(newmemb, expiry); existing=tr_comm_table_find_idp_memb_origin(ctab, tr_idp_realm_get_id(realm), @@ -278,6 +279,7 @@ void tr_comm_add_rp_realm(TR_COMM_TABLE *ctab, tr_comm_memb_set_comm(newmemb, comm); tr_comm_memb_set_interval(newmemb, interval); tr_comm_memb_set_provenance(newmemb, provenance); + tr_comm_memb_set_expiry(newmemb, expiry); existing=tr_comm_table_find_rp_memb_origin(ctab, tr_rp_realm_get_id(realm), @@ -1017,6 +1019,11 @@ struct timespec *tr_comm_memb_get_expiry(TR_COMM_MEMB *memb) int tr_comm_memb_is_expired(TR_COMM_MEMB *memb, struct timespec *curtime) { + tr_debug("tr_comm_memb_is_expired: (cur->tv_sec>memb->expiry->tv_sec)=(%u > %u)=%s", + curtime->tv_sec, + memb->expiry->tv_sec, + (curtime->tv_sec > memb->expiry->tv_sec)?"true":"false"); + return ((curtime->tv_sec > memb->expiry->tv_sec) || ((curtime->tv_sec == memb->expiry->tv_sec) &&(curtime->tv_nsec >= memb->expiry->tv_nsec))); diff --git a/common/tr_mq.c b/common/tr_mq.c index 944ba32..07080b6 100644 --- a/common/tr_mq.c +++ b/common/tr_mq.c @@ -294,7 +294,8 @@ int tr_mq_pop_timeout(time_t seconds, struct timespec *ts) * has passed, returns an existing message but will not wait if one is * not already available. If ts_abort is null, no blocking. Not * guaranteed to wait if an error occurs - immediately returns without - * a message. */ + * a message. Use tr_mq_pop_timeout() to get an absolute time that + * is guaranteed compatible with this function. */ TR_MQ_MSG *tr_mq_pop(TR_MQ *mq, struct timespec *ts_abort) { TR_MQ_MSG *popped=NULL; diff --git a/include/trp_internal.h b/include/trp_internal.h index 23d20e8..d6828d5 100644 --- a/include/trp_internal.h +++ b/include/trp_internal.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,9 @@ #include #include +/* what clock do we use with clock_gettime() ? */ +#define TRP_CLOCK CLOCK_MONOTONIC + /* info records */ /* TRP update record types */ typedef struct trp_inforec_route { diff --git a/trp/trps.c b/trp/trps.c index e5fd7e1..bb9dbc7 100644 --- a/trp/trps.c +++ b/trp/trps.c @@ -651,11 +651,12 @@ static int trps_check_feasibility(TRPS_INSTANCE *trps, TR_NAME *realm, TR_NAME * static struct timespec *trps_compute_expiry(TRPS_INSTANCE *trps, unsigned int interval, struct timespec *ts) { const unsigned int small_factor=3; /* how many intervals we wait before expiring */ - if (0!=clock_gettime(CLOCK_REALTIME, ts)) { + if (0!=clock_gettime(TRP_CLOCK, ts)) { tr_err("trps_compute_expiry: could not read realtime clock."); ts->tv_sec=0; ts->tv_nsec=0; } + tr_debug("trps_compute_expiry: tv_sec=%u, interval=%u, small_factor*interval=%u", ts->tv_sec, interval, small_factor*interval); ts->tv_sec += small_factor*interval; return ts; } @@ -1157,7 +1158,7 @@ TRP_RC trps_sweep_routes(TRPS_INSTANCE *trps) size_t ii=0; /* use a single time for the entire sweep */ - if (0!=clock_gettime(CLOCK_REALTIME, &sweep_time)) { + if (0!=clock_gettime(TRP_CLOCK, &sweep_time)) { tr_err("trps_sweep_routes: could not read realtime clock."); sweep_time.tv_sec=0; sweep_time.tv_nsec=0; @@ -1221,7 +1222,7 @@ TRP_RC trps_sweep_ctable(TRPS_INSTANCE *trps) TRP_RC rc=TRP_ERROR; /* use a single time for the entire sweep */ - if (0!=clock_gettime(CLOCK_REALTIME, &sweep_time)) { + if (0!=clock_gettime(TRP_CLOCK, &sweep_time)) { tr_err("trps_sweep_ctable: could not read realtime clock."); sweep_time.tv_sec=0; sweep_time.tv_nsec=0; @@ -1255,7 +1256,8 @@ TRP_RC trps_sweep_ctable(TRPS_INSTANCE *trps) /* This is the first expiration. Note this and reset the expiry time. */ tr_comm_memb_expire(memb); trps_compute_expiry(trps, tr_comm_memb_get_interval(memb), tr_comm_memb_get_expiry(memb)); - tr_debug("trps_sweep_ctable: community membership expired, resetting expiry to %s (%.*s in %.*s, origin %.*s).", + tr_debug("trps_sweep_ctable: community membership expired at %s, resetting expiry to %s (%.*s in %.*s, origin %.*s).", + timespec_to_str(&sweep_time), timespec_to_str(tr_comm_memb_get_expiry(memb)), tr_comm_memb_get_realm_id(memb)->len, tr_comm_memb_get_realm_id(memb)->buf, tr_comm_get_id(tr_comm_memb_get_comm(memb))->len, tr_comm_get_id(tr_comm_memb_get_comm(memb))->buf, -- 2.1.4