[#1793] node/netmap: Change interface of the latest network map reader

Replace `ProcessCurrentNetMap` method of `NodeState` interface with
`ReadCurrentNetMap` one with two changes:
 * Replace network map type from NeoFS SDK package with the
   protocol-generated message. This replaces all the business logic to
   the application layer.
 * Support error return. This allows to cover problem node states.

Return an error from `NodeState.ReadCurrentNetMap` method implemeted
through `atomic.Value` if `Store` method has not been called yet.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-09-26 10:31:44 +04:00 committed by fyrchik
parent 485a5418d2
commit 93742d37b7
2 changed files with 24 additions and 10 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"fmt"
"net"
"path/filepath"
@ -140,8 +141,19 @@ type cfg struct {
netMap atomicstd.Value // type netmap.NetMap
}
func (c *cfg) ProcessCurrentNetMap(f func(netmap.NetMap)) {
f(c.netMap.Load().(netmap.NetMap))
// ReadCurrentNetMap reads network map which has been cached at the
// latest epoch. Returns an error if value has not been cached yet.
//
// Provides interface for NetmapService server.
func (c *cfg) ReadCurrentNetMap(msg *netmapV2.NetMap) error {
val := c.netMap.Load()
if val == nil {
return errors.New("missing local network map")
}
val.(netmap.NetMap).WriteToV2(msg)
return nil
}
type cfgGRPC struct {