Skip to main content

shardline_server_core/
lib.rs

1#![deny(unsafe_code)]
2#![cfg_attr(
3    test,
4    allow(
5        clippy::unwrap_used,
6        clippy::expect_used,
7        clippy::indexing_slicing,
8        clippy::shadow_unrelated,
9        clippy::let_underscore_must_use,
10        clippy::format_push_string,
11        clippy::panic
12    )
13)]
14
15//! Shared core types for the Shardline server ecosystem.
16//!
17//! This crate contains pure data structures and constants that are shared
18//! between the server crate and potential future crate extractions.
19//!
20//! # Quick start
21//!
22//! Store a content-addressed object under a validated key. This example uses
23//! a `blackhole` store, which discards all writes and performs no I/O:
24//!
25//! ```
26//! use shardline_protocol::ShardlineHash;
27//! use shardline_server_core::ServerObjectStore;
28//! use shardline_storage::{ObjectBody, ObjectIntegrity, ObjectKey, ObjectStore, PutOutcome};
29//!
30//! let store = ServerObjectStore::blackhole();
31//! let key = ObjectKey::parse("chunks/aa/bb/example.xorb")?;
32//!
33//! let hash = ShardlineHash::from_bytes([7; 32]);
34//! let body = ObjectBody::from_slice(b"serialized chunk bytes");
35//! let integrity = ObjectIntegrity::new(hash, body.as_slice().len() as u64);
36//!
37//! assert_eq!(
38//!     ObjectStore::put_if_absent(&store, &key, body, &integrity)?,
39//!     PutOutcome::Inserted
40//! );
41//! assert!(!ObjectStore::contains(&store, &key)?);
42//! # Ok::<(), Box<dyn std::error::Error>>(())
43//! ```
44//!
45//! For filesystem-backed storage, use [`ServerObjectStore::local`] (see its
46//! documentation for a `no_run` example).
47
48// ---------------------------------------------------------------------------
49// Submodules
50// ---------------------------------------------------------------------------
51
52/// Authentication and authorization types used by the Shardline server.
53///
54/// Re-exported from the `shardline-auth` crate for backward compatibility.
55pub mod auth;
56
57pub mod auth_capability;
58
59pub mod at_rest;
60pub mod object_store;
61pub mod ops;
62pub mod protocol_support;
63#[doc(hidden)]
64pub mod remote_delete;
65pub mod server_frontend;
66pub mod validation;
67
68#[cfg(test)]
69mod tests;
70
71// ---------------------------------------------------------------------------
72// Re-exports from submodules
73// ---------------------------------------------------------------------------
74
75// Auth capabilities
76pub use auth_capability::{AuthorizedRepository, scope_allows};
77
78// Object store
79pub use object_store::{
80    BoundedObjectReadError, MaterializedObject, OpsRecordKind, OpsRecordStore, ServerObjectStore,
81    ServerObjectStoreError, read_full_object,
82};
83
84// Validation (leftover functions that depend on server_core types)
85pub use validation::{
86    chunk_hash, chunk_hash_from_chunk_object_key_if_present, chunk_object_key, content_hash,
87};
88
89// Ops (leftover functions that depend on server_core or external crate types)
90pub use ops::{ParseStoredFileRecordError, parse_stored_file_record_bytes, provider_directory};
91
92// ---------------------------------------------------------------------------
93// Re-exports from new crates (full backward compatibility)
94// ---------------------------------------------------------------------------
95
96// Explicit re-exports from shardline-auth (backward compatibility)
97pub use shardline_auth::{
98    AuthContext, AuthError, AuthProvider, Ed25519AuthProvider, LocalHmacProvider,
99    PassthroughProvider, VerifiedAuthContext,
100};
101// Explicit re-exports from shardline-validation (backward compatibility)
102pub use shardline_validation::{
103    DEFAULT_LOCAL_GC_RETENTION_SECONDS, DEFAULT_MAX_SHARD_FILES,
104    DEFAULT_MAX_SHARD_RECONSTRUCTION_TERMS, DEFAULT_MAX_SHARD_XORB_CHUNKS, DEFAULT_MAX_SHARD_XORBS,
105    DEFAULT_SHARD_METADATA_LIMITS, InvalidLifecycleMetadataError,
106    InvalidReconstructionResponseError, InvalidSerializedShardError,
107    MAX_LOCAL_RECORD_METADATA_BYTES, RebuildOverflowError, ShardMetadataLimits,
108    ValidateContentHashError, ValidateIdentifierError, checked_add, checked_increment,
109    unix_now_seconds_checked, validate_content_hash, validate_content_hash_with,
110    validate_identifier,
111};