diff --git a/doc/articles/client.md b/doc/articles/client.md index c96460f..367dccb 100644 --- a/doc/articles/client.md +++ b/doc/articles/client.md @@ -36,6 +36,7 @@ string text = await ipfs.FileSystem.ReadAllTextAsync(filename); | ------- | ------- | | [Bitswap](xref:Ipfs.CoreApi.IBitswapApi) | Data trading module for IPFS; requests blocks from and sends blocks to other peers | | [Block](xref:Ipfs.CoreApi.IBlockApi) | Manages the blocks | +| [BlockRepository](xref:Ipfs.CoreApi.IBlockRepositoryApi) | Manages the repository of blocks | | [Bootstrap](xref:Ipfs.CoreApi.IBootstrapApi) | Trusted peers | | [Config](xref:Ipfs.CoreApi.IConfigApi) | Manages the configuration of the local peer | | [Dag](xref:Ipfs.CoreApi.IDagApi) | Manages the IPLD (linked data) Directed Acrylic Graph | diff --git a/src/CoreApi/BlockRepositoryApi.cs b/src/CoreApi/BlockRepositoryApi.cs new file mode 100644 index 0000000..ca8a257 --- /dev/null +++ b/src/CoreApi/BlockRepositoryApi.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Ipfs.CoreApi; +using System.IO; + +namespace Ipfs.Http +{ + + class BlockRepositoryApi : IBlockRepositoryApi + { + IpfsClient ipfs; + + internal BlockRepositoryApi(IpfsClient ipfs) + { + this.ipfs = ipfs; + } + + public async Task RemoveGarbageAsync(CancellationToken cancel = default(CancellationToken)) + { + await ipfs.DoCommandAsync("repo/gc", cancel); + } + + public Task StatisticsAsync(CancellationToken cancel = default(CancellationToken)) + { + return ipfs.DoCommandAsync("repo/stat", cancel); + } + + public async Task VerifyAsync(CancellationToken cancel = default(CancellationToken)) + { + await ipfs.DoCommandAsync("repo/verify", cancel); + } + + public async Task VersionAsync(CancellationToken cancel = default(CancellationToken)) + { + var json = await ipfs.DoCommandAsync("repo/version", cancel); + var info = JObject.Parse(json); + return (string)info["Version"]; + } + } +} diff --git a/src/IpfsClient.cs b/src/IpfsClient.cs index 093e349..0b8ce55 100644 --- a/src/IpfsClient.cs +++ b/src/IpfsClient.cs @@ -66,6 +66,7 @@ public IpfsClient() Bootstrap = new BootstrapApi(this); Bitswap = new BitswapApi(this); Block = new BlockApi(this); + BlockRepository = new BlockRepositoryApi(this); Config = new ConfigApi(this); Pin = new PinApi(this); Dht = new DhtApi(this); @@ -138,6 +139,9 @@ public IpfsClient(string host) /// public IBlockApi Block { get; private set; } + /// + public IBlockRepositoryApi BlockRepository { get; private set; } + /// public IConfigApi Config { get; private set; } diff --git a/src/IpfsHttpClient.csproj b/src/IpfsHttpClient.csproj index 303b7a9..9034510 100644 --- a/src/IpfsHttpClient.csproj +++ b/src/IpfsHttpClient.csproj @@ -27,7 +27,7 @@ - + diff --git a/test/CoreApi/BlockRepositoryTest.cs b/test/CoreApi/BlockRepositoryTest.cs new file mode 100644 index 0000000..569e3da --- /dev/null +++ b/test/CoreApi/BlockRepositoryTest.cs @@ -0,0 +1,32 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using System; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ipfs.Http +{ + + [TestClass] + public class BlockRepositoryTest + { + + [TestMethod] + public async Task Stats() + { + var ipfs = TestFixture.Ipfs; + var stats = await ipfs.BlockRepository.StatisticsAsync(); + Assert.IsNotNull(stats); + } + + [TestMethod] + public async Task Version() + { + var ipfs = TestFixture.Ipfs; + var version = await ipfs.BlockRepository.VersionAsync(); + Assert.IsFalse(string.IsNullOrWhiteSpace(version)); + } + + } +}