utils

package
v0.0.0-...-5f892d9 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRetryFailed = errors.New("all retry attempts failed")
)

Functions

func B2s

func B2s(b []byte) string

nolint

func CheckLink(link string) ([]string, error)

func DecodeB64

func DecodeB64(s string) (string, error)

func DecodeB64Bytes

func DecodeB64Bytes(s string) ([]byte, error)

func Fastrandn

func Fastrandn(x uint32) uint32

fastrandn returns a pseudorandom uint32 in [0,n).

func GetListens

func GetListens(ctx context.Context, network, address string) ([]net.Listener, error)

func IsFilePath

func IsFilePath(message string) bool

func IsUrl

func IsUrl(message string) bool

func Listen

func Listen(ctx context.Context, network, address string) (net.Listener, error)

func U16toa

func U16toa(i uint16) string

func UnsafeGetBytes

func UnsafeGetBytes(s string) []byte

Types

type Strategy

type Strategy interface {
	// On performs a retry on a specific function, until it doesn't return any error.
	On(func() error) error
}

Strategy is a way to retry on a specific function.

func ExponentialBackoff

func ExponentialBackoff(attempts int, delay uint32) Strategy

func Timed

func Timed(attempts int, delay uint32) Strategy

Timed returns a retry strategy with fixed interval.

type WorkerPool

type WorkerPool struct {
	// Function for serving server connections.
	WorkerFunc func(conn tunnel.Conn) error

	MaxWorkersCount int

	LogAllErrors bool

	MaxIdleWorkerDuration time.Duration
	// contains filtered or unexported fields
}

WorkerPool serves incoming connections via a pool of workers in FILO order, i.e. the most recently stopped worker will serve the next incoming connection.

Such a scheme keeps CPU caches hot (in theory).

func (*WorkerPool) Serve

func (wp *WorkerPool) Serve(conn tunnel.Conn) bool

func (*WorkerPool) Start

func (wp *WorkerPool) Start()

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Jump to

Keyboard shortcuts

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