dnslink

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 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 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 `txtEntries` are a reduced form of the links that contains the namespace
// as part of the value.
result.TxtEntries === [{ value: "/ipfs/QmTg....yomU", ttl: 60 }]

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.Resolve("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.

.code Meaning Additional properties
FALLBACK No _dnslink. prefixed domain was found. Falling back to the regular domain.
INVALID_ENTRY A TXT entry with dnslink= prefix has formatting errors. .entry, .reason

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 MAX_UINT_32 uint32 = 4294967295
View Source
const Version = "v0.6.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type ByValue added in v0.1.0

type ByValue struct{ NamespaceEntries }

func (ByValue) Less added in v0.1.0

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

type DNSRCode added in v0.6.0

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

	BADVERS_BADSIG
	BADKEY
	BADTIME
	BADMODE
	BADNAME
	BADALG
	BADTRUNC
	BADCOOKIE
)

func (DNSRCode) Detail added in v0.6.0

func (code DNSRCode) Detail() string

func (DNSRCode) Name added in v0.6.0

func (code DNSRCode) Name() string

type DNSRCodeError added in v0.6.0

type DNSRCodeError struct {
	DNSRCode DNSRCode `json:"dnsrcode"`
	Code     string   `json:"code"`
	Name     string   `json:"error"`
	Domain   string   `json:"domain"`
}

func NewDNSRCodeError added in v0.6.0

func NewDNSRCodeError(dnsrcode int, domain string) DNSRCodeError

func (DNSRCodeError) Error added in v0.6.0

func (e DNSRCodeError) Error() string

type LogStatement

type LogStatement struct {
	Code   string
	Entry  string
	Reason string
}

func (*LogStatement) Error added in v0.1.0

func (l *LogStatement) Error() string

func (*LogStatement) MarshalJSON

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

type LookupEntry added in v0.1.0

type LookupEntry struct {
	Value string
	Ttl   uint32
}

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 NamespaceEntries added in v0.5.0

type NamespaceEntries []NamespaceEntry

func (NamespaceEntries) Len added in v0.5.0

func (l NamespaceEntries) Len() int

func (NamespaceEntries) Swap added in v0.5.0

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

type NamespaceEntry added in v0.5.0

type NamespaceEntry struct {
	Identifier string `json:"identifier"`
	Ttl        uint32 `json:"ttl"`
}

type Resolver

type Resolver struct {
	LookupTXT LookupTXTFunc
}

func (*Resolver) Resolve

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

type Result

type Result struct {
	TxtEntries []TxtEntry                  `json:"txtEntries"`
	Links      map[string]NamespaceEntries `json:"links"`
	Log        []LogStatement              `json:"log"`
}

func Resolve

func Resolve(domain string) (Result, error)

func (*Result) NoTtl added in v0.6.0

func (result *Result) NoTtl() ResultNoTtl

type ResultNoTtl added in v0.6.0

type ResultNoTtl struct {
	TxtEntries []string            `json:"txtEntries"`
	Links      map[string][]string `json:"links"`
	Log        []LogStatement      `json:"log"`
}

type TxtEntry added in v0.5.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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