Documentation
¶
Index ¶
- type HealthCheckSettings
- type Listener
- type Manager
- func (m *Manager) AddPeer(peerHostname string, overlayIP net.IP, settings HealthCheckSettings) error
- func (m *Manager) GetAllPeerStatuses() map[string]*PeerStatus
- func (m *Manager) GetPeerStatus(peerHostname string) (*PeerStatus, error)
- func (m *Manager) RemovePeer(peerHostname string) error
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Stop()
- func (m *Manager) UpdatePeerSettings(peerHostname string, settings HealthCheckSettings) error
- type PeerStatus
- type SessionState
- type StateChangeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HealthCheckSettings ¶
type HealthCheckSettings struct {
TransmitInterval time.Duration
ReceiveInterval time.Duration
DetectMultiplier int
MaxBackoff time.Duration
}
HealthCheckSettings contains the configuration for a health check session.
func DefaultSettings ¶
func DefaultSettings() HealthCheckSettings
DefaultSettings returns the default health check settings.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener handles incoming health check packets on a UDP port. When a valid request is received matching the local hostname, it sends a reply with swapped source/destination.
The handler and all packet processing are lock-free by design. SetHandler must be called before Start; after that the handler field is read-only and safe for concurrent access from the read loop goroutine.
func NewListener ¶
NewListener creates a Listener bound to the given UDP port.
func (*Listener) SetHandler ¶
func (l *Listener) SetHandler(h packetHandler)
SetHandler registers a callback for incoming reply packets destined to the local hostname. It must be called before Start; the handler is not safe to change after the read loop begins.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple peer health check sessions. It coordinates the listener and all active sessions, and dispatches state change callbacks when peer health transitions occur.
func NewManager ¶
func NewManager(localHostname string, port int, onStateChange StateChangeFunc) (*Manager, error)
NewManager creates a Manager that will listen on the given UDP port and invoke onStateChange whenever a peer transitions state.
func (*Manager) AddPeer ¶
func (m *Manager) AddPeer(peerHostname string, overlayIP net.IP, settings HealthCheckSettings) error
AddPeer registers a new peer for health checking. If the manager is already running, the session starts immediately.
func (*Manager) GetAllPeerStatuses ¶
func (m *Manager) GetAllPeerStatuses() map[string]*PeerStatus
GetAllPeerStatuses returns the current health status for all peers.
func (*Manager) GetPeerStatus ¶
func (m *Manager) GetPeerStatus(peerHostname string) (*PeerStatus, error)
GetPeerStatus returns the current health status for a single peer.
func (*Manager) RemovePeer ¶
RemovePeer stops and removes a peer session.
func (*Manager) Stop ¶
func (m *Manager) Stop()
Stop gracefully shuts down the listener and all sessions.
func (*Manager) UpdatePeerSettings ¶
func (m *Manager) UpdatePeerSettings(peerHostname string, settings HealthCheckSettings) error
UpdatePeerSettings modifies the health check parameters for an existing peer.
type PeerStatus ¶
type PeerStatus struct {
State SessionState
Since time.Time
LastRTT time.Duration
PacketsSent uint64
PacketsReceived uint64
ConsecutiveReplies int
RequiredReplies int
FlapCount int
}
PeerStatus contains the current health status of a peer.
type SessionState ¶
type SessionState int
SessionState represents the health state of a peer session.
const ( // StateDown indicates the peer is unreachable. StateDown SessionState = iota // StateUp indicates the peer is healthy and responding. StateUp // StateAdminDown indicates the session has been administratively disabled. StateAdminDown )
func (SessionState) String ¶
func (s SessionState) String() string
String returns a human-readable session state.
type StateChangeFunc ¶
type StateChangeFunc func(peerHostname string, newState, oldState SessionState)
StateChangeFunc is called when a peer's health state changes.