util

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2017 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CryptoRandBytes

func CryptoRandBytes(size int) ([]byte, error)

func CryptoRandInt

func CryptoRandInt(min, max int64) int64

func MergeSeeds

func MergeSeeds(one [][]byte, two [][]byte) [][]byte

func RandInt

func RandInt(min, max int) int

func ReadPost

func ReadPost(r io.Reader, delim byte)

func ShuffleBytes

func ShuffleBytes(slice [][]byte)

func SliceDiff

func SliceDiff(one [][]byte, two [][]byte) [][]byte

Returns everything in two that is not in one

Types

type Limiter

type Limiter struct {
	Throttle chan time.Time
	Ticker   *time.Ticker
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(rate time.Duration, burst int, fill bool) *Limiter

Return a new rate limiter. This is used to make sure that something like a requrest for instance does not run too many times. However, it does allow bursting. For example, it may refill at a rate of 3 tokens per minute, and have a burst of three. This means that if it has been running for more than a minute without being used then, it will be able to be used 3 times in rapid succession - no limiting will apply.

func (*Limiter) Stop

func (l *Limiter) Stop()

Finish running.

func (*Limiter) Wait

func (l *Limiter) Wait()

Block until the given time has elapsed. Or just use a token from the bucket.

type PeerLimiter

type PeerLimiter struct {
	// contains filtered or unexported fields
}

Limits requests from peers

func (*PeerLimiter) Setup

func (pl *PeerLimiter) Setup()

Jump to

Keyboard shortcuts

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