forked from TrueCloudLab/frostfs-node
[#316] ir: Use LOCODE validator as NodeValidator in Netmap processor
Implement DB interface required by LOCODE validator on new wrapper over the LOCODE Bolt DB (Record on new wrapper over LOCODE Bolt DB entries). Construct LOCODE validator and pass it to Netmap processor's constructor as NodeValidator parameter. Thus, candidates for a network map must set LOCODE attribute for which there is an entry in the NeoFS location database. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
ff814aec26
commit
97264acb26
2 changed files with 57 additions and 0 deletions
|
@ -373,6 +373,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
settlement.WithLogger(server.log),
|
||||
)
|
||||
|
||||
locodeValidator, err := server.newLocodeValidator(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create netmap processor
|
||||
netmapProcessor, err := netmap.New(&netmap.Params{
|
||||
Log: log,
|
||||
|
@ -391,6 +396,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
AuditSettlementsHandler: server.onlyActiveEventHandler(
|
||||
settlementProcessor.HandleAuditEvent,
|
||||
),
|
||||
NodeValidator: locodeValidator,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
51
pkg/innerring/locode.go
Normal file
51
pkg/innerring/locode.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package innerring
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap"
|
||||
irlocode "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/locode"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/locode"
|
||||
locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db"
|
||||
locodebolt "github.com/nspcc-dev/neofs-node/pkg/util/locode/db/boltdb"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func (s *Server) newLocodeValidator(cfg *viper.Viper) (netmap.NodeValidator, error) {
|
||||
locodeDB := locodebolt.New(locodebolt.Prm{
|
||||
Path: cfg.GetString("locode.db.path"),
|
||||
})
|
||||
|
||||
s.registerStarter(locodeDB.Open)
|
||||
s.registerIOCloser(locodeDB)
|
||||
|
||||
return irlocode.New(irlocode.Prm{
|
||||
DB: (*locodeBoltDBWrapper)(locodeDB),
|
||||
}), nil
|
||||
}
|
||||
|
||||
type locodeBoltEntryWrapper struct {
|
||||
*locodedb.Key
|
||||
*locodedb.Record
|
||||
}
|
||||
|
||||
func (l *locodeBoltEntryWrapper) LocationName() string {
|
||||
return l.Record.CityName()
|
||||
}
|
||||
|
||||
type locodeBoltDBWrapper locodebolt.DB
|
||||
|
||||
func (l *locodeBoltDBWrapper) Get(lc *locode.LOCODE) (irlocode.Record, error) {
|
||||
key, err := locodedb.NewKey(*lc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rec, err := (*locodebolt.DB)(l).Get(*key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &locodeBoltEntryWrapper{
|
||||
Key: key,
|
||||
Record: rec,
|
||||
}, nil
|
||||
}
|
Loading…
Reference in a new issue