rcudp

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 12 Imported by: 0

README

Raptor code over User Datagram Protocol

RC-UDP implements Raptor Coding over UDP transport protocol with tunable overhead.

The package provides two utilities - a RC-UDP Reader (Client) and a RC-UDP Writer (Server). Message encoding/decoding is based on the Raptor fountain code (also called the R10 code) from RFC 5053.

Naming convention

In this package a message means the complete data blob to be transmitted on the wire.
Packet is the UDP packet which includes a single block of the message.
Blocks are the segments which a message is encoded to.

Writer


rcudp.Writer(...) function is a UDP client that uses gofountain Raptor Code encoder to split a message into source blocks. An encoded block together with metadata is marshalled into a UDP packet with following structure:

    MessageID           8 bytes
	NumSourceSymbols    2 bytes
	PaddingSize         2 bytes
	TransferLength      4 bytes
	BlockID             4 bytes
	BlockData        1452 bytes

Note that overall size of a packet is up to 1472 (=1500-8-20) bytes. (default MTU size minus UDP Header size minus IPv4 header size)

The size of a complete wire message is TransferLength - PaddingSize. A limitation is that the code supports a maximum of 8192 source blocks. With current BlockData size of 1452, the maximum length of a message that can be transmitted is 1452*8192 (~11.89 MB)

NumSourceSymbols - K. Must be in the range [4, 8192] (inclusive). This is how many source symbols the input message will be divided into.

Tuning

backoffTimeout (config.go) - defines delay before each UDP socket write. This is intended to reduce the load on both sender and recv udp buffers.

writeBufferSize (config.go) - UDP Sender buffer size can be up to net.core.wmem_max (Linux)

redundancyFactor input param - defines the count of additional encoded blocks to be generated and sent

Reader


UDPReader is a UDP server that collects Raptor fountain code blocks from the wire and makes attempts to decode (recover) the complete and original message. It correlates blocks by MessageID. When a message is decoded, its processing is delegated to the MessageCollector (a callback).

Tuning

staleTimeout - The size of the time-window within which a message should be completely received and decoded. Out of this time-window, the message is marked as stale and deleted.

readBufferSize - UDP Recv buffer size can be up to net.core.rmem_max (Linux)

Documentation

Index

Constants

View Source
const (

	// BcastHeightPos is position in packet binary of height byte.
	BcastHeightPos = 20
)
View Source
const (

	// BlockSize - max length of an encoding symbol that can fit into a single wire packet.
	BlockSize = maxUDPLength - 8 - 2 - 2 - 4 - 4 - 8
)

Variables

View Source
var (

	// ErrTooLargeUDP packet cannot fit into default MTU of 1500.
	ErrTooLargeUDP = errors.New("packet cannot fit into default MTU of 1500")
)

Functions

func CompileRaptorRFC5053 added in v0.4.3

func CompileRaptorRFC5053(height byte, message []byte, redundancyFactor uint8) ([]byte, [][]byte, error)

CompileRaptorRFC5053 compiles raptorRFC5053 blocks from message with a specified redundancyFactor. In Kadcast, one could compile blocks once but send them to multiple delegates.

func WriteBlocks added in v0.4.3

func WriteBlocks(laddr, raddr *net.UDPAddr, blocks [][]byte, height byte) error

WriteBlocks writes already compiled raptor blocks to raddr via UDP. It utilizes a simple back-off.

Types

type Decoder

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

Decoder is based on fountain.newRaptorDecoder.

func NewDecoder

func NewDecoder(numSourceSymbols, symbolAlignmentSize, transferLength, paddingSize int) *Decoder

NewDecoder creates a wrapper decoder of fountain.Decoder.

func (*Decoder) AddBlock

func (d *Decoder) AddBlock(b fountain.LTBlock) []byte

AddBlock add a LTBlock to the a decoder.

func (*Decoder) AddBlocks

func (d *Decoder) AddBlocks(blocks []fountain.LTBlock) []byte

AddBlocks add a set of LTBlock to the a decoder If the object is reconsturcted (fully decoded), AddBlocks returns the decoded object.

func (*Decoder) IsReady

func (d *Decoder) IsReady() bool

IsReady returns true, if the object is already reconstructed.

type Encoder

type Encoder struct {
	SymbolAlignmentSize uint16

	// output parameters.
	PaddingSize      uint16
	NumSourceSymbols int
	// contains filtered or unexported fields
}

Encoder is wrapper around Raptor RFC5053 from gofountain.EncodeLTBlocks.

func NewEncoder

func NewEncoder(message []byte, maxPacketSize uint16, redundancyFactor uint8, symbolAlignmentSize uint16) (*Encoder, error)

NewEncoder creates a Raptor RFC5053 wrapper.

func (*Encoder) GenerateBlocks

func (e *Encoder) GenerateBlocks() []fountain.LTBlock

GenerateBlocks encodes raptor codes. NB: This method is destructive to the w.message array.

func (*Encoder) TransferLength

func (e *Encoder) TransferLength() int

TransferLength is the number of message plus calculated padding.

type MessageCollector

type MessageCollector func(reserved byte, addr string, decoded []byte) error

MessageCollector callback to be run on a newly decoded message.

type Packet

type Packet struct {
	NumSourceSymbols uint16
	PaddingSize      uint16
	// contains filtered or unexported fields
}

Packet is the UDP packet that consists of encoding symbol data unit and raptor-specific data.

type UDPReader

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

UDPReader that supports decoding Raptor codes packets.

func NewUDPReader

func NewUDPReader(lAddr *net.UDPAddr, h MessageCollector) (*UDPReader, error)

NewUDPReader instantiate a UDP reader of raptor code packets.

func (*UDPReader) Serve

func (r *UDPReader) Serve()

Serve reads data from UDP socket and tries to re-assemble the sourceObject.

Jump to

Keyboard shortcuts

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