madns

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 5 Imported by: 313

README

go-multiaddr-dns

Resolve /dns4, /dns6, and /dnsaddr multiaddrs.

> madns /dnsaddr/ipfs.io/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
/ip6/fc3d:9a4e:3c96:2fd2:1afa:18fe:8dd2:b602/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
/dns4/jupiter.i.ipfs.io/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
/dns6/jupiter.i.ipfs.io/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx

In more detail:

> madns /dns6/example.net
/ip6/2001:db8::a3
/ip6/2001:db8::a4
...

> madns /dns4/example.net/tcp/443/wss
/ip4/192.0.2.1/tcp/443/wss
/ip4/192.0.2.2/tcp/443/wss

# No-op if it's not a dns-ish address.

> madns /ip4/127.0.0.1/tcp/8080
/ip4/127.0.0.1/tcp/8080

# /dnsaddr resolves by looking up TXT records.

> dig +short TXT _dnsaddr.example.net
"dnsaddr=/ip6/2001:db8::a3/tcp/443/wss/ipfs/Qmfoo"
"dnsaddr=/ip6/2001:db8::a4/tcp/443/wss/ipfs/Qmbar"
"dnsaddr=/ip4/192.0.2.1/tcp/443/wss/ipfs/Qmfoo"
"dnsaddr=/ip4/192.0.2.2/tcp/443/wss/ipfs/Qmbar"
...

# /dnsaddr returns addrs which encapsulate whatever /dnsaddr encapsulates too.

> madns example.net/ipfs/Qmfoo
info: changing query to /dnsaddr/example.net/ipfs/Qmfoo
/ip6/2001:db8::a3/tcp/443/wss/ipfs/Qmfoo
/ip4/192.0.2.1/tcp/443/wss/ipfs/Qmfoo

# TODO -p filters by protocol stacks.

> madns -p /ip6/tcp/wss /dnsaddr/example.net
/ip6/2001:db8::a3/tcp/443/wss/ipfs/Qmfoo
/ip6/2001:db8::a4/tcp/443/wss/ipfs/Qmbar

# TODO -c filters by CIDR
> madns -c /ip4/104.236.76.0/ipcidr/24 /dnsaddr/example.net
/ip4/192.0.2.2/tcp/443/wss/ipfs/Qmbar

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ResolvableProtocols = []ma.Protocol{dnsaddrProtocol, dns4Protocol, dns6Protocol, dnsProtocol}
	DefaultResolver     = &Resolver{def: net.DefaultResolver}
)

Functions

func Matches

func Matches(maddr ma.Multiaddr) (matches bool)

func Resolve

func Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error)

Types

type BasicResolver added in v0.3.0

type BasicResolver interface {
	LookupIPAddr(context.Context, string) ([]net.IPAddr, error)
	LookupTXT(context.Context, string) ([]string, error)
}

BasicResolver is a low level interface for DNS resolution

type MockResolver added in v0.3.0

type MockResolver struct {
	IP  map[string][]net.IPAddr
	TXT map[string][]string
}

func (*MockResolver) LookupIPAddr added in v0.3.0

func (r *MockResolver) LookupIPAddr(ctx context.Context, name string) ([]net.IPAddr, error)

func (*MockResolver) LookupTXT added in v0.3.0

func (r *MockResolver) LookupTXT(ctx context.Context, name string) ([]string, error)

type Option added in v0.3.0

type Option func(*Resolver) error

func WithDefaultResolver added in v0.3.0

func WithDefaultResolver(def BasicResolver) Option

WithDefaultResolver is an option that specifies the default basic resolver, which resolves any TLD that doesn't have a custom resolver. Defaults to net.DefaultResolver

func WithDomainResolver added in v0.3.0

func WithDomainResolver(domain string, rslv BasicResolver) Option

WithDomainResolver specifies a custom resolver for a domain/TLD. Custom resolver selection matches domains left to right, with more specific resolvers superseding generic ones.

type Resolver

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

Resolver is an object capable of resolving dns multiaddrs by using one or more BasicResolvers; it supports custom per domain/TLD resolvers. It also implements the BasicResolver interface so that it can act as a custom per domain/TLD resolver.

func NewResolver added in v0.3.0

func NewResolver(opts ...Option) (*Resolver, error)

NewResolver creates a new Resolver instance with the specified options

func (*Resolver) LookupIPAddr added in v0.3.0

func (r *Resolver) LookupIPAddr(ctx context.Context, domain string) ([]net.IPAddr, error)

func (*Resolver) LookupTXT added in v0.3.0

func (r *Resolver) LookupTXT(ctx context.Context, txt string) ([]string, error)

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error)

Resolve resolves a DNS multiaddr. It will only resolve the first DNS component in the multiaddr. If you need to resolve multiple DNS components, you may call this function again with each returned address.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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