Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
fix: move bootstrap and add_peer methods to Node
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Jul 22, 2020
1 parent b41490f commit 5b02b62
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,25 +617,6 @@ impl<Types: IpfsTypes> Ipfs<Types> {
rx.await?
}

/// Initiate a query for random key to discover peers.
pub async fn bootstrap(&self) -> Result<(), Error> {
let (tx, rx) = oneshot_channel::<Result<FutureSubscription<(), String>, Error>>();

self.to_task.clone().send(IpfsEvent::Bootstrap(tx)).await?;

rx.await??.await?.map_err(|e| anyhow!(e))
}

/// Add a known peer to the DHT.
pub async fn add_peer(&self, peer_id: PeerId, addr: Multiaddr) -> Result<(), Error> {
self.to_task
.clone()
.send(IpfsEvent::AddPeer(peer_id, addr))
.await?;

Ok(())
}

/// Exit daemon.
pub async fn exit_daemon(self) {
// FIXME: this is a stopgap measure needed while repo is part of the struct Ipfs instead of
Expand Down Expand Up @@ -1013,6 +994,25 @@ mod node {
rx.await?.await?.map_err(|e| anyhow!(e))
}

/// Initiate a query for random key to discover peers.
pub async fn bootstrap(&self) -> Result<(), Error> {
let (tx, rx) = oneshot_channel::<Result<FutureSubscription<(), String>, Error>>();

self.to_task.clone().send(IpfsEvent::Bootstrap(tx)).await?;

rx.await??.await?.map_err(|e| anyhow!(e))
}

/// Add a known peer to the DHT.
pub async fn add_peer(&self, peer_id: PeerId, addr: Multiaddr) -> Result<(), Error> {
self.to_task
.clone()
.send(IpfsEvent::AddPeer(peer_id, addr))
.await?;

Ok(())
}

pub async fn shutdown(self) {
self.ipfs.exit_daemon().await;
self.background_task.await;
Expand Down

0 comments on commit 5b02b62

Please sign in to comment.