[#1513] Upgrade NeoFS SDK Go with changed netmap package

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-06-09 02:18:26 +03:00 committed by LeL
parent 24b4c1ecf4
commit 21d2f8f861
70 changed files with 878 additions and 992 deletions

View file

@ -56,6 +56,21 @@ func NewManagerBuilder(prm ManagersPrm, opts ...MngOption) ManagerBuilder {
}
}
// implements Server on apiNetmap.NodeInfo
type nodeServer apiNetmap.NodeInfo
func (x nodeServer) PublicKey() []byte {
return (apiNetmap.NodeInfo)(x).PublicKey()
}
func (x nodeServer) IterateAddresses(f func(string) bool) {
(apiNetmap.NodeInfo)(x).IterateNetworkEndpoints(f)
}
func (x nodeServer) NumberOfAddresses() int {
return (apiNetmap.NodeInfo)(x).NumberOfNetworkEndpoints()
}
// BuildManagers sorts nodes in NetMap with HRW algorithms and
// takes the next node after the current one as the only manager.
func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]ServerInfo, error) {
@ -69,10 +84,12 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]Se
return nil, err
}
// make a copy to keep order consistency of the origin netmap after sorting
nodes := make([]apiNetmap.Node, len(nm.Nodes))
nmNodes := nm.Nodes()
copy(nodes, nm.Nodes)
// make a copy to keep order consistency of the origin netmap after sorting
nodes := make([]apiNetmap.NodeInfo, len(nmNodes))
copy(nodes, nmNodes)
hrw.SortSliceByValue(nodes, epoch)
@ -84,7 +101,7 @@ func (mb *managerBuilder) BuildManagers(epoch uint64, p reputation.PeerID) ([]Se
managerIndex = 0
}
return []ServerInfo{nodes[managerIndex]}, nil
return []ServerInfo{nodeServer(nodes[managerIndex])}, nil
}
}