From c77d346016f38806575d7d08cddca46e7a0de7af Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 25 Jan 2021 11:02:20 +0300 Subject: [PATCH] [#339] services/netmap: Use dynamic node information Replace static NodeInfo structure with NodeState interface that provides method to read node information in runtime. Signed-off-by: Leonard Lyubich --- pkg/services/netmap/executor.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/services/netmap/executor.go b/pkg/services/netmap/executor.go index 1a48c6408..e80dfce7e 100644 --- a/pkg/services/netmap/executor.go +++ b/pkg/services/netmap/executor.go @@ -8,28 +8,41 @@ import ( ) type executorSvc struct { - version *pkg.Version - localNodeInfo *netmap.NodeInfo + version *pkg.Version + state NodeState } -func NewExecutionService(ni *netmap.NodeInfo, v *pkg.Version) netmap.Service { - if ni == nil || v == nil { +// NodeState encapsulates information +// about current node state. +type NodeState interface { + // Must return current node state + // in NeoFS API v2 NodeInfo structure. + LocalNodeInfo() (*netmap.NodeInfo, error) +} + +func NewExecutionService(s NodeState, v *pkg.Version) netmap.Service { + if s == nil || v == nil { // this should never happen, otherwise it programmers bug panic("can't create netmap execution service") } return &executorSvc{ - version: v, - localNodeInfo: ni, + version: v, + state: s, } } func (s *executorSvc) LocalNodeInfo( _ context.Context, _ *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) { + ni, err := s.state.LocalNodeInfo() + if err != nil { + return nil, err + } + body := new(netmap.LocalNodeInfoResponseBody) body.SetVersion(s.version.ToV2()) - body.SetNodeInfo(s.localNodeInfo) + body.SetNodeInfo(ni) resp := new(netmap.LocalNodeInfoResponse) resp.SetBody(body)