peerpicker

package
v0.0.0-...-8e84a60 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package peerpicker provides a groupcache.PeerPicker that utilizes a LAN peer discovery mechanism and sets up the groupcache to use the HTTPPool for communication between nodes.

Example:

picker, err := peerpicker.New(7586)
if err != nil {
	// Do something
}

fsys, err := groupcache.New(picker)
if err != nil {
	// Do something
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IsPeer

type IsPeer func(peer peerdiscovery.Discovered) (bool, string)

IsPeer determines if a discovered peer is a peer for our groupcache. Each peer will send a peer.Payload of [peer key]:[iam address], such as "groupcache:127.0.01". IsPeer() should return true if the key matches and return the iam address. We get the iam address from the message instead of the IP that sent it because discovery happens on all IPs configured for a device.

type LAN

type LAN struct {
	*groupcache.HTTPPool
	// contains filtered or unexported fields
}

LAN provides a groupcache.PeerPicker utilizing schollz peerdiscovery.

func New

func New(port int, options ...Option) (*LAN, error)

New creates a New *LAN instance listening on 'port' for groupcache connections.

func (*LAN) Close

func (l *LAN) Close()

Close stops peer discovery and shuts down the http server used with groupcache.

func (*LAN) Peers

func (l *LAN) Peers() []string

Peers retrieves the list of peers. This is only useful for debugging and monitoring. Changing a peer in this list may result in unintended behavior.

type Option

type Option func(l *LAN) error

Option is optional settings for the New() constructor.

func WithLogger

func WithLogger(logger jsfs.Logger) Option

WithLogger specifies a logger for us to use.

func WithSettings

func WithSettings(iam net.IP, settings []peerdiscovery.Settings, isPeer IsPeer) Option

WithSettings allows passing your own settings for peer discovery. If not specified this will go with our own default values for ipv4 and ipv6 (if setup). We default to port 9999. iam in the net.IP that you wish to broadcast as. This defaults to an IPv6 address on hosts with IPv6.

Directories

Path Synopsis
So....
So....

Jump to

Keyboard shortcuts

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