[][src]Struct ipfs::Ipfs

pub struct Ipfs<Types: IpfsTypes> { /* fields omitted */ }

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

impl<Types: IpfsTypes> Ipfs<Types>[src]

pub fn dag(&self) -> IpldDag<Types>[src]

Return an IpldDag for DAG operations

pub async fn put_block<'_>(&'_ self, block: Block) -> Result<Cid, Error>[src]

Puts a block into the ipfs repo.

Forget safety

Forgetting the returned future will not result in memory unsafety, but it can deadlock other tasks.

pub async fn get_block<'_, '_>(&'_ self, cid: &'_ Cid) -> Result<Block, Error>[src]

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

pub async fn remove_block<'_>(&'_ self, cid: Cid) -> Result<Cid, Error>[src]

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

pub async fn insert_pin<'_, '_>(
    &'_ self,
    cid: &'_ Cid,
    recursive: bool
) -> Result<(), Error>
[src]

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.

pub async fn remove_pin<'_, '_>(
    &'_ self,
    cid: &'_ Cid,
    recursive: bool
) -> Result<(), Error>
[src]

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.

pub async fn is_pinned<'_, '_>(&'_ self, cid: &'_ Cid) -> Result<bool, Error>[src]

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(cid, true) 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.

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

Lists all pins, or the specific kind thereof.

Crash unsafety

Does not currently recover from partial recursive pin insertions.

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

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.

pub async fn put_dag<'_>(&'_ self, ipld: Ipld) -> Result<Cid, Error>[src]

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

Returns Cid version 1 for the document

pub async fn get_dag<'_>(&'_ self, path: IpfsPath) -> Result<Ipld, Error>[src]

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

See IpldDag::get for more information.

pub async fn cat_unixfs<'_, '_>(
    &'_ self,
    starting_point: impl Into<StartingPoint>,
    range: Option<Range<u64>>
) -> Result<impl Stream<Item = Result<Vec<u8>, TraversalFailed>> + Send + '_, TraversalFailed>
[src]

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.

To create an owned version of the stream, please use ipfs::unixfs::cat directly.

pub async fn resolve_ipns<'_, '_>(
    &'_ self,
    path: &'_ IpfsPath,
    recursive: bool
) -> Result<IpfsPath, Error>
[src]

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

pub async fn connect<'_>(
    &'_ self,
    target: MultiaddrWithPeerId
) -> Result<(), Error>
[src]

Connects to the peer at the given Multiaddress.

Accepts only multiaddresses with the PeerId to authenticate the connection.

Returns a future which will complete when the connection has been successfully made or failed for whatever reason.

pub async fn addrs<'_>(&'_ self) -> Result<Vec<(PeerId, Vec<Multiaddr>)>, Error>[src]

Returns known peer addresses

pub async fn addrs_local<'_>(&'_ self) -> Result<Vec<Multiaddr>, Error>[src]

Returns local listening addresses

pub async fn peers<'_>(&'_ self) -> Result<Vec<Connection>, Error>[src]

Returns the connected peers

pub async fn disconnect<'_>(
    &'_ self,
    target: MultiaddrWithPeerId
) -> Result<(), Error>
[src]

Disconnects a given peer.

At the moment the peer is disconnected by temporarily banning the peer and unbanning it right after. This should always disconnect all connections to the peer.

pub async fn identity<'_>(
    &'_ self
) -> Result<(PublicKey, Vec<Multiaddr>), Error>
[src]

Returns the local node public key and the listened and externally visible addresses. The addresses are suffixed with the P2p protocol containing the node's PeerId.

Public key can be converted to PeerId.

pub async fn pubsub_subscribe<'_>(
    &'_ self,
    topic: String
) -> Result<SubscriptionStream, Error>
[src]

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.

pub async fn pubsub_publish<'_>(
    &'_ self,
    topic: String,
    data: Vec<u8>
) -> Result<(), Error>
[src]

Publishes to the topic which may have been subscribed to earlier

pub async fn pubsub_unsubscribe<'_, '_>(
    &'_ self,
    topic: &'_ str
) -> Result<bool, Error>
[src]

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

Returns true if unsubscription was successful

pub async fn pubsub_peers<'_>(
    &'_ self,
    topic: Option<String>
) -> Result<Vec<PeerId>, Error>
[src]

Returns all known pubsub peers with the optional topic filter

pub async fn pubsub_subscribed<'_>(&'_ self) -> Result<Vec<String>, Error>[src]

Returns all currently subscribed topics

pub async fn bitswap_wantlist<'_>(
    &'_ self,
    peer: Option<PeerId>
) -> Result<Vec<(Cid, Priority)>, Error>
[src]

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

pub async fn refs_local<'_>(&'_ self) -> Result<Vec<Cid>, Error>[src]

Returns a list of local blocks

This implementation is subject to change into a stream, which might only include the pinned blocks.

pub async fn bitswap_stats<'_>(&'_ self) -> Result<BitswapStats, Error>[src]

Returns the accumulated bitswap stats

pub async fn add_listening_address<'_>(
    &'_ self,
    addr: Multiaddr
) -> Result<Multiaddr, Error>
[src]

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, keep the ListenerId for later remove_listening_address use in a HashMap.

The returned future will resolve on the first bound listening address when this is called with /ip4/0.0.0.0/... or anything similar which will bound through multiple concrete listening addresses.

Trying to add an unspecified listening address while any other listening address adding is in progress will result in error.

Returns the bound multiaddress, which in the case of original containing an ephemeral port has now been changed.

pub async fn remove_listening_address<'_>(
    &'_ self,
    addr: Multiaddr
) -> Result<(), Error>
[src]

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.

pub async fn find_peer<'_>(
    &'_ self,
    peer_id: PeerId
) -> Result<Vec<Multiaddr>, Error>
[src]

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.

pub async fn get_providers<'_>(&'_ self, cid: Cid) -> Result<Vec<PeerId>, Error>[src]

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

Returns a list of peers found providing the Cid.

pub async fn provide<'_>(&'_ self, cid: Cid) -> Result<(), Error>[src]

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.

pub async fn get_closest_peers<'_>(
    &'_ self,
    peer_id: PeerId
) -> Result<Vec<PeerId>, Error>
[src]

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.

pub async fn dht_get<T: Into<Key>, '_>(
    &'_ self,
    key: T,
    quorum: Quorum
) -> Result<Vec<Vec<u8>>, Error>
[src]

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

pub async fn dht_put<T: Into<Key>, '_>(
    &'_ self,
    key: T,
    value: Vec<u8>,
    quorum: Quorum
) -> Result<(), Error>
[src]

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.

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

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.

pub async fn get_bootstrappers<'_>(&'_ self) -> Result<Vec<Multiaddr>, Error>[src]

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

pub async fn add_bootstrapper<'_>(
    &'_ self,
    addr: MultiaddrWithPeerId
) -> Result<Multiaddr, Error>
[src]

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.

pub async fn remove_bootstrapper<'_>(
    &'_ self,
    addr: MultiaddrWithPeerId
) -> Result<Multiaddr, Error>
[src]

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.

pub async fn clear_bootstrappers<'_>(&'_ self) -> Result<Vec<Multiaddr>, Error>[src]

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

pub async fn restore_bootstrappers<'_>(
    &'_ self
) -> Result<Vec<Multiaddr>, Error>
[src]

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.

pub async fn exit_daemon(__arg0: Self)[src]

Exit daemon.

Trait Implementations

impl<Types: IpfsTypes> Clone for Ipfs<Types>[src]

impl<Types: Debug + IpfsTypes> Debug for Ipfs<Types>[src]

Auto Trait Implementations

impl<Types> !RefUnwindSafe for Ipfs<Types>

impl<Types> Send for Ipfs<Types> where
    <Types as RepoTypes>::TBlockStore: Send + Sync,
    <Types as RepoTypes>::TDataStore: Send + Sync

impl<Types> Sync for Ipfs<Types> where
    <Types as RepoTypes>::TBlockStore: Send + Sync,
    <Types as RepoTypes>::TDataStore: Send + Sync

impl<Types> Unpin for Ipfs<Types>

impl<Types> !UnwindSafe for Ipfs<Types>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]