Documentation ¶
Index ¶
- Constants
- Variables
- func DialTCP(x context.Context, s string) (net.Conn, error)
- func DialTLS(x context.Context, s string, c *tls.Config) (net.Conn, error)
- func ListenTCP(x context.Context, s string) (net.Listener, error)
- func ListenTLS(x context.Context, s string, c *tls.Config) (net.Listener, error)
- func NewTLSConfig(mu bool, ver uint16, ca, pem, key []byte) (*tls.Config, error)
- func SetListenerDeadline(l net.Listener, t time.Time) error
- type Connector
- type Flag
- func (f *Flag) Clear()
- func (f Flag) Group() uint16
- func (f Flag) Len() uint16
- func (f Flag) MarshalStream(w data.Writer) error
- func (f Flag) Position() uint16
- func (f *Flag) Set(n Flag)
- func (f *Flag) SetGroup(n uint16)
- func (f *Flag) SetLen(n uint16)
- func (f *Flag) SetPosition(n uint16)
- func (f Flag) String() string
- func (f *Flag) UnmarshalStream(r data.Reader) error
- func (f *Flag) Unset(n Flag)
- type Packet
- func (p *Packet) Add(n *Packet) error
- func (p *Packet) Belongs(n *Packet) bool
- func (p *Packet) Marshal(w io.Writer) error
- func (p *Packet) MarshalStream(w data.Writer) error
- func (p *Packet) Size() int
- func (p *Packet) String() string
- func (p *Packet) Unmarshal(r io.Reader) error
- func (p *Packet) UnmarshalStream(r data.Reader) error
Constants ¶
const ( // FlagFrag is a flag used to indicate that the packet is part of a // fragment group and the server should re-assemble the packet before // preforming actions on it. FlagFrag = 1 << iota // FlagMulti is a flag used to indicate that the packet is a container // for multiple packets, auto added by a processing agent. This Flag also // carries the 'FlagFrag' flag. 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'. Can only be used once per single connection. FlagChannel // FlagChannelEnd is a flag used to signify that a Channel connection should // be terminated. Unlike the 'FlagChannel' option, this will only affect the // targeted hop. // // Incompatible with 'FlagOneshot'. Can only be used once per single connection. FlagChannelEnd // 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 // FlagCrypt is used to indicate that the Packet is carrying Crypt related // information or a side of the conversation is asking for a re-key. FlagCrypt )
const ( // PacketMaxTags is the max amount of tags that are allowed on a specific // Packet. PacketMaxTags = 2 << 14 // PacketHeaderSize is the length of the Packet header in bytes. PacketHeaderSize = 46 )
const ( NameIP = "ip" NameTCP = "tcp" NameUDP = "udp" NamePipe = "pipe" NameUnix = "unix" NameHTTP = "http" )
Named Network Constants
const DefaultTimeout = time.Second * 15 //30
DefaultTimeout is the default timeout used for the default connectors. The default is 15 seconds.
Variables ¶
var ( // ErrMalformedTag is an error returned when a read on a Packet Tag returns // an empty (zero) tag value. ErrMalformedTag = xerr.Sub("malformed Tag", 0x2A) // ErrTagsTooLarge is an error returned when attempting to write a Packet // that contains too many Tags (> 32768) ErrTagsTooLarge = xerr.Sub("tags list is too large", 0x2B) )
var ( // TCP is the TCP Raw connector. This connector uses raw TCP connections for // communication. TCP = NewTCP(DefaultTimeout) // 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. // // TODO(dij): I think ICMP is bugged ATM, "NewIP(<anything greater than 1>, DefaultTimeout)" works, weird. ICMP = NewIP(DefaultTimeout, 1) // 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.(*tcpConnector).Dialer}} // TLSInsecure 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. TLSInsecure = &tcpClient{c: tcpConnector{tls: &tls.Config{InsecureSkipVerify: true}, Dialer: TCP.(*tcpConnector).Dialer}} )
var ErrInvalidTLSConfig = xerr.Sub("invalid or missing TLS certificates", 0x2D)
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.
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 ¶
func DialTCP ¶ added in v0.1.0
DialTCP is a quick utility function that can be used to quickly create a TCP connection to the provided address.
This function uses the 'com.TCP' var.
func DialTLS ¶ added in v0.1.0
DialTLS is a quick utility function that can be used to quickly create a TLS connection to the provided address.
This function uses the 'com.TLS' var if the provided tls config is nil.
func ListenTCP ¶ added in v0.1.0
ListenTCP is a quick utility function that can be used to quickly create a TCP listener using the 'TCP' Acceptor.
func ListenTLS ¶ added in v0.1.0
ListenTLS is a quick utility function that can be used to quickly create a TLS listener using the provided TLS config.
func NewTLSConfig ¶ added in v0.1.0
NewTLSConfig generates a new 'tls.Config' struct from the provided TLS details. This can be used to generate mTLS or just simple CA-based TLS server/clients Connectors.
The provided ca bytes (in PEM format) can be used to validate client certificates while the pem and key bytes (in PEM format) are used for the listening socket.
The 'ver' integer represents the TLS-min version requirement. Setting it to zero will default to TLSv1. SSLv3 is NOT SUPPORTED!
This function returns an error if the ca, pem and/or key are empty. The 'mu' bool will determine if mTLS should be enforced.
mTLS insights sourced from: https://kofo.dev/how-to-mtls-in-golang
func SetListenerDeadline ¶ added in v0.1.0
SetListenerDeadline attempts to set a deadline on the 'Accept; function of a Listener if applicable. This function will return any errors if they occur and always returns 'nil' if the Listener does not support deadlines.
Types ¶
type Connector ¶
type Connector interface { Connect(context.Context, string) (net.Conn, error) Listen(context.Context, string) (net.Listener, error) }
Connector is an interface that represents an object that can create and establish connections on various protocols.
func NewIP ¶
NewIP creates a new simple IP based connector with the supplied timeout and protocol number.
func NewSecureUNIX ¶
NewSecureUNIX creates a new simple TLS wrapped UNIX socket based connector with the supplied timeout.
func NewTLS ¶ added in v0.1.0
NewTLS creates a new simple TLS wrapped TCP 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 | |
func (Flag) MarshalStream ¶
MarshalStream writes the data of this Flag to the supplied Writer.
func (*Flag) SetPosition ¶
SetPosition sets the position this packet is located in the fragment group.
func (*Flag) UnmarshalStream ¶
UnmarshalStream reads the data of this Flag from the supplied Reader.
type Packet ¶
type Packet struct { Tags []uint32 data.Chunk Flags Flag Job uint16 Device device.ID ID uint8 // 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.
Acts as a data buffer and 'child' of 'data.Chunk'.
func (*Packet) Add ¶
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 ¶
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) Marshal ¶ added in v0.1.0
Marshal will attempt to write this Packet's data and headers to the specified Writer. This function will return any errors that have occur during writing.
func (*Packet) MarshalStream ¶
MarshalStream writes the data of this Packet to the supplied Writer.
func (*Packet) Size ¶
Size returns the amount of bytes written or contained in this Packet with the header size added.