retransmission

package
v1.2.4-rc Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: MIT Imports: 6 Imported by: 4

Documentation

Overview

Package retransmission implements a simple retransmission mechanism for network messages based on their sequence number. Retransmitting message several times for the lifetime of the given phase helps to improve message delivery rate for senders and receivers who are not perfectly synced on time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScheduleRetransmissions

func ScheduleRetransmissions(
	ctx context.Context,
	ticker *Ticker,
	retransmit func() error,
)

ScheduleRetransmissions takes the provided message and retransmits it for every new tick received from the provided Ticker for the entire lifetime of the Context calling the provided retransmit function. The retransmit function has to guarantee that every call from this function sends a message with the same sequence number.

func WithRetransmissionSupport

func WithRetransmissionSupport(delegate func(m net.Message)) func(m net.Message)

WithRetransmissionSupport takes the standard network message handler and enhances it with functionality allowing to handle retransmissions. The returned handler filters out retransmissions and calls the delegate handler only if the received message is not a retransmission or if it is a retransmission but it has not been seen by the original handler yet. The returned handler is thread-safe.

Retransmissions are identified by sender transport ID and message sequence number. Two messages with the same sender ID and sequence number are considered the same. Handler can not be reused between channels if sequence number of message is local for channel.

Types

type Ticker

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

Ticker controls the frequency of retransmissions.

func NewTicker

func NewTicker(ticks <-chan uint64) *Ticker

NewTicker creates and starts a new Ticker for the provided channel. For each item read from the channel, new tick is triggered. All handlers are unregistered and ticker is stopped when the provided channel gets closed.

func NewTimeTicker

func NewTimeTicker(ctx context.Context, duration time.Duration) *Ticker

NewTimeTicker is a convenience function allowing to create time-based retransmission.Ticker for the provided duration. When the provided context is done, all handlers are unregistered and retransmission.Ticker is stopped.

Jump to

Keyboard shortcuts

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