alo

package
v0.0.2-0...-1c7e8a7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: Unlicense Imports: 6 Imported by: 0

Documentation

Overview

Package alo implements a forward error correction scheme using Reed Solomon Erasure Coding. It segments the data into 1kb chunks in 16kb segments and contains a function for use in a network handler to process received packets

Index

Constants

View Source
const (
	SegmentSize = 2 << 13
	ShardSize   = 2 << 9
)

Variables

This section is empty.

Functions

func Check

func Check(err error) bool

func Debug

func Debug(a ...interface{})

func Debugc

func Debugc(fn func() string)

func Debugf

func Debugf(format string, a ...interface{})

func Debugs

func Debugs(a interface{})

func Error

func Error(a ...interface{})

func Errorc

func Errorc(fn func() string)

func Errorf

func Errorf(format string, a ...interface{})

func Errors

func Errors(a interface{})

func Fatal

func Fatal(a ...interface{})

func Fatalc

func Fatalc(fn func() string)

func Fatalf

func Fatalf(format string, a ...interface{})

func Fatals

func Fatals(a interface{})

func Info

func Info(a ...interface{})

func Infoc

func Infoc(fn func() string)

func Infof

func Infof(format string, a ...interface{})

func Infos

func Infos(a interface{})

func Pieces

func Pieces(dLen, size int) (s int)

Pieces computes the number of pieces based on a given chunk size

func SegmentBytes

func SegmentBytes(buf []byte, lim int) (out [][]byte)

SegmentBytes breaks a chunk of data into requested sized limit chunks

func ShardsPerRedundancy

func ShardsPerRedundancy(nShards, redundancy int) int

func Trace

func Trace(a ...interface{})

func Tracec

func Tracec(fn func() string)

func Tracef

func Tracef(format string, a ...interface{})

func Traces

func Traces(a interface{})

func Warn

func Warn(a ...interface{})

func Warnc

func Warnc(fn func() string)

func Warnf

func Warnf(format string, a ...interface{})

func Warns

func Warns(a interface{})

Types

type PartialSegment

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

PartialSegment is a max 16kb long segment with arbitrary redundancy parameters when all of the data segments are successfully received hasAll indicates the segment may be ready to reassemble

func (PartialSegment) GetShardCount

func (p PartialSegment) GetShardCount() (count int)

GetShardCount returns the number of shards already acquired

type Partials

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

Partials is a structure for storing a new inbound packet

func NewPacket

func NewPacket(firstShard []byte) (o *Partials, err error)

NewPacket creates a new structure to store a collection of incoming shards when the first of a new packet arrives

func (*Partials) AddShard

func (p *Partials) AddShard(newShard []byte) (err error)

AddShard adds a newly received shard to a Partials, ensuring that it has matching parameters (if the HMAC on the packet's wrapper passes it should be unless someone is playing silly buggers)

func (*Partials) Decode

func (p *Partials) Decode() (final []byte, err error)

Decode the received message if we have sufficient pieces

func (*Partials) GetRatio

func (p *Partials) GetRatio() (out float64)

GetRatio is used after the receive delay period expires to determine how successful a packet was. If it was exactly enough with no surplus, return 0, if there is more than the minimum, return the proportion compared to the total redundancy of the packet, if there is less, return a negative proportion versus the amount, -1 means zero received, and a fraction of 1 indicates the proportion that was received compared to the minimum

func (*Partials) HasAllDataShards

func (p *Partials) HasAllDataShards() bool

HasAllDataShards returns true if all data shards are present in a Partials

func (*Partials) HasMinimum

func (p *Partials) HasMinimum() bool

HasMinimum returns true if there may be enough data to decode

func (*Partials) IsDecoded

func (p *Partials) IsDecoded() bool

type Segments

type Segments [][]byte

type ShardPrefix

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

func GetParams

func GetParams(data []byte) (
	p ShardPrefix, err error,
)

GetParams reads the shard's prefix to provide the correct parameters for the RS codec the packet requires based on the prefix on a shard (presumably to create the codec when a new packet/group of shards arrives)

type ShardedSegments

type ShardedSegments []Segments

func GetShards

func GetShards(buf []byte, redundancy int) (out ShardedSegments)

GetShards returns a bundle of segments to be sent or stored in a 1kb segment size with redundancy shards added to each segment's shards that can reconstruct the original message by derivation via the available parity shards.

Jump to

Keyboard shortcuts

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