From e7f2734efa82ddce605a570bc097c93df627e685 Mon Sep 17 00:00:00 2001 From: Acha Bill <57879913+acha-bill@users.noreply.github.com> Date: Mon, 23 Sep 2024 04:28:28 -0400 Subject: [PATCH] feat: specify retrieval redundancy level via api (#4814) --- openapi/Swarm.yaml | 4 +++- pkg/api/bzz.go | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/openapi/Swarm.yaml b/openapi/Swarm.yaml index e9ef6b840a4..98afdaa4d34 100644 --- a/openapi/Swarm.yaml +++ b/openapi/Swarm.yaml @@ -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" @@ -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" @@ -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" diff --git a/pkg/api/bzz.go b/pkg/api/bzz.go index 559ce652c43..a07f3f0f54f 100644 --- a/pkg/api/bzz.go +++ b/pkg/api/bzz.go @@ -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 { @@ -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 @@ -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 { @@ -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