Documentation ¶
Overview ¶
Package ncutils contains utility functions
Index ¶
- Constants
- func CheckFirewall()
- func CheckIPAddress(ip string) error
- func CheckWG()
- func ConvHostPassToHash(hostPass string) string
- func ConvertBytesToKey(data []byte) (*[32]byte, error)
- func ConvertKeyToBytes(key *[32]byte) ([]byte, error)
- func Copy(src, dst string) error
- func DNSFormatString(input string) string
- func FileExists(f string) bool
- func GetEmbedded() error
- func GetFileAsString(path string) (string, error)
- func GetFileWithRetry(path string, retryCount int) ([]byte, error)
- func GetFreePort(rangestart, currListenPort int, init bool) (int, error)
- func GetFreeTCPPort() (string, error)
- func GetHomeDirWindows() string
- func GetHostname() string
- func GetIPNetFromString(ip string) (net.IPNet, error)
- func GetInterfaceName() string
- func GetLocalIP(localrange net.IPNet) (*net.IPNet, error)
- func GetMacAddr() ([]net.HardwareAddr, error)
- func GetNetworkIPMask(networkstring string) (string, string, error)
- func GetNewIface(dir string) (string, error)
- func GetPublicIP(api string) (net.IP, error)
- func GetPublicIPv6() (net.IP, error)
- func GetSeparator() string
- func GetWireGuard() string
- func HasWG() bool
- func HasWgQuick() bool
- func IPIsPrivate(ipnet net.IP) bool
- func InterfaceExists(ifaceName string) (bool, error)
- func IsBridgeNetwork(ifaceName string) bool
- func IsEmptyRecord(err error) bool
- func IsFreeBSD() bool
- func IsIPTablesPresent() bool
- func IsKernel() bool
- func IsLinux() bool
- func IsMac() bool
- func IsNFTablesPresent() bool
- func IsPortFree(port int) (free bool)
- func IsWindows() bool
- func RandomMacAddress() net.HardwareAddr
- func RandomString(length int) string
- func ReadPID() (int, error)
- func RunCmd(command string, printerr bool) (string, error)
- func RunCmdFormatted(command string, printerr bool) (string, error)
- func RunCmds(commands []string, printerr bool) error
- func SavePID() error
- func ServerAddrSliceContains(slice []models.ServerAddr, item models.ServerAddr) bool
- func SetInterfaceName(iface string)
- func ShortenString(input string, length int) string
- type WindowsPIDError
Constants ¶
const DefaultGCPercent = 10
DefaultGCPercent - garbage collection percent
const KeySize = 2048
KeySize = ideal length for keys
const MaxNameLength = 62
MaxNameLength - maximum node name length
const NetclientDefaultPort = 51821
NetclientDefaultPort - default port
const NoDBRecord = "no result found"
NoDBRecord - error message result
const NoDBRecords = "could not find any records"
NoDBRecords - error record result
const PidFile = "/var/run/netclient.pid"
PidFile - path/name of pid file
const WindowsSvcName = "netclient"
WindowsSvcName - service name
Variables ¶
This section is empty.
Functions ¶
func CheckFirewall ¶
func CheckFirewall()
CheckFirewall - checks if iptables of nft install, if not exit
func CheckIPAddress ¶
func ConvHostPassToHash ¶
ConvHostPassToHash - converts password to md5 hash
func ConvertBytesToKey ¶
ConvertBytesToKey - util to convert bytes to a key to use elsewhere
func ConvertKeyToBytes ¶
ConvertKeyToBytes - util to convert a key to bytes to use elsewhere
func DNSFormatString ¶
DNSFormatString - Formats a string with correct usage for DNS
func GetFileAsString ¶
GetFileAsString - returns the string contents of a given file
func GetFileWithRetry ¶
GetFileWithRetry - retry getting file X number of times before failing
func GetFreePort ¶
GetFreePort - gets free port of machine
func GetHomeDirWindows ¶
func GetHomeDirWindows() string
GetHomeDirWindows - gets home directory in windows
func GetInterfaceName ¶
func GetInterfaceName() string
GetInterfaceName - fetches the interface name
func GetLocalIP ¶
GetLocalIP - gets local ip of machine returns first interface that is up, is not a loopback and is
func GetNetworkIPMask ¶
GetNetworkIPMask - Pulls the netmask out of the network
func GetNewIface ¶
GetNewIface - Gets the name of the real interface created on Mac
func IPIsPrivate ¶
func InterfaceExists ¶
InterfaceExists - checks if iface exists already
func IsBridgeNetwork ¶
IsBridgeNetwork - check if the interface is a bridge type
func IsIPTablesPresent ¶
func IsIPTablesPresent() bool
IsIPTablesPresent - returns true if iptables is present, false otherwise Does not consider OS, up to the caller to determine if the OS supports iptables/whether this check is valid.
func IsNFTablesPresent ¶
func IsNFTablesPresent() bool
IsNFTablesPresent - returns true if nftables is present, false otherwise. Does not consider OS, up to the caller to determine if the OS supports nftables/whether this check is valid.
func RandomMacAddress ¶
func RandomMacAddress() net.HardwareAddr
RandomMacAddress returns a random macaddress
func RandomString ¶
RandomString - returns a random string in a charset
func RunCmdFormatted ¶
RunCmdFormatted - does nothing for linux
func ServerAddrSliceContains ¶
func ServerAddrSliceContains(slice []models.ServerAddr, item models.ServerAddr) bool
ServerAddrSliceContains - sees if a string slice contains a string element
func SetInterfaceName ¶
func SetInterfaceName(iface string)
func ShortenString ¶
ShortenString - Brings string down to specified length. Stops names from being too long
Types ¶
type WindowsPIDError ¶
type WindowsPIDError struct{}
WindowsPIDError - error returned from pid function on windows
func (*WindowsPIDError) Error ¶
func (*WindowsPIDError) Error() string
Error generates error for windows os