discovery

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MPL-2.0 Copyright (c) 2025 KeibiSoft S.R.L. This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. Package discovery implements LAN peer discovery over UDP multicast, stdlib only. Beacons carry a random per-session two-word name and the listen port; no fingerprints, no identity data.

SPDX-License-Identifier: MPL-2.0 Copyright (c) 2025 KeibiSoft S.R.L. This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Beacon

type Beacon struct {
	Name string `json:"n"`           // random two-word name (e.g., "Cosmic Waffle")
	Port int    `json:"p"`           // TCP listening port for KeibiDrop
	Ver  int    `json:"v,omitempty"` // protocol version (1)
	ID   string `json:"i,omitempty"` // random per-session id; self-filter uses this, not Name
}

Beacon is the UDP payload broadcast by each peer.

type Peer

type Peer struct {
	Name     string
	Addr     string // "192.168.1.42:26431"
	LastSeen time.Time
}

Peer represents a discovered peer on the LAN.

type Service

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

Service handles both advertising and browsing for KeibiDrop peers.

func New

func New(port int, logger *slog.Logger) *Service

New creates a discovery service with a random two-word name.

func (*Service) ClearPeers added in v0.3.0

func (s *Service) ClearPeers()

ClearPeers removes all discovered peers without stopping the service.

func (*Service) Name

func (s *Service) Name() string

Name returns this peer's random display name.

func (*Service) Peers

func (s *Service) Peers() []Peer

Peers returns a snapshot of currently discovered peers.

func (*Service) Start

func (s *Service) Start() error

Start begins advertising this peer and listening for others.

func (*Service) Stop

func (s *Service) Stop()

Stop stops advertising and listening.

Jump to

Keyboard shortcuts

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