madns

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT, MIT Imports: 4 Imported by: 0

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

View Source
const (
	// Deprecated: use ma.P_DNS
	P_DNS = ma.P_DNS
	// Deprecated: use ma.P_DNS4
	P_DNS4 = ma.P_DNS4
	// Deprecated: use ma.P_DNS6
	P_DNS6 = ma.P_DNS6
	// Deprecated: use ma.P_DNSADDR
	P_DNSADDR = ma.P_DNSADDR
)

Extracted from source of truth for multicodec codes: https://github.com/multiformats/multicodec

Variables

View Source
var DefaultResolver = &Resolver{Backend: net.DefaultResolver}
View Source
var Dns4Protocol = ma.ProtocolWithCode(P_DNS4)

Deprecated: use ma.ProtocolWithCode(P_DNS4)

View Source
var Dns6Protocol = ma.ProtocolWithCode(P_DNS6)

Deprecated: use ma.ProtocolWithCode(P_DNS6)

View Source
var DnsProtocol = ma.ProtocolWithCode(P_DNS)

Deprecated: use ma.ProtocolWithCode(P_DNS)

View Source
var DnsaddrProtocol = ma.ProtocolWithCode(P_DNSADDR)

Deprecated: use ma.ProtocolWithCode(P_DNSADDR)

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 MockBackend

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

func (*MockBackend) LookupIPAddr

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

func (*MockBackend) LookupTXT

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

type Resolver

type Resolver struct {
	Backend backend
}

func (*Resolver) Resolve

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

Jump to

Keyboard shortcuts

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