packeter

package module
v0.0.0-...-ca39263 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: BSD-3-Clause Imports: 8 Imported by: 1

README

Packeter

Takes large messages and breaks them down into small packets with parity shards to provide a minimum guarentee that the recipient will be able to reassemble the message, even if some packets are lost. Also handles the process of reassembling the message as the packets are received.

GoDoc

Documentation

Overview

Package packeter breaks a message into Reed-Solomon shards with enough parity shards to accommodate for expected losses.

Index

Constants

This section is empty.

Variables

View Source
var BufferSize = 50

BufferSize is the default channel buffer size for a Packeter

View Source
var Packetlength = 10000

Packetlength is the max packet length in bytes. Defaults to 10k. This cannot be higher than 65535 because of the UDP standard.

View Source
var TTL = time.Second * 10

TTL sets the time that a partial message will wait until is deleted

Functions

This section is empty.

Types

type Package

type Package struct {
	ID   uint32
	Addr *rnet.Addr
	Body []byte
	Err  error
}

Package represents a message that was transmitted.

func (*Package) GetAddr

func (m *Package) GetAddr() *rnet.Addr

GetAddr allows Package to be abstracted as an interface

func (*Package) GetBody

func (m *Package) GetBody() []byte

GetBody allow Package to be abstracted as an interface

type Packet

type Packet struct {
	PackageID    uint32
	PacketID     uint16
	ParityShards uint16
	Packets      uint16
	Data         []byte
}

Packet represents a shard of a message. If enough shards from a message are collected, the message can be reconstructed.

func Unmarshal

func Unmarshal(b []byte) *Packet

Unmarshal deserializes a byte slice to a Packet

func (*Packet) DataShards

func (p *Packet) DataShards() uint16

DataShards returns the number of DataShards in a message, this is also the number of shards needed to reconstruct the message

func (*Packet) Marshal

func (p *Packet) Marshal(tag []byte) []byte

Marshal serializes a Packet to a byte slice. Prepend allows additional meta-data to be added to the begining of each packet.

type Packeter

type Packeter struct {
	sync.Mutex

	Handler func(*Package)
	// contains filtered or unexported fields
}

Packeter manages the process of collecting packets and resolving them to messages as well as converting a message into a set of packets

func New

func New() *Packeter

New returns a new Packeter

func (*Packeter) Chan

func (p *Packeter) Chan() <-chan *Package

Chan returns the channel that can receive Packages after the packeter has reassembled them

func (*Packeter) Make

func (p *Packeter) Make(prefix, msg []byte, loss, reliability float64, id uint32) ([][]byte, error)

Make takes a message as a byte slice, along with the expected loss rate and target reliability and produces the packets for that message. The packets are returned as a slice of byte-slices.

func (*Packeter) Receive

func (p *Packeter) Receive(b []byte, addr *rnet.Addr)

Receive collects packets. When exactly enough packets have been recovered to reconstruct the message, the message is sent to the Handler if one is defined or over the channel otherwise. Receive can continue to collect packets after the message has been constructed for reliability statistics.

Jump to

Keyboard shortcuts

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