Struct rust_ipfs::Ipfs

source ·
pub struct Ipfs { /* private fields */ }
Expand description

The facade for the Ipfs node.

The facade has most of the functionality either directly as a method or the functionality can be implemented using the provided methods. For more information, see examples or the HTTP endpoint implementations in ipfs-http.

The facade is created through UninitializedIpfs which is configured with IpfsOptions.

Implementations§

source§

impl Ipfs

source

pub fn dag(&self) -> IpldDag

Return an IpldDag for DAG operations

source

pub fn repo(&self) -> &Repo

Return an Repo to access the internal repo of the node

source

pub fn unixfs(&self) -> IpfsUnixfs

Returns an IpfsUnixfs for files operations

source

pub fn ipns(&self) -> Ipns

Returns a Ipns for ipns operations

source

pub async fn put_block(&self, block: Block) -> Result<Cid, Error>

Puts a block into the ipfs repo.

source

pub async fn get_block(&self, cid: &Cid) -> Result<Block, Error>

Retrieves a block from the local blockstore, or starts fetching from the network or join an already started fetch.

source

pub async fn remove_block( &self, cid: Cid, recursive: bool, ) -> Result<Vec<Cid>, Error>

Remove block from the ipfs repo. A pinned block cannot be removed.

source

pub async fn gc(&self) -> Result<Vec<Cid>, Error>

Cleans up of all unpinned blocks Note: This will prevent writing operations in Repo until it finish clearing unpinned blocks.

source

pub fn insert_pin(&self, cid: &Cid) -> RepoInsertPin

Pins a given Cid recursively or directly (non-recursively).

Pins on a block are additive in sense that a previously directly (non-recursively) pinned can be made recursive, but removing the recursive pin on the block removes also the direct pin as well.

Pinning a Cid recursively (for supported dag-protobuf and dag-cbor) will walk its references and pin the references indirectly. When a Cid is pinned indirectly it will keep its previous direct or recursive pin and be indirect in addition.

Recursively pinned Cids cannot be re-pinned non-recursively but non-recursively pinned Cids can be “upgraded to” being recursively pinned.

§Crash unsafety

If a recursive insert_pin operation is interrupted because of a crash or the crash prevents from synchronizing the data store to disk, this will leave the system in an inconsistent state. The remedy is to re-pin recursive pins.

source

pub fn remove_pin(&self, cid: &Cid) -> RepoRemovePin

Unpins a given Cid recursively or only directly.

Recursively unpinning a previously only directly pinned Cid will remove the direct pin.

Unpinning an indirectly pinned Cid is not possible other than through its recursively pinned tree roots.

source

pub async fn is_pinned(&self, cid: &Cid) -> Result<bool, Error>

Checks whether a given block is pinned.

Returns true if the block is pinned, false if not. See Crash unsafety notes for the false response.

§Crash unsafety

Cannot currently detect partially written recursive pins. Those can happen if Ipfs::insert_pin is interrupted by a crash for example.

Works correctly only under no-crash situations. Workaround for hitting a crash is to re-pin any existing recursive pins.

source

pub async fn list_pins( &self, filter: Option<PinMode>, ) -> BoxStream<'static, Result<(Cid, PinMode), Error>>

Lists all pins, or the specific kind thereof.

§Crash unsafety

Does not currently recover from partial recursive pin insertions.

source

pub async fn query_pins( &self, cids: Vec<Cid>, requirement: Option<PinMode>, ) -> Result<Vec<(Cid, PinKind<Cid>)>, Error>

Read specific pins. When requirement is Some, all pins are required to be of the given PinMode.

§Crash unsafety

Does not currently recover from partial recursive pin insertions.

source

pub fn put_dag(&self, ipld: Ipld) -> DagPut

Puts an ipld node into the ipfs repo using dag-cbor codec and Sha2_256 hash.

Returns Cid version 1 for the document

source

pub fn get_dag<I: Into<IpfsPath>>(&self, path: I) -> DagGet

Gets an ipld node from the ipfs, fetching the block if necessary.

See IpldDag::get for more information.

source

pub fn cat_unixfs(&self, starting_point: impl Into<StartingPoint>) -> UnixfsCat

Creates a stream which will yield the bytes of an UnixFS file from the root Cid, with the optional file byte range. If the range is specified and is outside of the file, the stream will end without producing any bytes.

source

pub fn add_unixfs(&self, opt: impl Into<AddOpt>) -> UnixfsAdd

Add a file through a stream of data to the blockstore

source

pub fn get_unixfs<P: AsRef<Path>>(&self, path: IpfsPath, dest: P) -> UnixfsGet

Retreive a file and saving it to a path.

source

pub fn ls_unixfs(&self, path: IpfsPath) -> UnixfsLs

List directory contents

source

pub async fn resolve_ipns( &self, path: &IpfsPath, recursive: bool, ) -> Result<IpfsPath, Error>

Resolves a ipns path to an ipld path; currently only supports dht and dnslink resolution.

source

pub async fn publish_ipns(&self, path: &IpfsPath) -> Result<IpfsPath, Error>

Publish ipns record to DHT

source

pub async fn connect(&self, target: impl Into<DialOpts>) -> Result<(), Error>

Connects to the peer

source

pub async fn addrs(&self) -> Result<Vec<(PeerId, Vec<Multiaddr>)>, Error>

Returns known peer addresses

source

pub async fn is_connected(&self, peer_id: PeerId) -> Result<bool, Error>

Checks whether there is an established connection to a peer.

source

pub async fn connected(&self) -> Result<Vec<PeerId>, Error>

Returns the connected peers

source

pub async fn disconnect(&self, target: PeerId) -> Result<(), Error>

Disconnects a given peer.

source

pub async fn ban_peer(&self, target: PeerId) -> Result<(), Error>

Bans a peer.

source

pub async fn unban_peer(&self, target: PeerId) -> Result<(), Error>

Unbans a peer.

source

pub async fn identity(&self, peer_id: Option<PeerId>) -> Result<PeerInfo, Error>

Returns the peer identity information. If no peer id is supplied the local node identity is used.

source

pub async fn pubsub_subscribe( &self, topic: impl Into<String>, ) -> Result<SubscriptionStream, Error>

Subscribes to a given topic. Can be done at most once without unsubscribing in the between. The subscription can be unsubscribed by dropping the stream or calling Ipfs::pubsub_unsubscribe.

source

pub async fn pubsub_events( &self, topic: impl Into<String>, ) -> Result<BoxStream<'static, PubsubEvent>, Error>

Stream that returns PubsubEvent for a given topic

source

pub async fn pubsub_publish( &self, topic: impl Into<String>, data: impl Into<Bytes>, ) -> Result<MessageId, Error>

Publishes to the topic which may have been subscribed to earlier

source

pub async fn pubsub_unsubscribe( &self, topic: impl Into<String>, ) -> Result<bool, Error>

Forcibly unsubscribes a previously made SubscriptionStream, which could also be unsubscribed by dropping the stream.

Returns true if unsubscription was successful

source

pub async fn pubsub_peers( &self, topic: impl Into<Option<String>>, ) -> Result<Vec<PeerId>, Error>

Returns all known pubsub peers with the optional topic filter

source

pub async fn pubsub_subscribed(&self) -> Result<Vec<String>, Error>

Returns all currently subscribed topics

source

pub async fn bitswap_wantlist( &self, peer: impl Into<Option<PeerId>>, ) -> Result<Vec<Cid>, Error>

Returns the known wantlist for the local node when the peer is None or the wantlist of the given peer

source

pub async fn refs_local(&self) -> Vec<Cid>

Returns a list of local blocks

source

pub async fn listening_addresses(&self) -> Result<Vec<Multiaddr>, Error>

Returns local listening addresses

source

pub async fn external_addresses(&self) -> Result<Vec<Multiaddr>, Error>

Returns external addresses

source

pub async fn add_listening_address( &self, addr: Multiaddr, ) -> Result<Multiaddr, Error>

Add a given multiaddr as a listening address. Will fail if the address is unsupported, or if it is already being listened on. Currently will invoke Swarm::listen_on internally, returning the first Multiaddr that is being listened on.

source

pub async fn remove_listening_address( &self, addr: Multiaddr, ) -> Result<(), Error>

Stop listening on a previously added listening address. Fails if the address is not being listened to.

The removal of all listening addresses added through unspecified addresses is not supported.

source

pub async fn add_external_address(&self, addr: Multiaddr) -> Result<(), Error>

Add a given multiaddr as a external address to indenticate how our node can be reached. Note: We will not perform checks

source

pub async fn remove_external_address( &self, addr: Multiaddr, ) -> Result<(), Error>

Removes a previously added external address.

source

pub async fn find_peer(&self, peer_id: PeerId) -> Result<Vec<Multiaddr>, Error>

Obtain the addresses associated with the given PeerId; they are first searched for locally and the DHT is used as a fallback: a Kademlia::get_closest_peers(peer_id) query is run and when it’s finished, the newly added DHT records are checked for the existence of the desired peer_id and if it’s there, the list of its known addresses is returned.

source

pub async fn get_providers( &self, cid: Cid, ) -> Result<BoxStream<'static, PeerId>, Error>

Performs a DHT lookup for providers of a value to the given key.

Returns a list of peers found providing the Cid.

source

pub async fn provide(&self, cid: Cid) -> Result<(), Error>

Establishes the node as a provider of a block with the given Cid: it publishes a provider record with the given key (Cid) and the node’s PeerId to the peers closest to the key. The publication of provider records is periodically repeated as per the interval specified in libp2p’s KademliaConfig.

source

pub fn fetch(&self, cid: &Cid) -> RepoFetch

Fetches the block, and, if set, recursively walk the graph loading all the blocks to the blockstore.

source

pub async fn get_closest_peers( &self, peer_id: PeerId, ) -> Result<Vec<PeerId>, Error>

Returns a list of peers closest to the given PeerId, as suggested by the DHT. The node must have at least one known peer in its routing table in order for the query to return any values.

source

pub async fn dht_mode(&self, mode: DhtMode) -> Result<(), Error>

Change the DHT mode

source

pub async fn dht_get<T: AsRef<[u8]>>( &self, key: T, ) -> Result<BoxStream<'static, Record>, Error>

Attempts to look a key up in the DHT and returns the values found in the records containing that key.

source

pub async fn dht_put( &self, key: impl AsRef<[u8]>, value: impl Into<Vec<u8>>, quorum: Quorum, ) -> Result<(), Error>

Stores the given key + value record locally and replicates it in the DHT. It doesn’t expire locally and is periodically replicated in the DHT, as per the KademliaConfig setup.

source

pub async fn add_relay( &self, peer_id: PeerId, addr: Multiaddr, ) -> Result<(), Error>

Add relay address

source

pub async fn remove_relay( &self, peer_id: PeerId, addr: Multiaddr, ) -> Result<(), Error>

Remove relay address

source

pub async fn list_relays( &self, active: bool, ) -> Result<Vec<(PeerId, Vec<Multiaddr>)>, Error>

List all relays. if active is true, it will list all active relays

source

pub async fn enable_autorelay(&self) -> Result<(), Error>

source

pub async fn disable_autorelay(&self) -> Result<(), Error>

source

pub async fn enable_relay( &self, peer_id: impl Into<Option<PeerId>>, ) -> Result<(), Error>

Enable use of a relay. If peer_id is None, it will select a relay at random to use, if one have been added

source

pub async fn disable_relay(&self, peer_id: PeerId) -> Result<(), Error>

Disable the use of a selected relay.

source

pub async fn rendezvous_register_namespace( &self, namespace: impl Into<String>, ttl: impl Into<Option<u64>>, peer_id: PeerId, ) -> Result<(), Error>

source

pub async fn rendezvous_unregister_namespace( &self, namespace: impl Into<String>, peer_id: PeerId, ) -> Result<(), Error>

source

pub async fn rendezvous_namespace_discovery( &self, namespace: impl Into<String>, ttl: impl Into<Option<u64>>, peer_id: PeerId, ) -> Result<HashMap<PeerId, Vec<Multiaddr>>, Error>

source

pub fn refs<'a, Iter>( &'a self, iplds: Iter, max_depth: Option<u64>, unique: bool, ) -> impl Stream<Item = Result<Edge, Error>> + Send + 'a
where Iter: IntoIterator<Item = (Cid, Ipld)> + Send + 'a,

Walk the given Iplds’ links up to max_depth (or indefinitely for None). Will return any duplicate trees unless unique is true.

More information and a 'static lifetime version available at refs::iplds_refs.

source

pub async fn get_bootstraps(&self) -> Result<Vec<Multiaddr>, Error>

Obtain the list of addresses of bootstrapper nodes that are currently used.

source

pub async fn add_bootstrap(&self, addr: Multiaddr) -> Result<Multiaddr, Error>

Extend the list of used bootstrapper nodes with an additional address. Return value cannot be used to determine if the addr was a new bootstrapper, subject to change.

source

pub async fn remove_bootstrap( &self, addr: Multiaddr, ) -> Result<Multiaddr, Error>

Remove an address from the currently used list of bootstrapper nodes. Return value cannot be used to determine if the addr was an actual bootstrapper, subject to change.

source

pub async fn clear_bootstrap(&self) -> Result<Vec<Multiaddr>, Error>

Clear the currently used list of bootstrapper nodes, returning the removed addresses.

source

pub async fn default_bootstrap(&self) -> Result<Vec<Multiaddr>, Error>

Restore the originally configured bootstrapper node list by adding them to the list of the currently used bootstrapper node address list; returns the restored addresses.

source

pub async fn bootstrap(&self) -> Result<(), Error>

Bootstraps the local node to join the DHT: it looks up the node’s own ID in the DHT and introduces it to the other nodes in it; at least one other node must be known in order for the process to succeed. Subsequently, additional queries are ran with random keys so that the buckets farther from the closest neighbor also get refreshed.

source

pub async fn add_peer( &self, peer_id: PeerId, addr: Multiaddr, ) -> Result<(), Error>

Add address of a peer to the address book

source

pub async fn remove_peer(&self, peer_id: PeerId) -> Result<bool, Error>

Remove peer from the address book

source

pub async fn remove_peer_address( &self, peer_id: PeerId, addr: Multiaddr, ) -> Result<bool, Error>

Remove peer address from the address book

source

pub async fn get_bitswap_peers(&self) -> Result<Vec<PeerId>, Error>

Returns the Bitswap peers for the a Node.

source

pub fn keypair(&self) -> &Keypair

Returns the keypair to the node

source

pub fn keystore(&self) -> &Keystore

Returns the keystore

source

pub async fn exit_daemon(self)

Exit daemon.

Trait Implementations§

source§

impl Clone for Ipfs

source§

fn clone(&self) -> Ipfs

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ipfs

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Ipfs

§

impl !RefUnwindSafe for Ipfs

§

impl Send for Ipfs

§

impl Sync for Ipfs

§

impl Unpin for Ipfs

§

impl !UnwindSafe for Ipfs

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> 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> References<RawCodec> for T

source§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>
where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> TimeoutExt for T

source§

fn timeout(self, duration: Duration) -> Timeout<Self>

Requires a Future or Stream to complete before the specific duration has elapsed. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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
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