forked from TrueCloudLab/frostfs-node
[#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 <alexey@nspcc.ru>
This commit is contained in:
parent
2456873473
commit
16f13bc0a5
13 changed files with 23 additions and 23 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue