peerdiscovery

package
v0.0.0-...-0810b70 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: GPL-3.0 Imports: 8 Imported by: 1

Documentation

Overview

Package peerdiscovery provides automatic detection of other peers in the same subnet. It does this by utilizing broadcastmessages over UDP. The package is in part based on https://github.com/TTK4145/Network-go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLocalIP

func GetLocalIP() (string, error)

GetLocalIP return the IP-address of the local client. It does this by dialing the Google DNS service, hence it will fail if it is unable to reach the internet.

func Start

func Start(c Config)

Start initiate listening for other peers while also start broadcasting to others. The `id`-field in the callbacks have the form:

"nick"@"ip-address":"raft-port"

where the latter part is the IPv4 address of the peer.

Types

type Config

type Config struct {
	Nick              string
	RaftPort          int
	BroadcastPort     int
	OnNewPeer         func(Peer)
	OnLostPeer        func(Peer)
	BroadcastInterval time.Duration
	Timeout           time.Duration
	Logger            *log.Logger
}

Config defines configuration for the package, including callbacks.

type Peer

type Peer struct {
	IP       string
	Nick     string
	JoinPort string
	RaftPort string
	// contains filtered or unexported fields
}

Peer holds information of address, ports and when it was detected.

func (*Peer) DeepCopy

func (p *Peer) DeepCopy() Peer

DeepCopy safely returns a copy of the peer.

Jump to

Keyboard shortcuts

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