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 ¶
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 ¶
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 ¶
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 ¶
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.