Skip to content

Commit

Permalink
merge hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Sep 25, 2022
2 parents 6fd13f2 + 921cf33 commit d2f84f0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task<string> BuyPostageBatchAsync(long amount, int depth, string? l
Status.HeartbeatTimeStamp,
Status.IsAlive,
Status.PinnedHashes,
(Status.PostageBatchesId ?? Array.Empty<string>()).Append(batchId).ToArray());
(Status.PostageBatchesId ?? Array.Empty<string>()).Append(batchId).ToHashSet());
}
finally
{
Expand All @@ -98,6 +98,25 @@ public async Task<bool> IsPinningResourceAsync(string hash)
}
}

public async Task NotifyPinnedResourceAsync(string hash)
{
//immediately add the pin to the node
await statusRefreshSemaphore.WaitAsync();
try
{
Status = new BeeNodeStatus(
Status.Errors,
Status.HeartbeatTimeStamp,
Status.IsAlive,
(Status.PinnedHashes ?? Array.Empty<string>()).Append(hash).ToHashSet(),
Status.PostageBatchesId);
}
finally
{
statusRefreshSemaphore.Release();
}
}

public async Task PinResourceAsync(string hash)
{
_inProgressPins.TryAdd(hash, false);
Expand Down
15 changes: 15 additions & 0 deletions src/BeehiveManager/Areas/Api/Controllers/NodesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ public Task<BeeNodeDto> RegisterAsync(
[Required] BeeNodeInput nodeInput) =>
service.AddBeeNodeAsync(nodeInput);

/// <summary>
/// Notify live manager of pinned content during upload
/// </summary>
/// <param name="id">Id of the bee node</param>
/// <param name="hash">Resource hash</param>
[HttpPost("{id}/pins/{hash}/uploaded")]
[SimpleExceptionFilter]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public Task NotifyPinningOfUploadedContentAsync(
[Required] string id,
[Required] string hash) =>
service.NotifyPinningOfUploadedContentAsync(id, hash);

// Put.

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface INodesControllerService
Task<IEnumerable<string>> GetPinsByNodeAsync(string id);
Task<PostageBatchDto> GetPostageBatchDetailsAsync(string id, string batchId);
Task<IEnumerable<PostageBatchDto>> GetPostageBatchesByNodeAsync(string id);
Task NotifyPinningOfUploadedContentAsync(string id, string hash);
Task RemoveBeeNodeAsync(string id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public async Task<IEnumerable<PostageBatchDto>> GetPostageBatchesByNodeAsync(str
return batches.Select(b => new PostageBatchDto(b));
}

public async Task NotifyPinningOfUploadedContentAsync(string id, string hash)
{
var beeNodeInstance = await beeNodeLiveManager.GetBeeNodeLiveInstanceAsync(id);
await beeNodeInstance.NotifyPinnedResourceAsync(hash);
}

public async Task RemoveBeeNodeAsync(string id)
{
if (id is null)
Expand Down

0 comments on commit d2f84f0

Please sign in to comment.