Struct ipfs_embed::Ipfs
source · pub struct Ipfs<P: StoreParams> { /* private fields */ }
Expand description
Ipfs node.
Implementations§
source§impl<P: StoreParams> Ipfs<P>where
Ipld: References<P::Codecs>,
impl<P: StoreParams> Ipfs<P>where
Ipld: References<P::Codecs>,
sourcepub async fn new(config: Config) -> Result<Self>
pub async fn new(config: Config) -> Result<Self>
Creates a new Ipfs
from a Config
.
This starts three background tasks. The swarm, garbage collector and the dht cleanup tasks run in the background.
sourcepub fn local_public_key(&self) -> PublicKey
pub fn local_public_key(&self) -> PublicKey
Returns the local PublicKey
.
sourcepub fn local_peer_id(&self) -> PeerId
pub fn local_peer_id(&self) -> PeerId
Returns the local PeerId
.
sourcepub fn local_node_name(&self) -> String
pub fn local_node_name(&self) -> String
Returns the local node name.
sourcepub fn listen_on(&mut self, addr: Multiaddr) -> impl Stream<Item = ListenerEvent>
pub fn listen_on(&mut self, addr: Multiaddr) -> impl Stream<Item = ListenerEvent>
Listens on a new Multiaddr
.
sourcepub fn add_external_address(&mut self, addr: Multiaddr)
pub fn add_external_address(&mut self, addr: Multiaddr)
Adds an external address.
sourcepub fn external_addresses(&self) -> Vec<AddressRecord> ⓘ
pub fn external_addresses(&self) -> Vec<AddressRecord> ⓘ
Returns the currently used external addresses.
sourcepub fn add_address(&mut self, peer: PeerId, addr: Multiaddr)
pub fn add_address(&mut self, peer: PeerId, addr: Multiaddr)
Adds a known Multiaddr
for a PeerId
.
sourcepub fn remove_address(&mut self, peer: PeerId, addr: Multiaddr)
pub fn remove_address(&mut self, peer: PeerId, addr: Multiaddr)
Removes a Multiaddr
for a PeerId
.
sourcepub fn prune_peers(&mut self, min_age: Duration)
pub fn prune_peers(&mut self, min_age: Duration)
Removes all unconnected peers without addresses which have been in this state for at least the given duration
sourcepub fn dial_address(&mut self, peer: PeerId, addr: Multiaddr)
pub fn dial_address(&mut self, peer: PeerId, addr: Multiaddr)
Dials a PeerId
using Multiaddr
.
sourcepub fn ban(&mut self, peer: PeerId)
pub fn ban(&mut self, peer: PeerId)
Bans a PeerId
from the swarm, dropping all existing connections and
preventing new connections from the peer.
sourcepub fn connections(&self) -> Vec<(PeerId, Multiaddr, DateTime<Utc>, Direction)> ⓘ
pub fn connections(&self) -> Vec<(PeerId, Multiaddr, DateTime<Utc>, Direction)> ⓘ
Returns a list of connected peers.
sourcepub fn is_connected(&self, peer: &PeerId) -> bool
pub fn is_connected(&self, peer: &PeerId) -> bool
Returns true
if there is a connection to peer.
sourcepub fn bootstrap(
&mut self,
nodes: Vec<(PeerId, Multiaddr)>
) -> impl Future<Output = Result<()>>
pub fn bootstrap(
&mut self,
nodes: Vec<(PeerId, Multiaddr)>
) -> impl Future<Output = Result<()>>
Bootstraps the dht using a set of bootstrap nodes. After bootstrap completes it provides all blocks in the block store.
sourcepub fn is_bootstrapped(&self) -> bool
pub fn is_bootstrapped(&self) -> bool
Returns true if the dht was bootstrapped.
sourcepub fn providers(
&mut self,
key: Key
) -> impl Future<Output = Result<HashSet<PeerId>>>
pub fn providers(
&mut self,
key: Key
) -> impl Future<Output = Result<HashSet<PeerId>>>
Gets the closest peer to a key. Useful for finding the Multiaddr
of a
PeerId
.
Gets providers of a key from the dht.
sourcepub fn provide(&mut self, key: Key) -> impl Future<Output = Result<()>>
pub fn provide(&mut self, key: Key) -> impl Future<Output = Result<()>>
Provides a key in the dht.
sourcepub fn get_record(
&mut self,
key: Key,
quorum: Quorum
) -> impl Future<Output = Result<Vec<PeerRecord>>>
pub fn get_record(
&mut self,
key: Key,
quorum: Quorum
) -> impl Future<Output = Result<Vec<PeerRecord>>>
Gets a record from the dht.
sourcepub fn put_record(
&mut self,
record: Record,
quorum: Quorum
) -> impl Future<Output = Result<()>>
pub fn put_record(
&mut self,
record: Record,
quorum: Quorum
) -> impl Future<Output = Result<()>>
Puts a new record in the dht.
sourcepub fn remove_record(&mut self, key: Key) -> Result<()>
pub fn remove_record(&mut self, key: Key) -> Result<()>
Removes a record from the dht.
sourcepub fn subscribe(
&mut self,
topic: String
) -> impl Future<Output = Result<impl Stream<Item = GossipEvent>>>
pub fn subscribe(
&mut self,
topic: String
) -> impl Future<Output = Result<impl Stream<Item = GossipEvent>>>
Subscribes to a topic
returning a Stream
of messages. If all
Stream
s for a topic are dropped it unsubscribes from the topic
.
sourcepub fn publish(
&mut self,
topic: String,
msg: Vec<u8>
) -> impl Future<Output = Result<()>>
pub fn publish(
&mut self,
topic: String,
msg: Vec<u8>
) -> impl Future<Output = Result<()>>
Publishes a new message in a topic
, sending the message to all
subscribed peers.
sourcepub fn broadcast(
&mut self,
topic: String,
msg: Vec<u8>
) -> impl Future<Output = Result<()>>
pub fn broadcast(
&mut self,
topic: String,
msg: Vec<u8>
) -> impl Future<Output = Result<()>>
Publishes a new message in a topic
, sending the message to all
subscribed connected peers.
sourcepub fn create_temp_pin(&self) -> Result<TempPin>
pub fn create_temp_pin(&self) -> Result<TempPin>
Creates a temporary pin in the block store. A temporary pin is not persisted to disk and is released once it is dropped.
sourcepub fn temp_pin(&self, tmp: &mut TempPin, cid: &Cid) -> Result<()>
pub fn temp_pin(&self, tmp: &mut TempPin, cid: &Cid) -> Result<()>
Adds a new root to a temporary pin.
sourcepub fn iter(&self) -> Result<impl Iterator<Item = Cid>>
pub fn iter(&self) -> Result<impl Iterator<Item = Cid>>
Returns an Iterator
of Cid
s stored in the block store.
sourcepub async fn fetch(&self, cid: &Cid, providers: Vec<PeerId>) -> Result<Block<P>>
pub async fn fetch(&self, cid: &Cid, providers: Vec<PeerId>) -> Result<Block<P>>
Either returns a block if it’s in the block store or tries to retrieve it from a peer.
sourcepub fn evict(&self) -> impl Future<Output = Result<()>>
pub fn evict(&self) -> impl Future<Output = Result<()>>
Manually runs garbage collection to completion. This is mainly useful for testing and administrative interfaces. During normal operation, the garbage collector automatically runs in the background.
pub fn sync(
&self,
cid: &Cid,
providers: Vec<PeerId>
) -> impl Future<Output = Result<SyncQuery>>
sourcepub fn alias<T: AsRef<[u8]> + Send + Sync>(
&self,
alias: T,
cid: Option<&Cid>
) -> Result<()>
pub fn alias<T: AsRef<[u8]> + Send + Sync>(
&self,
alias: T,
cid: Option<&Cid>
) -> Result<()>
Creates, updates or removes an alias with a new root Cid
.
sourcepub fn resolve<T: AsRef<[u8]> + Send + Sync>(
&self,
alias: T
) -> Result<Option<Cid>>
pub fn resolve<T: AsRef<[u8]> + Send + Sync>(
&self,
alias: T
) -> Result<Option<Cid>>
Returns the root of an alias.
sourcepub fn reverse_alias(&self, cid: &Cid) -> Result<Option<HashSet<Vec<u8>>>>
pub fn reverse_alias(&self, cid: &Cid) -> Result<Option<HashSet<Vec<u8>>>>
Returns a list of aliases preventing a Cid
from being garbage
collected.
sourcepub fn flush(&self) -> impl Future<Output = Result<()>>
pub fn flush(&self) -> impl Future<Output = Result<()>>
Flushes the block store. After flush
completes successfully it is
guaranteed that all writes have been persisted to disk.
sourcepub fn batch_ops<R>(
&self,
f: impl FnOnce(&mut Batch<'_, P>) -> Result<R>
) -> Result<R>
pub fn batch_ops<R>(
&self,
f: impl FnOnce(&mut Batch<'_, P>) -> Result<R>
) -> Result<R>
Perform a set of storage operations in a batch
The batching concerns only the CacheTracker, it implies no atomicity guarantees!
sourcepub fn register_metrics(&self, registry: &Registry) -> Result<()>
pub fn register_metrics(&self, registry: &Registry) -> Result<()>
Registers prometheus metrics in a registry.
sourcepub fn swarm_events(&mut self) -> impl Future<Output = Result<SwarmEvents>>
pub fn swarm_events(&mut self) -> impl Future<Output = Result<SwarmEvents>>
Subscribes to the swarm event stream.
Trait Implementations§
source§impl<P: StoreParams> Debug for Ipfs<P>
impl<P: StoreParams> Debug for Ipfs<P>
source§impl<P: StoreParams> Store for Ipfs<P>where
Ipld: References<P::Codecs>,
impl<P: StoreParams> Store for Ipfs<P>where
Ipld: References<P::Codecs>,
source§fn create_temp_pin(&self) -> Result<Self::TempPin>
fn create_temp_pin(&self) -> Result<Self::TempPin>
source§fn get(&self, cid: &Cid) -> Result<Block<P>>
fn get(&self, cid: &Cid) -> Result<Block<P>>
BlockNotFound
error. Read moresource§fn insert(&self, block: &Block<P>) -> Result<()>
fn insert(&self, block: &Block<P>) -> Result<()>
source§fn alias<T: AsRef<[u8]> + Send + Sync>(
&self,
alias: T,
cid: Option<&Cid>
) -> Result<()>
fn alias<T: AsRef<[u8]> + Send + Sync>(
&self,
alias: T,
cid: Option<&Cid>
) -> Result<()>
Cid
.source§fn resolve<T: AsRef<[u8]> + Send + Sync>(&self, alias: T) -> Result<Option<Cid>>
fn resolve<T: AsRef<[u8]> + Send + Sync>(&self, alias: T) -> Result<Option<Cid>>
Cid
.source§fn reverse_alias(&self, cid: &Cid) -> Result<Option<Vec<Vec<u8>>>>
fn reverse_alias(&self, cid: &Cid) -> Result<Option<Vec<Vec<u8>>>>
source§fn flush<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn flush<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
source§fn fetch<'life0, 'life1, 'async_trait>(
&'life0 self,
cid: &'life1 Cid
) -> Pin<Box<dyn Future<Output = Result<Block<Self::Params>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn fetch<'life0, 'life1, 'async_trait>(
&'life0 self,
cid: &'life1 Cid
) -> Pin<Box<dyn Future<Output = Result<Block<Self::Params>>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
source§fn sync<'life0, 'life1, 'async_trait>(
&'life0 self,
cid: &'life1 Cid
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn sync<'life0, 'life1, 'async_trait>(
&'life0 self,
cid: &'life1 Cid
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
BlockNotFound
error. Read more