2020-08-22 15:20:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-04-05 13:58:32 +00:00
|
|
|
"context"
|
2023-11-30 17:51:23 +00:00
|
|
|
"net"
|
2024-11-11 15:54:07 +00:00
|
|
|
"strings"
|
2023-04-05 13:58:32 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/balance"
|
|
|
|
accountingTransportGRPC "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network/transport/accounting/grpc"
|
|
|
|
accountingService "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/accounting"
|
|
|
|
accounting "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/accounting/morph"
|
2024-11-07 14:32:10 +00:00
|
|
|
accountingGRPC "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/accounting/grpc"
|
2023-11-30 17:51:23 +00:00
|
|
|
"google.golang.org/grpc"
|
2020-08-22 15:20:47 +00:00
|
|
|
)
|
|
|
|
|
2023-04-05 13:58:32 +00:00
|
|
|
func initAccountingService(ctx context.Context, c *cfg) {
|
2024-10-23 07:39:19 +00:00
|
|
|
c.initMorphComponents(ctx)
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2022-01-31 09:24:25 +00:00
|
|
|
balanceMorphWrapper, err := balance.NewFromMorph(c.cfgMorph.client, c.cfgAccounting.scriptHash, 0)
|
2020-09-01 14:33:26 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2024-06-26 09:37:20 +00:00
|
|
|
server := accountingTransportGRPC.New(
|
|
|
|
accountingService.NewSignService(
|
|
|
|
&c.key.PrivateKey,
|
|
|
|
accountingService.NewExecutionService(
|
|
|
|
accounting.NewExecutor(balanceMorphWrapper),
|
|
|
|
c.respSvc,
|
|
|
|
),
|
2020-08-22 15:20:47 +00:00
|
|
|
),
|
|
|
|
)
|
2021-06-22 17:25:18 +00:00
|
|
|
|
2023-11-30 17:51:23 +00:00
|
|
|
c.cfgGRPC.performAndSave(func(_ string, _ net.Listener, s *grpc.Server) {
|
|
|
|
accountingGRPC.RegisterAccountingServiceServer(s, server)
|
2024-11-11 15:54:07 +00:00
|
|
|
|
|
|
|
// TODO(@aarifullin): #1487 remove the dual service support.
|
|
|
|
s.RegisterService(frostFSServiceDesc(accountingGRPC.AccountingService_ServiceDesc), server)
|
2023-11-30 17:51:23 +00:00
|
|
|
})
|
2020-08-22 15:20:47 +00:00
|
|
|
}
|
2024-11-11 15:54:07 +00:00
|
|
|
|
|
|
|
// frostFSServiceDesc creates a service descriptor with the new namespace for dual service support.
|
|
|
|
func frostFSServiceDesc(sd grpc.ServiceDesc) *grpc.ServiceDesc {
|
|
|
|
sdLegacy := new(grpc.ServiceDesc)
|
|
|
|
*sdLegacy = sd
|
|
|
|
|
|
|
|
const (
|
|
|
|
legacyNamespace = "neo.fs.v2"
|
|
|
|
apemanagerLegacyNamespace = "frostfs.v2"
|
|
|
|
newNamespace = "frost.fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
if strings.HasPrefix(sd.ServiceName, legacyNamespace) {
|
|
|
|
sdLegacy.ServiceName = strings.ReplaceAll(sd.ServiceName, legacyNamespace, newNamespace)
|
|
|
|
} else if strings.HasPrefix(sd.ServiceName, apemanagerLegacyNamespace) {
|
|
|
|
sdLegacy.ServiceName = strings.ReplaceAll(sd.ServiceName, apemanagerLegacyNamespace, newNamespace)
|
|
|
|
}
|
|
|
|
return sdLegacy
|
|
|
|
}
|