Documentation
¶
Overview ¶
Package discovery provides mDNS-based agent discovery for the Hub-Agent architecture.
Index ¶
- Constants
- func GetHostname() string
- func GetPlatform() string
- type Client
- func (c *Client) Clear()
- func (c *Client) Close()
- func (c *Client) Discover(ctx context.Context, timeout time.Duration) ([]*DiscoveredAgent, error)
- func (c *Client) Events() <-chan DiscoveryEvent
- func (c *Client) GetAgent(id string) *DiscoveredAgent
- func (c *Client) GetAgents() []*DiscoveredAgent
- func (c *Client) RemoveAgent(id string)
- func (c *Client) SetTimeout(d time.Duration)
- func (c *Client) StartContinuousDiscovery(ctx context.Context, interval time.Duration)
- type DiscoveredAgent
- type DiscoveryEvent
- type EventType
- type Server
- type ServiceInfo
Constants ¶
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.
const DefaultTTL = 120
DefaultTTL is the default TTL for mDNS records.
const ServiceName = "_capydeploy._tcp"
ServiceName is the mDNS service type for CapyDeploy agents.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client discovers agents on the local network via mDNS/DNS-SD.
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 ¶
RemoveAgent removes an agent from tracking.
func (*Client) SetTimeout ¶
SetTimeout sets the stale agent timeout.
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 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 ¶
RunContext runs the server until the context is cancelled.
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.