Struct ipfs_embed::Ipfs
source · [−]pub struct Ipfs<P: StoreParams> { /* private fields */ }
Expand description
Ipfs node.
Implementations
sourceimpl<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(
&self,
addr: Multiaddr
) -> Result<impl Stream<Item = ListenerEvent>>
pub fn listen_on(
&self,
addr: Multiaddr
) -> Result<impl Stream<Item = ListenerEvent>>
Listens on a new Multiaddr
.
sourcepub fn listeners(&self) -> Vec<Multiaddr>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn listeners(&self) -> Vec<Multiaddr>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns the currently active listener addresses.
sourcepub fn add_external_address(&self, addr: Multiaddr)
pub fn add_external_address(&self, addr: Multiaddr)
Adds an external address.
sourcepub fn external_addresses(&self) -> Vec<AddressRecord>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn external_addresses(&self) -> Vec<AddressRecord>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns the currently used external addresses.
sourcepub fn add_address(&self, peer: &PeerId, addr: Multiaddr)
pub fn add_address(&self, peer: &PeerId, addr: Multiaddr)
Adds a known Multiaddr
for a PeerId
.
sourcepub fn remove_address(&self, peer: &PeerId, addr: &Multiaddr)
pub fn remove_address(&self, peer: &PeerId, addr: &Multiaddr)
Removes a Multiaddr
for a PeerId
.
sourcepub fn prune_peers(&self, min_age: Duration)
pub fn prune_peers(&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(&self, peer: &PeerId, addr: Multiaddr)
pub fn dial_address(&self, peer: &PeerId, addr: Multiaddr)
Dials a PeerId
using Multiaddr
.
sourcepub fn ban(&self, peer: PeerId)
pub fn ban(&self, peer: PeerId)
Bans a PeerId
from the swarm, dropping all existing connections and
preventing new connections from the peer.
sourcepub fn peers(&self) -> Vec<PeerId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn peers(&self) -> Vec<PeerId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns the known peers.
sourcepub fn connections(&self) -> Vec<(PeerId, Multiaddr, DateTime<Utc>, Direction)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn connections(&self) -> Vec<(PeerId, Multiaddr, DateTime<Utc>, Direction)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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 async fn bootstrap(&self, nodes: &[(PeerId, Multiaddr)]) -> Result<()>
pub async fn bootstrap(&self, nodes: &[(PeerId, Multiaddr)]) -> 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 async fn get_closest_peers<K>(&self, key: K) -> Result<()> where
K: Into<BucketKey<K>> + Into<Vec<u8>> + Clone,
pub async fn get_closest_peers<K>(&self, key: K) -> Result<()> where
K: Into<BucketKey<K>> + Into<Vec<u8>> + Clone,
Gets the closest peer to a key. Useful for finding the Multiaddr
of a
PeerId
.
sourcepub async fn providers(&self, key: Key) -> Result<HashSet<PeerId>>
pub async fn providers(&self, key: Key) -> Result<HashSet<PeerId>>
Gets providers of a key from the dht.
sourcepub async fn get_record(
&self,
key: Key,
quorum: Quorum
) -> Result<Vec<PeerRecord>>
pub async fn get_record(
&self,
key: Key,
quorum: Quorum
) -> Result<Vec<PeerRecord>>
Gets a record from the dht.
sourcepub async fn put_record(&self, record: Record, quorum: Quorum) -> Result<()>
pub async fn put_record(&self, record: Record, quorum: Quorum) -> Result<()>
Puts a new record in the dht.
sourcepub fn remove_record(&self, key: &Key)
pub fn remove_record(&self, key: &Key)
Removes a record from the dht.
sourcepub fn subscribe(&self, topic: &str) -> Result<impl Stream<Item = GossipEvent>>
pub fn subscribe(&self, topic: &str) -> 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(&self, topic: &str, msg: Vec<u8>) -> Result<()>
pub fn publish(&self, topic: &str, msg: Vec<u8>) -> Result<()>
Publishes a new message in a topic
, sending the message to all
subscribed peers.
sourcepub fn broadcast(&self, topic: &str, msg: Vec<u8>) -> Result<()>
pub fn broadcast(&self, topic: &str, msg: Vec<u8>) -> 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 async fn evict(&self) -> Result<()>
pub async fn evict(&self) -> 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>) -> SyncQuery<P>ⓘNotable traits for SyncQuery<P>impl<P: StoreParams> Future for SyncQuery<P> type Output = Result<()>;
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 async fn flush(&self) -> Result<()>
pub async fn flush(&self) -> 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(&self) -> SwarmEvents
pub fn swarm_events(&self) -> SwarmEvents
Subscribes to the swarm event stream.
Trait Implementations
sourceimpl<P: Clone + StoreParams> Clone for Ipfs<P>
impl<P: Clone + StoreParams> Clone for Ipfs<P>
sourceimpl<P: StoreParams> Debug for Ipfs<P>
impl<P: StoreParams> Debug for Ipfs<P>
sourceimpl<P: StoreParams> Store for Ipfs<P> where
Ipld: References<P::Codecs>,
impl<P: StoreParams> Store for Ipfs<P> where
Ipld: References<P::Codecs>,
type Params = P
type Params = P
Store parameters.
sourcefn create_temp_pin(&self) -> Result<Self::TempPin>
fn create_temp_pin(&self) -> Result<Self::TempPin>
Creates a new temporary pin.
sourcefn get(&self, cid: &Cid) -> Result<Block<P>>
fn get(&self, cid: &Cid) -> Result<Block<P>>
Returns a block from the store. If the block wasn’t found it returns a BlockNotFound
error. Read more
sourcefn insert(&self, block: &Block<P>) -> Result<()>
fn insert(&self, block: &Block<P>) -> Result<()>
Inserts a block into the store and publishes the block on the network.
sourcefn 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<()>
Creates an alias for a Cid
.
sourcefn 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>>
Resolves an alias for a Cid
.
sourcefn reverse_alias(&self, cid: &Cid) -> Result<Option<Vec<Vec<u8>>>>
fn reverse_alias(&self, cid: &Cid) -> Result<Option<Vec<Vec<u8>>>>
Returns all the aliases that are keeping the block around.
sourcefn 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,
Flushes the store.
sourcefn 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,
Returns a block from the store. If the store supports networking and the block is not in the store it fetches it from the network and inserts it into the store. Dropping the future cancels the request. Read more
sourcefn 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,
Fetches all missing blocks recursively from the network. If a block isn’t found it
returns a BlockNotFound
error. Read more
sourcefn query<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 DagPath<'life2>
) -> Pin<Box<dyn Future<Output = Result<Ipld, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Ipld: Decode<<Self::Params as StoreParams>::Codecs>,
fn query<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 DagPath<'life2>
) -> Pin<Box<dyn Future<Output = Result<Ipld, Error>> + Send + 'async_trait, Global>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Ipld: Decode<<Self::Params as StoreParams>::Codecs>,
Resolves a path recursively and returns the ipld.
Auto Trait Implementations
impl<P> !RefUnwindSafe for Ipfs<P>
impl<P> Send for Ipfs<P>
impl<P> Sync for Ipfs<P>
impl<P> Unpin for Ipfs<P>
impl<P> !UnwindSafe for Ipfs<P>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more