forked from TrueCloudLab/frostfs-node
[#1133] services/session: remove expired tokens every epoch
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
b3b3b8b20f
commit
0695ec4125
2 changed files with 17 additions and 0 deletions
|
@ -2,6 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||
sessionTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/session/grpc"
|
||||
sessionSvc "github.com/nspcc-dev/neofs-node/pkg/services/session"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
|
||||
|
@ -9,6 +11,9 @@ import (
|
|||
|
||||
func initSessionService(c *cfg) {
|
||||
c.privateTokenStore = storage.New()
|
||||
addNewEpochNotificationHandler(c, func(ev event.Event) {
|
||||
c.privateTokenStore.RemoveOld(ev.(netmap.NewEpoch).EpochNumber())
|
||||
})
|
||||
|
||||
server := sessionTransportGRPC.New(
|
||||
sessionSvc.NewSignService(
|
||||
|
|
|
@ -49,3 +49,15 @@ func (s *TokenStore) Get(ownerID *owner.ID, tokenID []byte) *PrivateToken {
|
|||
|
||||
return t
|
||||
}
|
||||
|
||||
// RemoveOld removes all tokens expired since provided epoch.
|
||||
func (s *TokenStore) RemoveOld(epoch uint64) {
|
||||
s.mtx.Lock()
|
||||
defer s.mtx.Unlock()
|
||||
|
||||
for k, tok := range s.tokens {
|
||||
if tok.ExpiredAt() <= epoch {
|
||||
delete(s.tokens, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue