beacon

package
v0.0.0-...-f03685a Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2018 License: LGPL-3.0 Imports: 10 Imported by: 5

README

To test beacon package, first execute the following command:

export BEACON_INTERFACE=eth0

Then:

go test

For docker wou might want to use docker0 interface.

Documentation

Overview

Package beacon implements a peer-to-peer discovery service for local networks. A beacon can broadcast and/or capture service announcements using UDP messages on the local area network. This implementation uses IPv4 UDP broadcasts. You can define the format of your outgoing beacons, and set a filter that validates incoming beacons. Beacons are sent and received asynchronously in the background.

This package is an idiomatic go translation of zbeacon class of czmq at following address:

https://github.com/zeromq/czmq

Instead of ZMQ_PEER socket it uses go channel and also uses go routine instead of zthread. To simplify the implementation it doesn't pass API calls through the pipe (as zbeacon does) instead it modifies beacon struct directly.

For more information please visit:

http://hintjens.com/blog:32

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Beacon

type Beacon struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Beacon defines main structure of the application

func New

func New() (b *Beacon)

New creates a new beacon on a certain UDP port.

func (*Beacon) Addr

func (b *Beacon) Addr() string

Addr returns our own IP address as printable string

func (*Beacon) Close

func (b *Beacon) Close()

Close terminates the beacon.

func (*Beacon) NoEcho

func (b *Beacon) NoEcho() *Beacon

NoEcho filters out any beacon that looks exactly like ours.

func (*Beacon) Port

func (b *Beacon) Port() int

Port returns port number

func (*Beacon) Publish

func (b *Beacon) Publish(transmit []byte) error

Publish starts broadcasting beacon to peers at the specified interval.

func (*Beacon) SetInterface

func (b *Beacon) SetInterface(iface string) *Beacon

SetInterface sets interface to bind and listen on.

func (*Beacon) SetInterval

func (b *Beacon) SetInterval(interval time.Duration) *Beacon

SetInterval sets broadcast interval.

func (*Beacon) SetPort

func (b *Beacon) SetPort(port int) *Beacon

SetPort sets UDP port.

func (*Beacon) Signals

func (b *Beacon) Signals() chan interface{}

Signals returns Signals channel

func (*Beacon) Silence

func (b *Beacon) Silence() *Beacon

Silence stops broadcasting beacon.

func (*Beacon) Subscribe

func (b *Beacon) Subscribe(filter []byte) *Beacon

Subscribe starts listening to other peers; zero-sized filter means get everything.

func (*Beacon) Unsubscribe

func (b *Beacon) Unsubscribe() *Beacon

Unsubscribe stops listening to other peers.

type Signal

type Signal struct {
	Addr     string
	Transmit []byte
}

Signal contains the body of the beacon (Transmit) and the source address

Jump to

Keyboard shortcuts

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