network

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectRemoteArch

func DetectRemoteArch(ip string, port int) string

attempts to detect the architecture of a remote Baleen node by querying its metadata server.

func DiscoverPeers

func DiscoverPeers(ctx context.Context, wg *sync.WaitGroup, currentNodeName string, registry *PeerRegistry, enabled *atomic.Bool)

continuously sweeps the local network for Baleen nodes.

func GenerateTLS

func GenerateTLS() (*tls.Config, error)

Generates a TLS config for the daemon session.

func GetCertificateFingerprint

func GetCertificateFingerprint(config *tls.Config) string

GetCertificateFingerprint returns the SHA-256 fingerprint of the primary certificate in the config

func LoadStaticPeers

func LoadStaticPeers(pr *PeerRegistry)

func ResolveTargetAddress

func ResolveTargetAddress(registry *PeerRegistry, peer string) (ip string, port int, fingerprint string, err error)

ResolveTargetAddress resolves a peer name or address to an IP and port, using the peer registry if available.

func StartBroadcaster

func StartBroadcaster(ctx context.Context, wg *sync.WaitGroup, nodeName string, port int, fingerprint string, enabled *atomic.Bool)

advertises this node via mDNS. The enabled flag is checked every 200 ms

func StartMetadataServer

func StartMetadataServer(port int, broadcastEnabled *atomic.Bool)

runs a lightweight HTTP server to expose the node's architecture.

Types

type APINode

type APINode struct {
	Address     string
	Source      string
	Status      string
	Arch        string
	Fingerprint string
	LastSeen    time.Time
}

type NetworkController

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

manages the mDNS discovery and broadcast goroutines, allowing them to be toggled on/off at runtime.

func NewNetworkController

func NewNetworkController(
	parentCtx context.Context,
	nodeName string,
	port int,
	fingerprint string,
	registry *PeerRegistry,
	discoveryEnabled bool,
	broadcastEnabled bool,
) *NetworkController

starts both mDNS goroutines immediately and sets their initial enabled states from the persisted settings.

func (*NetworkController) BroadcastEnabledFlag

func (nc *NetworkController) BroadcastEnabledFlag() *atomic.Bool

returns a pointer to the atomic boolean controlling broadcast presence.

func (*NetworkController) GetNodeName

func (nc *NetworkController) GetNodeName() string

returns the current node name safely.

func (*NetworkController) IsBroadcastEnabled

func (nc *NetworkController) IsBroadcastEnabled() bool

reports whether presence broadcasting is currently enabled.

func (*NetworkController) IsDiscoveryEnabled

func (nc *NetworkController) IsDiscoveryEnabled() bool

reports whether mDNS discovery is currently enabled.

func (*NetworkController) SetBroadcast

func (nc *NetworkController) SetBroadcast(enabled bool)

enables or disables presence broadcasting. Takes effect within 200 ms.

func (*NetworkController) SetDiscovery

func (nc *NetworkController) SetDiscovery(enabled bool)

enables or disables peer discovery. Takes effect within 500 ms.

func (*NetworkController) UpdateNodeName

func (nc *NetworkController) UpdateNodeName(newName string)

updates the node name and restarts mDNS routines if the name changed.

type PeerMeta

type PeerMeta struct {
	Source      string
	Status      string
	Arch        string
	Fingerprint string
	LastSeen    time.Time
}

API Metadata struct (Invisible to CLI)

type PeerRegistry

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

safely stores active nodes to prevent race conditions

func NewPeerRegistry

func NewPeerRegistry() *PeerRegistry

func (*PeerRegistry) AddCustomPeer

func (pr *PeerRegistry) AddCustomPeer(name, address, source string)

func (*PeerRegistry) AddPeer

func (pr *PeerRegistry) AddPeer(name, address, fingerprint string)

func (*PeerRegistry) ClearMDNSPeers

func (pr *PeerRegistry) ClearMDNSPeers()

clears all peers from the registry, leaving only static or manually added peers.

func (*PeerRegistry) GetAllPeers

func (pr *PeerRegistry) GetAllPeers() map[string]string

func (*PeerRegistry) GetDetailedPeers

func (pr *PeerRegistry) GetDetailedPeers() map[string]*APINode

func (*PeerRegistry) RemovePeer

func (pr *PeerRegistry) RemovePeer(name string)

safely deletes a disconnected node from the registry

func (*PeerRegistry) StartHealthChecker

func (pr *PeerRegistry) StartHealthChecker(ctx context.Context, wg *sync.WaitGroup)

constantly pings known peers to ensure they are still online

Jump to

Keyboard shortcuts

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