mdns

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package `mdns` implements a multicast DNS client and server to be used to discover and register services over local networks

Index

Constants

View Source
const (
	DefaultName  = "mdns"  // Name of the plugin
	DefaultLabel = "local" // Default domain label and zone

)
View Source
const (
	ScopeRead  = "github.com/mutablelogic/go-server/mdns:read"
	ScopeWrite = "github.com/mutablelogic/go-server/mdns:write"
)

Variables

This section is empty.

Functions

func NewWithPlugin added in v1.1.3

func NewWithPlugin(p Plugin, label string) (*mdns, error)

Create a new logger task with provider of other tasks

Types

type EventType

type EventType uint
const (
	None EventType = iota
	Question
	Answer
	Registered
	Resolved
	Expired
	Sent
)

func (EventType) String

func (t EventType) String() string

type Message added in v1.1.3

type Message interface {
	PTR() []Ptr              // Return PTR records
	A() []net.IP             // Return A and AAAA records
	TXT() (string, []string) // Return TXT records
	SRV() (string, []Srv)    // Return SRV records
	Bytes() ([]byte, error)  // Return the packed message
	IsAnswer() bool          // Return true when the message is an answer
	IfIndex() int            // Interface to send and receive on, or nil
}

A sent or received message

func MessageFromPacket added in v1.1.3

func MessageFromPacket(packet []byte, sender net.Addr, iface net.Interface) (Message, error)

Create a message from a received packet, with a sender and the interface that the message was received on

func NewBrowseQuestion added in v1.1.5

func NewBrowseQuestion(question string, iface net.Interface) (Message, error)

Create a message from a question, to be sent on a specific interface or on all interfaces if the index is zero

func NewDiscoverQuestion added in v1.1.5

func NewDiscoverQuestion(question string, iface net.Interface) (Message, error)

Create a message from a question, to be sent on a specific interface or on all interfaces if the index is zero

func NewLookupQuestion added in v1.1.5

func NewLookupQuestion(question string, iface net.Interface) (Message, error)

Create a message from a question to retrieve TXT and SRV records, to be sent on a specific interface or on all interfaces if the index is zero

type Plugin added in v1.1.3

type Plugin struct {
	task.Plugin
	Interface string `json:"interface,omitempty"`
	Domain_   string `json:"domain,omitempty"`
}

func WithLabel added in v1.1.3

func WithLabel(label string) Plugin

func (Plugin) Domain added in v1.1.5

func (p Plugin) Domain() string

func (Plugin) Interfaces added in v1.1.3

func (p Plugin) Interfaces() ([]net.Interface, error)

func (Plugin) Label added in v1.1.3

func (p Plugin) Label() string

func (Plugin) Name added in v1.1.3

func (p Plugin) Name() string

func (Plugin) New added in v1.1.3

func (p Plugin) New(parent context.Context, _ iface.Provider) (iface.Task, error)

Create a new logger task with provider of other tasks

type Ptr added in v1.1.3

type Ptr interface {
	Service() string    // Return service
	Name() string       // Return name
	TTL() time.Duration // Return time-to-live for record
}

type Registration added in v1.1.5

type Registration struct {
	Browsed time.Time
	Expires time.Time
}

type RespInstances added in v1.1.5

type RespInstances struct {
	Zone      string     `json:"zone,omitempty"`
	Service   string     `json:"service,omitempty"`
	Instances []*Service `json:"instances,omitempty"`
}

type RespServices added in v1.1.5

type RespServices struct {
	Zone     string   `json:"zone,omitempty"`
	Services []string `json:"services,omitempty"`
}

type Service added in v1.0.46

type Service struct {
	Name    string            `json:"name,omitempty"`
	Service string            `json:"service,omitempty"`
	Added   time.Time         `json:"added,omitempty"`
	Expires time.Time         `json:"expires,omitempty"`
	A       []net.IP          `json:"a,omitempty"`
	SRV     []Srv             `json:"srv,omitempty"`
	TXT     map[string]string `json:"txt,omitempty"`
	IfIndex int               `json:"-"`
}

type Services added in v1.1.5

type Services struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Services stores the service names and registrations

func (*Services) AddA added in v1.1.5

func (srv *Services) AddA(key string, r []net.IP)

AddAddr to instance

func (*Services) AddPTR added in v1.1.5

func (srv *Services) AddPTR(key, service string, ptr Ptr, ifindex int) bool

AddPTR from service name to record, with a TTL, and return true if the service was registered rather than updated

func (*Services) AddSRV added in v1.1.5

func (srv *Services) AddSRV(key string, r []Srv)

AddSRV to instance

func (*Services) AddTXT added in v1.1.5

func (srv *Services) AddTXT(key string, txt []string)

AddTXT to instance

func (*Services) ExpireInstances added in v1.1.5

func (srv *Services) ExpireInstances() []*Service

Expire service instances and return them

func (*Services) Expired added in v1.1.5

func (srv *Services) Expired(key string) bool

Expire a service instance and return true if the service was deleted

func (*Services) GetInstances added in v1.1.5

func (srv *Services) GetInstances(services ...string) []*Service

Get the list of service instances which have not expired.

func (*Services) GetNames added in v1.1.5

func (srv *Services) GetNames() []string

Get the list of service names which have not expired.

func (*Services) NextBrowseName added in v1.1.5

func (srv *Services) NextBrowseName(ttl time.Duration) string

Returns a service name which should be browsed for instances. Will return an empty string if no service names are available, or if browsing has occurred within the ttl period.

func (*Services) NextLookupInstance added in v1.1.5

func (srv *Services) NextLookupInstance() *Service

Returns an instance name which should be looked up. Will return an empty string if no instances are available

func (*Services) Registered added in v1.1.5

func (srv *Services) Registered(name string, ttl time.Duration) bool

Register a service name to the list of services, with a TTL and return true if the service was registered rather than updated

type Srv added in v1.1.3

type Srv interface {
	Host() string     // Return host
	Port() uint16     // Return port
	Priority() uint16 // Return priority
}

Jump to

Keyboard shortcuts

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