Documentation ¶
Index ¶
- Constants
- Variables
- func AddrIsLocal(addr net.Addr) bool
- func AddrIsUnix(addr net.Addr) bool
- func AddrToIP(addr net.Addr) net.IP
- func ArgsToStrings(maxLength int, arguments []string, delim string) []string
- func BitsetCopy(set []uint32, other []uint32)
- func BitsetEmpty(set []uint32) (empty bool)
- func BitsetGet(set []uint32, position uint) bool
- func BitsetSet(set []uint32, position uint, on bool) (changed bool)
- func BitsetSubtract(set []uint32, other []uint32)
- func BitsetUnion(set []uint32, other []uint32)
- func CopyFile(src string, dst string) (err error)
- func FieldsFuncN(s string, f func(rune) bool, n int) []string
- func FieldsN(s string, n int) []string
- func GenerateSecretKey() string
- func GenerateSecretToken() string
- func IPInNets(ip net.IP, nets []net.IPNet) bool
- func IsHostname(name string) bool
- func LookupHostname(addr string) string
- func MungeSecretToken(token string) (result string)
- func NetToNormalizedString(network net.IPNet) string
- func NormalizeIPToNet(addr net.IP) (network net.IPNet)
- func NormalizeNet(network net.IPNet) (result net.IPNet)
- func NormalizedNetFromString(str string) (result net.IPNet, err error)
- func ParseNetList(netList []string) (nets []net.IPNet, err error)
- func SecretTokensMatch(storedToken string, suppliedToken string) bool
- func StringToBool(str string) (result bool, err error)
- func WordWrap(text string, lineWidth int) []string
- type MessagePair
- type Once
- type Semaphore
- func (semaphore *Semaphore) Acquire()
- func (semaphore *Semaphore) AcquireWithContext(ctx context.Context) (acquired bool)
- func (semaphore *Semaphore) AcquireWithTimeout(timeout time.Duration) (acquired bool)
- func (semaphore *Semaphore) Initialize(capacity int)
- func (semaphore *Semaphore) Release()
- func (semaphore *Semaphore) TryAcquire() (acquired bool)
- type SplitMessage
- type TokenLineBuilder
Constants ¶
const (
SecretTokenLength = 26
)
Variables ¶
var ( // slingamn's own private b32 alphabet, removing 1, l, o, and 0 B32Encoder = base32.NewEncoding("abcdefghijkmnpqrstuvwxyz23456789").WithPadding(base32.NoPadding) )
var (
ErrInvalidParams = errors.New("Invalid parameters")
)
var (
IPv4LoopbackAddress = net.ParseIP("127.0.0.1").To16()
)
Functions ¶
func AddrIsLocal ¶ added in v0.11.0
AddrIsLocal returns whether the address is from a trusted local connection (loopback or unix).
func AddrIsUnix ¶ added in v0.11.0
AddrIsUnix returns whether the address is a unix domain socket.
func AddrToIP ¶ added in v0.11.0
AddrToIP returns the IP address for a net.Addr; unix domain sockets are treated as IPv4 loopback
func ArgsToStrings ¶
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
BitsetCopy copies the contents of `other` over `set`. Similar caveats about race conditions as with `BitsetUnion` apply.
func BitsetEmpty ¶ added in v0.12.0
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 BitsetSet ¶ added in v0.12.0
BitsetSet sets a given bit of the bitset to 0 or 1, returning whether it changed.
func BitsetSubtract ¶ added in v1.0.0
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
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 FieldsFuncN ¶ added in v1.0.0
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
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 GenerateSecretKey ¶ added in v1.1.0
func GenerateSecretKey() string
generate a 256-bit secret key that can be written into a config file
func GenerateSecretToken ¶ added in v1.0.0
func GenerateSecretToken() string
generate a secret token that cannot be brute-forced via online attacks
func IsHostname ¶
IsHostname returns whether we consider `name` a valid hostname.
func LookupHostname ¶
LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
func MungeSecretToken ¶ added in v1.1.0
"munge" a secret token to a new value. requirements: 1. MUST be roughly as unlikely to collide with `GenerateSecretToken` outputs as those outputs are with each other 2. SHOULD be deterministic (motivation: if a JOIN line has msgid x, create a deterministic msgid y for the fake HistServ PRIVMSG that "replays" it) 3. SHOULD be in the same "namespace" as `GenerateSecretToken` outputs (same length and character set)
func NetToNormalizedString ¶ added in v1.0.0
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
NormalizeIPToNet represents an address (v4 or v6) as the v6 /128 CIDR containing only it.
func NormalizeNet ¶ added in v1.0.0
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
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
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
securely check if a supplied token matches a stored token
func StringToBool ¶ added in v1.1.0
Types ¶
type MessagePair ¶ added in v1.1.0
type Once ¶ added in v1.1.0
type Once struct {
// contains filtered or unexported fields
}
Once is a fork of sync.Once to expose a Done() method.
type Semaphore ¶ added in v1.1.0
type Semaphore (chan e)
Semaphore is a counting semaphore. A semaphore of capacity 1 can be used as a trylock.
func (*Semaphore) Acquire ¶ added in v1.1.0
func (semaphore *Semaphore) Acquire()
Acquire acquires a semaphore, blocking if necessary.
func (*Semaphore) AcquireWithContext ¶ added in v1.2.0
AcquireWithContext tries to acquire a semaphore, blocking at most until the context expires. It returns whether the acquire was successful. Note that if the context is already expired, the acquire may succeed anyway.
func (*Semaphore) AcquireWithTimeout ¶ added in v1.1.0
AcquireWithTimeout tries to acquire a semaphore, blocking for a maximum of approximately `d` while waiting for it. It returns whether the acquire was successful.
func (*Semaphore) Initialize ¶ added in v1.1.0
Initialize initializes a semaphore to a given capacity.
func (*Semaphore) Release ¶ added in v1.1.0
func (semaphore *Semaphore) Release()
Release releases a semaphore. It never blocks. (This is not a license to program spurious releases.)
func (*Semaphore) TryAcquire ¶ added in v1.1.0
TryAcquire tries to acquire a semaphore, returning whether the acquire was successful. It never blocks.
type SplitMessage ¶ added in v1.0.0
type SplitMessage struct { MessagePair Wrapped []MessagePair // if this is nil, `Message` didn't need wrapping and can be sent to anyone Time time.Time }
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)
type TokenLineBuilder ¶ added in v1.2.0
type TokenLineBuilder struct {
// contains filtered or unexported fields
}
TokenLineBuilder is a helper for building IRC lines composed of delimited tokens, with a maximum line length.
func (*TokenLineBuilder) Add ¶ added in v1.2.0
func (t *TokenLineBuilder) Add(token string)
Add adds a token to the line, creating a new line if necessary.
func (*TokenLineBuilder) Initialize ¶ added in v1.2.0
func (t *TokenLineBuilder) Initialize(lineLen int, delim string)
func (*TokenLineBuilder) Lines ¶ added in v1.2.0
func (t *TokenLineBuilder) Lines() (result []string)
Lines terminates the line-building and returns all the lines.