[#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("key:", hex.EncodeToString(i.PublicKey()))
cmd.Println("address:", i.Address())
cmd.Println("state:", i.State()) cmd.Println("state:", i.State())
netmap.IterateAllAddresses(i, func(s string) {
cmd.Println("address:", s)
})
for _, attribute := range i.Attributes() { for _, attribute := range i.Attributes() {
cmd.Printf("attribute: %s=%s\n", attribute.Key(), attribute.Value()) cmd.Printf("attribute: %s=%s\n", attribute.Key(), attribute.Value())

View file

@ -2,6 +2,7 @@ package audit
import ( import (
"context" "context"
"encoding/hex"
"github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/client"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" 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 for i := range shuffled { // consider iterating over some part of container
log := ap.log.With( log := ap.log.With(
zap.Stringer("cid", cid), zap.Stringer("cid", cid),
zap.String("address", shuffled[0].Address()), zap.String("key", hex.EncodeToString(shuffled[0].PublicKey())),
zap.Int("try", i), zap.Int("try", i),
zap.Int("total_tries", ln), zap.Int("total_tries", ln),
) )

View file

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

View file

@ -2,6 +2,7 @@ package network
import ( import (
"errors" "errors"
"fmt"
"sort" "sort"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
@ -78,13 +79,12 @@ type MultiAddressIterator interface {
// The result is sorted with sort.Sort. // The result is sorted with sort.Sort.
// //
// Returns an error in the absence of addresses or if any of the addresses are incorrect. // 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 as := *x
addrNum := iter.NumberOfAddresses() addrNum := iter.NumberOfAddresses()
if addrNum <= 0 { if addrNum <= 0 {
err = errors.New("missing network addresses") return errors.New("missing network addresses")
return
} }
if cap(as) >= addrNum { if cap(as) >= addrNum {
@ -93,17 +93,9 @@ func (x *AddressGroup) FromIterator(iter MultiAddressIterator) (err error) {
as = make(AddressGroup, 0, addrNum) as = make(AddressGroup, 0, addrNum)
} }
iter.IterateAddresses(func(s string) bool { err := iterateParsedAddresses(iter, func(a Address) error {
var a Address
err = a.FromString(s)
fail := err != nil
if !fail {
as = append(as, a) as = append(as, a)
} return nil
return fail
}) })
if err == nil { if err == nil {
@ -111,6 +103,26 @@ func (x *AddressGroup) FromIterator(iter MultiAddressIterator) (err error) {
*x = as *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 return
} }

View file

@ -2,7 +2,6 @@ package network
import ( import (
"errors" "errors"
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
) )
@ -47,16 +46,7 @@ var (
// 3. tls(optional, may be absent) // 3. tls(optional, may be absent)
// //
func VerifyMultiAddress(ni *netmap.NodeInfo) error { func VerifyMultiAddress(ni *netmap.NodeInfo) error {
// check if it can be parsed to network.Address return iterateParsedAddresses(ni, checkProtocols)
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)
} }
func checkProtocols(a Address) error { func checkProtocols(a Address) error {

View file

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

View file

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

View file

@ -2,6 +2,7 @@ package auditor
import ( import (
"bytes" "bytes"
"encoding/hex"
"sync" "sync"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "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) hdr, err := c.cnrCom.GetHeader(c.task, flat[j], members[i], true)
if err != nil { if err != nil {
c.log.Debug("can't head object", 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])) zap.Stringer("oid", members[i]))
continue continue

View file

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

View file

@ -201,7 +201,7 @@ func testNodeMatrix(t testing.TB, dim []int) ([]netmap.Nodes, [][]string) {
) )
ni := netmap.NewNodeInfo() ni := netmap.NewNodeInfo()
ni.SetAddress(a) ni.SetAddresses(a)
var na network.AddressGroup 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) { 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 return n
} }