diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index ac3ed7bd..25c66b6d 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -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 { diff --git a/pkg/services/netmap/executor.go b/pkg/services/netmap/executor.go index c4453327..b9989e91 100644 --- a/pkg/services/netmap/executor.go +++ b/pkg/services/netmap/executor.go @@ -27,9 +27,10 @@ type NodeState interface { // in NeoFS API v2 NodeInfo structure. LocalNodeInfo() (*netmap.NodeInfo, error) - // ProcessCurrentNetMap passes current local network map of the storage node - // into the given handler. - ProcessCurrentNetMap(func(netmapSDK.NetMap)) + // ReadCurrentNetMap reads current local network map of the storage node + // into the given parameter. Returns any error encountered which prevented + // the network map to be read. + ReadCurrentNetMap(*netmap.NetMap) error } // NetworkInfo encapsulates source of the @@ -129,14 +130,15 @@ func (s *executorSvc) NetworkInfo( } func (s *executorSvc) Snapshot(_ context.Context, req *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error) { - var nmV2 netmap.NetMap + var nm netmap.NetMap - s.state.ProcessCurrentNetMap(func(netMap netmapSDK.NetMap) { - netMap.WriteToV2(&nmV2) - }) + err := s.state.ReadCurrentNetMap(&nm) + if err != nil { + return nil, fmt.Errorf("read current local network map: %w", err) + } body := new(netmap.SnapshotResponseBody) - body.SetNetMap(&nmV2) + body.SetNetMap(&nm) resp := new(netmap.SnapshotResponse) resp.SetBody(body)