Skip to content

Commit 0323849

Browse files
committed
*: Use new iterators from NeoFS SDK
Completes 8340c91. No more wrappers and closures needed. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent 702eeea commit 0323849

File tree

20 files changed

+41
-51
lines changed

20 files changed

+41
-51
lines changed

cmd/internal/cmdprinter/netmap.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ func PrettyPrintNodeInfo(cmd *cobra.Command, node netmap.NodeInfo,
2626

2727
cmd.Printf("%sNode %d: %s %s ", indent, index+1, hex.EncodeToString(node.PublicKey()), strState)
2828

29-
for endpoint := range func(f func(string) bool) { node.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
29+
for endpoint := range node.NetworkEndpoints() {
3030
cmd.Printf("%s ", endpoint)
3131
}
3232
cmd.Println()
3333

3434
if !short {
35-
node.IterateAttributes(func(key, value string) {
35+
for key, value := range node.Attributes() {
3636
cmd.Printf("%s\t%s: %s\n", indent, key, value)
37-
})
37+
}
3838
}
3939
}
4040

cmd/neofs-cli/modules/container/get.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ func prettyPrintContainer(cmd *cobra.Command, cnr container.Container, jsonEncod
105105
cmd.Println("created:", cnr.CreatedAt())
106106

107107
cmd.Println("attributes:")
108-
cnr.IterateAttributes(func(key, val string) {
108+
for key, val := range cnr.Attributes() {
109109
cmd.Printf("\t%s=%s\n", key, val)
110-
})
110+
}
111111

112112
cmd.Println("placement policy:")
113113
if err := cnr.PlacementPolicy().WriteStringTo((*stringWriter)(cmd)); err != nil {

cmd/neofs-cli/modules/container/list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ var listContainersCmd = &cobra.Command{
7373

7474
res, err := internalclient.GetContainer(ctx, prmGet)
7575
if err == nil {
76-
res.Container().IterateUserAttributes(func(key, val string) {
76+
for key, val := range res.Container().UserAttributes() {
7777
cmd.Printf(" %s: %s\n", key, val)
78-
})
78+
}
7979
} else {
8080
cmd.Printf(" failed to read attributes: %v\n", err)
8181
}

cmd/neofs-cli/modules/netmap/netinfo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ var netInfoCmd = &cobra.Command{
6060
cmd.Printf(format, "Maintenance mode allowed", netInfo.MaintenanceModeAllowed())
6161

6262
cmd.Println("NeoFS network configuration (other)")
63-
netInfo.IterateRawNetworkParameters(func(name string, value []byte) {
63+
for name, value := range netInfo.RawNetworkParameters() {
6464
cmd.Printf(format, name, hex.EncodeToString(value))
65-
})
65+
}
6666
return nil
6767
},
6868
}

cmd/neofs-cli/modules/netmap/nodeinfo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ func prettyPrintNodeInfo(cmd *cobra.Command, i netmap.NodeInfo) {
6969

7070
cmd.Println("state:", stateWord)
7171

72-
for s := range func(f func(string) bool) { i.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
72+
for s := range i.NetworkEndpoints() {
7373
cmd.Println("address:", s)
7474
}
7575

76-
i.IterateAttributes(func(key, value string) {
76+
for key, value := range i.Attributes() {
7777
cmd.Printf("attribute: %s=%s\n", key, value)
78-
})
78+
}
7979
}

cmd/neofs-node/netmap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func nodeKeyFromNetmap(c *cfg) []byte {
144144

145145
func (c *cfg) iterateNetworkAddresses(f func(string) bool) {
146146
ni := c.cfgNodeInfo.localInfo
147-
ni.IterateNetworkEndpoints(func(s string) bool { return !f(s) })
147+
ni.NetworkEndpoints()(f)
148148
}
149149

150150
func (c *cfg) addressNum() int {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/nspcc-dev/neo-go v0.108.1
2020
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea
2121
github.com/nspcc-dev/neofs-contract v0.21.0
22-
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.13
22+
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.13.0.20250311165714-441b37a4bc03
2323
github.com/nspcc-dev/tzhash v1.8.2
2424
github.com/olekukonko/tablewriter v0.0.5
2525
github.com/panjf2000/ants/v2 v2.9.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea h1:mK
192192
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea/go.mod h1:YzhD4EZmC9Z/PNyd7ysC7WXgIgURc9uCG1UWDeV027Y=
193193
github.com/nspcc-dev/neofs-contract v0.21.0 h1:dJkrZr7C8ngMiShwdUl27nbLCGez1KD7W1l7RRXFoN8=
194194
github.com/nspcc-dev/neofs-contract v0.21.0/go.mod h1:TKR2DJiZCdzq9CPljI101c9S3uK5CsVK5WQrX4C+Y7A=
195-
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.13 h1:q1ne/4d10NuHSqs+fA5XVVBRJ9jSap4cjrsxYzNvYZA=
196-
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.13/go.mod h1:ycdDlPq8Wy+w5ePCmCfbHuEWQXbP7ZjBL5rj3QDiiM0=
195+
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.13.0.20250311165714-441b37a4bc03 h1:hHAt6pUuhkmcCRXKKYa93FGwDMC13kN7sAq3mXR1YAw=
196+
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.13.0.20250311165714-441b37a4bc03/go.mod h1:ycdDlPq8Wy+w5ePCmCfbHuEWQXbP7ZjBL5rj3QDiiM0=
197197
github.com/nspcc-dev/rfc6979 v0.2.3 h1:QNVykGZ3XjFwM/88rGfV3oj4rKNBy+nYI6jM7q19hDI=
198198
github.com/nspcc-dev/rfc6979 v0.2.3/go.mod h1:q3sCL1Ed7homjqYK8KmFSzEmm+7Ngyo7PePbZanhaDE=
199199
github.com/nspcc-dev/tzhash v1.8.2 h1:ebRCbPoEuoqrhC6sSZmrT/jI3h1SzCWakxxV6gp5QAg=

pkg/core/netmap/nodes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (x Node) PublicKey() []byte {
2121
// IterateAddresses iterates over all announced network addresses
2222
// and passes them into f. Handler MUST NOT be nil.
2323
func (x Node) IterateAddresses(f func(string) bool) {
24-
(netmap.NodeInfo)(x).IterateNetworkEndpoints(func(s string) bool { return !f(s) })
24+
(netmap.NodeInfo)(x).NetworkEndpoints()(f)
2525
slices.Values((netmap.NodeInfo)(x).ExternalAddresses())(f)
2626
}
2727

pkg/innerring/processors/container/process_container.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,16 @@ func (cp *Processor) checkPutContainer(ctx *putContainerContext) error {
7878
return fmt.Errorf("invalid binary container: %w", err)
7979
}
8080

81-
var denyErr error
82-
ctx.cnr.IterateAttributes(func(k, v string) {
83-
if denyErr == nil && strings.HasPrefix(k, sysAttrPrefix) {
81+
for k := range ctx.cnr.Attributes() {
82+
if strings.HasPrefix(k, sysAttrPrefix) {
8483
if _, ok := allowedSystemAttributes[k]; !ok {
85-
denyErr = fmt.Errorf("system attribute %s is not allowed", k)
84+
return fmt.Errorf("system attribute %s is not allowed", k)
8685
}
8786

8887
if k == sysAttrChainMeta && !cp.metaEnabled {
89-
denyErr = fmt.Errorf("chain meta data attribute is not allowed")
88+
return fmt.Errorf("chain meta data attribute is not allowed")
9089
}
9190
}
92-
})
93-
if denyErr != nil {
94-
return denyErr
9591
}
9692

9793
err = cp.verifySignature(signatureVerificationData{

pkg/innerring/processors/netmap/nodevalidation/availability/validator.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (v Validator) Verify(nodeInfo netmap.NodeInfo) error {
2323
var results []*client.ResEndpointInfo
2424
var err error
2525

26-
for s := range func(f func(string) bool) { nodeInfo.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
26+
for s := range nodeInfo.NetworkEndpoints() {
2727
var res *client.ResEndpointInfo
2828
var c *client.Client
2929

@@ -75,8 +75,6 @@ func compareNodeInfos(niExp, niGot netmap.NodeInfo) error {
7575
return nil
7676
}
7777

78-
var err error
79-
8078
if exp, got := niExp.PublicKey(), niGot.PublicKey(); !bytes.Equal(exp, got) {
8179
return fmt.Errorf("public key: got %x, expect %x", got, exp)
8280
}
@@ -85,26 +83,23 @@ func compareNodeInfos(niExp, niGot netmap.NodeInfo) error {
8583
return fmt.Errorf("attr number: got %d, expect %d", got, exp)
8684
}
8785

88-
niExp.IterateAttributes(func(key, value string) {
86+
for key, value := range niExp.Attributes() {
8987
vGot := niGot.Attribute(key)
9088
if vGot != value {
91-
err = fmt.Errorf("non-equal %s attribute: got %s, expect %s", key, vGot, value)
89+
return fmt.Errorf("non-equal %s attribute: got %s, expect %s", key, vGot, value)
9290
}
93-
})
94-
if err != nil {
95-
return err
9691
}
9792

9893
if exp, got := niExp.NumberOfNetworkEndpoints(), niGot.NumberOfNetworkEndpoints(); exp != got {
9994
return fmt.Errorf("address number: got %d, expect %d", got, exp)
10095
}
10196

10297
expAddrM := make(map[string]struct{}, niExp.NumberOfAttributes())
103-
for s := range func(f func(string) bool) { niExp.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
98+
for s := range niExp.NetworkEndpoints() {
10499
expAddrM[s] = struct{}{}
105100
}
106101

107-
for s := range func(f func(string) bool) { niGot.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
102+
for s := range niGot.NetworkEndpoints() {
108103
if _, ok := expAddrM[s]; !ok {
109104
return fmt.Errorf("got unexpected address: %s", s)
110105
}

pkg/innerring/processors/netmap/nodevalidation/structure/calls.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ func (v *Validator) Verify(n netmap.NodeInfo) error {
1515
}
1616

1717
attrM := make(map[string]struct{}, n.NumberOfAttributes())
18-
n.IterateAttributes(func(key, _ string) {
18+
for key := range n.Attributes() {
1919
if _, alreadyHave := attrM[key]; alreadyHave {
20-
err = fmt.Errorf("repeating node attribute: '%s'", key)
21-
return
20+
return fmt.Errorf("repeating node attribute: '%s'", key)
2221
}
2322
attrM[key] = struct{}{}
24-
})
23+
}
2524

26-
return err
25+
return nil
2726
}

pkg/innerring/processors/netmap/nodevalidation/structure/calls_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ func TestValidator_Verify(t *testing.T) {
1818
{"key1", "val3"},
1919
{"key2", "val4"},
2020
})
21-
require.EqualError(t, v.Verify(n), "repeating node attribute: 'key2'")
21+
require.EqualError(t, v.Verify(n), "repeating node attribute: 'key1'")
2222
})
2323
}

pkg/morph/client/netmap/add_peer.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ func (c *Client) AddPeer(ni netmap.NodeInfo, pkey *keys.PublicKey) error {
2828
Key: pkey,
2929
State: netmaprpc.NodeStateOnline,
3030
}
31-
node.Addresses = slices.Collect(func(f func(s string) bool) { ni.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) })
32-
ni.IterateAttributes(func(k, v string) {
31+
node.Addresses = slices.Collect(ni.NetworkEndpoints())
32+
for k, v := range ni.Attributes() {
3333
node.Attributes[k] = v
34-
})
34+
}
3535

3636
prm := client.InvokePrm{}
3737
prm.SetMethod(addNodeMethod)

pkg/network/validation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var (
3535
type NodeEndpointsIterator netmap.NodeInfo
3636

3737
func (x NodeEndpointsIterator) IterateAddresses(f func(string) bool) {
38-
(netmap.NodeInfo)(x).IterateNetworkEndpoints(func(s string) bool { return !f(s) })
38+
(netmap.NodeInfo)(x).NetworkEndpoints()(f)
3939
}
4040

4141
func (x NodeEndpointsIterator) NumberOfAddresses() int {

pkg/services/reputation/common/managers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (x nodeServer) PublicKey() []byte {
6262
}
6363

6464
func (x nodeServer) IterateAddresses(f func(string) bool) {
65-
(apiNetmap.NodeInfo)(x).IterateNetworkEndpoints(func(s string) bool { return !f(s) })
65+
(apiNetmap.NodeInfo)(x).NetworkEndpoints()(f)
6666
}
6767

6868
func (x nodeServer) NumberOfAddresses() int {

pkg/services/tree/redirect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (s *Service) forEachNode(ctx context.Context, cntNodes []netmapSDK.NodeInfo
2222

2323
var called bool
2424
for _, n := range cntNodes {
25-
for endpoint := range func(f func(string) bool) { n.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
25+
for endpoint := range n.NetworkEndpoints() {
2626
c, err := s.cache.get(endpoint)
2727
if err != nil {
2828
continue

pkg/services/tree/replicator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (s *Service) replicationWorker(ctx context.Context) {
6262
var lastErr error
6363
var lastAddr string
6464

65-
for addr := range func(f func(string) bool) { task.n.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
65+
for addr := range task.n.NetworkEndpoints() {
6666
lastAddr = addr
6767

6868
c, err := s.cache.get(addr)

pkg/services/tree/sync.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (s *Service) synchronizeTree(ctx context.Context, d pilorama.CIDDescriptor,
147147
for _, n := range nodes {
148148
height := from
149149
loop:
150-
for addr := range func(f func(string) bool) { n.IterateNetworkEndpoints(func(s string) bool { return !f(s) }) } {
150+
for addr := range n.NetworkEndpoints() {
151151
var a network.Address
152152
if err := a.FromString(addr); err != nil {
153153
continue

pkg/util/attributes/parser_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ func testAttributeMap(t *testing.T, mSrc, mExp map[string]string) {
2323
mExp = mSrc
2424
}
2525

26-
node.IterateAttributes(func(key, value string) {
26+
for key, value := range node.Attributes() {
2727
v, ok := mExp[key]
2828
require.True(t, ok)
2929
require.Equal(t, value, v)
3030
delete(mExp, key)
31-
})
31+
}
3232

3333
require.Empty(t, mExp)
3434
}

0 commit comments

Comments
 (0)