utils

package
v0.0.0-...-79bdfdd Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const EOF byte = 26
View Source
const SocketAddressSize int = 6 // Bytes

Variables

This section is empty.

Functions

func GetOutboundIP

func GetOutboundIP() string

GetOutboundIP gets the preferred outbound ip of this machine

func MbToBytes

func MbToBytes(mb uint64) uint64

MbToBytes converts a megabyte value to bytes.

func ParsePacket

func ParsePacket(packet []byte) ([]byte, []byte, error)

ParsePacket into its component route URI and payload

func Ping

func Ping(remoteHost SocketAddr) error

Ping a remote host in an attempts to create a connection, returns an error if the host is unreachable

func Read

func Read(conn *net.Conn) ([]byte, error)

func Request

func Request(remoteHost SocketAddr, route []byte, payload []byte) ([]byte, error)

func Write

func Write(conn *net.Conn, packet []byte) error

Types

type SocketAddr

type SocketAddr struct {
	Ip   string
	Port uint16
}

SocketAddr has a size 4 bytes (IPv4) + 2 bytes (port) = 6 bytes

func AddrFromJson

func AddrFromJson(addressInJson []byte) (SocketAddr, error)

func AddrFromString

func AddrFromString(address string) (SocketAddr, error)

func (*SocketAddr) IsEmpty

func (s *SocketAddr) IsEmpty() bool

func (*SocketAddr) ToJson

func (s *SocketAddr) ToJson() ([]byte, error)

func (*SocketAddr) ToString

func (s *SocketAddr) ToString() string

type SocketAddrSlice

type SocketAddrSlice []SocketAddr

func AddrSliceFromJson

func AddrSliceFromJson(addrJson []byte) (SocketAddrSlice, error)

func (*SocketAddrSlice) ToJson

func (s *SocketAddrSlice) ToJson() ([]byte, error)

Jump to

Keyboard shortcuts

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