uplink/storage/segments: non-functional improvements (#3400)
* uplink/storage/streams: Remove unused field of struct Remove an unused field from a struct type because it isn't used. * uplink/storage/streams: Add end period in func doc Add missing end period in some functions documentation comments for following conventions. * uplink/storage/segments: Replace switch by if Replace the switch statement of 2 branches one with a condition which returns and the second is the default by a if conditional because it's easy to read.
This commit is contained in:
parent
6354b38849
commit
14e661a1b0
@ -158,48 +158,43 @@ func (s *segmentStore) Ranger(
|
||||
) (rr ranger.Ranger, err error) {
|
||||
defer mon.Task()(&ctx, info, limits, objectRS)(&err)
|
||||
|
||||
switch {
|
||||
// no order limits also means its inline segment
|
||||
case len(info.EncryptedInlineData) != 0 || len(limits) == 0:
|
||||
if len(info.EncryptedInlineData) != 0 || len(limits) == 0 {
|
||||
return ranger.ByteRanger(info.EncryptedInlineData), nil
|
||||
default:
|
||||
needed := CalcNeededNodes(objectRS)
|
||||
selected := make([]*pb.AddressedOrderLimit, len(limits))
|
||||
s.rngMu.Lock()
|
||||
perm := s.rng.Perm(len(limits))
|
||||
s.rngMu.Unlock()
|
||||
|
||||
for _, i := range perm {
|
||||
limit := limits[i]
|
||||
if limit == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
selected[i] = limit
|
||||
|
||||
needed--
|
||||
if needed <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fc, err := infectious.NewFEC(int(objectRS.RequiredShares), int(objectRS.TotalShares))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
es := eestream.NewRSScheme(fc, int(objectRS.ShareSize))
|
||||
redundancy, err := eestream.NewRedundancyStrategy(es, int(objectRS.RepairShares), int(objectRS.OptimalShares))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rr, err = s.ec.Get(ctx, selected, info.PiecePrivateKey, redundancy, info.Size)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
||||
return rr, nil
|
||||
}
|
||||
|
||||
needed := CalcNeededNodes(objectRS)
|
||||
selected := make([]*pb.AddressedOrderLimit, len(limits))
|
||||
s.rngMu.Lock()
|
||||
perm := s.rng.Perm(len(limits))
|
||||
s.rngMu.Unlock()
|
||||
|
||||
for _, i := range perm {
|
||||
limit := limits[i]
|
||||
if limit == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
selected[i] = limit
|
||||
|
||||
needed--
|
||||
if needed <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fc, err := infectious.NewFEC(int(objectRS.RequiredShares), int(objectRS.TotalShares))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
es := eestream.NewRSScheme(fc, int(objectRS.ShareSize))
|
||||
redundancy, err := eestream.NewRedundancyStrategy(es, int(objectRS.RepairShares), int(objectRS.OptimalShares))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rr, err = s.ec.Get(ctx, selected, info.PiecePrivateKey, redundancy, info.Size)
|
||||
return rr, Error.Wrap(err)
|
||||
}
|
||||
|
||||
// Delete requests the satellite to delete a segment and tells storage nodes
|
||||
|
@ -378,7 +378,6 @@ func (s *streamStore) Get(ctx context.Context, path Path, pathCipher storj.Ciphe
|
||||
streamID: object.StreamID,
|
||||
segmentIndex: int32(i),
|
||||
rs: object.RedundancyScheme,
|
||||
m: streamMeta.LastSegmentMeta,
|
||||
size: stream.SegmentsSize,
|
||||
derivedKey: derivedKey,
|
||||
startingNonce: &contentNonce,
|
||||
@ -618,7 +617,6 @@ type lazySegmentRanger struct {
|
||||
streamID storj.StreamID
|
||||
segmentIndex int32
|
||||
rs storj.RedundancyScheme
|
||||
m *pb.SegmentMeta
|
||||
size int64
|
||||
derivedKey *storj.Key
|
||||
startingNonce *storj.Nonce
|
||||
@ -626,12 +624,12 @@ type lazySegmentRanger struct {
|
||||
cipher storj.CipherSuite
|
||||
}
|
||||
|
||||
// Size implements Ranger.Size
|
||||
// Size implements Ranger.Size.
|
||||
func (lr *lazySegmentRanger) Size() int64 {
|
||||
return lr.size
|
||||
}
|
||||
|
||||
// Range implements Ranger.Range to be lazily connected
|
||||
// Range implements Ranger.Range to be lazily connected.
|
||||
func (lr *lazySegmentRanger) Range(ctx context.Context, offset, length int64) (_ io.ReadCloser, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
if lr.ranger == nil {
|
||||
@ -659,7 +657,7 @@ func (lr *lazySegmentRanger) Range(ctx context.Context, offset, length int64) (_
|
||||
return lr.ranger.Range(ctx, offset, length)
|
||||
}
|
||||
|
||||
// decryptRanger returns a decrypted ranger of the given rr ranger
|
||||
// decryptRanger returns a decrypted ranger of the given rr ranger.
|
||||
func decryptRanger(ctx context.Context, rr ranger.Ranger, decryptedSize int64, cipher storj.CipherSuite, derivedKey *storj.Key, encryptedKey storj.EncryptedPrivateKey, encryptedKeyNonce, startingNonce *storj.Nonce, encBlockSize int) (decrypted ranger.Ranger, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
contentKey, err := encryption.DecryptKey(encryptedKey, cipher, derivedKey, encryptedKeyNonce)
|
||||
|
Loading…
Reference in New Issue
Block a user