utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecretTokenLength = 26
)

Variables

View Source
var (
	IPv4LoopbackAddress = net.ParseIP("127.0.0.1").To16()
)

Functions

func AddrIsLocal added in v0.11.0

func AddrIsLocal(addr net.Addr) bool

AddrIsLocal returns whether the address is from a trusted local connection (loopback or unix).

func AddrIsUnix added in v0.11.0

func AddrIsUnix(addr net.Addr) bool

AddrIsUnix returns whether the address is a unix domain socket.

func AddrToIP added in v0.11.0

func AddrToIP(addr net.Addr) net.IP

AddrToIP returns the IP address for a net.Addr; unix domain sockets are treated as IPv4 loopback

func ArgsToStrings

func ArgsToStrings(maxLength int, arguments []string, delim string) []string

ArgsToStrings takes the arguments and splits them into a series of strings, each argument separated by delim and each string bounded by maxLength.

func BitsetCopy added in v1.0.0

func BitsetCopy(set []uint64, other []uint64)

BitsetCopy copies the contents of `other` over `set`. Similar caveats about race conditions as with `BitsetUnion` apply.

func BitsetEmpty added in v0.12.0

func BitsetEmpty(set []uint64) (empty bool)

BitsetEmpty returns whether the bitset is empty. This has false positives under concurrent modification (i.e., it can return true even though w.r.t. the sequence of atomic modifications, there was no point at which the bitset was completely empty), but that's not how we're using this method.

func BitsetGet added in v0.12.0

func BitsetGet(set []uint64, position uint) bool

BitsetGet returns whether a given bit of the bitset is set.

func BitsetInitialize added in v0.12.0

func BitsetInitialize(set []uint64)

BitsetInitialize initializes a bitset.

func BitsetSet added in v0.12.0

func BitsetSet(set []uint64, position uint, on bool) (changed bool)

BitsetSet sets a given bit of the bitset to 0 or 1, returning whether it changed.

func BitsetSubtract added in v1.0.0

func BitsetSubtract(set []uint64, other []uint64)

BitsetSubtract modifies `set` to subtract the contents of `other`. Similar caveats about race conditions as with `BitsetUnion` apply.

func BitsetUnion added in v0.12.0

func BitsetUnion(set []uint64, other []uint64)

BitsetUnion modifies `set` to be the union of `set` and `other`. This has race conditions in that we don't necessarily get a single consistent view of `other` across word boundaries.

func CopyFile added in v0.12.0

func CopyFile(src string, dst string) (err error)

implementation of `cp` (go should really provide this...)

func FieldsFuncN added in v1.0.0

func FieldsFuncN(s string, f func(rune) bool, n int) []string

FieldsFuncN is like strings.FieldsFunc, but returns at most n fields, and the nth field includes any runes at the end of the string normally excluded by f.

func FieldsN added in v1.0.0

func FieldsN(s string, n int) []string

FieldsN is like strings.Fields, but returns at most n fields, and the nth field includes any whitespace at the end of the string.

func GenerateSecretToken added in v1.0.0

func GenerateSecretToken() string

generate a secret token that cannot be brute-forced via online attacks

func GetClientOnlyTags added in v0.11.0

func GetClientOnlyTags(tags map[string]ircmsg.TagValue) *map[string]ircmsg.TagValue

GetClientOnlyTags takes a tag map and returns a map containing just the client-only tags from it.

func IPInNets added in v1.0.0

func IPInNets(ip net.IP, nets []net.IPNet) bool

Convenience to test whether `ip` is contained in any of `nets`.

func IsHostname

func IsHostname(name string) bool

IsHostname returns whether we consider `name` a valid hostname.

func LookupHostname

func LookupHostname(addr string) string

LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.

func NetToNormalizedString added in v1.0.0

func NetToNormalizedString(network net.IPNet) string

Given a network, produce a human-readable string (i.e., CIDR if it's actually a network, IPv6 address if it's a v6 /128, dotted quad if it's a v4 /32).

func NormalizeIPToNet added in v1.0.0

func NormalizeIPToNet(addr net.IP) (network net.IPNet)

NormalizeIPToNet represents an address (v4 or v6) as the v6 /128 CIDR containing only it.

func NormalizeNet added in v1.0.0

func NormalizeNet(network net.IPNet) (result net.IPNet)

NormalizeNet normalizes an IPNet to a v6 CIDR, using the 4-in-6 prefix. (this is like IP.To16(), but for IPNet instead of IP)

func NormalizedNetFromString added in v1.0.0

func NormalizedNetFromString(str string) (result net.IPNet, err error)

Parse a human-readable description (an address or CIDR, either v4 or v6) into a normalized v6 net.IPNet.

func ParseNetList added in v1.0.0

func ParseNetList(netList []string) (nets []net.IPNet, err error)

Parse a list of IPs and nets as they would appear in one of our config files, e.g., proxy-allowed-from or a throttling exemption list.

func SecretTokensMatch added in v1.0.0

func SecretTokensMatch(storedToken string, suppliedToken string) bool

securely check if a supplied token matches a stored token

func WordWrap added in v1.0.0

func WordWrap(text string, lineWidth int) []string

WordWrap wraps the given text into a series of lines that don't exceed lineWidth characters.

Types

type SplitMessage added in v1.0.0

type SplitMessage struct {
	Original string
	Wrapped  []string // if this is nil, Original didn't need wrapping and can be sent to anyone
}

SplitMessage represents a message that's been split for sending.

func MakeSplitMessage added in v1.0.0

func MakeSplitMessage(original string, origIs512 bool) (result SplitMessage)

Jump to

Keyboard shortcuts

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