com

package module
v0.0.0-...-09a0c22 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: GPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PacketHeaderSize is the length of the Packet header in bytes.
	PacketHeaderSize = 44
)

Variables

View Source
var (
	// ErrTooLarge is raised if memory cannot be allocated to store data in a buffer.
	ErrTooLarge = errors.New("buffer size is too large")
	// ErrInvalidIndex is raised if a specified Grow or index function is supplied with an
	// negative or out of bounds number.
	ErrInvalidIndex = errors.New("buffer index provided is not valid")
	// ErrMismatchedID is an error that occurs when attempting to combine a Packet with a Packet that does
	// not match the ID of the parent Packet.
	ErrMismatchedID = errors.New("packet ID does not match combining packet ID")
)
View Source
var (
	// ErrWriterAttached is an error returned by the Read function
	// when a Packet Writer is not nil. When a Writer is attached, the Stream
	// is considered a 'write-only' stream.
	ErrWriterAttached = errors.New("cannot read while a Packet Writer is attached")
	// ErrAlreadyAttached is an error returned by the Writer function. This
	// error is only returned if a Packet Writer is already attached.
	ErrAlreadyAttached = errors.New("a Packet Writer is already attached")
)
View Source
var (
	// ErrInvalidNetwork is an error returned from the NewStreamConnector function
	// when a non-stream network is used, or the NewChunkConnector function when a stream
	// network is used.
	ErrInvalidNetwork = errors.New("invalid network type")
)

Functions

This section is empty.

Types

type Connector

type Connector interface {
	Connect(string) (net.Conn, error)
}

Connector is an interface that passes methods that can be used to form connections between the client and server. Other functions include the process of listening and accepting connections.

type Flag

type Flag uint64

Flag is a bitwise integer that represents important information about the packet that its assigned to.

Mapping 64 56 48 40 32 24 16 8 0

| 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 | 8 4 2 1 |
|    Frag Total     |   Frag Position   |   Frag Group ID   |       Flags       |
|                         Frag Data                         |                   |
const (
	// FlagData is a flag used to indicate that Hello/Echo/Sleep packets
	// also include additional data to be read.
	FlagData Flag = 1 << iota
	// FlagFrag is a flag used to indicate that the packet is part of a
	// fragment group (PacketGroup) and the server should re-assemble the packet
	// before preforming actions on it.
	FlagFrag
	// FlagMulti is a flag used to indicate that the packet is a container
	// for multiple packets, auto addded by a processing agent.
	FlagMulti
	// FlagProxy is a flag used to indicate that the packet was sent from another client
	// acting as a forwarding proxy.
	FlagProxy
	// FlagError is a flag used to indicate that the packet indicates that an error
	// condition has occurred. The contents of the Packet can be used to understand the error cause.
	FlagError
	// FlagIgnore is used to signal to the server or client that this Packet should be dropped and
	// not processed. Can be used for connectivity checks.
	FlagIgnore
	// FlagOneshot is used to signal that the Packet contains information and should not be used to
	// create or re-establish a session.
	FlagOneshot
	// FlagMultiDevice is used to determine if the Multi packet contains Packets with separate device IDs.
	// This is used to speed up processing and allows packets that are all destined for the same host to be
	// batch processed.
	FlagMultiDevice
)

func (*Flag) Add

func (f *Flag) Add(n Flag)

Add appends the Flag to this current flag value using the Bitwise OR operator.

func (*Flag) ClearFrag

func (f *Flag) ClearFrag()

ClearFrag clears all Frag and Multi related flags and data.

func (Flag) FragGroup

func (f Flag) FragGroup() uint16

FragGroup returns the fragment group ID that this packet is part of.

func (Flag) FragLen

func (f Flag) FragLen() int

FragLen is similar to the Total function. This returns the total amount of fragmentented packets to expect.

func (Flag) FragPosition

func (f Flag) FragPosition() uint16

FragPosition represents position of this packet in a fragment group.

func (Flag) FragTotal

func (f Flag) FragTotal() uint16

FragTotal returns the count of fragmented packets that make up this fragment group.

func (Flag) MarshalStream

func (f Flag) MarshalStream(w data.Writer) error

MarshalStream writes the data of this Flag to the supplied Writer.

func (*Flag) SetFragGroup

func (f *Flag) SetFragGroup(n uint16)

SetFragGroup sets the group ID of the fragment group this packet is part of.

func (*Flag) SetFragPosition

func (f *Flag) SetFragPosition(n uint16)

SetFragPosition sets the position this packet is located in the fragment group.

func (*Flag) SetFragTotal

func (f *Flag) SetFragTotal(n uint16)

SetFragTotal sets the total count of packets in the fragment group.

func (Flag) String

func (f Flag) String() string

String returns a character representation of this Flag integer.

func (*Flag) UnmarshalStream

func (f *Flag) UnmarshalStream(r data.Reader) error

UnmarshalStream reads the data of this Flag from the supplied Reader.

type PPacket

type PPacket interface {
	Reset()
	Clear()
	Len() int
	Size() int
	ID() uint16
	Job() uint16
	Flags() Flag
	IsEmpty() bool
	String() string
	Payload() []byte
	Device() device.ID
	MarshalJSON() ([]byte, error)
	UnmarshalJSON(b []byte) error
	MarshalStream(data.Writer) error
	UnmarshalStream(data.Reader) error
	data.Writer
	data.Reader
	io.Closer
}

PPacket is a work in progress interface for a method to combine packets and streams into single

type Packet

type Packet struct {
	ID, Job uint16
	Flags   Flag
	Device  device.ID
	// contains filtered or unexported fields
}

Packet is a struct that is a Reader and Writer that can be generated to be sent, or received from a Connection.

func NewStream

func NewStream(p *Packet) *Packet

NewStream converts a Packet into a Packet Stream and sets the underlying buffer to a Packet Stream.

func (*Packet) Bool

func (p *Packet) Bool() (bool, error)

Bool reads the value from the Packet payload buffer.

func (*Packet) Bytes

func (p *Packet) Bytes() ([]byte, error)

Bytes reads the value from the Packet payload buffer.

func (*Packet) Check

func (p *Packet) Check(i device.ID) bool

Check is a function that will set any missing Job or device parameters. This function will return true if the Device is nil or matches the specified host ID, false if otherwise.

func (*Packet) Clear

func (p *Packet) Clear()

Clear is similar to Reset, but discards the buffer, which must be allocated again. If using the buffer the Reset function is preferable.

func (*Packet) Close

func (p *Packet) Close() error

Close will truncate the writing stream if this Packet has been written to. This will allow the packet payload to be uniform to the data written to it.

func (*Packet) Combine

func (p *Packet) Combine(o *Packet) error

Combine attempts to append the Payload of the supplied Packet to this Packet's current buffer. Combine fails with the 'ErrMismatchedID' if the ID values are not the same. This function keeps the original Flag, ID and Job values of the parent Packet.

func (*Packet) Float32

func (p *Packet) Float32() (float32, error)

Float32 reads the value from the Packet payload buffer.

func (*Packet) Float64

func (p *Packet) Float64() (float64, error)

Float64 reads the value from the Packet payload buffer.

func (Packet) Flush

func (Packet) Flush() error

Flush does nothing for the Packet struct. Just here for compatibility.

func (*Packet) Grow

func (p *Packet) Grow(n int) error

Grow grows the payload buffer's capacity, if necessary, to guarantee space for another n bytes.

func (*Packet) Int

func (p *Packet) Int() (int, error)

Int reads the value from the Packet payload buffer.

func (*Packet) Int8

func (p *Packet) Int8() (int8, error)

Int8 reads the value from the Packet payload buffer.

func (*Packet) Int16

func (p *Packet) Int16() (int16, error)

Int16 reads the value from the Packet payload buffer.

func (*Packet) Int32

func (p *Packet) Int32() (int32, error)

Int32 reads the value from the Packet payload buffer.

func (*Packet) Int64

func (p *Packet) Int64() (int64, error)

Int64 reads the value from the Packet payload buffer.

func (*Packet) IsEmpty

func (p *Packet) IsEmpty() bool

IsEmpty returns true if this packet is nil or does not have any value or data associated with it.

func (Packet) Len

func (p Packet) Len() int

Len returns the total size of this Packet payload.

func (*Packet) MarshalJSON

func (p *Packet) MarshalJSON() ([]byte, error)

MarshalJSON writes the data of this Packet into JSON format.

func (*Packet) MarshalStream

func (p *Packet) MarshalStream(w data.Writer) error

MarshalStream writes the data of this Packet to the supplied Writer.

func (*Packet) Payload

func (p *Packet) Payload() []byte

Payload returns a slice of length p.Len() holding the unread portion of the Packet payload buffer.

func (*Packet) Read

func (p *Packet) Read(b []byte) (int, error)

Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read.

func (*Packet) ReadBool

func (p *Packet) ReadBool(i *bool) error

ReadBool reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadFloat32

func (p *Packet) ReadFloat32(i *float32) error

ReadFloat32 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadFloat64

func (p *Packet) ReadFloat64(i *float64) error

ReadFloat64 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadInt

func (p *Packet) ReadInt(i *int) error

ReadInt reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadInt8

func (p *Packet) ReadInt8(i *int8) error

ReadInt8 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadInt16

func (p *Packet) ReadInt16(i *int16) error

ReadInt16 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadInt32

func (p *Packet) ReadInt32(i *int32) error

ReadInt32 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadInt64

func (p *Packet) ReadInt64(i *int64) error

ReadInt64 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadString

func (p *Packet) ReadString(i *string) error

ReadString reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadUint

func (p *Packet) ReadUint(i *uint) error

ReadUint reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadUint8

func (p *Packet) ReadUint8(i *uint8) error

ReadUint8 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadUint16

func (p *Packet) ReadUint16(i *uint16) error

ReadUint16 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadUint32

func (p *Packet) ReadUint32(i *uint32) error

ReadUint32 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) ReadUint64

func (p *Packet) ReadUint64(i *uint64) error

ReadUint64 reads the value from the Packet payload buffer into the provided pointer.

func (*Packet) Reset

func (p *Packet) Reset()

Reset resets the payload buffer to be empty, but it retains the underlying storage for use by future writes.

func (*Packet) Size

func (p *Packet) Size() int

Size returns the total size of this Packet payload.

func (*Packet) String

func (p *Packet) String() string

String returns the contents of the unread portion of the buffer as a string.

func (*Packet) StringVal

func (p *Packet) StringVal() (string, error)

StringVal reads the value from the Packet payload buffer.

func (*Packet) Uint

func (p *Packet) Uint() (uint, error)

Uint reads the value from the Packet payload buffer.

func (*Packet) Uint8

func (p *Packet) Uint8() (uint8, error)

Uint8 reads the value from the Packet payload buffer.

func (*Packet) Uint16

func (p *Packet) Uint16() (uint16, error)

Uint16 reads the value from the Packet payload buffer.

func (*Packet) Uint32

func (p *Packet) Uint32() (uint32, error)

Uint32 reads the value from the Packet payload buffer.

func (*Packet) Uint64

func (p *Packet) Uint64() (uint64, error)

Uint64 reads the value from the Packet payload buffer.

func (*Packet) UnmarshalJSON

func (p *Packet) UnmarshalJSON(b []byte) error

UnmarshalJSON read the data of this Packet from JSON format.

func (*Packet) UnmarshalStream

func (p *Packet) UnmarshalStream(r data.Reader) error

UnmarshalStream reads the data of this Packet from the supplied Reader.

func (*Packet) Write

func (p *Packet) Write(b []byte) (int, error)

Write appends the contents of p to the buffer, growing the buffer as needed. If the buffer becomes too large, Write will return ErrTooLarge.

func (*Packet) WriteBool

func (p *Packet) WriteBool(n bool) error

WriteBool writes the supplied value to the Packet payload buffer.

func (*Packet) WriteBytes

func (p *Packet) WriteBytes(b []byte) error

WriteBytes writes the supplied value to the Packet payload buffer.

func (*Packet) WriteFloat32

func (p *Packet) WriteFloat32(n float32) error

WriteFloat32 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteFloat64

func (p *Packet) WriteFloat64(n float64) error

WriteFloat64 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteInt

func (p *Packet) WriteInt(n int) error

WriteInt writes the supplied value to the Packet payload buffer.

func (*Packet) WriteInt8

func (p *Packet) WriteInt8(n int8) error

WriteInt8 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteInt16

func (p *Packet) WriteInt16(n int16) error

WriteInt16 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteInt32

func (p *Packet) WriteInt32(n int32) error

WriteInt32 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteInt64

func (p *Packet) WriteInt64(n int64) error

WriteInt64 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteString

func (p *Packet) WriteString(n string) error

WriteString writes the supplied value to the Packet payload buffer.

func (*Packet) WriteUint

func (p *Packet) WriteUint(n uint) error

WriteUint writes the supplied value to the Packet payload buffer.

func (*Packet) WriteUint8

func (p *Packet) WriteUint8(n uint8) error

WriteUint8 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteUint16

func (p *Packet) WriteUint16(n uint16) error

WriteUint16 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteUint32

func (p *Packet) WriteUint32(n uint32) error

WriteUint32 writes the supplied value to the Packet payload buffer.

func (*Packet) WriteUint64

func (p *Packet) WriteUint64(n uint64) error

WriteUint64 writes the supplied value to the Packet payload buffer.

type Provider

type Provider interface {
	Connector
	Server
}

Provider is a combined interface that inherits the Server and Connector interfaces. This allows a single struct to provide listening and connection capabilities.

type SPacket

type SPacket struct {
	ID, Job uint16
	Device  device.ID
	Single  bool
	// contains filtered or unexported fields
}

type Server

type Server interface {
	Listen(string) (net.Listener, error)
}

Server is an interface that is used to Listen on a specific protocol for client connections. The Listener does not take any actions on the clients but transcribes the data into bytes for the Session handler.

type Stream

type Stream struct {
	ID, Job uint16
	Max     int
	Flags   Flag
	Device  device.ID
	// contains filtered or unexported fields
}

Stream is a struct that can be used to write and fragment large Packets transparently. This struct can be used to write-on-demand the Packet buffer if a Packet Writer is supplied via the Writer function.

func (*Stream) Add

func (s *Stream) Add(p *Packet) error

Add adds the supplied Packet to the stream array. This function triggers a sort of the array to ensure the Frags are in the correct position.

func (*Stream) Clear

func (s *Stream) Clear()

Clear discards the underlying buffers, which must be regenerated again.

func (*Stream) Close

func (s *Stream) Close() error

Close fulfills the io.Closer interface and will commit all the packets to the assigned Packet Writer (if not nil) and will set the correct position and total Packet Flags.

func (*Stream) Consolidate

func (s *Stream) Consolidate() *Packet

Consolidate combines the data in the underling Packet array into a single Packet.

func (*Stream) Flush

func (s *Stream) Flush() error

Flush will push out any Packets to the underlying Packet Writer (if not nil).

func (Stream) Len

func (s Stream) Len() int

Len returns the number of Packets in the underlying Packet array.

func (Stream) Less

func (s Stream) Less(i, j int) bool

Less returns true if the Frag Position of the Packet is less than the other supplied Packet position.

func (*Stream) New

func (s *Stream) New() *Packet

New creates a new Packet to be added to the underlying Stream. This packet will inherit the ID, Job and Flags of the Parent stream.

func (*Stream) Read

func (s *Stream) Read(b []byte) (int, error)

Read fulfills the io.Reader interface. This function will return ErrWriterAttached if a Packet Writer is attached.

func (*Stream) Size

func (s *Stream) Size() int

Size returns the total size of this Stream payload.

func (*Stream) Swap

func (s *Stream) Swap(i, j int)

Swap swaps the Packets in the array in the current supplied positions.

func (*Stream) Write

func (s *Stream) Write(b []byte) (int, error)

Write fulfills the io.Writer interface. This will generate and allocate new Packets on the fly. This will also send Packets out, if a Packet Session Writer is set.

func (*Stream) WriteAll

func (s *Stream) WriteAll(w writer) error

WriteAll attempts to flush all the underlying Packets to the provided writer.

func (*Stream) WriteBool

func (s *Stream) WriteBool(n bool) error

WriteBool writes the supplied value to the Stream payload buffer.

func (*Stream) WriteBytes

func (s *Stream) WriteBytes(b []byte) error

WriteBytes writes the supplied value to the Stream payload buffer.

func (*Stream) WriteFloat32

func (s *Stream) WriteFloat32(n float32) error

WriteFloat32 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteFloat64

func (s *Stream) WriteFloat64(n float64) error

WriteFloat64 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteInt

func (s *Stream) WriteInt(n int) error

WriteInt writes the supplied value to the Stream payload buffer.

func (*Stream) WriteInt8

func (s *Stream) WriteInt8(n int8) error

WriteInt8 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteInt16

func (s *Stream) WriteInt16(n int16) error

WriteInt16 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteInt32

func (s *Stream) WriteInt32(n int32) error

WriteInt32 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteInt64

func (s *Stream) WriteInt64(n int64) error

WriteInt64 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteString

func (s *Stream) WriteString(n string) error

WriteString writes the supplied value to the Stream payload buffer.

func (*Stream) WriteUint

func (s *Stream) WriteUint(n uint) error

WriteUint writes the supplied value to the Stream payload buffer.

func (*Stream) WriteUint8

func (s *Stream) WriteUint8(n uint8) error

WriteUint8 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteUint16

func (s *Stream) WriteUint16(n uint16) error

WriteUint16 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteUint32

func (s *Stream) WriteUint32(n uint32) error

WriteUint32 writes the supplied value to the Stream payload buffer.

func (*Stream) WriteUint64

func (s *Stream) WriteUint64(n uint64) error

WriteUint64 writes the supplied value to the Stream payload buffer.

func (*Stream) Writer

func (s *Stream) Writer(w writer) error

Writer attaches the Packet Writer to this stream. This enables the write-on-demand function and will attempt to write all Packets in the backlog on subsequent writes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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