Skip to main content

Node

Struct Node 

Source
pub struct Node<R> {
    pub endpoint: Endpoint,
    pub store: FsStore,
    pub registry: R,
    pub grants: GrantStore,
    /* private fields */
}
Expand description

A ringdrop P2P node.

Owns an iroh QUIC Endpoint, an iroh-blobs FsStore, a RingGate that enforces ring-based access control, and the Registry that tracks ring membership.

Create a node with Node::start; shut it down cleanly with Node::shutdown so the blob store is flushed to disk before the process exits.

Fields§

§endpoint: Endpoint

The iroh QUIC endpoint — manages connections, NAT traversal, and relay fallback.

§store: FsStore

The iroh-blobs persistent store — holds all locally imported and received blobs.

§registry: R

The ring registry — tracks ring membership and permission-typed resource associations.

§grants: GrantStore

The grant store — controls which peers may invoke catalog operations.

Implementations§

Source§

impl<R: Registry + Clone + Send + Sync + 'static> Node<R>

Source

pub async fn start( data_dir: impl AsRef<Path>, cfg: Config, registry: R, ) -> Result<Self>

Start a node, binding a QUIC endpoint and loading the blob store from data_dir.

The node is immediately reachable for inbound connections once this returns. The blob store is created under data_dir/blobs/ if it does not yet exist.

§Errors

Returns an error if the QUIC endpoint cannot bind, or if the blob store cannot be opened or created.

Source

pub fn node_addr(&self) -> EndpointAddr

Returns the network address of this node (relay URL + node ID).

Source

pub async fn import_file( &self, path: impl AsRef<Path>, ) -> Result<(Hash, BlobFormat)>

Import a single file into the blob store.

The file is chunked, BLAKE3-hashed, and pinned with a named tag (the leaf filename, i.e. path.file_name()). Returns the root hash and BlobFormat::Raw.

§Errors

Returns an error if the file cannot be read or the store operation fails.

Source

pub async fn import_directory( &self, dir: impl AsRef<Path>, ) -> Result<(Hash, BlobFormat)>

Import a directory into the blob store as an iroh-blobs collection.

Each file under dir is imported individually; the resulting hashes are assembled into a HashSeq collection pinned under the directory name. Returns the collection root hash and BlobFormat::HashSeq.

§Errors

Returns an error if any file cannot be read or the store operation fails.

Source

pub async fn list_blobs( &self, peer: Option<&str>, rings: Option<Vec<String>>, ) -> Result<Vec<(Hash, BlobFormat, String)>>

List blobs in the local store as (hash, format, tag_name) triples.

When peer is supplied only blobs accessible to that peer are returned (i.e. blobs associated with at least one ring that both includes the peer and grants Permission::Read). When rings is supplied only blobs tagged with at least one of those ring names are returned (OR semantics). When both are given the filters are combined: a blob must satisfy both independently.

§Errors

Returns an error if the tag store cannot be read, if peer is not a valid EndpointId encoding, or if a registry lookup fails.

Source

pub async fn delete_blob(&self, hash: Hash) -> Result<()>

Remove a blob from the local store by deleting its named tags.

Ring tags in the registry must be removed separately by the caller before invoking this method. Disk space is reclaimed on the next GC cycle (every 30 s while the node is running).

§Errors

Returns an error if no tag is found for the given hash, or if the tag deletion fails.

Source

pub fn make_ticket( &self, hash: Hash, format: BlobFormat, name: Option<String>, ) -> ShareTicket

Build a ShareTicket for a locally-stored blob.

The ticket embeds the relay URL and node ID but omits direct IP addresses — tickets remain valid across daemon restarts and IP changes.

Source

pub async fn catalog_connect( &self, peer_addr: EndpointAddr, ) -> Result<Vec<CatalogEntry>>

Connect to a remote node and fetch its catalog — the list of blobs the caller is allowed to download.

The remote node must have granted crate::core::grants::Privilege::BlobList to this node’s identity. Only blobs that the calling peer has iroh_rings::Permission::Read on (via ring membership) will be included.

§Errors

Returns an error if the connection fails, the remote node denies access, or the response stream is malformed.

Source

pub async fn import_path(&self, path: &Path) -> Result<(Hash, BlobFormat)>

Import a file or directory, dispatching to Node::import_file or Node::import_directory based on whether path is a file or a dir.

§Errors

Returns an error if the import fails (see the individual methods for details).

Source

pub async fn download( &self, ticket: &ShareTicket, dest: impl AsRef<Path>, ) -> Result<()>

Download the blob described by ticket and export it under dest.

If the blob is already complete in the local store the download is skipped entirely. For collections, each member blob is fetched individually before the directory is reassembled on disk.

§Errors

Returns an error if the remote peer denies access, the connection cannot be established, or the export to disk fails.

Source

pub async fn download_with_progress<F: Fn(u64, u64) + Send + Sync>( &self, ticket: &ShareTicket, dest: impl AsRef<Path>, on_progress: F, ) -> Result<()>

Like Node::download, but calls on_progress(bytes_done, total_bytes) as each chunk is received, suitable for driving a progress bar.

§Errors

Returns an error under the same conditions as Node::download.

Source

pub async fn shutdown(self) -> Result<()>

Shut down the node, flushing all pending blob-store writes to disk.

Must be called before the process exits to avoid data loss: the iroh-blobs store batches redb transactions and sync_db waits for all of them to commit.

§Errors

Returns an error if the router shutdown or the blob-store flush fails.

Auto Trait Implementations§

§

impl<R> Freeze for Node<R>
where R: Freeze,

§

impl<R> !RefUnwindSafe for Node<R>

§

impl<R> Send for Node<R>
where R: Send,

§

impl<R> Sync for Node<R>
where R: Sync,

§

impl<R> Unpin for Node<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for Node<R>
where R: UnsafeUnpin,

§

impl<R> !UnwindSafe for Node<R>

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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