listener

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package listener monitors IP changes on a network interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileState

type FileState struct {
	// contains filtered or unexported fields
}

FileState supplies methods to handle the state via a file

func NewFileState

func NewFileState(path string) (*FileState, error)

NewFileState creates a new FileState

func (*FileState) Get

func (f *FileState) Get() (MonitoredIPs, error)

Get reads the state from a YAML file from disk

func (*FileState) InSync

func (f *FileState) InSync(with MonitoredIPs) bool

InSync tests whether the internal state corresponds to the provided one

func (*FileState) Reset

func (f *FileState) Reset() error

Reset writes an epty state to disk

func (*FileState) Set

func (f *FileState) Set(ips MonitoredIPs) error

Set writes a the state to disk in YAML representation

type Getter

type Getter interface {
	Get() (MonitoredIPs, error)
}

Getter allows to retrieve the current state of the MonitoredIPs

type InMemoryState

type InMemoryState struct {
	// contains filtered or unexported fields
}

InMemoryState stores the state in memory. It is hence volatile and only persistent as long as the program is running.

func NewInMemoryState

func NewInMemoryState() *InMemoryState

NewInMemoryState creates a new in-memory state

func (*InMemoryState) Get

func (m *InMemoryState) Get() (MonitoredIPs, error)

Get returns the currently stored state

func (*InMemoryState) InSync

func (m *InMemoryState) InSync(with MonitoredIPs) bool

InSync tests whether the internal state corresponds to the provided one

func (*InMemoryState) Reset

func (m *InMemoryState) Reset() error

Reset returns the state to its default value

func (*InMemoryState) Set

func (m *InMemoryState) Set(ips MonitoredIPs) error

Set sets the state to ips

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener listens for IP changes on an interface and updates all its configured destinations

func New

func New(cfg *cfg.ListenConfig, state State, upds ...update.Updater) (*Listener, error)

New creates a new listener

func (*Listener) Run

func (l *Listener) Run() chan struct{}

Run starts the IP change listener

type MonitoredIPs

type MonitoredIPs struct {
	IPv4 string
	IPv6 string
}

MonitoredIPs stores the IP objects

func (MonitoredIPs) String

func (m MonitoredIPs) String() string

String outputs the stored IPv4 and IPv6 information

type Setter

type Setter interface {
	Set(MonitoredIPs) error
}

Setter allows to set the state to MonitoredIPs

type State

type State interface {
	Setter
	Getter
	Reset() error
	InSync(MonitoredIPs) bool
}

State stores and informs about the current state of the monitored interface's IPs

Jump to

Keyboard shortcuts

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