Try CART cache

cart
Frank Denis 3 years ago
parent 897d854362
commit a5acc15800

@ -15,7 +15,7 @@ readme = "README.md"
anyhow = "1.0.38" anyhow = "1.0.38"
byteorder = "1.4.2" byteorder = "1.4.2"
clap = { version = "2.33.3", default-features = false, features = ["wrap_help"] } clap = { version = "2.33.3", default-features = false, features = ["wrap_help"] }
clockpro-cache = "0.1.9" cart-cache = "0.1.5"
coarsetime = "0.1.18" coarsetime = "0.1.18"
daemonize-simple = "0.1.4" daemonize-simple = "0.1.4"
derivative = "2.2.0" derivative = "2.2.0"

@ -1,6 +1,6 @@
use crate::dns; use crate::dns;
use clockpro_cache::ClockProCache; use cart_cache::CartCache;
use coarsetime::{Duration, Instant}; use coarsetime::{Duration, Instant};
use parking_lot::{Mutex, MutexGuard}; use parking_lot::{Mutex, MutexGuard};
use std::sync::Arc; use std::sync::Arc;
@ -54,7 +54,7 @@ impl CachedResponse {
#[derivative(Debug)] #[derivative(Debug)]
pub struct Cache { pub struct Cache {
#[derivative(Debug = "ignore")] #[derivative(Debug = "ignore")]
cache: Arc<Mutex<ClockProCache<u128, CachedResponse>>>, cache: Arc<Mutex<CartCache<u128, CachedResponse>>>,
pub ttl_min: u32, pub ttl_min: u32,
pub ttl_max: u32, pub ttl_max: u32,
pub ttl_error: u32, pub ttl_error: u32,
@ -62,7 +62,7 @@ pub struct Cache {
impl Cache { impl Cache {
pub fn new( pub fn new(
clockpro_cache: ClockProCache<u128, CachedResponse>, clockpro_cache: CartCache<u128, CachedResponse>,
ttl_min: u32, ttl_min: u32,
ttl_max: u32, ttl_max: u32,
ttl_error: u32, ttl_error: u32,
@ -76,7 +76,7 @@ impl Cache {
} }
#[inline] #[inline]
pub fn lock(&self) -> MutexGuard<'_, ClockProCache<u128, CachedResponse>> { pub fn lock(&self) -> MutexGuard<'_, CartCache<u128, CachedResponse>> {
self.cache.lock() self.cache.lock()
} }
} }

@ -5,7 +5,7 @@ use crate::dnscrypt::*;
use crate::globals::*; use crate::globals::*;
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use clockpro_cache::ClockProCache; use cart_cache::CartCache;
use parking_lot::Mutex; use parking_lot::Mutex;
use std::mem; use std::mem;
use std::slice; use std::slice;
@ -104,7 +104,7 @@ pub struct DNSCryptEncryptionParams {
resolver_kp: CryptKeyPair, resolver_kp: CryptKeyPair,
#[serde(skip)] #[serde(skip)]
#[derivative(Debug = "ignore")] #[derivative(Debug = "ignore")]
pub cache: Option<Arc<Mutex<ClockProCache<[u8; DNSCRYPT_QUERY_PK_SIZE], SharedKey>>>>, pub cache: Option<Arc<Mutex<CartCache<[u8; DNSCRYPT_QUERY_PK_SIZE], SharedKey>>>>,
} }
impl DNSCryptEncryptionParams { impl DNSCryptEncryptionParams {
@ -116,7 +116,7 @@ impl DNSCryptEncryptionParams {
== &ANONYMIZED_DNSCRYPT_QUERY_MAGIC[..DNSCRYPT_QUERY_MAGIC_SIZE] == &ANONYMIZED_DNSCRYPT_QUERY_MAGIC[..DNSCRYPT_QUERY_MAGIC_SIZE]
} {} } {}
let dnscrypt_cert = DNSCryptCert::new(&provider_kp, &resolver_kp); let dnscrypt_cert = DNSCryptCert::new(&provider_kp, &resolver_kp);
let cache = ClockProCache::new(cache_capacity).unwrap(); let cache = CartCache::new(cache_capacity).unwrap();
DNSCryptEncryptionParams { DNSCryptEncryptionParams {
dnscrypt_cert, dnscrypt_cert,
resolver_kp, resolver_kp,
@ -125,7 +125,7 @@ impl DNSCryptEncryptionParams {
} }
pub fn add_key_cache(&mut self, cache_capacity: usize) { pub fn add_key_cache(&mut self, cache_capacity: usize) {
let cache = ClockProCache::new(cache_capacity).unwrap(); let cache = CartCache::new(cache_capacity).unwrap();
self.cache = Some(Arc::new(Mutex::new(cache))); self.cache = Some(Arc::new(Mutex::new(cache)));
} }

@ -50,8 +50,8 @@ use globals::*;
use varz::*; use varz::*;
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use cart_cache::CartCache;
use clap::Arg; use clap::Arg;
use clockpro_cache::ClockProCache;
use dnsstamps::{InformalProperty, WithInformalProperty}; use dnsstamps::{InformalProperty, WithInformalProperty};
use futures::join; use futures::join;
use futures::prelude::*; use futures::prelude::*;
@ -643,14 +643,14 @@ fn main() -> Result<(), Error> {
let hasher = SipHasher13::new_with_keys(sh_k0, sh_k1); let hasher = SipHasher13::new_with_keys(sh_k0, sh_k1);
let cache = Cache::new( let cache = Cache::new(
ClockProCache::new(cache_capacity) CartCache::new(cache_capacity)
.map_err(|e| anyhow!("Unable to create the DNS cache: [{}]", e))?, .map_err(|e| anyhow!("Unable to create the DNS cache: [{}]", e))?,
config.cache_ttl_min, config.cache_ttl_min,
config.cache_ttl_max, config.cache_ttl_max,
config.cache_ttl_error, config.cache_ttl_error,
); );
let cert_cache = Cache::new( let cert_cache = Cache::new(
ClockProCache::new(RELAYED_CERT_CACHE_SIZE) CartCache::new(RELAYED_CERT_CACHE_SIZE)
.map_err(|e| anyhow!("Unable to create the relay cert cache: [{}]", e))?, .map_err(|e| anyhow!("Unable to create the relay cert cache: [{}]", e))?,
RELAYED_CERT_CACHE_TTL, RELAYED_CERT_CACHE_TTL,
RELAYED_CERT_CACHE_TTL, RELAYED_CERT_CACHE_TTL,

Loading…
Cancel
Save