Client & Server implementation for local DNS discovery
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-20 18:31:09 -04:00
.forgejo/workflows chore(deps): update https://vc.maxkaya.com/maxpeterkaya/changelog action to v2 2026-09-16 14:53:54 +00:00
.gitignore feat: add .idea to gitignore 2026-05-15 21:48:31 -04:00
buildinfo.go feat: add buildinfo 2026-05-15 21:49:12 -04:00
client.go feat(client): track clients in memory, dedupe by ID, and add OnDiscover callback 2026-08-16 20:01:18 -04:00
config.go feat(config): add BroadcastPort, BroadcastInterval, and OnDiscover options 2026-08-16 20:00:57 -04:00
go.mod chore(deps): update module charm.land/log/v2 to v2.0.1 2026-09-03 13:54:55 +00:00
go.sum feat: create module 2026-05-15 21:51:07 -04:00
keys.go refactor(keys): return errors instead of printing debug output 2026-08-16 20:01:12 -04:00
LICENSE Initial commit 2026-03-11 12:22:02 -04:00
logger.go feat: add logger 2026-05-15 21:49:25 -04:00
payload.go refactor(payload): propagate encode/decode errors instead of log.Fatal 2026-08-16 20:01:10 -04:00
README.md docs: add informational README 2026-08-16 20:03:24 -04:00
renovate.json Add renovate.json 2026-05-16 03:15:10 +00:00
server.go feat: broadcast to all interfaces 2026-08-21 12:42:39 -04:00
simplediscover.go feat(simplediscover): return setup errors and add SetAdvertisedPort 2026-08-16 20:01:14 -04:00
simplediscover_test.go feat: broadcast to all interfaces 2026-08-21 12:42:39 -04:00

simplediscover

Zero-config service discovery over UDP broadcast for local networks.

Each node announces its identity and advertised port on a fixed port. Neighbours listen for those announcements and keep a live list of every node they have seen.

Install

go get vc.maxkaya.com/maxpeterkaya/simplediscover

Usage

discover, err := simplediscover.New(&simplediscover.Options{
    Config: &simplediscover.Config{
        Name:       "my-service",
        Port:       9002,
        OnDiscover: handleNeighbour,
    },
})
if err != nil {
    log.Fatal(err)
}

stop := make(chan struct{})
go discover.StartServer(stop)
go discover.StartClient(stop)

OnDiscover fires when a neighbour is seen for the first time, changes, or checks in again with a refreshed timestamp. Close the stop channel to shut down cleanly.

Configuration

Option Purpose
Name Identifier for this node and its service
DataPath Directory for the node ID, keys, and clients.txt
ListenIP Address the listener binds to
BroadcastIP Address announcements are sent to
Port Listener port, also advertised to neighbours
BroadcastPort Destination port for announcements
BroadcastInterval Time between announcements
OnDiscover Callback for discovered or updated neighbours

Defaults cover a typical LAN. ListenIP defaults to 0.0.0.0, BroadcastIP to 255.255.255.255, and Port to 9002. DataPath defaults to a simplediscover folder in your system config directory.