A simple multicast LAN discovery library
Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples/basic
.gitignore
.travis.yml
LICENSE
README.md
doc.go
group.go
healthcheck.go
netutil.go
peer.go
peerevent.go
peertracker.go

README.md

Pir

GoDoc Build Status

Pir is a simple library for facilitating in device discovery on a LAN.

Installation

Using go get
go get github.com/jerluc/pir
From source
git clone https://github.com/jerluc/pir.git
cd pir
go install

Example usage

Basic usage (full source)
// Start a healthcheck server
healthcheck := pir.NewHealthCheck()
healthcheck.Start()

// Create a new peer
peer, _ := pir.NewPeer("tcp://10.1.1.1:80", healthcheck.URISpec())

// Join the group on port 9999
group := pir.NewGroup(group, 9999)
peer.Join(group)
Receiving membership updates
group.AddListener(func(event pir.MembershipEvent) bool {
  fmt.Println("Membership change event has occurred:", event)
  return true
})

Discovery protocol

Presently, this is done using a fairly common discovery protocol:

  • New peers join a group by connecting to a multicast UDP broadcast address.
    • Once joined, each peer broadcasts a simple payload consisting of the participating group, peer ID, healthcheck URI, and communications URI: GROUP_NAME|UUID4|proto://x.x.x.x:xxxxx|proto://x.x.x.x:xxxxx
  • Each participating peer in the group consumes these broadcasts, creating and updating peer trackers. Trackers are updated by attempting to send and receive data over the healthcheck URI:
    • Each successful send+receive improves tracker health
    • Each failure or timeout degrades tracker health
  • When tracker health degrades beyond a certain threshold, the tracker is removed, rendering the tracked peer invisible to the tracker