resolver

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package resolver handles name resolution for the Swarm . It implements the Resolver interface as well as clients to connect to external name resolution services.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTLDTooLong denotes when a TLD in a name exceeds maximum length.
	ErrTLDTooLong = fmt.Errorf("TLD exceeds maximum length of %d characters", maxTLDLength)
	// ErrInvalidTLD denotes passing an invalid TLD to the MultiResolver.
	ErrInvalidTLD = errors.New("invalid TLD")
	// ErrResolverChainEmpty denotes trying to pop an empty resolver chain.
	ErrResolverChainEmpty = errors.New("resolver chain empty")
)

Functions

This section is empty.

Types

type Address

type Address = swarm.Address

Address is the swarm hop address.

type CloseError

type CloseError struct {
	// contains filtered or unexported fields
}

CloseError denotes that at least one resolver in the MultiResolver has had an error when Close was called.

func (CloseError) Error

func (me CloseError) Error() string

Error returns a formatted multi close error.

type ConnectionConfig

type ConnectionConfig struct {
	TLD      string
	Address  string
	Endpoint string
}

ConnectionConfig contains the TLD, endpoint and contract address used to establish to a resolver.

func ParseConnectionStrings

func ParseConnectionStrings(cstrs []string) ([]*ConnectionConfig, error)

ParseConnectionStrings will apply ParseConnectionString to each connection string. Returns first error found.

type Interface

type Interface interface {
	Resolve(url string) (Address, error)
	io.Closer
}

Interface can resolve an URL into an associated Ethereum address.

type MultiResolver

type MultiResolver struct {

	// ForceDefault will force all names to be resolved by the default
	// resolution chain, regadless of their TLD.
	ForceDefault bool
	// contains filtered or unexported fields
}

MultiResolver performs name resolutions based on the TLD label in the name.

func NewMultiResolver

func NewMultiResolver(opts ...Option) *MultiResolver

NewMultiResolver will return a new MultiResolver instance.

func (*MultiResolver) ChainCount

func (mr *MultiResolver) ChainCount(tld string) int

ChainCount retruns the number of resolvers in a resolver chain for the given tld. TLD names should be prepended with a dot (eg ".tld"). An empty TLD will return the number of resolvers in the default resolver chain.

func (*MultiResolver) Close

func (mr *MultiResolver) Close() error

Close all will call Close on all resolvers in all resolver chains.

func (*MultiResolver) GetChain

func (mr *MultiResolver) GetChain(tld string) []Interface

GetChain will return the resolution chain for a given TLD. TLD names should be prepended with a dot (eg ".tld"). An empty TLD will return all resolvers in the default resolver chain.

func (*MultiResolver) PopResolver

func (mr *MultiResolver) PopResolver(tld string) error

PopResolver will pop the last reslover from the name resolution chain for the given TLD. TLD names should be prepended with a dot (eg ".tld"). An empty TLD will pop from the default resolver chain.

func (*MultiResolver) PushResolver

func (mr *MultiResolver) PushResolver(tld string, r Interface) error

PushResolver will push a new Resolver to the name resolution chain for the given TLD. TLD names should be prepended with a dot (eg ".tld"). An empty TLD will push to the default resolver chain.

func (*MultiResolver) Resolve

func (mr *MultiResolver) Resolve(name string) (Address, error)

Resolve will attempt to resolve a name to an address. The resolution chain is selected based on the TLD of the name. If the name does not end in a TLD, the default resolution chain is selected. The resolution will be performed iteratively on the resolution chain, returning the result of the first Resolver that succeeds. If all resolvers in the chain return an error, the function will return an ErrResolveFailed.

type Option

type Option func(*MultiResolver)

Option is a function that applies an option to a MultiResolver.

func WithForceDefault

func WithForceDefault() Option

WithForceDefault will force resolution using the default resolver chain.

Directories

Path Synopsis
ens

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL