conncheck

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

conncheck

Golang package to check connectivity and latency between one-to-many hosts using UDP

Documentation

Index

Constants

View Source
const (

	// ConnectionErrorMessage is the message sent when a connection error occurs.
	ConnectionErrorMessage = "Cannot ping the other cluster."
)

Variables

View Source
var (
	// ConnectionCheckInterval is the interval at which the connection check is performed.
	ConnectionCheckInterval time.Duration = 1 * time.Second
	// ExceedingTime is the time after which the connection check is considered as failed.
	ExceedingTime time.Duration = 5 * time.Second
	// PeriodicPingInterval is the interval at which the ping is sent.
	PeriodicPingInterval time.Duration = 1 * time.Second
)

Functions

func MarshalMsg

func MarshalMsg(msg Msg) ([]byte, error)

MarshalMsg marshals a message.

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

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

RunReceiver runs the receiver.

func (*ConnChecker) RunReceiverDisconnectObserver

func (c *ConnChecker) RunReceiverDisconnectObserver() error

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 UnmarshalMsg

func UnmarshalMsg(bytes []byte) (*Msg, error)

UnmarshalMsg unmarshals a message.

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(ctx context.Context, conn *net.UDPConn, cancel context.CancelFunc) *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) error

Run starts the receiver.

func (*Receiver) RunDisconnectObserver

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

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.

func (*Sender) Stop

func (s *Sender) Stop() error

Stop stops the sender.

type UpdateFunc

type UpdateFunc func(connected bool) error

UpdateFunc is a callback function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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