conncheck

package
v0.11.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package conncheck checks if a connection is alive.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnChecker

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

ConnChecker is a struct that holds the receiver and senders.

func NewConnChecker

func NewConnChecker(opts *Options) (*ConnChecker, error)

NewConnChecker creates a new ConnChecker.

func (*ConnChecker) AddSender

func (c *ConnChecker) AddSender(ctx context.Context, clusterID, ip string, updateCallback UpdateFunc) error

AddSender adds a sender.

func (*ConnChecker) DelAndStopSender

func (c *ConnChecker) DelAndStopSender(clusterID string)

DelAndStopSender stops and deletes a sender. If sender has been already stoped and deleted is a no-op function.

func (*ConnChecker) GetConnected

func (c *ConnChecker) GetConnected(clusterID string) (bool, error)

GetConnected returns the connection status with clusterID.

func (*ConnChecker) GetLatency

func (c *ConnChecker) GetLatency(clusterID string) (time.Duration, error)

GetLatency returns the latency with clusterID.

func (*ConnChecker) RunReceiver

func (c *ConnChecker) RunReceiver(ctx context.Context)

RunReceiver runs the receiver.

func (*ConnChecker) RunReceiverDisconnectObserver

func (c *ConnChecker) RunReceiverDisconnectObserver(ctx context.Context)

RunReceiverDisconnectObserver runs the receiver disconnect observer.

func (*ConnChecker) RunSender

func (c *ConnChecker) RunSender(clusterID string)

RunSender runs a sender.

type DuplicateError

type DuplicateError struct {
	Err error
}

DuplicateError is an error type for ConnChecker. It is returned when an already present sender is added.

func NewDuplicateError

func NewDuplicateError(clusterID string) *DuplicateError

NewDuplicateError returns a new DuplicateError.

func (DuplicateError) Error

func (e DuplicateError) Error() string

Error returns the error message.

type Msg

type Msg struct {
	ClusterID string    `json:"clusterID"`
	MsgType   MsgTypes  `json:"msgType"`
	TimeStamp time.Time `json:"timeStamp"`
}

Msg represents a message sent between two nodes.

func (Msg) String

func (msg Msg) String() string

type MsgTypes

type MsgTypes string

MsgTypes represents the type of a message.

const (
	// PING is the type of a ping message.
	PING MsgTypes = "PING"
	// PONG is the type of a pong message.
	PONG MsgTypes = "PONG"
)

type Options

type Options struct {
	// PingPort is the port used for the ping check.
	PingPort int
	// PingBufferSize is the size of the buffer used for the ping check.
	PingBufferSize uint
	// PingLossThreshold is the number of lost packets after which the connection check is considered as failed.
	PingLossThreshold uint
	// PingInterval is the interval at which the ping is sent.
	PingInterval time.Duration
}

Options contains the options for the wireguard interface.

func NewOptions

func NewOptions() *Options

NewOptions returns a new Options struct.

type Peer

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

Peer represents a peer.

type Receiver

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

Receiver is a receiver for conncheck messages.

func NewReceiver

func NewReceiver(conn *net.UDPConn, opts *Options) *Receiver

NewReceiver creates a new conncheck receiver.

func (*Receiver) InitPeer

func (r *Receiver) InitPeer(clusterID string, updateCallback UpdateFunc) error

InitPeer initializes a peer.

func (*Receiver) ReceivePong

func (r *Receiver) ReceivePong(msg *Msg) error

ReceivePong receives a PONG message.

func (*Receiver) Run

func (r *Receiver) Run(ctx context.Context)

Run starts the receiver.

func (*Receiver) RunDisconnectObserver

func (r *Receiver) RunDisconnectObserver(ctx context.Context)

RunDisconnectObserver starts the disconnect observer.

func (*Receiver) SendPong

func (r *Receiver) SendPong(raddr *net.UDPAddr, msg *Msg) error

SendPong sends a PONG message to the given address.

type Sender

type Sender struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

Sender is a sender for the conncheck server.

func NewSender

func NewSender(ctx context.Context, opts *Options, clusterID string, cancel func(), conn *net.UDPConn, ip string) (*Sender, error)

NewSender creates a new conncheck sender.

func (*Sender) SendPing

func (s *Sender) SendPing() error

SendPing sends a PING message to the given address.

type UpdateFunc

type UpdateFunc func(connected bool, latency time.Duration, time time.Time) error

UpdateFunc is a function called when a Receiver gets a PONG or when a connection is declared failed.

Jump to

Keyboard shortcuts

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