kapiti 0.0.3

The Kapiti DNS Server
Documentation
use anyhow::Result;
use async_trait::async_trait;

use crate::codec::message::RequestInfo;
use crate::specs::message::Message;

#[async_trait]
pub trait DnsCache {
    /// Queries the cache for a response.
    async fn fetch(&mut self, request_info: RequestInfo) -> Result<Option<Message>>;

    /// Stores an upstream server response Message to the cache.
    async fn store(&mut self, request_info: RequestInfo, response: Message) -> Result<()>;
}

/// Cache: Retainer (local)
pub mod memory;

/// Cache: Redis (client)
pub mod redis;

/// Cache background task that handles fetch/store requests
pub mod task;

/// Calculates a reasonable cache key string for the provided request information.
/// This is effectively what's used to differentiate between requests for caching purposes.
fn cache_key(request_info: &RequestInfo) -> String {
    format!(
        "{:?}__do{}__{}",
        request_info.resource_type, request_info.dnssec_ok as u8, request_info.name
    )
}