[#1689] network,core/netmap: Replace Iterate*() functions with iterators
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m25s
Build / Build Components (push) Successful in 1m57s
Pre-commit hooks / Pre-commit (push) Successful in 1m58s
Tests and linters / Run gofumpt (push) Successful in 3m50s
Tests and linters / Staticcheck (push) Successful in 4m21s
Tests and linters / Lint (push) Successful in 4m25s
Tests and linters / gopls check (push) Successful in 4m27s
Tests and linters / Tests (push) Successful in 4m44s
OCI image / Build container images (push) Successful in 5m19s
Tests and linters / Tests with -race (push) Successful in 5m32s
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m25s
Build / Build Components (push) Successful in 1m57s
Pre-commit hooks / Pre-commit (push) Successful in 1m58s
Tests and linters / Run gofumpt (push) Successful in 3m50s
Tests and linters / Staticcheck (push) Successful in 4m21s
Tests and linters / Lint (push) Successful in 4m25s
Tests and linters / gopls check (push) Successful in 4m27s
Tests and linters / Tests (push) Successful in 4m44s
OCI image / Build container images (push) Successful in 5m19s
Tests and linters / Tests with -race (push) Successful in 5m32s
Change-Id: I4842a3160d74c56d99ea9465d4be2f0662080605 Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
e65d578ba9
commit
2d1232ce6d
6 changed files with 33 additions and 27 deletions
|
@ -3,7 +3,9 @@ package nodeconfig
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"iter"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
||||||
|
@ -88,12 +90,8 @@ func Wallet(c *config.Config) *keys.PrivateKey {
|
||||||
|
|
||||||
type stringAddressGroup []string
|
type stringAddressGroup []string
|
||||||
|
|
||||||
func (x stringAddressGroup) IterateAddresses(f func(string) bool) {
|
func (x stringAddressGroup) Addresses() iter.Seq[string] {
|
||||||
for i := range x {
|
return slices.Values(x)
|
||||||
if f(x[i]) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x stringAddressGroup) NumberOfAddresses() int {
|
func (x stringAddressGroup) NumberOfAddresses() int {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package client
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"iter"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
|
@ -19,7 +20,7 @@ func nodeInfoFromKeyAddr(dst *NodeInfo, k []byte, a, external network.AddressGro
|
||||||
// Args must not be nil.
|
// Args must not be nil.
|
||||||
func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
|
func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
|
||||||
PublicKey() []byte
|
PublicKey() []byte
|
||||||
IterateAddresses(func(string) bool)
|
Addresses() iter.Seq[string]
|
||||||
NumberOfAddresses() int
|
NumberOfAddresses() int
|
||||||
ExternalAddresses() []string
|
ExternalAddresses() []string
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package netmap
|
package netmap
|
||||||
|
|
||||||
import "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
import (
|
||||||
|
"iter"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||||
|
)
|
||||||
|
|
||||||
// Node is a named type of netmap.NodeInfo which provides interface needed
|
// Node is a named type of netmap.NodeInfo which provides interface needed
|
||||||
// in the current repository. Node is expected to be used everywhere instead
|
// in the current repository. Node is expected to be used everywhere instead
|
||||||
|
@ -14,8 +18,14 @@ func (x Node) PublicKey() []byte {
|
||||||
return (netmap.NodeInfo)(x).PublicKey()
|
return (netmap.NodeInfo)(x).PublicKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Addresses returns an iterator over all announced network addresses.
|
||||||
|
func (x Node) Addresses() iter.Seq[string] {
|
||||||
|
return (netmap.NodeInfo)(x).NetworkEndpoints()
|
||||||
|
}
|
||||||
|
|
||||||
// IterateAddresses iterates over all announced network addresses
|
// IterateAddresses iterates over all announced network addresses
|
||||||
// and passes them into f. Handler MUST NOT be nil.
|
// and passes them into f. Handler MUST NOT be nil.
|
||||||
|
// Deprecated: use [Node.Addresses] instead.
|
||||||
func (x Node) IterateAddresses(f func(string) bool) {
|
func (x Node) IterateAddresses(f func(string) bool) {
|
||||||
for s := range (netmap.NodeInfo)(x).NetworkEndpoints() {
|
for s := range (netmap.NodeInfo)(x).NetworkEndpoints() {
|
||||||
if f(s) {
|
if f(s) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package network
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"iter"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
@ -68,9 +69,8 @@ func (x AddressGroup) Swap(i, j int) {
|
||||||
|
|
||||||
// MultiAddressIterator is an interface of network address group.
|
// MultiAddressIterator is an interface of network address group.
|
||||||
type MultiAddressIterator interface {
|
type MultiAddressIterator interface {
|
||||||
// IterateAddresses must iterate over network addresses and pass each one
|
// Addresses must return an iterator over network addresses.
|
||||||
// to the handler until it returns true.
|
Addresses() iter.Seq[string]
|
||||||
IterateAddresses(func(string) bool)
|
|
||||||
|
|
||||||
// NumberOfAddresses must return number of addresses in group.
|
// NumberOfAddresses must return number of addresses in group.
|
||||||
NumberOfAddresses() int
|
NumberOfAddresses() int
|
||||||
|
@ -131,19 +131,19 @@ func (x *AddressGroup) FromIterator(iter MultiAddressIterator) error {
|
||||||
// iterateParsedAddresses parses each address from MultiAddressIterator and passes it to f
|
// iterateParsedAddresses parses each address from MultiAddressIterator and passes it to f
|
||||||
// until 1st parsing failure or f's error.
|
// until 1st parsing failure or f's error.
|
||||||
func iterateParsedAddresses(iter MultiAddressIterator, f func(s Address) error) (err error) {
|
func iterateParsedAddresses(iter MultiAddressIterator, f func(s Address) error) (err error) {
|
||||||
iter.IterateAddresses(func(s string) bool {
|
for s := range iter.Addresses() {
|
||||||
var a Address
|
var a Address
|
||||||
|
|
||||||
err = a.FromString(s)
|
err = a.FromString(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("could not parse address from string: %w", err)
|
return fmt.Errorf("could not parse address from string: %w", err)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = f(a)
|
err = f(a)
|
||||||
|
if err != nil {
|
||||||
return err != nil
|
return err
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"iter"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -58,10 +60,8 @@ func TestAddressGroup_FromIterator(t *testing.T) {
|
||||||
|
|
||||||
type testIterator []string
|
type testIterator []string
|
||||||
|
|
||||||
func (t testIterator) IterateAddresses(f func(string) bool) {
|
func (t testIterator) Addresses() iter.Seq[string] {
|
||||||
for i := range t {
|
return slices.Values(t)
|
||||||
f(t[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t testIterator) NumberOfAddresses() int {
|
func (t testIterator) NumberOfAddresses() int {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"iter"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||||
)
|
)
|
||||||
|
@ -34,12 +35,8 @@ var (
|
||||||
// MultiAddressIterator.
|
// MultiAddressIterator.
|
||||||
type NodeEndpointsIterator netmap.NodeInfo
|
type NodeEndpointsIterator netmap.NodeInfo
|
||||||
|
|
||||||
func (x NodeEndpointsIterator) IterateAddresses(f func(string) bool) {
|
func (x NodeEndpointsIterator) Addresses() iter.Seq[string] {
|
||||||
for s := range (netmap.NodeInfo)(x).NetworkEndpoints() {
|
return (netmap.NodeInfo)(x).NetworkEndpoints()
|
||||||
if f(s) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x NodeEndpointsIterator) NumberOfAddresses() int {
|
func (x NodeEndpointsIterator) NumberOfAddresses() int {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue