Documentation ¶
Overview ¶
Package packet handles segmenting messages into uniform sized packets and generating a stream of cipher halves and receiver cloaked addresses, and reassembling the segments into their original form.
Index ¶
- Constants
- func EncodePacket(ep *PacketParams) (pkt []byte, e error)
- func GetKeysFromPacket(d []byte) (from *crypto.Pub, to crypto.CloakedPubKey, iv nonce.IV, e error)
- func SplitToPackets(pp *PacketParams, segSize int, ks *crypto.KeySet) (dataShards int, packets [][]byte, e error)
- type Packet
- type PacketParams
- type PacketSegment
- type PacketSegments
- type Packets
Constants ¶
const ( // Overhead is the base overhead on a packet, use GetOverhead to add any extra // as found in a Packet. Overhead = 4 + crypto.PubKeyLen + crypto.CloakLen + nonce.IVLen PacketMagic = "rpkt" )
const ( ErrEmptyBytes = "cannot encode empty bytes" ErrDupe = "found duplicate packet, no redundancy, decoding failed" ErrLostNoRedundant = "no redundancy with %d lost of %d" ErrMismatch = "found disagreement about common data in segment %d of %d" + " in field %s value: got %v expected %v" ErrNotEnough = "too many lost to recover in section %d, have %d, need " + "%d minimum" )
Variables ¶
This section is empty.
Functions ¶
func EncodePacket ¶
func EncodePacket(ep *PacketParams) (pkt []byte, e error)
EncodePacket creates a Packet, encrypts the payload using the given private from key and the public to key, serializes the form and signs the bytes. the signature to the end.
func GetKeysFromPacket ¶
GetKeysFromPacket returns the ToHeaderPub 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 DecodePacket function will then decode a OnionSkin.
func SplitToPackets ¶
func SplitToPackets(pp *PacketParams, segSize int, ks *crypto.KeySet) (dataShards int, packets [][]byte, e error)
SplitToPackets 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 Packet ¶
type Packet struct { ID nonce.ID // 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. The remainder from 256 is the // proportion from 256 of data shards in a packet batch. Parity byte // Data is the message. Data []byte TimeStamp time.Time }
Packet is the standard format for an encrypted, possibly segmented message container with parameters for Reed Solomon Forward Error Correction.
func DecodePacket ¶
DecodePacket decodes a packet and return the Packet with encrypted payload and signer's public key. This assumes GetKeysFromPacket succeeded and the matching private key was found.
func (*Packet) GetOverhead ¶
GetOverhead returns the packet frame overhead given the settings found in the packet.
type PacketParams ¶
type PacketParams struct { ID nonce.ID To *crypto.Pub From *crypto.Prv Parity int Seq int Length int Data []byte }
PacketParams defines the parameters for creating a ( split) packet given a set of keys, cipher, and data. To, From, Data are required, Parity is optional, set it to define a level of Reed Solomon redundancy on the split packets.
func (PacketParams) GetOverhead ¶
func (ep PacketParams) GetOverhead() int
GetOverhead returns the amount of the message that will not be part of the payload.
type PacketSegment ¶
type PacketSegment struct {
DStart, DEnd, PEnd, SLen, Last int
}
func (PacketSegment) String ¶
func (s PacketSegment) String() (o string)
String is a printer that produces a Go syntax formatted version of the PacketSegment.
type PacketSegments ¶
type PacketSegments []PacketSegment
func NewPacketSegments ¶
func NewPacketSegments(payloadLen, segmentSize, overhead, parity int) (s PacketSegments)
func (PacketSegments) AddParity ¶
func (s PacketSegments) AddParity(segs [][]byte) (shards [][]byte, e error)
func (PacketSegments) String ¶
func (s PacketSegments) String() (o string)
String is a printer that produces a Go syntax formatted version of the PacketSegments.
type Packets ¶
type Packets []*Packet
Packets is a slice of pointers to packets.
func JoinPackets ¶
JoinPackets a collection of Packets together.