Skip to content

Commit

Permalink
Remove support for optional rootHash parameter in get chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Oct 27, 2024
1 parent d5595c6 commit 1ffa442
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 86 deletions.
4 changes: 0 additions & 4 deletions src/BeeNet.Client/BeeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ public async Task<ChequebookCheque> GetChequebookChequeForPeerAsync(
public async Task<SwarmChunk> GetChunkAsync(
SwarmHash hash,
int maxRetryAttempts = 10,
SwarmHash? rootHash = null,
bool? swarmCache = null,
long? swarmActTimestamp = null,
string? swarmActPublisher = null,
Expand All @@ -500,7 +499,6 @@ public async Task<SwarmChunk> GetChunkAsync(
using var stream = await GetChunkStreamAsync(
(string)hash,
maxRetryAttempts,
rootHash,
swarmCache,
swarmActTimestamp,
swarmActPublisher,
Expand All @@ -515,7 +513,6 @@ public async Task<SwarmChunk> GetChunkAsync(
public async Task<Stream> GetChunkStreamAsync(
SwarmHash hash,
int maxRetryAttempts = 10,
SwarmHash? rootHash = null,
bool? swarmCache = null,
long? swarmActTimestamp = null,
string? swarmActPublisher = null,
Expand All @@ -529,7 +526,6 @@ public async Task<Stream> GetChunkStreamAsync(
{
return (await generatedClient.ChunksGetAsync(
hash.ToString(),
i == 0 ? rootHash?.ToString() : null, //use rootHash only for first attempt
swarmCache,
swarmActTimestamp,
swarmActPublisher,
Expand Down
12 changes: 2 additions & 10 deletions src/BeeNet.Client/Clients/BeeGeneratedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,12 @@ internal partial interface IBeeGeneratedClient
/// Get chunk
/// </summary>
/// <param name="reference">Swarm address of chunk</param>
/// <param name="rootHash">Optional root hash to route the request</param>
/// <param name="swarm_act_timestamp">ACT history Unix timestamp</param>
/// <param name="swarm_act_publisher">ACT content publisher's public key</param>
/// <param name="swarm_act_history_address">ACT history reference address</param>
/// <returns>Retrieved chunk content</returns>
/// <exception cref="BeeNetApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<FileResponse> ChunksGetAsync(string reference, string? rootHash = null, object? swarm_cache = null, long? swarm_act_timestamp = null, string? swarm_act_publisher = null, string? swarm_act_history_address = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
System.Threading.Tasks.Task<FileResponse> ChunksGetAsync(string reference, object? swarm_cache = null, long? swarm_act_timestamp = null, string? swarm_act_publisher = null, string? swarm_act_history_address = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
Expand Down Expand Up @@ -5272,13 +5271,12 @@ public string BaseUrl
/// Get chunk
/// </summary>
/// <param name="reference">Swarm address of chunk</param>
/// <param name="rootHash">Optional root hash to route the request</param>
/// <param name="swarm_act_timestamp">ACT history Unix timestamp</param>
/// <param name="swarm_act_publisher">ACT content publisher's public key</param>
/// <param name="swarm_act_history_address">ACT history reference address</param>
/// <returns>Retrieved chunk content</returns>
/// <exception cref="BeeNetApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<FileResponse> ChunksGetAsync(string reference, string? rootHash = null, object? swarm_cache = null, long? swarm_act_timestamp = null, string? swarm_act_publisher = null, string? swarm_act_history_address = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public virtual async System.Threading.Tasks.Task<FileResponse> ChunksGetAsync(string reference, object? swarm_cache = null, long? swarm_act_timestamp = null, string? swarm_act_publisher = null, string? swarm_act_history_address = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
if (reference == null)
throw new System.ArgumentNullException("reference");
Expand Down Expand Up @@ -5309,12 +5307,6 @@ public string BaseUrl
// Operation Path: "chunks/{reference}"
urlBuilder_.Append("chunks/");
urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(reference, System.Globalization.CultureInfo.InvariantCulture)));
urlBuilder_.Append('?');
if (rootHash != null)
{
urlBuilder_.Append(System.Uri.EscapeDataString("rootHash")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(rootHash, System.Globalization.CultureInfo.InvariantCulture))).Append('&');
}
urlBuilder_.Length--;

PrepareRequest(client_, request_, urlBuilder_);

Expand Down
16 changes: 4 additions & 12 deletions src/BeeNet.Util/Hashing/Store/BeeClientChunkStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ namespace Etherna.BeeNet.Hashing.Store
public class BeeClientChunkStore(IBeeClient beeClient)
: IReadOnlyChunkStore
{
public Task<SwarmChunk> GetAsync(
SwarmHash hash,
SwarmHash? rootHash) =>
beeClient.GetChunkAsync(
hash,
rootHash: rootHash);
public Task<SwarmChunk> GetAsync(SwarmHash hash) =>
beeClient.GetChunkAsync(hash);

public async Task<SwarmChunk?> TryGetAsync(
SwarmHash hash,
SwarmHash? rootHash)
public async Task<SwarmChunk?> TryGetAsync(SwarmHash hash)
{
try
{
return await beeClient.GetChunkAsync(
hash,
rootHash: rootHash).ConfigureAwait(false);
return await beeClient.GetChunkAsync(hash).ConfigureAwait(false);
}
catch (BeeNetApiException)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BeeNet.Util/Hashing/Store/ChunkJoiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private async Task GetJoinedChunkDataHelperAsync(
CancellationToken cancellationToken)
{
// Read and decrypt chunk data.
var chunk = await chunkStore.GetAsync(chunkReference.Hash, null).ConfigureAwait(false);
var chunk = await chunkStore.GetAsync(chunkReference.Hash).ConfigureAwait(false);
var dataArray = chunk.Data.ToArray();
chunkReference.EncryptionKey?.EncryptDecrypt(dataArray);

Expand Down
4 changes: 2 additions & 2 deletions src/BeeNet.Util/Hashing/Store/FakeChunkStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ namespace Etherna.BeeNet.Hashing.Store
{
public class FakeChunkStore : IChunkStore
{
public Task<SwarmChunk> GetAsync(SwarmHash hash, SwarmHash? rootHash) =>
public Task<SwarmChunk> GetAsync(SwarmHash hash) =>
throw new KeyNotFoundException("Chunk get on a fake chunk store");

public Task<SwarmChunk?> TryGetAsync(SwarmHash hash, SwarmHash? rootHash) => Task.FromResult<SwarmChunk?>(null);
public Task<SwarmChunk?> TryGetAsync(SwarmHash hash) => Task.FromResult<SwarmChunk?>(null);

public Task<bool> AddAsync(SwarmChunk chunk) => Task.FromResult(true);
}
Expand Down
8 changes: 2 additions & 6 deletions src/BeeNet.Util/Hashing/Store/IReadOnlyChunkStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ namespace Etherna.BeeNet.Hashing.Store
{
public interface IReadOnlyChunkStore
{
public Task<SwarmChunk> GetAsync(
SwarmHash hash,
SwarmHash? rootHash);
public Task<SwarmChunk> GetAsync(SwarmHash hash);

public Task<SwarmChunk?> TryGetAsync(
SwarmHash hash,
SwarmHash? rootHash);
public Task<SwarmChunk?> TryGetAsync(SwarmHash hash);
}
}
6 changes: 3 additions & 3 deletions src/BeeNet.Util/Hashing/Store/LocalDirectoryChunkStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public Task<IEnumerable<SwarmHash>> GetAllHashesAsync()
return Task.FromResult<IEnumerable<SwarmHash>>(hashes);
}

public async Task<SwarmChunk> GetAsync(SwarmHash hash, SwarmHash? rootHash)
public async Task<SwarmChunk> GetAsync(SwarmHash hash)
{
var chunk = await TryGetAsync(hash, rootHash).ConfigureAwait(false);
var chunk = await TryGetAsync(hash).ConfigureAwait(false);
if (chunk is null)
throw new KeyNotFoundException($"Chunk {hash} doesnt' exist");
return chunk;
}

public async Task<SwarmChunk?> TryGetAsync(SwarmHash hash, SwarmHash? rootHash)
public async Task<SwarmChunk?> TryGetAsync(SwarmHash hash)
{
var chunkPath = Path.Combine(DirectoryPath, hash + ChunkFileExtension);

Expand Down
2 changes: 0 additions & 2 deletions src/BeeNet.Util/IBeeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ Task<ChequebookCheque> GetChequebookChequeForPeerAsync(
Task<SwarmChunk> GetChunkAsync(
SwarmHash hash,
int maxRetryAttempts = 10,
SwarmHash? rootHash = null,
bool? swarmCache = null,
long? swarmActTimestamp = null,
string? swarmActPublisher = null,
Expand All @@ -343,7 +342,6 @@ Task<SwarmChunk> GetChunkAsync(
Task<Stream> GetChunkStreamAsync(
SwarmHash hash,
int maxRetryAttempts = 10,
SwarmHash? rootHash = null,
bool? swarmCache = null,
long? swarmActTimestamp = null,
string? swarmActPublisher = null,
Expand Down
2 changes: 1 addition & 1 deletion src/BeeNet.Util/Manifest/ReferencedMantarayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task DecodeFromChunkAsync(SwarmHash manifestHash)
if (IsDecoded)
return;

var chunk = await chunkStore.GetAsync(Hash, rootHash: manifestHash).ConfigureAwait(false);
var chunk = await chunkStore.GetAsync(Hash).ConfigureAwait(false);

var data = chunk.Data.ToArray();
var readIndex = 0;
Expand Down
Loading

0 comments on commit 1ffa442

Please sign in to comment.