[#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:
Alexey Vanin 2022-09-01 15:46:29 +03:00 committed by Kira
parent 70eec56f8a
commit fa2bcf198f
2 changed files with 18 additions and 3 deletions

View file

@ -4,6 +4,9 @@ This document outlines major changes between releases.
## [Unreleased]
### Fixed
- Fix expiration epoch calculation (#62)
### Changed
- Update go version for build to 1.19 (#61)

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"
"strconv"
"time"
@ -153,9 +154,20 @@ func prepareExpirationHeader(headers map[string]string, epochDurations *epochDur
}
func updateExpirationHeader(headers map[string]string, durations *epochDurations, expDuration time.Duration) {
epochDuration := durations.msPerBlock * int64(durations.blockPerEpoch)
numEpoch := expDuration.Milliseconds() / epochDuration
headers[objectv2.SysAttributeExpEpoch] = strconv.FormatInt(int64(durations.currentEpoch)+numEpoch, 10)
epochDuration := uint64(durations.msPerBlock) * durations.blockPerEpoch
currentEpoch := durations.currentEpoch
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.