Skip to main content

ServerState

Struct ServerState 

Source
pub struct ServerState {
    pub storage: Arc<dyn StorageBackend>,
    pub verifier: Arc<dyn TokenVerifier>,
    pub validator: Arc<dyn Validator>,
    pub path_codec: Arc<dyn PathCodec>,
    pub compression: CompressionFormat,
    pub max_upload_size: u64,
    pub limits: Option<Limits>,
    pub zrip_levels: Option<ZripLevels>,
    pub cleanup_interval: Duration,
    pub session_ttl: Duration,
}
Expand description

Immutable server configuration shared by all handlers.

Fields§

§storage: Arc<dyn StorageBackend>

The storage backend serving file content.

§verifier: Arc<dyn TokenVerifier>

Turns bearer tokens into claims.

§validator: Arc<dyn Validator>

Decides whether claims may access a path.

§path_codec: Arc<dyn PathCodec>

Real storage paths ↔ client-visible shadow paths.

Defaults to IdentityPathCodec (no translation).

§compression: CompressionFormat

Compression applied to downloads when the client asks for it.

§max_upload_size: u64

Upper bound for a single upload body.

§limits: Option<Limits>

Advertised tuning-parameter ranges; None exports the libfw built-in defaults (and enforces nothing beyond existing hard caps).

§zrip_levels: Option<ZripLevels>

Advertised zrip level range; None ignores the level header, so every zrip download uses ZRIP_DEFAULT_LEVEL.

§cleanup_interval: Duration

Sweep period of the stale session-temp cleaner (tus Expiration), see ServerState::spawn_stale_session_cleanup.

Defaults to 1 hour; Duration::ZERO disables the sweeper.

§session_ttl: Duration

Max age of an abandoned session upload temp before it is removed.

Defaults to DEFAULT_SESSION_TTL (24 hours).

Implementations§

Source§

impl ServerState

Source

pub fn builder() -> ServerStateBuilder

Start building a server state.

Source

pub fn authorize( &self, claims: &TokenClaims, path: &str, action: Action, ) -> Result<(), AuthError>

Check whether claims may perform action on path.

Source§

impl ServerState

Source

pub fn resolve_client_path( &self, claims: &TokenClaims, shadow: &str, action: Action, ) -> Result<String, PathResolveError>

Resolve a client-supplied (shadow) path to the canonical real path.

Pipeline: shape-validate the shadow → PathCodec::decode → shape-validate the decoded real path (defense in depth) → authorize action against the real path, so allowed_paths keeps its exact pre-translation semantics.

Hierarchical composition: when the whole string is not a valid shadow (e.g. a directory shadow with literal child segments appended, {dirShadow}/sub/file.txt), the longest decodable segment prefix is decoded and the remaining segments are appended verbatim to the decoded real path before authorization. A directory shadow therefore covers its whole subtree — uploads into not-yet-listed children, downloads of freshly created files — with no per-path shadow minting. The fallback only ever succeeds on a prefix the codec itself accepts, so tampered or unknown shadows still surface the original codec error (→ 400); authorization still runs on the combined real path, so allowed_paths prefix semantics are unchanged.

The returned real path is safe to hand to the storage backend; it must never be echoed back to the client — responses go through ServerState::expose_path.

Source

pub fn expose_path(&self, real: &str) -> String

Translate a real storage path for client consumption (shadow).

Source§

impl ServerState

Source

pub fn capabilities(&self) -> Capabilities

The capability advertisement served at GET /capabilities.

Filters the compression formats by the configured download compression and overlays the optional builder overrides; unset dimensions fall back to the libfw built-in defaults.

Source

pub fn spawn_stale_session_cleanup(self: &Arc<Self>) -> JoinHandle<()> ⓘ

Spawn the stale session-temp cleaner as a background task.

Every cleanup_interval it sweeps the storage for abandoned session-upload temps and removes the ones whose last write is older than session_ttl (tus Expiration; a client that vanished mid-upload never leaves its .libfw-sess-* temp / .blocks sidecar behind forever).

A zero cleanup_interval disables the sweeper: the returned handle completes immediately. Backends that keep no long-lived session temps (the StorageBackend trait default) simply report 0 removals.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more