dnssd

package
v0.0.0-...-67cf1be Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package dnssd provides tools for DNS-based service discovery as specified by RFC-6763. See https://tools.ietf.org/html/rfc6763.

Index

Constants

View Source
const DefaultTTL = 120 * time.Second

DefaultTTL is the default TTL for all DNS records.

Variables

This section is empty.

Functions

func InstanceEnumDomain

func InstanceEnumDomain(t ServiceType, domain names.FQDN) names.FQDN

InstanceEnumDomain returns the DNS name that is queried to perform "service instance enumeration" (aka "browse") on a service within a given domain.

See https://tools.ietf.org/html/rfc6763#section-4.

func SubTypeEnumDomain

func SubTypeEnumDomain(
	subtype names.Label,
	service names.UDN,
	domain names.FQDN,
) names.FQDN

SubTypeEnumDomain returns the DNS name that is queried to perform "selective instance enumeration" for a specific service sub-type within a single domain.

See https://tools.ietf.org/html/rfc6763#section-7.1

func TypeEnumDomain

func TypeEnumDomain(domain names.FQDN) names.FQDN

TypeEnumDomain returns the DNS name that is queried to perform "service type enumeration" for a single domain.

See https://tools.ietf.org/html/rfc6763#section-9

func ValidateTextKey

func ValidateTextKey(k string) error

ValidateTextKey if k is not a valid TXT record key.

See https://tools.ietf.org/html/rfc6763#section-6.4

func ValidateTextValue

func ValidateTextValue(v string) error

ValidateTextValue if v is not a valid TXT record value.

https://tools.ietf.org/html/rfc6763#section-6.5

Types

type Domain

type Domain struct {
	// Name is the fully-qualified name of the domain such as "example.org.".
	Name names.FQDN

	// Services is the set of services within the zone.
	Services ServiceCollection
}

Domain is a representation of an internet domain name that has DNS-SD service instances.

func (*Domain) SubTypeEnumDomain

func (d *Domain) SubTypeEnumDomain(subtype names.Label, service names.UDN) names.FQDN

SubTypeEnumDomain returns the DNS name that is queried to perform "selective instance enumeration" for a specific service sub-type within this domain.

See https://tools.ietf.org/html/rfc6763#section-7.1

func (*Domain) TypeEnumDomain

func (d *Domain) TypeEnumDomain() names.FQDN

TypeEnumDomain returns DNS name that is queried perform "service type enumeration" for this domain.

See https://tools.ietf.org/html/rfc6763#section-4.

func (*Domain) Validate

func (d *Domain) Validate() error

Validate returns an error if the service is configured incorrectly.

type DomainCollection

type DomainCollection map[names.FQDN]*Domain

DomainCollection is the map of domain name to domain.

func (DomainCollection) Add

func (c DomainCollection) Add(d *Domain)

Add adds a domain to the collection.

type Instance

type Instance struct {
	// Name is the instance's unique name.
	Name InstanceName

	// ServiceType is the type of service that this instance is.
	ServiceType ServiceType

	// Domain is the domain under which the instance is advertised.
	Domain names.FQDN

	// TargetHost is the hostname of the service. This is not necessarily in the
	// same domain as the DNS-SD records.
	//
	// If TargetHost is unqualified, it is assumed to be relative to Domain.
	TargetHost names.Name

	// TargetPort is TCP/UDP port that the service instance listens on.
	TargetPort uint16

	// Text contains a set of key/value pairs that are encoded in the instance's
	// TXT record, as per https://tools.ietf.org/html/rfc6763#section-6.3.
	Text Text

	// Priority is the "service priority" value to use for the service's SRV
	// record. It controls which servers are contacted first. Lower values have a
	// higher priority.
	//
	// See https://tools.ietf.org/html/rfc2782.
	Priority uint16

	// Weight is the "service weight" value to use for the service's SRV record.
	// It controls the likelihood that a server will be chosen from a pool of SRV
	// records with the same priority. Higher values are more likely to be chosen.
	//
	// See https://tools.ietf.org/html/rfc2782.
	Weight uint16

	// TTL is the TTL of the instance's DNS records.
	TTL time.Duration
}

Instance is a DNS-SD service instance.

func (*Instance) A

func (i *Instance) A(ip net.IP) *dns.A

A returns an instance's A record for the instance.

func (*Instance) AAAA

func (i *Instance) AAAA(ip net.IP) *dns.AAAA

AAAA returns an instance's AAAA record for the instance.

func (*Instance) FQDN

func (i *Instance) FQDN() names.FQDN

FQDN returns the instance's fully-qualified domain name.

func (*Instance) PTR

func (i *Instance) PTR() *dns.PTR

PTR returns the instance's PTR record.

func (*Instance) SRV

func (i *Instance) SRV() *dns.SRV

SRV returns the instance's SRV record.

func (*Instance) TTLInSeconds

func (i *Instance) TTLInSeconds() uint32

TTLInSeconds returns the instance's DNS record TTL in seconds. If i.TTL is 0, it uses DefaultTTL.

func (*Instance) TXT

func (i *Instance) TXT() *dns.TXT

TXT returns the instance's TXT record.

func (*Instance) TargetFQDN

func (i *Instance) TargetFQDN() names.FQDN

TargetFQDN returns the FQDN of the target host.

func (*Instance) Validate

func (i *Instance) Validate() error

Validate returns an error if the instance is configured incorrectly.

type InstanceCollection

type InstanceCollection map[InstanceName]*Instance

InstanceCollection is the map of the unqualified service instance name to the instance.

func (InstanceCollection) Add

func (c InstanceCollection) Add(i *Instance)

Add adds an instance to the collection.

type InstanceName

type InstanceName string

InstanceName is an implementation of names.Name that represents an unqualified instance name.

func SplitInstanceName

func SplitInstanceName(n names.Name) (head InstanceName, tail names.Name)

SplitInstanceName parses the first label of n as a backslash-escaped instance name. If n contains only a single label, tail is nil.

func (InstanceName) IsQualified

func (n InstanceName) IsQualified() bool

IsQualified returns false.

func (InstanceName) Join

func (n InstanceName) Join(s names.Name) names.Name

Join returns a name produced by concatenating this name with s. It panics if this name is fully qualified.

func (InstanceName) Labels

func (n InstanceName) Labels() []names.Label

Labels returns the DNS labels that form this name.

func (InstanceName) Qualify

func (n InstanceName) Qualify(f names.FQDN) names.FQDN

Qualify returns a fully-qualified domain name produced by "qualifying" this name with f.

func (InstanceName) Split

func (n InstanceName) Split() (head names.Label, tail names.Name)

Split splits the "hostname" from the name. If the name does not contain any dots, tail is nil.

func (InstanceName) String

func (n InstanceName) String() string

String returns a representation of the name as used by DNS systems. It panics if the name is not valid.

func (InstanceName) Validate

func (n InstanceName) Validate() error

Validate returns nil if the name is valid.

type Service

type Service struct {
	// Type is the DNS-SD service type, including the protocol, such as
	// "_http._tcp".
	Type ServiceType

	// Domain is the fully-qualified name of the domain that the service is
	// advertised within. For example, Bonjour typically uses "local."
	Domain names.FQDN

	// Instance is the set of instances of this services, keyed by the instance
	// name.
	Instances InstanceCollection
}

Service represents a DNS-SD service.

func (*Service) InstanceEnumDomain

func (s *Service) InstanceEnumDomain() names.FQDN

InstanceEnumDomain returns the DNS name that is queried to perform "service instance enumeration" (aka "browse") on a service within this domain.

See https://tools.ietf.org/html/rfc6763#section-4.

func (*Service) PTR

func (s *Service) PTR() (*dns.PTR, bool)

PTR returns the service's PTR record as queried when performing "service type enumeration".

It returns false if the service does not have any instances.

See https://tools.ietf.org/html/rfc6763#section-9.

func (*Service) Validate

func (s *Service) Validate() error

Validate returns an error if the service is configured incorrectly.

type ServiceCollection

type ServiceCollection map[ServiceType]*Service

ServiceCollection is the map of service type (such as "_http._tcp") to the service.

func (ServiceCollection) Add

func (c ServiceCollection) Add(s *Service)

Add adds a domain to the collection.

type ServiceType

type ServiceType string

ServiceType is an implementation of names.Name that represents a DNS-SD service type.

func (ServiceType) IsQualified

func (n ServiceType) IsQualified() bool

IsQualified returns false.

func (ServiceType) Join

func (n ServiceType) Join(s names.Name) names.Name

Join returns a name produced by concatenating this name with s. It panics if this name is fully qualified.

func (ServiceType) Labels

func (n ServiceType) Labels() []names.Label

Labels returns the DNS labels that form this name. It panics if the name is not valid.

func (ServiceType) Qualify

func (n ServiceType) Qualify(f names.FQDN) names.FQDN

Qualify returns a fully-qualified domain name produced by "qualifying" this name with f.

func (ServiceType) Split

func (n ServiceType) Split() (head names.Label, tail names.Name)

Split splits the first label from the name. If the name only has single label, tail is nil.

func (ServiceType) String

func (n ServiceType) String() string

String returns a representation of the name as used by DNS systems. It panics if the name is not valid.

func (ServiceType) Validate

func (n ServiceType) Validate() error

Validate returns nil if the name is valid.

type Text

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

Text is a map that represents the key/value pairs in a service instance's TXT record.

Keys are case-insensitive. The specification states that keys SHOULD be no longer than 9 characters. However since this is not a strict requirement, no such limit is enforced by this implementation.

See https://tools.ietf.org/html/rfc6763#section-6.1

func ParseTextPairs

func ParseTextPairs(pairs []string) (Text, error)

ParseTextPairs returns a Text map from the given set of key/value strings.

func (*Text) Delete

func (t *Text) Delete(k ...string)

Delete removes all of the given keys from the map.

func (*Text) Get

func (t *Text) Get(k string) (string, bool)

Get returns the first value that is associated with the key k.

func (*Text) GetBool

func (t *Text) GetBool(k string) bool

GetBool returns true if k is present in the map.

This method is similar to Has(). It is included to better express intent when a key is used as a boolean value as per the recommendations in https://tools.ietf.org/html/rfc6763#section-6.4.

func (*Text) Has

func (t *Text) Has(k ...string) bool

Has returns true if all of the keys in k are present in the map.

func (*Text) Pairs

func (t *Text) Pairs() []string

Pairs returns the string representation of each key/value pair, as they appear in the TXT record.

func (*Text) Set

func (t *Text) Set(k string, v string)

Set associates the value v with the key k. It is recommended that keys be no longer than 9 characters.

func (*Text) SetBool

func (t *Text) SetBool(k string, v bool)

SetBool associates an empty value with k if v is true; otherwise, it deletes the value associated with k, if any.

Jump to

Keyboard shortcuts

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