[#607] services/netmap: Support backward compatibility

Make Netmap service to return single network address on `LocalNodeInfo` RPC
in order to older clients.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-25 18:38:58 +03:00 committed by Leonard Lyubich
parent 81ddaeca16
commit f8ee6b1164

View file

@ -45,12 +45,30 @@ func NewExecutionService(s NodeState, v *pkg.Version, netInfo NetworkInfo) Serve
func (s *executorSvc) LocalNodeInfo(
_ context.Context,
_ *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) {
req *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) {
ver := pkg.NewVersionFromV2(req.GetMetaHeader().GetVersion())
if err := pkg.IsSupportedVersion(ver); err != nil {
return nil, err
}
ni, err := s.state.LocalNodeInfo()
if err != nil {
return nil, err
}
if addrNum := ni.NumberOfAddresses(); addrNum > 0 && ver.Minor() <= 7 {
ni2 := new(netmap.NodeInfo)
ni2.SetPublicKey(ni.GetPublicKey())
ni2.SetState(ni.GetState())
ni2.SetAttributes(ni.GetAttributes())
ni.IterateAddresses(func(s string) bool {
ni2.SetAddresses(s)
return true
})
ni = ni2
}
body := new(netmap.LocalNodeInfoResponseBody)
body.SetVersion(s.version.ToV2())
body.SetNodeInfo(ni)