Documentation
¶
Index ¶
Constants ¶
const (
// ProtocolVersion is the discovery protocol version
ProtocolVersion = "1.0"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClusterCallbacks ¶
type ClusterCallbacks interface {
GetNodeID() string
GetAddress() string
GetRPCPort() int
GetAllLocalIPs() []string
GetRole() string
GetCategory() string
GetTags() []string
LogInfo(msg string, args ...interface{})
LogError(msg string, args ...interface{})
LogDebug(msg string, args ...interface{})
HandleDiscoveredNode(nodeID, name string, addresses []string, rpcPort int, role, category string, tags []string, capabilities []string)
HandleNodeOffline(nodeID, reason string)
SyncToDisk() error
}
ClusterCallbacks defines the interface that discovery uses to interact with the cluster
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery handles UDP broadcast discovery
func NewDiscovery ¶
func NewDiscovery(port int, cluster ClusterCallbacks) (*Discovery, error)
NewDiscovery creates a new discovery instance
func (*Discovery) SetBroadcastInterval ¶
SetBroadcastInterval sets the broadcast interval
type DiscoveryMessage ¶
type DiscoveryMessage struct {
Version string `json:"version"` // Protocol version
Type MessageType `json:"type"` // Message type
NodeID string `json:"node_id"` // Unique node identifier
Name string `json:"name"` // Human-readable name
Addresses []string `json:"addresses"` // List of IP addresses (multiple NICs support)
RPCPort int `json:"rpc_port"` // RPC port number
Role string `json:"role"` // Cluster role: manager, coordinator, worker, observer, standby
Category string `json:"category"` // Business category: design, development, testing, etc.
Tags []string `json:"tags"` // Custom tags
Capabilities []string `json:"capabilities"` // List of capabilities
Timestamp int64 `json:"timestamp"` // Unix timestamp
}
DiscoveryMessage represents a UDP broadcast message
func NewAnnounceMessage ¶
func NewAnnounceMessage(nodeID, name string, addresses []string, rpcPort int, role, category string, tags []string, capabilities []string) *DiscoveryMessage
NewAnnounceMessage creates a new announce message
func NewByeMessage ¶
func NewByeMessage(nodeID string) *DiscoveryMessage
NewByeMessage creates a new bye message
func (*DiscoveryMessage) Bytes ¶
func (m *DiscoveryMessage) Bytes() ([]byte, error)
Bytes returns the message as JSON bytes
func (*DiscoveryMessage) IsExpired ¶
func (m *DiscoveryMessage) IsExpired() bool
IsExpired checks if the message is expired (older than 2 minutes)
func (*DiscoveryMessage) String ¶
func (m *DiscoveryMessage) String() string
String returns a string representation
func (*DiscoveryMessage) Validate ¶
func (m *DiscoveryMessage) Validate() error
Validate validates the discovery message
type LogFunc ¶
type LogFunc func(format string, args ...interface{})
LogFunc is a logging function callback
type MessageType ¶
type MessageType string
MessageType represents the type of discovery message
const ( MessageTypeAnnounce MessageType = "announce" MessageTypeBye MessageType = "bye" )
type UDPListener ¶
type UDPListener struct {
// contains filtered or unexported fields
}
UDPListener handles UDP broadcast discovery
func NewUDPListener ¶
func NewUDPListener(port int) (*UDPListener, error)
NewUDPListener creates a new UDP listener
func (*UDPListener) Broadcast ¶
func (l *UDPListener) Broadcast(msg *DiscoveryMessage) error
Broadcast sends a message to the broadcast address
func (*UDPListener) GetPort ¶
func (l *UDPListener) GetPort() int
GetPort returns the listening port
func (*UDPListener) IsRunning ¶
func (l *UDPListener) IsRunning() bool
IsRunning returns true if the listener is running
func (*UDPListener) SetMessageHandler ¶
func (l *UDPListener) SetMessageHandler(handler func(*DiscoveryMessage, *net.UDPAddr))
SetMessageHandler sets the callback for received messages