Skip to content

Commit

Permalink
feat: specify retrieval redundancy level via api (#4814)
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill authored Sep 23, 2024
1 parent 198d41f commit e7f2734
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion openapi/Swarm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.3

info:
version: 7.1.0
version: 7.1.1
title: Bee API
description: "A list of the currently provided Interfaces to interact with the swarm, implementing file operations and sending messages"

Expand Down Expand Up @@ -237,6 +237,7 @@ paths:
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmCache"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmRedundancyStrategyParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmRedundancyFallbackModeParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmRedundancyLevelParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmChunkRetrievalTimeoutParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmActTimestamp"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmActPublisher"
Expand Down Expand Up @@ -424,6 +425,7 @@ paths:
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmCache"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmRedundancyStrategyParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmRedundancyFallbackModeParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmRedundancyLevelParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmChunkRetrievalTimeoutParameter"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmActTimestamp"
- $ref: "SwarmCommon.yaml#/components/parameters/SwarmActPublisher"
Expand Down
26 changes: 17 additions & 9 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,11 @@ func (s *Service) serveReference(logger log.Logger, address swarm.Address, pathV
loggerV1 := logger.V(1).Build()

headers := struct {
Cache *bool `map:"Swarm-Cache"`
Strategy *getter.Strategy `map:"Swarm-Redundancy-Strategy"`
FallbackMode *bool `map:"Swarm-Redundancy-Fallback-Mode"`
ChunkRetrievalTimeout *string `map:"Swarm-Chunk-Retrieval-Timeout"`
Cache *bool `map:"Swarm-Cache"`
Strategy *getter.Strategy `map:"Swarm-Redundancy-Strategy"`
FallbackMode *bool `map:"Swarm-Redundancy-Fallback-Mode"`
RLevel *redundancy.Level `map:"Swarm-Redundancy-Level"`
ChunkRetrievalTimeout *string `map:"Swarm-Chunk-Retrieval-Timeout"`
}{}

if response := s.mapStructure(r.Header, &headers); response != nil {
Expand All @@ -388,6 +389,9 @@ func (s *Service) serveReference(logger log.Logger, address swarm.Address, pathV
jsonhttp.BadRequest(w, "could not parse headers")
return
}
if headers.RLevel != nil {
ctx = redundancy.SetLevelInContext(ctx, *headers.RLevel)
}

FETCH:
// read manifest entry
Expand Down Expand Up @@ -560,11 +564,12 @@ func (s *Service) serveManifestEntry(
// downloadHandler contains common logic for downloading Swarm file from API
func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *http.Request, reference swarm.Address, additionalHeaders http.Header, etag, headersOnly bool, rootCh swarm.Chunk) {
headers := struct {
Strategy *getter.Strategy `map:"Swarm-Redundancy-Strategy"`
FallbackMode *bool `map:"Swarm-Redundancy-Fallback-Mode"`
ChunkRetrievalTimeout *string `map:"Swarm-Chunk-Retrieval-Timeout"`
LookaheadBufferSize *int `map:"Swarm-Lookahead-Buffer-Size"`
Cache *bool `map:"Swarm-Cache"`
Strategy *getter.Strategy `map:"Swarm-Redundancy-Strategy"`
RLevel *redundancy.Level `map:"Swarm-Redundancy-Level"`
FallbackMode *bool `map:"Swarm-Redundancy-Fallback-Mode"`
ChunkRetrievalTimeout *string `map:"Swarm-Chunk-Retrieval-Timeout"`
LookaheadBufferSize *int `map:"Swarm-Lookahead-Buffer-Size"`
Cache *bool `map:"Swarm-Cache"`
}{}

if response := s.mapStructure(r.Header, &headers); response != nil {
Expand All @@ -583,6 +588,9 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h
jsonhttp.BadRequest(w, "could not parse headers")
return
}
if headers.RLevel != nil {
ctx = redundancy.SetLevelInContext(ctx, *headers.RLevel)
}

var (
reader file.Joiner
Expand Down

0 comments on commit e7f2734

Please sign in to comment.