libblobd_lite/
incomplete_token.rs

1use crate::util::get_now_sec;
2use serde::Deserialize;
3use serde::Serialize;
4use std::fmt::Debug;
5
6// This is intentionally an opaque token. To allow transporting it for implementers of libblobd, Serialize and Deserialize are derived.
7// SAFETY: Only DeletedList::maybe_reap_next reaps, and it reaps well after the token for an object expires (including if the object has been marked as deleted a lot earlier), so if this token hasn't expired (and our clock isn't broken), the object at `object_dev_offset` definitely still exists and its state can be safely read (e.g. to determine that it's deleted and return an error).
8#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub struct IncompleteToken {
10  pub(crate) created_sec: u64,
11  // We don't need to track the object ID as we guarantee that the object exists for the entire lifetime of this token.
12  pub(crate) object_dev_offset: u64,
13}
14
15impl IncompleteToken {
16  pub(crate) fn has_expired(&self, reap_objects_after_secs: u64) -> bool {
17    get_now_sec() - self.created_sec >= reap_objects_after_secs
18  }
19}
20
21impl Debug for IncompleteToken {
22  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23    f.debug_struct("IncompleteToken").finish()
24  }
25}