2020-08-24 14:07:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-02-01 11:59:35 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
apiClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2021-02-01 11:21:24 +00:00
|
|
|
containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2020-08-24 14:07:08 +00:00
|
|
|
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
2020-09-24 07:46:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
2020-08-24 14:07:08 +00:00
|
|
|
containerTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc"
|
|
|
|
containerService "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
2021-02-01 11:59:35 +00:00
|
|
|
loadcontroller "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/controller"
|
2020-08-24 14:07:08 +00:00
|
|
|
containerMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph"
|
2021-02-01 11:21:24 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
|
|
"go.uber.org/zap"
|
2020-08-24 14:07:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func initContainerService(c *cfg) {
|
2020-09-16 07:45:08 +00:00
|
|
|
staticClient, err := client.NewStatic(
|
|
|
|
c.cfgMorph.client,
|
|
|
|
c.cfgContainer.scriptHash,
|
|
|
|
c.cfgContainer.fee,
|
|
|
|
)
|
2020-08-24 14:07:08 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
cnrClient, err := container.New(staticClient)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
2020-09-24 07:46:47 +00:00
|
|
|
wrap, err := wrapper.New(cnrClient)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
c.cfgObject.cnrStorage = wrap // use RPC node as source of containers
|
2020-10-03 07:46:57 +00:00
|
|
|
c.cfgObject.cnrClient = wrap
|
2020-09-24 07:46:47 +00:00
|
|
|
|
2020-08-24 14:07:08 +00:00
|
|
|
containerGRPC.RegisterContainerServiceServer(c.cfgGRPC.server,
|
|
|
|
containerTransportGRPC.New(
|
|
|
|
containerService.NewSignService(
|
|
|
|
c.key,
|
2020-10-22 11:07:06 +00:00
|
|
|
containerService.NewResponseService(
|
|
|
|
containerService.NewExecutionService(
|
|
|
|
containerMorph.NewExecutor(cnrClient),
|
|
|
|
),
|
|
|
|
c.respSvc,
|
2020-08-24 14:07:08 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
2021-02-01 11:21:24 +00:00
|
|
|
|
|
|
|
type morphLoadWriter struct {
|
|
|
|
log *logger.Logger
|
|
|
|
|
|
|
|
cnrMorphClient *wrapper.Wrapper
|
|
|
|
|
|
|
|
key []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *morphLoadWriter) Put(a containerSDK.UsedSpaceAnnouncement) error {
|
|
|
|
w.log.Debug("save used space announcement in contract",
|
|
|
|
zap.Uint64("epoch", a.Epoch()),
|
|
|
|
zap.Stringer("cid", a.ContainerID()),
|
|
|
|
zap.Uint64("size", a.UsedSpace()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return w.cnrMorphClient.AnnounceLoad(a, w.key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*morphLoadWriter) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
2021-02-01 11:59:35 +00:00
|
|
|
|
|
|
|
type remoteLoadAnnounceWriterProvider struct {
|
|
|
|
client *apiClient.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *remoteLoadAnnounceWriterProvider) InitWriter(ctx context.Context) (loadcontroller.Writer, error) {
|
|
|
|
return &remoteLoadAnnounceWriter{
|
|
|
|
ctx: ctx,
|
|
|
|
client: p.client,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type remoteLoadAnnounceWriter struct {
|
|
|
|
ctx context.Context
|
|
|
|
|
|
|
|
client *apiClient.Client
|
|
|
|
|
|
|
|
buf []containerSDK.UsedSpaceAnnouncement
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remoteLoadAnnounceWriter) Put(a containerSDK.UsedSpaceAnnouncement) error {
|
|
|
|
r.buf = append(r.buf, a)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remoteLoadAnnounceWriter) Close() error {
|
|
|
|
return r.client.AnnounceContainerUsedSpace(r.ctx, r.buf)
|
|
|
|
}
|