packet

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: Unlicense Imports: 14 Imported by: 0

Documentation

Overview

Package packet provides a standard message binary serialised data format and message segmentation scheme which includes address.Sender cloaked public key and address.Receiver private keys for generating a shared cipher and applying to messages/message segments.

Index

Constants

View Source
const ErrDupe = "found duplicate packet, no redundancy, decoding failed"
View Source
const ErrEmptyBytes = "cannot encode empty bytes"
View Source
const ErrLostNoRedundant = "no redundancy with %d lost of %d"
View Source
const ErrMismatch = "found disagreement about common data in segment %d of %d" +
	" in field %s value: got %v expected %v"
View Source
const ErrNotEnough = "too many lost to recover in section %d, have %d, need " +
	"%d minimum"
View Source
const Overhead = 4 + nonce.IVLen + pub.KeyLen

Overhead is the base overhead on a packet, use GetOverhead to add any extra as found in a Packet.

Variables

This section is empty.

Functions

func Encode

func Encode(ep EP) (pkt []byte, e error)

Encode creates a Packet, encrypts the payload using the given private from key and the public to key, serializes the form, signs the bytes and appends the signature to the end.

func GetKeys

func GetKeys(d []byte) (from *pub.Key, e error)

GetKeys returns the To field of the message in order, checks the packet checksum and recovers the public key.

After this, if the matching private key to the cloaked address returned is found, it is combined with the public key to generate the cipher and the entire packet should then be decrypted, and the Decode function will then decode a OnionSkin.

func Join

func Join(packets Packets) (msg []byte, e error)

Join a collection of Packets together.

func Split

func Split(ep EP, segSize int) (packets [][]byte, e error)

Split creates a series of packets including the defined Reed Solomon parameters for extra parity shards and the return encryption public key for a reply.

The last packet that falls short of the segmentSize is padded random bytes.

Types

type EP

type EP struct {
	To       *pub.Key
	From     *prv.Key
	Parity   int
	Seq      int
	Length   int
	Deadline time.Time
	Data     []byte
}

EP defines the parameters for creating a (split) packet given a set of keys, cipher, and data. To, From, Blk and Data are required, Parity is optional, set it to define a level of Reed Solomon redundancy on the split packets. Seen should be populated to send a signal to the other side of keys that have been seen at time of constructing this packet that can now be discarded as they will not be used to generate a cipher again.

This library is for creating segmented, FEC redundancy protected network packets, and the To sender key should be the publicly advertised public key of a relay.

Deadline is a special field that gives a timeout period after which an incomplete message can be considered expired and flushed from the cache. It is 32 bits in size as precision to the second is sufficient, and low latency messages will potentially beat the deadline at one second.

func (EP) GetOverhead

func (ep EP) GetOverhead() int

GetOverhead returns the amount of the message that will not be part of the payload.

type Packet

type Packet struct {
	// Seq specifies the segment number of the message, 4 bytes long.
	Seq uint16
	// Length is the number of segments in the batch
	Length uint32
	// Parity is the ratio of redundancy. In each 256 segment
	Parity byte
	// Deadline is a time after which the message should be received and
	// dispatched.
	Deadline time.Time
	// Data is the message.
	Data []byte
}

Packet is the standard format for an encrypted, possibly segmented message container with parameters for Reed Solomon Forward Error Correction.

func Decode

func Decode(d []byte, from *pub.Key, to *prv.Key) (f *Packet, e error)

Decode a packet and return the Packet with encrypted payload and signer's public key. This assumes GetKeys succeeded and the matching private key was found.

func (*Packet) GetOverhead

func (p *Packet) GetOverhead() int

GetOverhead returns the packet frame overhead given the settings found in the packet.

type Packets

type Packets []*Packet

Packets is a slice of pointers to packets.

func RemovePacket

func RemovePacket(slice Packets, s int) Packets

func (Packets) Len

func (p Packets) Len() int

func (Packets) Less

func (p Packets) Less(i, j int) bool

func (Packets) Swap

func (p Packets) Swap(i, j int)

type Segment

type Segment struct {
	DStart, DEnd, PEnd, SLen, Last int
}

func (Segment) String

func (s Segment) String() (o string)

String is a printer that produces a Go syntax formatted version of the Segment.

type Segments

type Segments []Segment

func NewSegments

func NewSegments(payloadLen, segmentSize, overhead, redundancy int) (s Segments)

func (Segments) AddParity

func (s Segments) AddParity(segs [][]byte) (shards [][]byte, e error)

func (Segments) String

func (s Segments) String() (o string)

String is a printer that produces a Go syntax formatted version of the Segments.

Jump to

Keyboard shortcuts

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