Skip to content

Commit

Permalink
refactor: reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Dec 20, 2023
1 parent 8e3837c commit 2521f8a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *Service) bzzUploadHandler(w http.ResponseWriter, r *http.Request) {
}

if headers.IsDir || headers.ContentType == multiPartFormData {
s.dirUploadHandler(logger, ow, r, putter, r.Header.Get(ContentTypeHeader), headers.Encrypt, tag)
s.dirUploadHandler(logger, ow, r, putter, r.Header.Get(ContentTypeHeader), headers.Encrypt, tag, headers.RLevel)
return
}
s.fileUploadHandler(logger, ow, r, putter, headers.Encrypt, tag, headers.RLevel)
Expand Down
11 changes: 1 addition & 10 deletions pkg/api/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (s *Service) dirUploadHandler(
contentTypeString string,
encrypt bool,
tag uint64,
rLevel redundancy.Level,
) {
if r.Body == http.NoBody {
logger.Error(nil, "request has no body")
Expand All @@ -64,16 +65,6 @@ func (s *Service) dirUploadHandler(
}
defer r.Body.Close()

rLevelNum, err := strconv.ParseUint(r.Header.Get(SwarmRedundancyLevelHeader), 10, 8)
if err != nil {
logger.Debug("store directory failed", "redundancy level parsing error")
logger.Error(nil, "store directory failed")
}
rLevel, err := redundancy.NewLevel(uint8(rLevelNum))
if err != nil {
jsonhttp.BadRequest(w, err.Error())
}

reference, err := storeDir(
r.Context(),
encrypt,
Expand Down
19 changes: 6 additions & 13 deletions pkg/file/redundancy/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ const (
PARANOID
)

// NewLevel returns a Level coresponding to the passed number parameter
// throws an error if there is no level for the passed number
func NewLevel(n uint8) (Level, error) {
if n > uint8(PARANOID) {
return 0, fmt.Errorf("redundancy: number %d does not have corresponding level", n)
}
return Level(n), nil
}

// GetParities returns number of parities based on appendix F table 5
func (l Level) GetParities(shards int) int {
et, err := l.getErasureTable()
Expand All @@ -64,6 +55,8 @@ func (l Level) GetEncParities(shards int) int {

func (l Level) getErasureTable() (erasureTable, error) {
switch l {
case NONE:
return erasureTable{}, errors.New("redundancy: level NONE does not have erasure table")
case MEDIUM:
return mediumEt, nil
case STRONG:
Expand All @@ -73,12 +66,14 @@ func (l Level) getErasureTable() (erasureTable, error) {
case PARANOID:
return paranoidEt, nil
default:
return erasureTable{}, errors.New("redundancy: level NONE does not have erasure table")
return erasureTable{}, fmt.Errorf("redundancy: level value %d is not a legit redundancy level", l)
}
}

func (l Level) getEncErasureTable() (erasureTable, error) {
switch l {
case NONE:
return erasureTable{}, errors.New("redundancy: level NONE does not have erasure table")
case MEDIUM:
return encMediumEt, nil
case STRONG:
Expand All @@ -88,7 +83,7 @@ func (l Level) getEncErasureTable() (erasureTable, error) {
case PARANOID:
return encParanoidEt, nil
default:
return erasureTable{}, errors.New("redundancy: level NONE does not have erasure table")
return erasureTable{}, fmt.Errorf("redundancy: level value %d is not a legit redundancy level", l)
}
}

Expand Down Expand Up @@ -162,8 +157,6 @@ var encParanoidEt = newErasureTable(
},
)

// DISPERSED REPLICAS INIT

// GetReplicaCounts returns back the ascending dispersed replica counts for all redundancy levels
func GetReplicaCounts() [5]int {
c := replicaCounts
Expand Down

0 comments on commit 2521f8a

Please sign in to comment.