[#607] *: Do not use deprecated elements of code

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-23 15:27:00 +03:00 committed by Leonard Lyubich
parent cbe20a2bac
commit 43eff09944
11 changed files with 42 additions and 34 deletions

View file

@ -178,8 +178,10 @@ func prettyPrintNodeInfo(cmd *cobra.Command, i *netmap.NodeInfo, jsonEncoding bo
}
cmd.Println("key:", hex.EncodeToString(i.PublicKey()))
cmd.Println("address:", i.Address())
cmd.Println("state:", i.State())
netmap.IterateAllAddresses(i, func(s string) {
cmd.Println("address:", s)
})
for _, attribute := range i.Attributes() {
cmd.Printf("attribute: %s=%s\n", attribute.Key(), attribute.Value())

View file

@ -2,6 +2,7 @@ package audit
import (
"context"
"encoding/hex"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
@ -113,7 +114,7 @@ func (ap *Processor) findStorageGroups(cid *cid.ID, shuffled netmap.Nodes) []*ob
for i := range shuffled { // consider iterating over some part of container
log := ap.log.With(
zap.Stringer("cid", cid),
zap.String("address", shuffled[0].Address()),
zap.String("key", hex.EncodeToString(shuffled[0].PublicKey())),
zap.Int("try", i),
zap.Int("total_tries", ln),
)

View file

@ -3,6 +3,7 @@ package innerring
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"fmt"
"time"
@ -80,7 +81,7 @@ func (c *ClientCache) getSG(ctx context.Context, addr *object.Address, nm *netma
err := netAddr.FromIterator(node)
if err != nil {
c.log.Warn("can't parse remote address",
zap.String("address", node.Address()),
zap.String("key", hex.EncodeToString(node.PublicKey())),
zap.String("error", err.Error()))
continue

View file

@ -2,6 +2,7 @@ package network
import (
"errors"
"fmt"
"sort"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
@ -78,13 +79,12 @@ type MultiAddressIterator interface {
// The result is sorted with sort.Sort.
//
// Returns an error in the absence of addresses or if any of the addresses are incorrect.
func (x *AddressGroup) FromIterator(iter MultiAddressIterator) (err error) {
func (x *AddressGroup) FromIterator(iter MultiAddressIterator) error {
as := *x
addrNum := iter.NumberOfAddresses()
if addrNum <= 0 {
err = errors.New("missing network addresses")
return
return errors.New("missing network addresses")
}
if cap(as) >= addrNum {
@ -93,17 +93,9 @@ func (x *AddressGroup) FromIterator(iter MultiAddressIterator) (err error) {
as = make(AddressGroup, 0, addrNum)
}
iter.IterateAddresses(func(s string) bool {
var a Address
err = a.FromString(s)
fail := err != nil
if !fail {
err := iterateParsedAddresses(iter, func(a Address) error {
as = append(as, a)
}
return fail
return nil
})
if err == nil {
@ -111,6 +103,26 @@ func (x *AddressGroup) FromIterator(iter MultiAddressIterator) (err error) {
*x = as
}
return err
}
// iterateParsedAddresses parses each address from MultiAddressIterator and passes it to f
// until 1st parsing failure or f's error.
func iterateParsedAddresses(iter MultiAddressIterator, f func(s Address) error) (err error) {
iter.IterateAddresses(func(s string) bool {
var a Address
err = a.FromString(s)
if err != nil {
err = fmt.Errorf("could not parse address from string: %w", err)
return true
}
err = f(a)
return err != nil
})
return
}

View file

@ -2,7 +2,6 @@ package network
import (
"errors"
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
)
@ -47,16 +46,7 @@ var (
// 3. tls(optional, may be absent)
//
func VerifyMultiAddress(ni *netmap.NodeInfo) error {
// check if it can be parsed to network.Address
var netAddr Address
err := netAddr.FromString(ni.Address())
if err != nil {
return fmt.Errorf("could not parse multiaddr from NodeInfo: %w", err)
}
// check amount of protocols and its order
return checkProtocols(netAddr)
return iterateParsedAddresses(ni, checkProtocols)
}
func checkProtocols(a Address) error {

View file

@ -58,7 +58,7 @@ func TestVerifyMultiAddress_Order(t *testing.T) {
func constructNodeInfo(address string) *netmap.NodeInfo {
ni := new(netmap.NodeInfo)
ni.SetAddress(address)
ni.SetAddresses(address)
return ni
}

View file

@ -2,6 +2,7 @@ package auditor
import (
"bytes"
"encoding/hex"
"sync"
"time"
@ -117,7 +118,7 @@ func (c *Context) collectHashes(p *gamePair) {
if err != nil {
c.log.Debug("could not get payload range hash",
zap.Stringer("id", p.id),
zap.String("node", n.Address()),
zap.String("node", hex.EncodeToString(n.PublicKey())),
zap.String("error", err.Error()),
)
return

View file

@ -2,6 +2,7 @@ package auditor
import (
"bytes"
"encoding/hex"
"sync"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
@ -80,7 +81,7 @@ func (c *Context) checkStorageGroupPoR(ind int, sg *object.ID) {
hdr, err := c.cnrCom.GetHeader(c.task, flat[j], members[i], true)
if err != nil {
c.log.Debug("can't head object",
zap.String("remote_node", flat[j].Address()),
zap.String("remote_node", hex.EncodeToString(flat[j].PublicKey())),
zap.Stringer("oid", members[i]))
continue

View file

@ -407,7 +407,7 @@ func testNodeMatrix(t testing.TB, dim []int) ([]netmap.Nodes, [][]string) {
)
ni := netmap.NewNodeInfo()
ni.SetAddress(a)
ni.SetAddresses(a)
var na network.AddressGroup

View file

@ -201,7 +201,7 @@ func testNodeMatrix(t testing.TB, dim []int) ([]netmap.Nodes, [][]string) {
)
ni := netmap.NewNodeInfo()
ni.SetAddress(a)
ni.SetAddresses(a)
var na network.AddressGroup

View file

@ -20,7 +20,7 @@ func (b testBuilder) BuildPlacement(*object.Address, *netmap.PlacementPolicy) ([
}
func testNode(v uint32) (n netmap.NodeInfo) {
n.SetAddress("/ip4/0.0.0.0/tcp/" + strconv.Itoa(int(v)))
n.SetAddresses("/ip4/0.0.0.0/tcp/" + strconv.Itoa(int(v)))
return n
}