pub struct HashtreeStore { /* private fields */ }Implementations§
Source§impl HashtreeStore
impl HashtreeStore
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>
Create a new store with the configured local storage limit.
Sourcepub fn new_with_backend<P: AsRef<Path>>(
path: P,
backend: StorageBackend,
max_size_bytes: u64,
) -> Result<Self>
pub fn new_with_backend<P: AsRef<Path>>( path: P, backend: StorageBackend, max_size_bytes: u64, ) -> Result<Self>
Create a new store with an explicit local backend and size limit.
Sourcepub fn with_s3<P: AsRef<Path>>(
path: P,
s3_config: Option<&S3Config>,
) -> Result<Self>
pub fn with_s3<P: AsRef<Path>>( path: P, s3_config: Option<&S3Config>, ) -> Result<Self>
Create a new store with optional S3 backend and the configured local storage limit.
Sourcepub fn with_options<P: AsRef<Path>>(
path: P,
s3_config: Option<&S3Config>,
max_size_bytes: u64,
) -> Result<Self>
pub fn with_options<P: AsRef<Path>>( path: P, s3_config: Option<&S3Config>, max_size_bytes: u64, ) -> Result<Self>
Create a new store with optional S3 backend and custom size limit.
The raw local blob backend remains unbounded. HashtreeStore enforces
max_size_bytes at the tree-management layer so eviction can honor pins,
orphan handling, and local-only eviction when S3 is used as archive.
Sourcepub fn router(&self) -> &StorageRouter
pub fn router(&self) -> &StorageRouter
Get the storage router
Sourcepub fn store_arc(&self) -> Arc<StorageRouter>
pub fn store_arc(&self) -> Arc<StorageRouter>
Get the storage router as Arc (for use with HashTree which needs Arc
Sourcepub fn upload_file<P: AsRef<Path>>(&self, file_path: P) -> Result<String>
pub fn upload_file<P: AsRef<Path>>(&self, file_path: P) -> Result<String>
Upload a file as raw plaintext and return its CID, with auto-pin
Sourcepub fn upload_file_no_pin<P: AsRef<Path>>(&self, file_path: P) -> Result<String>
pub fn upload_file_no_pin<P: AsRef<Path>>(&self, file_path: P) -> Result<String>
Upload a file without pinning (for blossom uploads that can be evicted)
Sourcepub fn upload_file_stream<R: Read, F>(
&self,
reader: R,
_file_name: impl Into<String>,
callback: F,
) -> Result<String>
pub fn upload_file_stream<R: Read, F>( &self, reader: R, _file_name: impl Into<String>, callback: F, ) -> Result<String>
Upload a file from a stream with progress callbacks
Sourcepub fn upload_dir<P: AsRef<Path>>(&self, dir_path: P) -> Result<String>
pub fn upload_dir<P: AsRef<Path>>(&self, dir_path: P) -> Result<String>
Upload a directory and return its root hash (hex) Respects .gitignore by default
Sourcepub fn upload_dir_with_options<P: AsRef<Path>>(
&self,
dir_path: P,
respect_gitignore: bool,
) -> Result<String>
pub fn upload_dir_with_options<P: AsRef<Path>>( &self, dir_path: P, respect_gitignore: bool, ) -> Result<String>
Upload a directory with options as raw plaintext (no CHK encryption)
Sourcepub fn upload_file_encrypted<P: AsRef<Path>>(
&self,
file_path: P,
) -> Result<String>
pub fn upload_file_encrypted<P: AsRef<Path>>( &self, file_path: P, ) -> Result<String>
Upload a file with CHK encryption, returns CID in format “hash:key”
Sourcepub fn upload_dir_encrypted<P: AsRef<Path>>(
&self,
dir_path: P,
) -> Result<String>
pub fn upload_dir_encrypted<P: AsRef<Path>>( &self, dir_path: P, ) -> Result<String>
Upload a directory with CHK encryption, returns CID Respects .gitignore by default
Sourcepub fn upload_dir_encrypted_with_options<P: AsRef<Path>>(
&self,
dir_path: P,
respect_gitignore: bool,
) -> Result<String>
pub fn upload_dir_encrypted_with_options<P: AsRef<Path>>( &self, dir_path: P, respect_gitignore: bool, ) -> Result<String>
Upload a directory with CHK encryption and options Returns CID as “hash:key” format for encrypted directories
Sourcepub fn get_tree_node(&self, hash: &[u8; 32]) -> Result<Option<TreeNode>>
pub fn get_tree_node(&self, hash: &[u8; 32]) -> Result<Option<TreeNode>>
Get tree node by hash (raw bytes)
Sourcepub fn put_blob(&self, data: &[u8]) -> Result<String>
pub fn put_blob(&self, data: &[u8]) -> Result<String>
Store a raw blob, returns SHA256 hash as hex.
Sourcepub fn get_blob(&self, hash: &[u8; 32]) -> Result<Option<Vec<u8>>>
pub fn get_blob(&self, hash: &[u8; 32]) -> Result<Option<Vec<u8>>>
Get a raw blob by SHA256 hash (raw bytes).
Sourcepub fn blob_exists(&self, hash: &[u8; 32]) -> Result<bool>
pub fn blob_exists(&self, hash: &[u8; 32]) -> Result<bool>
Check if a blob exists by SHA256 hash (raw bytes).
Sourcepub fn set_blob_owner(&self, sha256: &[u8; 32], pubkey: &[u8; 32]) -> Result<()>
pub fn set_blob_owner(&self, sha256: &[u8; 32], pubkey: &[u8; 32]) -> Result<()>
Add an owner (pubkey) to a blob for Blossom protocol Multiple users can own the same blob - it’s only deleted when all owners remove it
Sourcepub fn is_blob_owner(
&self,
sha256: &[u8; 32],
pubkey: &[u8; 32],
) -> Result<bool>
pub fn is_blob_owner( &self, sha256: &[u8; 32], pubkey: &[u8; 32], ) -> Result<bool>
Check if a pubkey owns a blob
Sourcepub fn get_blob_owners(&self, sha256: &[u8; 32]) -> Result<Vec<[u8; 32]>>
pub fn get_blob_owners(&self, sha256: &[u8; 32]) -> Result<Vec<[u8; 32]>>
Get all owners (pubkeys) of a blob via prefix scan (returns raw bytes)
Sourcepub fn get_blob_owner(&self, sha256: &[u8; 32]) -> Result<Option<[u8; 32]>>
pub fn get_blob_owner(&self, sha256: &[u8; 32]) -> Result<Option<[u8; 32]>>
Get the first owner (pubkey) of a blob (for backwards compatibility)
Sourcepub fn delete_blossom_blob(
&self,
sha256: &[u8; 32],
pubkey: &[u8; 32],
) -> Result<bool>
pub fn delete_blossom_blob( &self, sha256: &[u8; 32], pubkey: &[u8; 32], ) -> Result<bool>
Remove a user’s ownership of a blossom blob Only deletes the actual blob when no owners remain Returns true if the blob was actually deleted (no owners left)
Sourcepub fn list_blobs_by_pubkey(
&self,
pubkey: &[u8; 32],
) -> Result<Vec<BlobDescriptor>>
pub fn list_blobs_by_pubkey( &self, pubkey: &[u8; 32], ) -> Result<Vec<BlobDescriptor>>
List all blobs owned by a pubkey (for Blossom /list endpoint)
Sourcepub fn get_chunk(&self, hash: &[u8; 32]) -> Result<Option<Vec<u8>>>
pub fn get_chunk(&self, hash: &[u8; 32]) -> Result<Option<Vec<u8>>>
Get a single chunk/blob by hash (raw bytes)
Sourcepub fn get_file(&self, hash: &[u8; 32]) -> Result<Option<Vec<u8>>>
pub fn get_file(&self, hash: &[u8; 32]) -> Result<Option<Vec<u8>>>
Get file content by hash (raw bytes) Returns raw bytes (caller handles decryption if needed)
Sourcepub fn get_file_by_cid(&self, cid: &Cid) -> Result<Option<Vec<u8>>>
pub fn get_file_by_cid(&self, cid: &Cid) -> Result<Option<Vec<u8>>>
Get file content by Cid (hash + optional decryption key as raw bytes) Handles decryption automatically if key is present
Sourcepub fn write_file_by_cid_to_writer<W: Write>(
&self,
cid: &Cid,
writer: &mut W,
) -> Result<u64>
pub fn write_file_by_cid_to_writer<W: Write>( &self, cid: &Cid, writer: &mut W, ) -> Result<u64>
Stream file content identified by Cid into a writer without buffering full file in memory.
Sourcepub fn write_file_by_cid<P: AsRef<Path>>(
&self,
cid: &Cid,
output_path: P,
) -> Result<u64>
pub fn write_file_by_cid<P: AsRef<Path>>( &self, cid: &Cid, output_path: P, ) -> Result<u64>
Stream file content identified by Cid directly into a destination path.
Sourcepub fn write_file<P: AsRef<Path>>(
&self,
hash: &[u8; 32],
output_path: P,
) -> Result<u64>
pub fn write_file<P: AsRef<Path>>( &self, hash: &[u8; 32], output_path: P, ) -> Result<u64>
Stream a public (unencrypted) file by hash directly into a destination path.
Sourcepub fn resolve_path(&self, cid: &Cid, path: &str) -> Result<Option<Cid>>
pub fn resolve_path(&self, cid: &Cid, path: &str) -> Result<Option<Cid>>
Resolve a path within a tree (returns Cid with key if encrypted)
Sourcepub fn get_file_chunk_metadata(
&self,
hash: &[u8; 32],
) -> Result<Option<FileChunkMetadata>>
pub fn get_file_chunk_metadata( &self, hash: &[u8; 32], ) -> Result<Option<FileChunkMetadata>>
Get chunk metadata for a file (chunk list, sizes, total size)
Sourcepub fn get_file_range(
&self,
hash: &[u8; 32],
start: u64,
end: Option<u64>,
) -> Result<Option<(Vec<u8>, u64)>>
pub fn get_file_range( &self, hash: &[u8; 32], start: u64, end: Option<u64>, ) -> Result<Option<(Vec<u8>, u64)>>
Get byte range from file
Sourcepub fn stream_file_range_chunks_owned(
self: Arc<Self>,
hash: &[u8; 32],
start: u64,
end: u64,
) -> Result<Option<FileRangeChunksOwned>>
pub fn stream_file_range_chunks_owned( self: Arc<Self>, hash: &[u8; 32], start: u64, end: u64, ) -> Result<Option<FileRangeChunksOwned>>
Stream file range as chunks using Arc for async/Send contexts
Sourcepub fn get_directory_listing(
&self,
hash: &[u8; 32],
) -> Result<Option<DirectoryListing>>
pub fn get_directory_listing( &self, hash: &[u8; 32], ) -> Result<Option<DirectoryListing>>
Get directory structure by hash (raw bytes)
Sourcepub fn get_directory_listing_by_cid(
&self,
cid: &Cid,
) -> Result<Option<DirectoryListing>>
pub fn get_directory_listing_by_cid( &self, cid: &Cid, ) -> Result<Option<DirectoryListing>>
Get directory structure by CID, supporting encrypted directories.
Sourcepub fn list_pins_with_names(&self) -> Result<Vec<PinnedItem>>
pub fn list_pins_with_names(&self) -> Result<Vec<PinnedItem>>
List all pinned hashes with names
Sourcepub fn index_tree(
&self,
root_hash: &Hash,
owner: &str,
name: Option<&str>,
priority: u8,
ref_key: Option<&str>,
) -> Result<()>
pub fn index_tree( &self, root_hash: &Hash, owner: &str, name: Option<&str>, priority: u8, ref_key: Option<&str>, ) -> Result<()>
Index a tree after sync - tracks all blobs in the tree for eviction
If ref_key is provided (e.g. “npub…/name”), it will replace any existing
tree with that ref, allowing old versions to be evicted.
Sourcepub fn unindex_tree(&self, root_hash: &Hash) -> Result<u64>
pub fn unindex_tree(&self, root_hash: &Hash) -> Result<u64>
Unindex a tree - removes blob-tree mappings and deletes orphaned blobs Returns the number of bytes freed
Sourcepub fn tracked_size(&self) -> Result<u64>
pub fn tracked_size(&self) -> Result<u64>
Get total tracked storage size (sum of all tree_meta.total_size)
Sourcepub fn evict_if_needed(&self) -> Result<u64>
pub fn evict_if_needed(&self) -> Result<u64>
Run eviction if storage is over quota Returns bytes freed
Eviction order:
- Orphaned blobs (not in any indexed tree and not pinned)
- Trees by priority (lowest first) and age (oldest first)
Sourcepub fn max_size_bytes(&self) -> u64
pub fn max_size_bytes(&self) -> u64
Get the maximum storage size in bytes
Sourcepub fn storage_by_priority(&self) -> Result<StorageByPriority>
pub fn storage_by_priority(&self) -> Result<StorageByPriority>
Get storage usage by priority tier
Sourcepub fn get_storage_stats(&self) -> Result<StorageStats>
pub fn get_storage_stats(&self) -> Result<StorageStats>
Get storage statistics
Sourcepub fn get_cached_root(
&self,
pubkey_hex: &str,
tree_name: &str,
) -> Result<Option<CachedRoot>>
pub fn get_cached_root( &self, pubkey_hex: &str, tree_name: &str, ) -> Result<Option<CachedRoot>>
Get cached root for a pubkey/tree_name pair
Sourcepub fn set_cached_root(
&self,
pubkey_hex: &str,
tree_name: &str,
hash: &str,
key: Option<&str>,
visibility: &str,
updated_at: u64,
) -> Result<()>
pub fn set_cached_root( &self, pubkey_hex: &str, tree_name: &str, hash: &str, key: Option<&str>, visibility: &str, updated_at: u64, ) -> Result<()>
Set cached root for a pubkey/tree_name pair
Sourcepub fn list_cached_roots(
&self,
pubkey_hex: &str,
) -> Result<Vec<(String, CachedRoot)>>
pub fn list_cached_roots( &self, pubkey_hex: &str, ) -> Result<Vec<(String, CachedRoot)>>
List all cached roots for a pubkey
Sourcepub fn delete_cached_root(
&self,
pubkey_hex: &str,
tree_name: &str,
) -> Result<bool>
pub fn delete_cached_root( &self, pubkey_hex: &str, tree_name: &str, ) -> Result<bool>
Delete a cached root
Sourcepub fn verify_lmdb_integrity(&self, delete: bool) -> Result<VerifyResult>
pub fn verify_lmdb_integrity(&self, delete: bool) -> Result<VerifyResult>
Verify LMDB blob integrity - checks that stored data matches its key hash Returns verification statistics and optionally deletes corrupted entries
Sourcepub async fn verify_r2_integrity(&self, _delete: bool) -> Result<VerifyResult>
pub async fn verify_r2_integrity(&self, _delete: bool) -> Result<VerifyResult>
Fallback for non-S3 builds
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HashtreeStore
impl RefUnwindSafe for HashtreeStore
impl Send for HashtreeStore
impl Sync for HashtreeStore
impl Unpin for HashtreeStore
impl UnsafeUnpin for HashtreeStore
impl UnwindSafe for HashtreeStore
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more