2022-04-20 09:17:20 +00:00
|
|
|
package resolver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/pool"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NeoFSResolver represents virtual connection to the NeoFS network.
|
|
|
|
// It implements resolver.NeoFS.
|
|
|
|
type NeoFSResolver struct {
|
|
|
|
pool *pool.Pool
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewNeoFSResolver creates new NeoFSResolver using provided pool.Pool.
|
|
|
|
func NewNeoFSResolver(p *pool.Pool) *NeoFSResolver {
|
|
|
|
return &NeoFSResolver{pool: p}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SystemDNS implements resolver.NeoFS interface method.
|
|
|
|
func (x *NeoFSResolver) SystemDNS(ctx context.Context) (string, error) {
|
|
|
|
networkInfo, err := x.pool.NetworkInfo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("read network info via client: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-07-25 09:47:48 +00:00
|
|
|
domain := networkInfo.RawNetworkParameter("SystemDNS")
|
|
|
|
if domain == nil {
|
2022-04-20 09:17:20 +00:00
|
|
|
return "", errors.New("system DNS parameter not found or empty")
|
|
|
|
}
|
|
|
|
|
2022-07-25 09:47:48 +00:00
|
|
|
return string(domain), nil
|
2022-04-20 09:17:20 +00:00
|
|
|
}
|