conncheck

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 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

View Source
var (
	// 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
)

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() (*ConnChecker, error)

NewConnChecker creates a new ConnChecker.

func (*ConnChecker) AddAndRunSender

func (c *ConnChecker) AddAndRunSender(clusterID, ip string, updateCallback UpdateFunc)

AddAndRunSender create a new sender and runs it.

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()

RunReceiver runs the receiver.

func (*ConnChecker) RunReceiverDisconnectObserver

func (c *ConnChecker) RunReceiverDisconnectObserver()

RunReceiverDisconnectObserver runs the receiver disconnect observer.

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 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) *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()

Run starts the receiver.

func (*Receiver) RunDisconnectObserver

func (r *Receiver) RunDisconnectObserver()

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 {
	// contains filtered or unexported fields
}

Sender is a sender for the conncheck server.

func NewSender

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

NewSender creates a new conncheck sender.

func (*Sender) SendPing

func (s *Sender) SendPing(ctx context.Context) 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