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
- func InstanceEnumDomain(t ServiceType, domain names.FQDN) names.FQDN
- func SubTypeEnumDomain(subtype names.Label, service names.UDN, domain names.FQDN) names.FQDN
- func TypeEnumDomain(domain names.FQDN) names.FQDN
- func ValidateTextKey(k string) error
- func ValidateTextValue(v string) error
- type Domain
- type DomainCollection
- type Instance
- func (i *Instance) A(ip net.IP) *dns.A
- func (i *Instance) AAAA(ip net.IP) *dns.AAAA
- func (i *Instance) FQDN() names.FQDN
- func (i *Instance) PTR() *dns.PTR
- func (i *Instance) SRV() *dns.SRV
- func (i *Instance) TTLInSeconds() uint32
- func (i *Instance) TXT() *dns.TXT
- func (i *Instance) TargetFQDN() names.FQDN
- func (i *Instance) Validate() error
- type InstanceCollection
- type InstanceName
- func (n InstanceName) IsQualified() bool
- func (n InstanceName) Join(s names.Name) names.Name
- func (n InstanceName) Labels() []names.Label
- func (n InstanceName) Qualify(f names.FQDN) names.FQDN
- func (n InstanceName) Split() (head names.Label, tail names.Name)
- func (n InstanceName) String() string
- func (n InstanceName) Validate() error
- type Service
- type ServiceCollection
- type ServiceType
- func (n ServiceType) IsQualified() bool
- func (n ServiceType) Join(s names.Name) names.Name
- func (n ServiceType) Labels() []names.Label
- func (n ServiceType) Qualify(f names.FQDN) names.FQDN
- func (n ServiceType) Split() (head names.Label, tail names.Name)
- func (n ServiceType) String() string
- func (n ServiceType) Validate() error
- type Text
Constants ¶
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.
func SubTypeEnumDomain ¶
SubTypeEnumDomain returns the DNS name that is queried to perform "selective instance enumeration" for a specific service sub-type within a single domain.
func TypeEnumDomain ¶
TypeEnumDomain returns the DNS name that is queried to perform "service type enumeration" for a single domain.
func ValidateTextKey ¶
ValidateTextKey if k is not a valid TXT record key.
func ValidateTextValue ¶
ValidateTextValue if v is not a valid TXT record value.
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 ¶
SubTypeEnumDomain returns the DNS name that is queried to perform "selective instance enumeration" for a specific service sub-type within this domain.
func (*Domain) TypeEnumDomain ¶
TypeEnumDomain returns DNS name that is queried perform "service type enumeration" for this domain.
type DomainCollection ¶
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) TTLInSeconds ¶
TTLInSeconds returns the instance's DNS record TTL in seconds. If i.TTL is 0, it uses DefaultTTL.
func (*Instance) TargetFQDN ¶
TargetFQDN returns the FQDN of the target host.
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 ¶
InstanceEnumDomain returns the DNS name that is queried to perform "service instance enumeration" (aka "browse") on a service within this domain.
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) 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 ¶
ParseTextPairs returns a Text map from the given set of key/value strings.
func (*Text) GetBool ¶
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) Pairs ¶
Pairs returns the string representation of each key/value pair, as they appear in the TXT record.