From 0c86bf203008025cc22e86e482cf728794432862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Mon, 25 Feb 2019 18:48:46 +0100 Subject: [PATCH] interest: fix timeout calculation for suite != NDN-TLV --- src/ccnl-core/include/ccnl-pkt-util.h | 12 ++++++++++++ src/ccnl-core/src/ccnl-interest.c | 3 ++- src/ccnl-core/src/ccnl-pkt-util.c | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ccnl-core/include/ccnl-pkt-util.h b/src/ccnl-core/include/ccnl-pkt-util.h index 67cd9dc69..628d78b1f 100644 --- a/src/ccnl-core/include/ccnl-pkt-util.h +++ b/src/ccnl-core/include/ccnl-pkt-util.h @@ -25,6 +25,8 @@ #include #include +#include "ccnl-pkt.h" + uint8_t ccnl_isSuite(int suite); @@ -52,4 +54,14 @@ ccnl_pkt2suite(uint8_t *data, size_t len, size_t *skip); int ccnl_cmp2int(unsigned char *cmp, size_t cmplen); +/** + * Return the Interest lifetime + * + * @param[in] pkt Pointer to the Interest packet + * + * @return The interest lifetime + */ +uint64_t +ccnl_pkt_interest_lifetime(const struct ccnl_pkt_s *pkt); + #endif diff --git a/src/ccnl-core/src/ccnl-interest.c b/src/ccnl-core/src/ccnl-interest.c index c7824e821..4e778b2e9 100644 --- a/src/ccnl-core/src/ccnl-interest.c +++ b/src/ccnl-core/src/ccnl-interest.c @@ -61,7 +61,8 @@ ccnl_interest_new(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from, return NULL; i->pkt = *pkt; /* currently, the aging function relies on seconds rather than on milli seconds */ - i->lifetime = (*pkt)->s.ndntlv.interestlifetime / 1000; + i->lifetime = ccnl_pkt_interest_lifetime(*pkt); + *pkt = NULL; i->from = from; i->last_used = CCNL_NOW(); diff --git a/src/ccnl-core/src/ccnl-pkt-util.c b/src/ccnl-core/src/ccnl-pkt-util.c index 907f3fef1..18b726c9c 100644 --- a/src/ccnl-core/src/ccnl-pkt-util.c +++ b/src/ccnl-core/src/ccnl-pkt-util.c @@ -220,3 +220,23 @@ ccnl_cmp2int(unsigned char *cmp, size_t cmplen) return 0; } + +uint64_t +ccnl_pkt_interest_lifetime(const struct ccnl_pkt_s *pkt) +{ + switch(pkt->suite) { +#ifdef USE_SUITE_CCNTLV + case CCNL_SUITE_CCNTLV: + /* CCN-TLV parser does not support lifetime parsing, yet. */ + return CCNL_INTEREST_TIMEOUT; +#endif +#ifdef USE_SUITE_NDNTLV + case CCNL_SUITE_NDNTLV: + return (pkt->s.ndntlv.interestlifetime / 1000); +#endif + default: + break; + } + + return CCNL_INTEREST_TIMEOUT; +}