Skip to content

Commit

Permalink
feat: implement IBlockRepository #40
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed May 29, 2019
1 parent 4b4eceb commit ae56cf6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/articles/core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions src/CoreApi/IBlockApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Ipfs.CoreApi
/// "blocks" in <see cref="IBitswapApi">Bitswap</see>
/// and other things that do not care about what is being stored.
/// </remarks>
/// <seealso cref="IBlockRepositoryApi"/>
/// <seealso href="https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md">Block API spec</seealso>
public interface IBlockApi
{
Expand Down
64 changes: 64 additions & 0 deletions src/CoreApi/IBlockRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Ipfs.CoreApi
{
/// <summary>
/// Manages all the blocks stored locally.
/// </summary>
/// <seealso cref="IBlockApi"/>
public interface IBlockRepositoryApi
{
/// <summary>
/// Perform a garbage collection sweep on the repo.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// TODO: not sure what this should return.
/// </returns>
Task RemoveGarage(CancellationToken cancel = default(CancellationToken));

/// <summary>
/// Get statistics on the repository.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's result is
/// the current <see cref="RepositoryData"/>.
/// </returns>
/// <remarks>
/// Same as <see cref="IStatsApi.RepositoryAsync(CancellationToken)"/>.
/// </remarks>
Task<RepositoryData> Statistics(CancellationToken cancel = default(CancellationToken));

/// <summary>
/// Verify all blocks in repo are not corrupted.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// TODO: not sure what this should return.
/// </returns>
Task Verify(CancellationToken cancel = default(CancellationToken));

/// <summary>
/// Gets the version number of the repo.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's result is
/// the version number of the data block repository.
/// </returns>
Task<string> Version(CancellationToken cancel = default(CancellationToken));
}
}
10 changes: 9 additions & 1 deletion src/CoreApi/ICoreApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ public interface ICoreApi
/// <value>
/// An object that implements <see cref="IBlockApi"/>.
/// </value>
IBlockApi Block { get; }
IBlockApi Block { get; }

/// <summary>
/// Provides access to the Block Repository API.
/// </summary>
/// <value>
/// An object that implements <see cref="IBlockRepositoryApi"/>.
/// </value>
IBlockRepositoryApi BlockRepository { get; }

/// <summary>
/// Provides access to the Bootstrap API.
Expand Down
8 changes: 6 additions & 2 deletions src/CoreApi/IStatsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ public interface IStatsApi
Task<BitswapData> BitswapAsync(CancellationToken cancel = default(CancellationToken));

/// <summary>
/// Get statistics on repository.
/// Get statistics on the repository.
/// </summary>
/// <param name="cancel">
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
/// </param>
/// <returns>
/// A task that represents the asynchronous operation. The task's result is
/// the current <see cref="BandwidthData"/>.
/// the current <see cref="RepositoryData"/>.
/// </returns>
/// <remarks>
/// Same as <see cref="IBlockRepositoryApi.Statistics(CancellationToken)"/>.
/// </remarks>
/// <seealso cref="IBlockRepositoryApi"/>
Task<RepositoryData> RepositoryAsync(CancellationToken cancel = default(CancellationToken));
}
}
17 changes: 16 additions & 1 deletion src/CoreApi/RepositoryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,41 @@ public class RepositoryData
/// <summary>
/// The number of blocks in the repository.
/// </summary>
/// <value>
/// The number of blocks in the <see cref="IBlockRepositoryApi">repository</see>.
/// </value>
public ulong NumObjects;

/// <summary>
/// The total number bytes in the repository.
/// </summary>
/// <value>
/// The total number bytes in the <see cref="IBlockRepositoryApi">repository</see>.
/// </value>
public ulong RepoSize;

/// <summary>
/// The fully qualified path to the repository.
/// </summary>
/// <value>
/// The directory of the <see cref="IBlockRepositoryApi">repository</see>.
/// </value>
public string RepoPath;

/// <summary>
/// The version number of the repository.
/// </summary>
/// <value>
/// The version number of the <see cref="IBlockRepositoryApi">repository</see>.
/// </value>
public string Version;

/// <summary>
/// The maximum number of bytes of the repository.
/// The maximum number of bytes allowed in the repository.
/// </summary>
/// <value>
/// Max bytes allowed in the <see cref="IBlockRepositoryApi">repository</see>.
/// </value>
public ulong StorageMax;

}
Expand Down

0 comments on commit ae56cf6

Please sign in to comment.