dnslink

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2021 License: Apache-2.0, MIT Imports: 11 Imported by: 1

README

The reference implementation for DNSLink in golang.

Usage

You can use dnslink both as code and as an CLI tool.

Golang API

Getting started with the dnslink in a jiffy:

import {
	dnslink "github.com/dnslink-std/go"
}

result, error := dnslink.Resolve("dnslink.dev")

// If you want to follow dnslink redirects, you need to use ResolveN
result, error = dnslink.ResolveN("dnslink.dev")

if error != nil {
  switch e := error.(type) {
  default:
    // A variety other errors may be returned. Possible causes include, but are not limited to:
    // - Invalid input
    // - Timeouts / aborts
    // - Networking errors
    // - Incompatible dns packets provided by server
    panic(e)
  case dnslink.RCodeError:
    err.RCode // Error code number following - https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
    err.RCode.Name() // Error code name following (same list)
    err.Code // "RCODE_%s", err.RCode
    err.Domain // Domain lookup that resulted in the error
    if e.RCode == 3 {
      // NXDomain = Domain not found; most relevant error
    }
  }
}

// `links` property is a map[string][]string containing given links for the different keys, sorted.
result.Links["ipfs"][0] == "QmTg....yomU"

// The `log` is always an Array and contains a list of log entries
// that were should help to trace back how the linked data was resolved.
result.Log

// The `path` is always an []dnslink.PathEntry array that may contain a list of paths that
// each link may uses to deep-resolve values. The list is sorted from
// first to last.
result.Path

You can configure the DNS resolution

import {
  "net"
  "context"
  "time"
}

resolver := &dnslink.Resolver{
  LookupTXT: dnslink.NewUDPLookup("1.1.1.1:53"),
}

// The resolver will now use googles 1.1.1.1 dns server.
resolver.ResolveN("dnslink.dev")

Possible log statements

The statements contained in the log are all dnslink.LogStatements. They may be helpful to figure out why dnslink is not behaving like you expect. Every statement contains the .code property that holds the .code property to understand what happened. Depending on the warnings code the errors may have additional .entry property that holds the problematic TXT entry. A .reason property may contain an additional reason for that error to occur. If redirects are employed or Note that the order of the RESOLVE and REDIRECT entries are relevant, as they are point to the .domain at which previous errors occured. The entries between RESOLVE and REDIRECT statements however may be shuffled. These and other codes may additionally contain a .pathname and .search property, each containing their contribution to the path.

.code Meaning Additional properties
RESOLVE This domain name will be used for resolving. .domain, (.pathname, .search)
REDIRECT Redirecting away from the specified domain name. .domain, (.pathname, .search)
CONFLICT_ENTRY Multiple entries for a key were found and an entry has been ignored. .entry
INVALID_ENTRY A TXT entry with dnslink= prefix has formatting errors. .entry, .reason
RECURSIVE_DNSLINK_PREFIX The hostname requested contains multiple _dnslink prefixes.
UNUSED_ENTRY An entry is unused because a redirect overrides it. .entry
ENDLESS_REDIRECT Endless DNSLink redirects detected. .domain, (.pathname, .search)
INVALID_REDIRECT A given redirect is of invalid format. .entry
TOO_MANY_REDIRECTS Too many redirects happend. (max=32 per dnslink spec) .domain, (.pathname, .search)

Command Line

To get the command line tool you can either install it using go get

go get -u github.com/dnslink-std/go/dnslink

Or download a binary asset from the github release page.

You can get detailed help for the app by passing a --help option at the end:

dnslink --help

License

Published under dual-license: MIT OR Apache-2.0

Documentation

Index

Constants

View Source
const Version = "v0.3.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type ByValue added in v0.1.0

type ByValue struct{ LookupEntries }

func (ByValue) Less added in v0.1.0

func (s ByValue) Less(i, j int) bool

type LogStatement

type LogStatement struct {
	Code     string
	Domain   string
	Entry    string
	Reason   string
	Pathname string
	Search   Search
}

func (*LogStatement) Error added in v0.1.0

func (l *LogStatement) Error() string

func (*LogStatement) MarshalJSON

func (stmt *LogStatement) MarshalJSON() ([]byte, error)

type LookupEntries added in v0.1.0

type LookupEntries []LookupEntry

func (LookupEntries) Len added in v0.1.0

func (l LookupEntries) Len() int

func (LookupEntries) Swap added in v0.1.0

func (l LookupEntries) Swap(i, j int)

type LookupEntry added in v0.1.0

type LookupEntry struct {
	Value string `json:"value"`
	Ttl   uint32 `json:"ttl"`
}

type LookupTXTFunc

type LookupTXTFunc func(name string) (txt []LookupEntry, err error)

func NewUDPLookup added in v0.1.0

func NewUDPLookup(servers []string, udpSize uint16) LookupTXTFunc

type PathEntries added in v0.3.0

type PathEntries []PathEntry

func (PathEntries) Reduce added in v0.3.0

func (paths PathEntries) Reduce(input string) (PathEntry, error)

type PathEntry

type PathEntry struct {
	Pathname string
	Search   Search
}

func (*PathEntry) MarshalJSON

func (p *PathEntry) MarshalJSON() ([]byte, error)

func (*PathEntry) String added in v0.3.0

func (p *PathEntry) String() string

type RCode added in v0.2.0

type RCode int
const (
	NoError RCode = iota
	Success
	FormErr
	ServFail
	NXDomain
	NotImp
	Refused
	YXDomain
	YXRRSet
	NXRRSet
	NotAuth
	NotZone
	DSOTYPENI

	BADVERS_BADSIG
	BADKEY
	BADTIME
	BADMODE
	BADNAME
	BADALG
	BADTRUNC
	BADCOOKIE
)

func (RCode) Detail added in v0.2.0

func (code RCode) Detail() string

func (RCode) Name added in v0.2.0

func (code RCode) Name() string

type RCodeError added in v0.2.0

type RCodeError struct {
	RCode  RCode  `json:"rcode"`
	Code   string `json:"code"`
	Name   string `json:"error"`
	Domain string `json:"domain"`
}

func NewRCodeError added in v0.2.0

func NewRCodeError(rcode int, domain string) RCodeError

func (RCodeError) Error added in v0.2.0

func (e RCodeError) Error() string

type Resolver

type Resolver struct {
	LookupTXT LookupTXTFunc
}

func (*Resolver) Resolve

func (r *Resolver) Resolve(domain string) (Result, error)

func (*Resolver) ResolveN

func (r *Resolver) ResolveN(domain string) (Result, error)

type Result

type Result struct {
	Links map[string][]LookupEntry `json:"links"`
	Path  PathEntries              `json:"path"`
	Log   []LogStatement           `json:"log"`
}

func Resolve

func Resolve(domain string) (Result, error)

func ResolveN

func ResolveN(domain string) (Result, error)
type Search map[string][]string

func (Search) String added in v0.3.0

func (search Search) String() string

type URLParts

type URLParts struct {
	Domain   string
	Pathname string
	Search   map[string][]string
}

func (*URLParts) MarshalJSON

func (url *URLParts) MarshalJSON() ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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