[#131] client: refactor netmap dialer
Signed-off-by: olefirenque <egor.olefirenko892@gmail.com>
This commit is contained in:
parent
dd8fb59efe
commit
cf4677ecb9
2 changed files with 20 additions and 27 deletions
|
@ -1,18 +1,19 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v2accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting"
|
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"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -113,29 +114,23 @@ func (c *Client) Dial(ctx context.Context, prm PrmDial) error {
|
||||||
return nil
|
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 {
|
func (c *Client) NetMapDial(ctx context.Context, endpoint string) error {
|
||||||
u, err := url.Parse(endpoint)
|
u, err := url.Parse(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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" {
|
if u.Scheme == "frostfs" {
|
||||||
nodes := c.prm.NetMap.GetNodes()
|
nodes := c.prm.NetMap.Nodes()
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if isEqualSlices([]byte(u.Host), node.PublicKey) {
|
if bytes.Equal([]byte(u.Host), node.PublicKey()) {
|
||||||
return c.Dial(ctx, PrmDial{Endpoint: node.Addresses[0]})
|
return c.netMapDialNode(ctx, &node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +168,7 @@ type PrmInit struct {
|
||||||
|
|
||||||
ResponseInfoCallback func(ResponseMetaInfo) error
|
ResponseInfoCallback func(ResponseMetaInfo) error
|
||||||
|
|
||||||
NetMap *netmap.Netmap
|
NetMap *netmap.NetMap
|
||||||
|
|
||||||
NetMagic uint64
|
NetMagic uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -74,15 +74,13 @@ func TestClient_NetMapDialContext(t *testing.T) {
|
||||||
publicKey := "foo"
|
publicKey := "foo"
|
||||||
endpoint := "localhost:8080"
|
endpoint := "localhost:8080"
|
||||||
|
|
||||||
prmInit.NetMap = &netmap.Netmap{
|
node := netmap.NodeInfo{}
|
||||||
Epoch: 0,
|
node.SetPublicKey([]byte(publicKey))
|
||||||
Nodes: []*netmap.NodeInfo{
|
node.SetExternalAddresses(endpoint)
|
||||||
{
|
netMap := &netmap.NetMap{}
|
||||||
PublicKey: []byte(publicKey),
|
netMap.SetNodes([]netmap.NodeInfo{node})
|
||||||
Addresses: []string{endpoint},
|
|
||||||
},
|
prmInit.NetMap = netMap
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Init(prmInit)
|
c.Init(prmInit)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue