com

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultTimeout = time.Duration(60) * time.Second

DefaultTimeout is the default timeout used for the default connectors. The default is 60 seconds (one minute).

View Source
const PacketHeaderSize = 45

PacketHeaderSize is the length of the Packet header in bytes.

Variables

View Source
var (
	// TCP is the TCP Raw connector. This connector uses raw TCP connections for communication.
	TCP = &tcpConnector{dialer: &net.Dialer{Timeout: DefaultTimeout, KeepAlive: DefaultTimeout, DualStack: true}}

	// UDP is the UDP Raw connector. This connector uses raw UDP connections for communication.
	UDP = NewUDP(DefaultTimeout)

	// ICMP is the ICMP Raw connector. This connector uses raw ICMP connections for communication.
	ICMP = NewIP(1, DefaultTimeout)

	// TLS is the TCP over TLS connector client. This client uses TCP wrapped in TLS encryption
	// using certificates. This client is only valid for clients that connect to servers with properly
	// signed and trusted certificates.
	TLS = &tcpClient{c: tcpConnector{tls: new(tls.Config), dialer: TCP.dialer}}
	// TLSNoCheck is the TCP over TLS connector profile. This client uses TCP wrapped in TLS encryption
	// using certificates. This instance DOES NOT check the server certificate for validity.
	TLSNoCheck = &tcpClient{c: tcpConnector{tls: &tls.Config{InsecureSkipVerify: true}, dialer: TCP.dialer}}
)
View Source
var ErrInvalidTLSConfig = xerr.New("TLS configuration is missing certificates")

ErrInvalidTLSConfig is returned when attempting to use the default TLS Connector as a listener. This error is also returned when attemtping to use a TLS configuration that does not have a valid server certificates.

View Source
var ListenConfig = net.ListenConfig{KeepAlive: DefaultTimeout}

ListenConfig is the default listener config that is used to generate the Listeners. This can be used to specify the listen 'KeepAlive' timeout.

Functions

This section is empty.

Types

type Connector

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

Connector is an interface that represents an object that can create and establish connections on various protocols.

func NewIP

func NewIP(p byte, t time.Duration) Connector

NewIP creates a new simple IP based connector with the supplied timeout and protocol number.

func NewSecureTCP

func NewSecureTCP(t time.Duration, c *tls.Config) (Connector, error)

NewSecureTCP creates a new simple TLS wrapped TCP based connector with the supplied timeout.

func NewSecureUNIX

func NewSecureUNIX(t time.Duration, c *tls.Config) (Connector, error)

NewSecureUNIX creates a new simple TLS wrapped UNIX socket based connector with the supplied timeout.

func NewTCP

func NewTCP(t time.Duration) (Connector, error)

NewTCP creates a new simple TCP based connector with the supplied timeout.

func NewUDP

func NewUDP(t time.Duration) Connector

NewUDP creates a new simple UDP based connector with the supplied timeout.

func NewUNIX

func NewUNIX(t time.Duration) (Connector, error)

NewUNIX creates a new simple UNIX socket based connector with the supplied timeout.

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
	// FlagChannel is a flag used to signify that the connection should be converted into/from a single
	// channel connection. This means that the connection is kept alive and the client will not poll the server.
	// This flag will be present on the top level multi-packet if included in a single packet inside. This flag will
	// take affect on each hop that it goes through. Incompatible with 'FlagOneshot'. Has to be used once per connection.
	FlagChannel
	// 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) Clear

func (f *Flag) Clear()

Clear clears all Frag and Multi related data values.

func (Flag) Group

func (f Flag) Group() uint16

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

func (Flag) Len

func (f Flag) Len() uint16

Len 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) Position

func (f Flag) Position() uint16

Position represents position of this packet in a fragment group.

func (*Flag) Set

func (f *Flag) Set(n Flag)

Set appends the Flag value to this current Flag value.

func (*Flag) SetGroup

func (f *Flag) SetGroup(n uint16)

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

func (*Flag) SetLen

func (f *Flag) SetLen(n uint16)

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

func (*Flag) SetPosition

func (f *Flag) SetPosition(n uint16)

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

func (Flag) String

func (f Flag) String() string

String returns a character representation of this Flag.

func (*Flag) UnmarshalStream

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

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

func (*Flag) Unset

func (f *Flag) Unset(n Flag)

Unset removes the Flag value to this current Flag value.

type Packet

type Packet struct {
	Tags []uint32
	data.Chunk

	Flags Flag
	Job   uint16

	Device device.ID
	ID     uint8
}

Packet is a struct that is a Reader and Writer that can be generated to be sent, or received from a Connection. Acts as a data buffer and 'child' of 'data.Chunk'.

func (*Packet) Add

func (p *Packet) Add(n *Packet) error

Add attempts to combine the data and properties the supplied Packet with the existsing Packet. This function will return an error if the ID's have a mismatch or there was an error during the write operation.

func (Packet) Belongs

func (p Packet) Belongs(n *Packet) bool

Belongs returns true if the specified Packet is a Frag that was a part of the split Chunks of this as the original packet.

func (Packet) MarshalStream

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

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

func (Packet) Size

func (p Packet) Size() int

Size returns the amount of bytes written or contained in this Packet with the header size added.

func (Packet) String

func (p Packet) String() string

String returns a string descriptor of the Packet struct.

func (*Packet) UnmarshalStream

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

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

func (*Packet) Verify

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

Verify 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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