Client & Server implementation for local DNS discovery
- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .forgejo/workflows | ||
| .gitignore | ||
| buildinfo.go | ||
| client.go | ||
| config.go | ||
| go.mod | ||
| go.sum | ||
| keys.go | ||
| LICENSE | ||
| logger.go | ||
| payload.go | ||
| README.md | ||
| renovate.json | ||
| server.go | ||
| simplediscover.go | ||
| simplediscover_test.go | ||
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.