frostfs-node/cmd/frostfs-node/session.go
Airat Arifullin b543569c3f [#1486] node: Introduce dual service support
* Register GRPC services for both neo.fs.v2 and frost.fs namespaces
* Use this temporary solution until all nodes are updated

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-11-12 08:43:47 +00:00

68 lines
2.3 KiB
Go

package main
import (
"context"
"fmt"
"net"
"time"
nodeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/node"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/netmap"
sessionTransportGRPC "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network/transport/session/grpc"
sessionSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session/storage"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session/storage/persistent"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/session/storage/temporary"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
sessionGRPC "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
"google.golang.org/grpc"
)
type sessionStorage interface {
Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error)
Get(ownerID user.ID, tokenID []byte) *storage.PrivateToken
RemoveOld(epoch uint64)
Close() error
}
func initSessionService(c *cfg) {
if persistentSessionPath := nodeconfig.PersistentSessions(c.appCfg).Path(); persistentSessionPath != "" {
persisessions, err := persistent.NewTokenStore(persistentSessionPath,
persistent.WithLogger(c.log),
persistent.WithTimeout(100*time.Millisecond),
persistent.WithEncryptionKey(&c.key.PrivateKey),
)
if err != nil {
panic(fmt.Errorf("could not create persistent session token storage: %w", err))
}
c.privateTokenStore = persisessions
} else {
c.privateTokenStore = temporary.NewTokenStore()
}
c.onShutdown(func() {
_ = c.privateTokenStore.Close()
})
addNewEpochNotificationHandler(c, func(ev event.Event) {
c.privateTokenStore.RemoveOld(ev.(netmap.NewEpoch).EpochNumber())
})
server := sessionTransportGRPC.New(
sessionSvc.NewSignService(
&c.key.PrivateKey,
sessionSvc.NewExecutionService(c.privateTokenStore, c.respSvc, c.log),
),
)
c.cfgGRPC.performAndSave(func(_ string, _ net.Listener, s *grpc.Server) {
sessionGRPC.RegisterSessionServiceServer(s, server)
// TODO(@aarifullin): #1487 remove the dual service support.
s.RegisterService(frostFSServiceDesc(sessionGRPC.SessionService_ServiceDesc), server)
})
}