From 1661d3e4a90ea2797b3b0485c9396b0b79473e0c Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Tue, 23 Jan 2018 20:24:44 -0500 Subject: add /bitswap/reprovide --- ipfs-api/src/client.rs | 23 ++++++++++++++++++++++- ipfs-api/src/request/bitswap.rs | 8 ++++++++ ipfs-api/src/response/bitswap.rs | 2 ++ ipfs-cli/src/command/bitswap.rs | 6 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ipfs-api/src/client.rs b/ipfs-api/src/client.rs index 564415f..7a4fbed 100644 --- a/ipfs-api/src/client.rs +++ b/ipfs-api/src/client.rs @@ -362,7 +362,28 @@ impl IpfsClient { self.request(&request::BitswapLedger { peer }, None) } - // TODO /bitswap/reprovide + /// Triggers a reprovide. + /// + /// # Examples + /// + /// ```no_run + /// # extern crate ipfs_api; + /// # extern crate tokio_core; + /// # + /// use ipfs_api::IpfsClient; + /// use tokio_core::reactor::Core; + /// + /// # fn main() { + /// let mut core = Core::new().unwrap(); + /// let client = IpfsClient::default(&core.handle()); + /// let req = client.bitswap_reprovide(); + /// # } + /// ``` + /// + #[inline] + pub fn bitswap_reprovide(&self) -> AsyncResponse { + self.request_empty(&request::BitswapReprovide, None) + } /// Returns some stats about the bitswap agent. /// diff --git a/ipfs-api/src/request/bitswap.rs b/ipfs-api/src/request/bitswap.rs index 1f795bb..326778e 100644 --- a/ipfs-api/src/request/bitswap.rs +++ b/ipfs-api/src/request/bitswap.rs @@ -17,6 +17,14 @@ impl<'a> ApiRequest for BitswapLedger<'a> { const PATH: &'static str = "/bitswap/ledger"; } +pub struct BitswapReprovide; + +impl_skip_serialize!(BitswapReprovide); + +impl ApiRequest for BitswapReprovide { + const PATH: &'static str = "/bitswap/reprovide"; +} + pub struct BitswapStat; impl_skip_serialize!(BitswapStat); diff --git a/ipfs-api/src/response/bitswap.rs b/ipfs-api/src/response/bitswap.rs index 69b9705..c1039de 100644 --- a/ipfs-api/src/response/bitswap.rs +++ b/ipfs-api/src/response/bitswap.rs @@ -18,6 +18,8 @@ pub struct BitswapLedgerResponse { pub exchanged: u64, } +pub type BitswapReprovideResponse = (); + #[derive(Debug, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct BitswapStatResponse { diff --git a/ipfs-cli/src/command/bitswap.rs b/ipfs-cli/src/command/bitswap.rs index 33f88ef..a63c21f 100644 --- a/ipfs-cli/src/command/bitswap.rs +++ b/ipfs-cli/src/command/bitswap.rs @@ -19,6 +19,9 @@ pub fn signature<'a, 'b>() -> App<'a, 'b> { (about: "Show the current ledger for a peer") (@arg PEER: +required "Peer to inspect") ) + (@subcommand reprovide => + (about: "Triggers a reprovide") + ) (@subcommand stat => (about: "Show some diagnostic information on the bitswap agent") ) @@ -46,6 +49,9 @@ pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) { println!(" exchanged : {}", ledger.exchanged); println!(); } + ("reprovide", _) => { + core.run(client.bitswap_reprovide()).expect(EXPECTED_API); + } ("stat", _) => { let stat = core.run(client.bitswap_stat()).expect(EXPECTED_API); -- cgit v1.2.3