Skip to content

Conversation

anestorov
Copy link

@anestorov anestorov commented Jul 24, 2025

This pull request is supposed to resolve issue #63

It fixes 3 issues :

  1. Reading record's ttl via getTtl() method always returns 1 when TTL is set to some expiration (withing few years).
  2. Reading record's ttl via getTtl() method returns random big int when TTL is set to never expire (-1)
  3. Fixes return of get_expiration which was not returning proper Expiration object

Problems seems to be in src/lib.rs - pub fn get_ttl(&self) -> Option<u32> and pub fn get_expiration(&self) -> Expiration

Abount the first issue I think the concept of TTL implemented in that function's body is wrong.
It considers TTL to be number of seconds since CITRUSLEAF_EPOCH but in fact it is not.
TTL in secs variable is the amount of seconds since the present moment when the record will expire.

Due to this conception misunderstanding all the code that adds it to CITRUSLEAF_EPOCH and compares it with the now time is not necesary. In fact the following check if expiration > now never gets true and the functions always return (1 as u32).into();

Second issue is due to wrong comparison as NEVER_EXPIRE is not 0 but 0xFFFFFFFF. So when ttl = NEVER_EXPIRE it then actually goes to the second match and subsequently satisfy if expiration > now and efectively returns NEVER_EXPIRE + CITRUSLEAF_EPOCH - NOW. I was thinking to make get_ttl method return i32 type value in order to represent NEVER_EXPIRE as -1 but finally I decided that it can return NULL when NEVER_EXPIRE otherwise return u32 as the original TTL type use.

@anestorov
Copy link
Author

anestorov commented Jul 24, 2025

I also noticed that get_expiration method of Record object is not correct. It does not return proper Expiration object so I did a second commit

@anestorov
Copy link
Author

I got a better idea - to return TTL as u32 (its original type) and return NULL when it Never Expires

@anestorov anestorov changed the title Fixing TTL value in get_ttl Fixing return in get_ttl and get_expiration Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant