discovery

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 10 Imported by: 0

Documentation

Overview

Package discovery provides mDNS-based agent discovery for the Hub-Agent architecture.

Index

Constants

View Source
const DefaultPort = 8765

DefaultPort was the default HTTP port for agent communication. Deprecated: Agents now use dynamic ports assigned by the OS. This constant is kept for reference and backwards compatibility with tests.

View Source
const DefaultTTL = 120

DefaultTTL is the default TTL for mDNS records.

View Source
const ServiceName = "_capydeploy._tcp"

ServiceName is the mDNS service type for CapyDeploy agents.

Variables

This section is empty.

Functions

func GetHostname

func GetHostname() string

GetHostname returns the local hostname.

func GetPlatform

func GetPlatform() string

GetPlatform returns the current platform identifier.

Types

type Client

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

Client discovers agents on the local network via mDNS/DNS-SD.

func NewClient

func NewClient() *Client

NewClient creates a new mDNS discovery client.

func (*Client) Clear

func (c *Client) Clear()

Clear removes all tracked agents.

func (*Client) Close

func (c *Client) Close()

Close closes the client and its event channel.

func (*Client) Discover

func (c *Client) Discover(ctx context.Context, timeout time.Duration) ([]*DiscoveredAgent, error)

Discover performs a one-time mDNS query and returns discovered agents.

func (*Client) Events

func (c *Client) Events() <-chan DiscoveryEvent

Events returns a channel of discovery events.

func (*Client) GetAgent

func (c *Client) GetAgent(id string) *DiscoveredAgent

GetAgent returns a specific agent by ID.

func (*Client) GetAgents

func (c *Client) GetAgents() []*DiscoveredAgent

GetAgents returns all currently known agents.

func (*Client) RemoveAgent

func (c *Client) RemoveAgent(id string)

RemoveAgent removes an agent from tracking.

func (*Client) SetTimeout

func (c *Client) SetTimeout(d time.Duration)

SetTimeout sets the stale agent timeout.

func (*Client) StartContinuousDiscovery

func (c *Client) StartContinuousDiscovery(ctx context.Context, interval time.Duration)

StartContinuousDiscovery begins continuous agent discovery.

type DiscoveredAgent

type DiscoveredAgent struct {
	Info         protocol.AgentInfo `json:"info"`
	Host         string             `json:"host"`
	Port         int                `json:"port"`
	IPs          []net.IP           `json:"ips"`
	DiscoveredAt time.Time          `json:"discoveredAt"`
	LastSeen     time.Time          `json:"lastSeen"`
}

DiscoveredAgent represents an agent found via mDNS.

func (*DiscoveredAgent) Address

func (a *DiscoveredAgent) Address() string

Address returns the HTTP address for connecting to the agent.

func (*DiscoveredAgent) IsStale

func (a *DiscoveredAgent) IsStale(timeout time.Duration) bool

IsStale returns true if the agent hasn't been seen recently.

func (*DiscoveredAgent) WebSocketAddress

func (a *DiscoveredAgent) WebSocketAddress() string

WebSocketAddress returns the WebSocket address for the agent.

type DiscoveryEvent

type DiscoveryEvent struct {
	Type  EventType        `json:"type"`
	Agent *DiscoveredAgent `json:"agent"`
}

DiscoveryEvent represents a discovery or loss event.

type EventType

type EventType int

EventType indicates the type of discovery event.

const (
	EventDiscovered EventType = iota
	EventUpdated
	EventLost
)

func (EventType) String

func (e EventType) String() string

type Server

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

Server advertises an agent on the local network via mDNS/DNS-SD.

func NewServer

func NewServer(info ServiceInfo) *Server

NewServer creates a new mDNS server for advertising an agent.

func (*Server) Info

func (s *Server) Info() ServiceInfo

Info returns the service info being advertised.

func (*Server) RunContext

func (s *Server) RunContext(ctx context.Context) error

RunContext runs the server until the context is cancelled.

func (*Server) Start

func (s *Server) Start() error

Start begins advertising the agent on the network. The port must be set before calling Start (no longer defaults to DefaultPort). Safe to call multiple times: stops the existing server before re-registering.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops advertising the agent.

type ServiceInfo

type ServiceInfo struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	Platform string   `json:"platform"`
	Version  string   `json:"version"`
	Port     int      `json:"port"`
	IPs      []net.IP `json:"ips,omitempty"`
}

ServiceInfo contains information for advertising an agent.

func (*ServiceInfo) ToAgentInfo

func (s *ServiceInfo) ToAgentInfo() protocol.AgentInfo

ToAgentInfo converts ServiceInfo to protocol.AgentInfo.

Jump to

Keyboard shortcuts

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