Struct hermes_ipfs::HermesIpfs

source ·
pub struct HermesIpfs {
    pub(crate) node: Ipfs,
}
Expand description

Hermes IPFS Node.

Fields§

§node: Ipfs

IPFS node

Implementations§

source§

impl HermesIpfs

source

pub async fn start() -> Result<Self>

Start a new node.

§Returns
  • HermesIpfs
§Errors

Returns an error if the IPFS daemon fails to start.

source

pub async fn add_ipfs_file(&self, ipfs_file: AddIpfsFile) -> Result<IpfsPath>

Add a file to IPFS.

§Parameters
  • file_path The file_path can be specified as a type that converts into std::path::PathBuf.
§Returns
  • A result with IpfsPath
§Errors

Returns an error if the file fails to upload.

source

pub async fn get_ipfs_file(&self, ipfs_path: GetIpfsFile) -> Result<Vec<u8>>

Get a file from IPFS

§Parameters
  • ipfs_path - GetIpfsFile(IpfsPath) Path used to get the file from IPFS.
§Returns
  • A result with Vec<u8>.
§Errors

Returns an error if the file fails to download.

source

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

Pin content to IPFS.

§Parameters
  • cid - Cid Content identifier to be pinned.
§Errors

Returns an error if pinning fails.

source

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

Checks whether a given block is pinned.

§Crash unsafety

Cannot currently detect partially written recursive pins. Those can happen if HermesIpfs::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.

§Parameters
  • cid - Cid Content identifier to be pinned.
§Returns

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

§Errors

Returns an error if checking pin fails.

source

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

List all pins in the IPFS node.

§Parameters
  • cid - Option<Cid> Optional content identifier to list pins. If None, lists all pins.
§Errors

Returns an error if listing pins fails.

source

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

Remove pinned content from IPFS.

§Parameters
  • cid - Cid Content identifier to be un-pinned.
§Errors

Returns an error if removing pin fails.

source

pub async fn stop(self)

Stop and exit the IPFS node daemon.

source

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

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

§Parameters
  • peer_id - Option<PeerId>
§Errors

Returns error if peer info cannot be retrieved.

source

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

Add peer to address book.

§Parameters
  • peer_id - PeerId
  • addr - Multiaddr
§Errors

Returns error if unable to add peer.

source

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

List of local listening addresses

§Returns
  • Result<Vec<Multiaddr>>
§Errors

Returns error if listening addresses cannot be retrieved.

source

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

Sets DHT mode in the IPFS node.

§Parameters
  • mode - DhtMode
§Returns
  • Result<()>
§Errors

Returns error if unable to set DHT mode

source

pub async fn dag_put(&self, ipld: Ipld) -> Result<Cid>

Add DAG data to IPFS.

§Parameters
  • ipld - Ipld
§Returns
  • Result<Cid>
§Errors

Returns error if unable to add DAG content.

source

pub async fn dag_get<T: Into<IpfsPath>>( &self, path: T, ) -> Result<Ipld, ResolveError>

Get DAG data from IPFS.

§Parameters
  • path - impl Into<IpfsPath>
§Returns
  • Result<Ipld>
§Errors

Returns error if unable to get DAG content.

source

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

Add content to DHT.

§Parameters
  • key - impl AsRef<[u8]>
  • value - impl Into<Vec<u8>>
§Returns
  • Result<()>
§Errors

Returns error if unable to add content to DHT

source

pub async fn dht_get(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>>

Get content from DHT.

§Parameters
  • key - impl AsRef<[u8]>
§Returns
  • Result<Vec<u8>>
§Errors

Returns error if unable to get content from DHT

source

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

Add address to bootstrap nodes.

§Parameters
  • address - Multiaddr
§Returns
  • Result<Multiaddr>
§Errors

Returns error if unable to add address to bootstrap nodes

source

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

Bootstrap the IPFS node.

§Returns
  • Result<()>
§Errors

Returns error if unable to retrieve bootstrap the node.

source

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

Returns a stream of pubsub swarm events for a topic.

§Parameters
  • topic - impl Into<String>
§Returns
  • A result with BoxStream<'static, PubsubEvent>
§Errors

Returns error if unable to retrieve pubsub swarm events.

source

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

Subscribes to a pubsub topic.

§Parameters
  • topic - impl Into<String>
§Returns
  • SubscriptionStream
§Errors

Returns error if unable to subscribe to pubsub topic.

source

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

Unsubscribes from a pubsub topic.

§Parameters
  • topic - impl Into<String>
§Returns
  • bool
§Errors

Returns error if unable to unsubscribe from pubsub topic.

source

pub async fn pubsub_publish( &self, topic: impl Into<String>, message: Vec<u8>, ) -> Result<MessageId>

Publishes a message to a pubsub topic.

§Parameters
  • topic - impl Into<String>
  • message - Vec<u8>
§Returns
  • Result<MessageId>
§Errors

Returns error if unable to publish to a pubsub topic.

source

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

Ban peer from node.

§Parameters
  • peer - PeerId
§Returns
  • Result<()>
§Errors

Returns error if unable to ban peer.

Trait Implementations§

source§

impl From<Ipfs> for HermesIpfs

source§

fn from(node: Ipfs) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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
§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

impl<T> References<RawCodec> for T

§

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

source§

type Output = T

Should always be Self
§

impl<T> TimeoutExt for T

§

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

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