server

package
v0.0.0-...-b56da86 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package server implements simple UDP server to work with NTP packets. In addition, it run checker, announce and stats implementations

Index

Constants

This section is empty.

Variables

View Source
var DefaultServerIPs = MultiIPs{net.ParseIP("127.0.0.1"), net.ParseIP("::1")}

DefaultServerIPs is a default list of IPs server will bind to if nothing else is specified

Functions

This section is empty.

Types

type Announce

type Announce interface {
	// Do the announcement
	// Usually here advertise config is renewed
	// Unblocking. Run periodically
	Advertise([]net.IP) error
	// Stop announcement
	// Usually here advertise config is deleted
	Withdraw() error
}

Announce is an announce interface

type Checker

type Checker interface {
	// Check is a method which performs basic validations that responder is alive
	Check() error

	// IncListeners atomically add 1 to the counter
	IncListeners()
	// IncWorkers atomically add 1 to the counter
	IncWorkers()

	// DecListeners atomically removes 1 from the counter
	DecListeners()
	// DecWorkers atomically removes 1 from the counter
	DecWorkers()
}

Checker is an internal healthcheck interface

type Config

type Config struct {
	ExtraOffset    time.Duration
	Iface          string
	IPs            MultiIPs
	ManageLoopback bool
	MonitoringPort int
	Port           int
	RefID          string
	ShouldAnnounce bool
	Stratum        int
	TimestampType  timestamp.Timestamp
	Workers        int
	// contains filtered or unexported fields
}

Config is a server config structure

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if config is valid

type MultiIPs

type MultiIPs []net.IP

MultiIPs is a wrapper allowing to set multiple IPs with flag parser

func (*MultiIPs) Set

func (m *MultiIPs) Set(ipaddr string) error

Set adds check to the runlist

func (*MultiIPs) SetDefault

func (m *MultiIPs) SetDefault()

SetDefault adds all checks to the runlist

func (*MultiIPs) String

func (m *MultiIPs) String() string

String returns joined list of checks

type Server

type Server struct {
	Config   Config
	Announce Announce
	Stats    Stats
	Checker  Checker
	// contains filtered or unexported fields
}

Server is a type for UDP server which handles connections.

func (*Server) DeleteAllIPs

func (s *Server) DeleteAllIPs()

DeleteAllIPs deletes all IPs from interface specified in config

func (*Server) Start

func (s *Server) Start(ctx context.Context, cancelFunc context.CancelFunc)

Start UDP server.

func (*Server) Stop

func (s *Server) Stop()

Stop will stop announcement, delete IPs from interfaces

type Stats

type Stats interface {
	// Start starts a stat reporter
	// Use this for passive reporters
	Start(int)

	// IncInvalidFormat atomically add 1 to the counter
	IncInvalidFormat()
	// IncRequests atomically add 1 to the counter
	IncRequests()
	// IncResponses atomically add 1 to the counter
	IncResponses()
	// IncListeners atomically add 1 to the counter
	IncListeners()
	// IncWorkers atomically add 1 to the counter
	IncWorkers()
	// IncReadError atomically add 1 to the counter
	IncReadError()

	// DecListeners atomically removes 1 from the counter
	DecListeners()
	// DecWorkers atomically removes 1 from the counter
	DecWorkers()

	// SetAnnounce atomically sets counter to 1
	SetAnnounce()
	// ResetAnnounce atomically sets counter to 0
	ResetAnnounce()
}

Stats is a metric collection interface

Jump to

Keyboard shortcuts

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