healthcheck

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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

func NewListener(localHostname string, port int) (*Listener, error)

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.

func (*Listener) Start

func (l *Listener) Start(ctx context.Context) error

Start begins listening for health check packets. It blocks until ctx is cancelled or Stop is called.

func (*Listener) Stop

func (l *Listener) Stop()

Stop gracefully shuts down the listener.

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

func (m *Manager) RemovePeer(peerHostname string) error

RemovePeer stops and removes a peer session.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start begins the listener and all registered sessions.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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