expire resolver cache entries
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
607e338ac2
commit
da9f1ae5d7
2 changed files with 24 additions and 22 deletions
|
@ -33,7 +33,7 @@ pub fn string_array<const LENGTH: usize>() -> ArrayString<LENGTH> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn timepoint_secs(range: Range<u64>) -> SystemTime {
|
pub fn time_from_now_secs(range: Range<u64>) -> SystemTime {
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
.checked_add(secs(range))
|
.checked_add(secs(range))
|
||||||
.expect("range does not overflow SystemTime")
|
.expect("range does not overflow SystemTime")
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::{net::IpAddr, sync::Arc, time::SystemTime};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
at, implement,
|
at, err, implement,
|
||||||
utils::{math::Expected, rand, stream::TryIgnore},
|
utils::{math::Expected, rand, stream::TryIgnore},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
@ -54,6 +54,18 @@ pub fn set_override(&self, name: &str, over: &CachedOverride) {
|
||||||
self.overrides.raw_put(name, Cbor(over));
|
self.overrides.raw_put(name, Cbor(over));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[implement(Cache)]
|
||||||
|
#[must_use]
|
||||||
|
pub async fn has_destination(&self, destination: &ServerName) -> bool {
|
||||||
|
self.get_destination(destination).await.is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[implement(Cache)]
|
||||||
|
#[must_use]
|
||||||
|
pub async fn has_override(&self, destination: &str) -> bool {
|
||||||
|
self.get_override(destination).await.is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
#[implement(Cache)]
|
#[implement(Cache)]
|
||||||
pub async fn get_destination(&self, name: &ServerName) -> Result<CachedDest> {
|
pub async fn get_destination(&self, name: &ServerName) -> Result<CachedDest> {
|
||||||
self.destinations
|
self.destinations
|
||||||
|
@ -61,6 +73,9 @@ pub async fn get_destination(&self, name: &ServerName) -> Result<CachedDest> {
|
||||||
.await
|
.await
|
||||||
.deserialized::<Cbor<_>>()
|
.deserialized::<Cbor<_>>()
|
||||||
.map(at!(0))
|
.map(at!(0))
|
||||||
|
.into_iter()
|
||||||
|
.find(CachedDest::valid)
|
||||||
|
.ok_or(err!(Request(NotFound("Expired from cache"))))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[implement(Cache)]
|
#[implement(Cache)]
|
||||||
|
@ -70,18 +85,9 @@ pub async fn get_override(&self, name: &str) -> Result<CachedOverride> {
|
||||||
.await
|
.await
|
||||||
.deserialized::<Cbor<_>>()
|
.deserialized::<Cbor<_>>()
|
||||||
.map(at!(0))
|
.map(at!(0))
|
||||||
}
|
.into_iter()
|
||||||
|
.find(CachedOverride::valid)
|
||||||
#[implement(Cache)]
|
.ok_or(err!(Request(NotFound("Expired from cache"))))
|
||||||
#[must_use]
|
|
||||||
pub async fn has_destination(&self, destination: &str) -> bool {
|
|
||||||
self.destinations.exists(destination).await.is_ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[implement(Cache)]
|
|
||||||
#[must_use]
|
|
||||||
pub async fn has_override(&self, destination: &str) -> bool {
|
|
||||||
self.overrides.exists(destination).await.is_ok()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[implement(Cache)]
|
#[implement(Cache)]
|
||||||
|
@ -103,13 +109,11 @@ pub fn overrides(&self) -> impl Stream<Item = (&ServerName, CachedOverride)> + S
|
||||||
impl CachedDest {
|
impl CachedDest {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn valid(&self) -> bool { true }
|
pub fn valid(&self) -> bool { self.expire > SystemTime::now() }
|
||||||
|
|
||||||
//pub fn valid(&self) -> bool { self.expire > SystemTime::now() }
|
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn default_expire() -> SystemTime {
|
pub(crate) fn default_expire() -> SystemTime {
|
||||||
rand::timepoint_secs(60 * 60 * 18..60 * 60 * 36)
|
rand::time_from_now_secs(60 * 60 * 18..60 * 60 * 36)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -125,13 +129,11 @@ impl CachedDest {
|
||||||
impl CachedOverride {
|
impl CachedOverride {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn valid(&self) -> bool { true }
|
pub fn valid(&self) -> bool { self.expire > SystemTime::now() }
|
||||||
|
|
||||||
//pub fn valid(&self) -> bool { self.expire > SystemTime::now() }
|
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn default_expire() -> SystemTime {
|
pub(crate) fn default_expire() -> SystemTime {
|
||||||
rand::timepoint_secs(60 * 60 * 6..60 * 60 * 12)
|
rand::time_from_now_secs(60 * 60 * 6..60 * 60 * 12)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue