From ae56cf6eb2577597645a5afec72900d3abf085a6 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Wed, 29 May 2019 18:02:37 +1200 Subject: [PATCH] feat: implement IBlockRepository #40 --- doc/articles/core-api.md | 1 + src/CoreApi/IBlockApi.cs | 1 + src/CoreApi/IBlockRepository.cs | 64 +++++++++++++++++++++++++++++++++ src/CoreApi/ICoreApi.cs | 10 +++++- src/CoreApi/IStatsApi.cs | 8 +++-- src/CoreApi/RepositoryData.cs | 17 ++++++++- 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 src/CoreApi/IBlockRepository.cs diff --git a/doc/articles/core-api.md b/doc/articles/core-api.md index 7b60443..0a06e79 100644 --- a/doc/articles/core-api.md +++ b/doc/articles/core-api.md @@ -7,6 +7,7 @@ | ------- | ------- | | [Bitswap](xref:Ipfs.CoreApi.IBitswapApi) | Block trading between peers | | [Block](xref:Ipfs.CoreApi.IBlockApi) | Manages the blocks | +| [BlockRepository](xref:Ipfs.CoreApi.IBlockRepositoryApi) | Manages the repository for [blocks](xref:Ipfs.CoreApi.IBlockApi) | | [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/IBlockApi.cs b/src/CoreApi/IBlockApi.cs index 53d79cb..44bed75 100644 --- a/src/CoreApi/IBlockApi.cs +++ b/src/CoreApi/IBlockApi.cs @@ -15,6 +15,7 @@ namespace Ipfs.CoreApi /// "blocks" in Bitswap /// and other things that do not care about what is being stored. /// + /// /// Block API spec public interface IBlockApi { diff --git a/src/CoreApi/IBlockRepository.cs b/src/CoreApi/IBlockRepository.cs new file mode 100644 index 0000000..51c5bd9 --- /dev/null +++ b/src/CoreApi/IBlockRepository.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Ipfs.CoreApi +{ + /// + /// Manages all the blocks stored locally. + /// + /// + public interface IBlockRepositoryApi + { + /// + /// Perform a garbage collection sweep on the repo. + /// + /// + /// Is used to stop the task. When cancelled, the is raised. + /// + /// + /// TODO: not sure what this should return. + /// + Task RemoveGarage(CancellationToken cancel = default(CancellationToken)); + + /// + /// Get statistics on the repository. + /// + /// + /// Is used to stop the task. When cancelled, the is raised. + /// + /// + /// A task that represents the asynchronous operation. The task's result is + /// the current . + /// + /// + /// Same as . + /// + Task Statistics(CancellationToken cancel = default(CancellationToken)); + + /// + /// Verify all blocks in repo are not corrupted. + /// + /// + /// Is used to stop the task. When cancelled, the is raised. + /// + /// + /// TODO: not sure what this should return. + /// + Task Verify(CancellationToken cancel = default(CancellationToken)); + + /// + /// Gets the version number of the repo. + /// + /// + /// Is used to stop the task. When cancelled, the is raised. + /// + /// + /// A task that represents the asynchronous operation. The task's result is + /// the version number of the data block repository. + /// + Task Version(CancellationToken cancel = default(CancellationToken)); + } +} diff --git a/src/CoreApi/ICoreApi.cs b/src/CoreApi/ICoreApi.cs index c59606d..1ca5a57 100644 --- a/src/CoreApi/ICoreApi.cs +++ b/src/CoreApi/ICoreApi.cs @@ -27,7 +27,15 @@ public interface ICoreApi /// /// An object that implements . /// - IBlockApi Block { get; } + IBlockApi Block { get; } + + /// + /// Provides access to the Block Repository API. + /// + /// + /// An object that implements . + /// + IBlockRepositoryApi BlockRepository { get; } /// /// Provides access to the Bootstrap API. diff --git a/src/CoreApi/IStatsApi.cs b/src/CoreApi/IStatsApi.cs index d1844bf..8dd1612 100644 --- a/src/CoreApi/IStatsApi.cs +++ b/src/CoreApi/IStatsApi.cs @@ -38,15 +38,19 @@ public interface IStatsApi Task BitswapAsync(CancellationToken cancel = default(CancellationToken)); /// - /// Get statistics on repository. + /// Get statistics on the repository. /// /// /// Is used to stop the task. When cancelled, the is raised. /// /// /// A task that represents the asynchronous operation. The task's result is - /// the current . + /// the current . /// + /// + /// Same as . + /// + /// Task RepositoryAsync(CancellationToken cancel = default(CancellationToken)); } } diff --git a/src/CoreApi/RepositoryData.cs b/src/CoreApi/RepositoryData.cs index 82f069c..8933b8e 100644 --- a/src/CoreApi/RepositoryData.cs +++ b/src/CoreApi/RepositoryData.cs @@ -12,26 +12,41 @@ public class RepositoryData /// /// The number of blocks in the repository. /// + /// + /// The number of blocks in the repository. + /// public ulong NumObjects; /// /// The total number bytes in the repository. /// + /// + /// The total number bytes in the repository. + /// public ulong RepoSize; /// /// The fully qualified path to the repository. /// + /// + /// The directory of the repository. + /// public string RepoPath; /// /// The version number of the repository. /// + /// + /// The version number of the repository. + /// public string Version; /// - /// The maximum number of bytes of the repository. + /// The maximum number of bytes allowed in the repository. /// + /// + /// Max bytes allowed in the repository. + /// public ulong StorageMax; }