From 16f13bc0a52cc13dfb4587ff8c207d8e2701665d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 17 May 2021 15:04:32 +0300 Subject: [PATCH] [#522] Use `HostAddrString` as RPC endpoint instead of `IPAddrString` To enable TLS support we can't operate with IP addresses directly. Certificates are issued with host names so it is required to pass them into RPC client. DNS resolving should be done by transport layer and not be a part of node. Therefore `IPAddrString` usage is removed from code. Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/root.go | 4 ++-- cmd/neofs-node/container.go | 4 ++-- cmd/neofs-node/object.go | 4 ++-- cmd/neofs-node/reputation/common/remote.go | 4 ++-- pkg/innerring/processors/audit/process.go | 2 +- pkg/innerring/rpc.go | 6 +++--- pkg/network/address.go | 6 +++--- pkg/services/object/get/exec.go | 4 ++-- pkg/services/object/get/get_test.go | 2 +- pkg/services/object/head/remote.go | 2 +- pkg/services/object/put/remote.go | 2 +- pkg/services/object/search/exec.go | 4 ++-- pkg/services/object/search/search_test.go | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index 269dbefd..a98efec9 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -235,12 +235,12 @@ func getSDKClient(key *ecdsa.PrivateKey) (client.Client, error) { return nil, err } - ipAddr, err := netAddr.IPAddrString() + hostAddr, err := netAddr.HostAddrString() if err != nil { return nil, errInvalidEndpoint } - c, err := client.New(client.WithAddress(ipAddr), client.WithDefaultPrivateKey(key)) + c, err := client.New(client.WithAddress(hostAddr), client.WithDefaultPrivateKey(key)) return c, err } diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index c28680ab..fb0578a0 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -228,12 +228,12 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc return loadcontroller.SimpleWriterProvider(new(nopLoadWriter)), nil } - ipAddr, err := network.IPAddrFromMultiaddr(addr) + hostAddr, err := network.HostAddrFromMultiaddr(addr) if err != nil { return nil, errors.Wrap(err, "could not convert address to IP format") } - c, err := r.clientCache.Get(ipAddr) + c, err := r.clientCache.Get(hostAddr) if err != nil { return nil, errors.Wrap(err, "could not initialize API client") } diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index a4398acc..26c425d1 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -492,9 +492,9 @@ func (c *reputationClientConstructor) Get(addr string) (client.Client, error) { nm, err := netmap.GetLatestNetworkMap(c.nmSrc) if err == nil { for i := range nm.Nodes { - ipAddr, err := network.IPAddrFromMultiaddr(nm.Nodes[i].Address()) + hostAddr, err := network.HostAddrFromMultiaddr(nm.Nodes[i].Address()) if err == nil { - if ipAddr == addr { + if hostAddr == addr { prm := truststorage.UpdatePrm{} prm.SetPeer(reputation.PeerIDFromBytes(nm.Nodes[i].PublicKey())) diff --git a/cmd/neofs-node/reputation/common/remote.go b/cmd/neofs-node/reputation/common/remote.go index 66d3d783..fd2c43ed 100644 --- a/cmd/neofs-node/reputation/common/remote.go +++ b/cmd/neofs-node/reputation/common/remote.go @@ -76,12 +76,12 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep return trustcontroller.SimpleWriterProvider(new(NopReputationWriter)), nil } - ipAddr, err := network.IPAddrFromMultiaddr(addr) + hostAddr, err := network.HostAddrFromMultiaddr(addr) if err != nil { return nil, errors.Wrap(err, "could not convert address to IP format") } - c, err := rtp.clientCache.Get(ipAddr) + c, err := rtp.clientCache.Get(hostAddr) if err != nil { return nil, errors.Wrap(err, "could not initialize API client") } diff --git a/pkg/innerring/processors/audit/process.go b/pkg/innerring/processors/audit/process.go index 625b9e1f..e4c3e9de 100644 --- a/pkg/innerring/processors/audit/process.go +++ b/pkg/innerring/processors/audit/process.go @@ -117,7 +117,7 @@ func (ap *Processor) findStorageGroups(cid *container.ID, shuffled netmap.Nodes) zap.Int("total_tries", ln), ) - addr, err := network.IPAddrFromMultiaddr(shuffled[i].Address()) + addr, err := network.HostAddrFromMultiaddr(shuffled[i].Address()) if err != nil { log.Warn("can't parse remote address", zap.String("error", err.Error())) diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index 7e81f70c..5f0b9837 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -74,7 +74,7 @@ func (c *ClientCache) getSG(ctx context.Context, addr *object.Address, nm *netma getParams.WithAddress(addr) for _, node := range placement.FlattenNodes(nodes) { - addr, err := network.IPAddrFromMultiaddr(node.Address()) + addr, err := network.HostAddrFromMultiaddr(node.Address()) if err != nil { c.log.Warn("can't parse remote address", zap.String("address", node.Address()), @@ -136,7 +136,7 @@ func (c *ClientCache) GetHeader(task *audit.Task, node *netmap.Node, id *object. headParams.WithMainFields() headParams.WithAddress(objAddress) - addr, err := network.IPAddrFromMultiaddr(node.Address()) + addr, err := network.HostAddrFromMultiaddr(node.Address()) if err != nil { return nil, fmt.Errorf("can't parse remote address %s: %w", node.Address(), err) } @@ -172,7 +172,7 @@ func (c *ClientCache) GetRangeHash(task *audit.Task, node *netmap.Node, id *obje rangeParams.WithRangeList(rng) rangeParams.WithSalt(nil) // it MUST be nil for correct hash concatenation in PDP game - addr, err := network.IPAddrFromMultiaddr(node.Address()) + addr, err := network.HostAddrFromMultiaddr(node.Address()) if err != nil { return nil, fmt.Errorf("can't parse remote address %s: %w", node.Address(), err) } diff --git a/pkg/network/address.go b/pkg/network/address.go index a62f71f4..4c459357 100644 --- a/pkg/network/address.go +++ b/pkg/network/address.go @@ -106,12 +106,12 @@ func IsLocalAddress(src LocalAddressSource, addr *Address) bool { return src.LocalAddress().ma.Equal(addr.ma) } -// IPAddrFromMultiaddr converts "/dns4/localhost/tcp/8080" to "192.168.0.1:8080". -func IPAddrFromMultiaddr(multiaddr string) (string, error) { +// HostAddrFromMultiaddr converts "/dns4/localhost/tcp/8080" to "localhost:8080". +func HostAddrFromMultiaddr(multiaddr string) (string, error) { address, err := AddressFromString(multiaddr) if err != nil { return "", err } - return address.IPAddrString() + return address.HostAddrString() } diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index 19fa646b..4752e60b 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -271,7 +271,7 @@ func (exec *execCtx) headChild(id *objectSDK.ID) (*object.Object, bool) { } func (exec execCtx) remoteClient(node *network.Address) (getClient, bool) { - ipAddr, err := node.IPAddrString() + hostAddr, err := node.HostAddrString() log := exec.log.With(zap.Stringer("node", node)) @@ -282,7 +282,7 @@ func (exec execCtx) remoteClient(node *network.Address) (getClient, bool) { log.Debug("could not calculate node IP address") case err == nil: - c, err := exec.svc.clientCache.get(ipAddr) + c, err := exec.svc.clientCache.get(hostAddr) switch { default: diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index f7d5fcd6..046bd470 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -411,7 +411,7 @@ func testNodeMatrix(t testing.TB, dim []int) ([]netmap.Nodes, [][]string) { na, err := network.AddressFromString(a) require.NoError(t, err) - as[j], err = na.IPAddrString() + as[j], err = na.HostAddrString() require.NoError(t, err) ni := netmap.NewNodeInfo() diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index 450d48c5..c8b252a8 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -65,7 +65,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob return nil, errors.Wrapf(err, "(%T) could not receive private key", h) } - addr, err := prm.node.IPAddrString() + addr, err := prm.node.HostAddrString() if err != nil { return nil, err } diff --git a/pkg/services/object/put/remote.go b/pkg/services/object/put/remote.go index 3c2b1535..426c0f51 100644 --- a/pkg/services/object/put/remote.go +++ b/pkg/services/object/put/remote.go @@ -54,7 +54,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) { return nil, errors.Wrapf(err, "(%T) could not receive private key", t) } - addr, err := t.addr.IPAddrString() + addr, err := t.addr.HostAddrString() if err != nil { return nil, err } diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index 226d5139..7a4e25a2 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -118,7 +118,7 @@ func (exec *execCtx) generateTraverser(cid *container.ID) (*placement.Traverser, } func (exec execCtx) remoteClient(node *network.Address) (searchClient, bool) { - ipAddr, err := node.IPAddrString() + hostAddr, err := node.HostAddrString() log := exec.log.With(zap.Stringer("node", node)) @@ -129,7 +129,7 @@ func (exec execCtx) remoteClient(node *network.Address) (searchClient, bool) { log.Debug("could not calculate node IP address") case err == nil: - c, err := exec.svc.clientConstructor.get(ipAddr) + c, err := exec.svc.clientConstructor.get(hostAddr) switch { default: diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index f803c2b4..339a8d24 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -209,7 +209,7 @@ func testNodeMatrix(t testing.TB, dim []int) ([]netmap.Nodes, [][]string) { na, err := network.AddressFromString(a) require.NoError(t, err) - as[j], err = na.IPAddrString() + as[j], err = na.HostAddrString() require.NoError(t, err) ni := netmap.NewNodeInfo()