Documentation ¶
Index ¶
- Constants
- Variables
- func MarshalMsg(msg Msg) ([]byte, error)
- type ConnChecker
- func (c *ConnChecker) AddAndRunSender(clusterID, ip string, updateCallback UpdateFunc) error
- func (c *ConnChecker) DelAndStopSender(clusterID string)
- func (c *ConnChecker) GetConnected(clusterID string) (bool, error)
- func (c *ConnChecker) GetLatency(clusterID string) (time.Duration, error)
- func (c *ConnChecker) RunReceiver() error
- func (c *ConnChecker) RunReceiverDisconnectObserver() error
- type Msg
- type MsgTypes
- type Peer
- type Receiver
- func (r *Receiver) InitPeer(clusterID string, updateCallback UpdateFunc) error
- func (r *Receiver) ReceivePong(msg *Msg) error
- func (r *Receiver) Run(ctx context.Context) error
- func (r *Receiver) RunDisconnectObserver(ctx context.Context) error
- func (r *Receiver) SendPong(raddr *net.UDPAddr, msg *Msg) error
- type Sender
- type UpdateFunc
Constants ¶
const (
// ConnectionErrorMessage is the message sent when a connection error occurs.
ConnectionErrorMessage = "Cannot ping the other cluster."
)
Variables ¶
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 ¶
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 ¶
UnmarshalMsg unmarshals a message.
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver is a receiver for conncheck messages.
func NewReceiver ¶
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 ¶
ReceivePong receives a PONG message.
func (*Receiver) RunDisconnectObserver ¶
RunDisconnectObserver starts the disconnect observer.
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.