diff --git a/client/client.go b/client/client.go index 5148838..ddc9b33 100644 --- a/client/client.go +++ b/client/client.go @@ -1,18 +1,19 @@ package client import ( + "bytes" "context" "crypto/ecdsa" "crypto/tls" "errors" "fmt" - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" "net/url" "time" v2accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap" "google.golang.org/grpc" ) @@ -113,29 +114,23 @@ func (c *Client) Dial(ctx context.Context, prm PrmDial) error { return nil } +func (c *Client) netMapDialNode(ctx context.Context, node *netmap.NodeInfo) error { + // TODO: implement dialing options + addresses := node.ExternalAddresses() + return c.Dial(ctx, PrmDial{Endpoint: addresses[0]}) +} + func (c *Client) NetMapDial(ctx context.Context, endpoint string) error { u, err := url.Parse(endpoint) if err != nil { return err } - isEqualSlices := func(a, b []byte) bool { - if len(a) != len(b) { - return false - } - for i := range a { - if a[i] != b[i] { - return false - } - } - return true - } - if u.Scheme == "frostfs" { - nodes := c.prm.NetMap.GetNodes() + nodes := c.prm.NetMap.Nodes() for _, node := range nodes { - if isEqualSlices([]byte(u.Host), node.PublicKey) { - return c.Dial(ctx, PrmDial{Endpoint: node.Addresses[0]}) + if bytes.Equal([]byte(u.Host), node.PublicKey()) { + return c.netMapDialNode(ctx, &node) } } } @@ -173,7 +168,7 @@ type PrmInit struct { ResponseInfoCallback func(ResponseMetaInfo) error - NetMap *netmap.Netmap + NetMap *netmap.NetMap NetMagic uint64 } diff --git a/client/client_test.go b/client/client_test.go index e09fc11..f3c97c9 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -6,10 +6,10 @@ import ( "crypto/elliptic" "crypto/rand" "fmt" - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" "testing" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap" "github.com/stretchr/testify/require" ) @@ -74,15 +74,13 @@ func TestClient_NetMapDialContext(t *testing.T) { publicKey := "foo" endpoint := "localhost:8080" - prmInit.NetMap = &netmap.Netmap{ - Epoch: 0, - Nodes: []*netmap.NodeInfo{ - { - PublicKey: []byte(publicKey), - Addresses: []string{endpoint}, - }, - }, - } + node := netmap.NodeInfo{} + node.SetPublicKey([]byte(publicKey)) + node.SetExternalAddresses(endpoint) + netMap := &netmap.NetMap{} + netMap.SetNodes([]netmap.NodeInfo{node}) + + prmInit.NetMap = netMap c.Init(prmInit)