[#62] Fix expiration epoch calculation
Previous implementation does not provide 'at least' lifetime guarantee. Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
70eec56f8a
commit
fa2bcf198f
2 changed files with 18 additions and 3 deletions
|
@ -4,6 +4,9 @@ This document outlines major changes between releases.
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix expiration epoch calculation (#62)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Update go version for build to 1.19 (#61)
|
- Update go version for build to 1.19 (#61)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -153,9 +154,20 @@ func prepareExpirationHeader(headers map[string]string, epochDurations *epochDur
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateExpirationHeader(headers map[string]string, durations *epochDurations, expDuration time.Duration) {
|
func updateExpirationHeader(headers map[string]string, durations *epochDurations, expDuration time.Duration) {
|
||||||
epochDuration := durations.msPerBlock * int64(durations.blockPerEpoch)
|
epochDuration := uint64(durations.msPerBlock) * durations.blockPerEpoch
|
||||||
numEpoch := expDuration.Milliseconds() / epochDuration
|
currentEpoch := durations.currentEpoch
|
||||||
headers[objectv2.SysAttributeExpEpoch] = strconv.FormatInt(int64(durations.currentEpoch)+numEpoch, 10)
|
numEpoch := uint64(expDuration.Milliseconds()) / epochDuration
|
||||||
|
|
||||||
|
if uint64(expDuration.Milliseconds())%epochDuration != 0 {
|
||||||
|
numEpoch++
|
||||||
|
}
|
||||||
|
|
||||||
|
expirationEpoch := uint64(math.MaxUint64)
|
||||||
|
if numEpoch < math.MaxUint64-currentEpoch {
|
||||||
|
expirationEpoch = currentEpoch + numEpoch
|
||||||
|
}
|
||||||
|
|
||||||
|
headers[objectv2.SysAttributeExpEpoch] = strconv.FormatUint(expirationEpoch, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsObjectToken check that provided token is for object.
|
// IsObjectToken check that provided token is for object.
|
||||||
|
|
Reference in a new issue