mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-28 18:58:30 +00:00
optimize override ips; utilize all ips from cache
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
f746be82c1
commit
1f1e2d547c
3 changed files with 15 additions and 13 deletions
|
@ -5,6 +5,7 @@ use std::{
|
|||
time::SystemTime,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use conduit::{trace, utils::rand};
|
||||
use ruma::{OwnedServerName, ServerName};
|
||||
|
||||
|
@ -24,7 +25,7 @@ pub struct CachedDest {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CachedOverride {
|
||||
pub ips: Vec<IpAddr>,
|
||||
pub ips: IpAddrs,
|
||||
pub port: u16,
|
||||
pub expire: SystemTime,
|
||||
}
|
||||
|
@ -32,6 +33,9 @@ pub struct CachedOverride {
|
|||
pub type WellKnownMap = HashMap<OwnedServerName, CachedDest>;
|
||||
pub type TlsNameMap = HashMap<String, CachedOverride>;
|
||||
|
||||
pub type IpAddrs = ArrayVec<IpAddr, MAX_IPS>;
|
||||
pub(crate) const MAX_IPS: usize = 3;
|
||||
|
||||
impl Cache {
|
||||
pub(super) fn new() -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
|
@ -61,13 +65,13 @@ impl super::Service {
|
|||
.cloned()
|
||||
}
|
||||
|
||||
pub fn set_cached_override(&self, name: String, over: CachedOverride) -> Option<CachedOverride> {
|
||||
pub fn set_cached_override(&self, name: &str, over: CachedOverride) -> Option<CachedOverride> {
|
||||
trace!(?name, ?over, "set cached override");
|
||||
self.cache
|
||||
.overrides
|
||||
.write()
|
||||
.expect("locked for writing")
|
||||
.insert(name, over)
|
||||
.insert(name.into(), over)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue