util

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	YukinetVersion          = "Unknown Version"
	BuildDate               = "Unknown Date"
	DiscoveryDirectProtocol = "xudp"
)

Functions

func BackoffRetry

func BackoffRetry(ctx context.Context, callback func() error, exp float32, base, min, max time.Duration, maxConsectiveRetries int) error

func ByteCountIEC

func ByteCountIEC(b uint64) string

func CalculateBackOff

func CalculateBackOff(retries int, exp float32, base, min, max time.Duration) time.Duration

func ExtractConnRemoteURL

func ExtractConnRemoteURL(Conn net.Conn) *url.URL

func GenerateDirectAccessAddresses

func GenerateDirectAccessAddresses(protocol string, addresses []string, port string, queryMap url.Values) ([]url.URL, error)

func NewHookedListener

func NewHookedListener(raw net.Listener, hook ListenerHook) net.Listener

func ResolveIPForInterface

func ResolveIPForInterface(devName string) ([]string, error)

`devName` can be a list of interface names separated by `,`.

Types

type Cache

type Cache struct {
	// MaxEntries is the maximum number of cache entries before
	// an item is evicted. Zero means no limit.
	MaxEntries int
	// contains filtered or unexported fields
}

Cache is an LRU cache. It is not safe for concurrent access.

func LRU

func LRU(maxEntries int) *Cache

LRU creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.

func (*Cache) Add

func (c *Cache) Add(key Key, value interface{})

func (*Cache) Clear

func (c *Cache) Clear()

func (*Cache) Get

func (c *Cache) Get(key Key) (value interface{}, ok bool)

func (*Cache) Len

func (c *Cache) Len() int

func (*Cache) Remove

func (c *Cache) Remove(key Key)

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

type DefaultLogger

type DefaultLogger struct{}

func (*DefaultLogger) Errorf

func (*DefaultLogger) Errorf(format string, args ...interface{})

func (*DefaultLogger) Printf

func (*DefaultLogger) Printf(format string, args ...interface{})

type HookedListener

type HookedListener struct {
	net.Listener
	// contains filtered or unexported fields
}

HookedListener is a listener with a customized hook function.

func (*HookedListener) Accept

func (l *HookedListener) Accept() (net.Conn, error)

func (*HookedListener) Addr

func (l *HookedListener) Addr() net.Addr

type InflightChannel added in v0.2.42

type InflightChannel[T any] struct {
	// contains filtered or unexported fields
}

func NewInflightChannel added in v0.2.42

func NewInflightChannel[T any](buf int, processor func(c chan *T)) *InflightChannel[T]

func (*InflightChannel[T]) Close added in v0.2.42

func (o *InflightChannel[T]) Close() error

func (*InflightChannel[T]) Send added in v0.2.42

func (o *InflightChannel[T]) Send(ctx context.Context, v *T) bool

Send returns true if it is enqueued.

type InflightObject

type InflightObject[T any] struct {
	// contains filtered or unexported fields
}

func NewInflightObject

func NewInflightObject[T any](t T) *InflightObject[T]

func (*InflightObject[T]) Acquire

func (o *InflightObject[T]) Acquire() *T

func (*InflightObject[T]) CloseAndWait

func (o *InflightObject[T]) CloseAndWait(gcFunc func(t *T))

func (*InflightObject[T]) Release added in v0.3.5

func (o *InflightObject[T]) Release()

type InmemoryListener

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

InmemoryListener implements a listener for testing purpose.

func NewInMemoryListener

func NewInMemoryListener() *InmemoryListener

NewInMemoryListener creates an inmemory listener.

func (*InmemoryListener) Accept

func (l *InmemoryListener) Accept() (net.Conn, error)

Accept returns a connection just like net.Listener.

func (*InmemoryListener) Addr

func (l *InmemoryListener) Addr() net.Addr

Addr returns the address of the listener.

func (*InmemoryListener) Close

func (l *InmemoryListener) Close() error

Close closes the listener. Will immeidately return nil if the listener is already closed.

func (*InmemoryListener) Dial

func (l *InmemoryListener) Dial() (net.Conn, error)

Dial creates a connection to the InMemoryListener directly.

func (*InmemoryListener) IsClosed

func (l *InmemoryListener) IsClosed() bool

IsClosed returns if the listener is closed.

type Key

type Key interface{}

A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators

type ListenerHook

type ListenerHook func(net.Conn, error) (bool, net.Conn, error)

ListenerHook specifies a callback that is invoked after inner listener returns a result from Accept(). If `skip` is true, returned connection will be closed (if not error) and will re-invoke the Accept for the next result.

type Logger

type Logger interface {
	Printf(string, ...interface{})
	Errorf(string, ...interface{})
}

Logger is a generic logging interface.

type LoggerTracker

type LoggerTracker struct{ Logger }

func (*LoggerTracker) Close

func (l *LoggerTracker) Close() error

type NopLogger

type NopLogger struct{}

NopLogger drops all loggings.

func (*NopLogger) Errorf

func (*NopLogger) Errorf(string, ...interface{})

func (*NopLogger) Printf

func (*NopLogger) Printf(string, ...interface{})

type NopTracer

type NopTracer struct{}

func (*NopTracer) Close

func (*NopTracer) Close() error

func (*NopTracer) Errorf

func (*NopTracer) Errorf(string, ...interface{})

func (*NopTracer) Printf

func (*NopTracer) Printf(string, ...interface{})

type Timer

type Timer struct {
	*time.Timer
	// contains filtered or unexported fields
}

Timer roughly copies the interface of the Linux kernel's struct timer_list.

func NewTimer

func NewTimer(whenExpired func()) *Timer

func (*Timer) Del

func (timer *Timer) Del()

func (*Timer) DelSync

func (timer *Timer) DelSync()

func (*Timer) IsPending

func (timer *Timer) IsPending() bool

func (*Timer) Mod

func (timer *Timer) Mod(d time.Duration)

type TraceWrapper

type TraceWrapper struct {
	Trace trace.Trace
	// contains filtered or unexported fields
}

func (*TraceWrapper) Close

func (t *TraceWrapper) Close() error

func (*TraceWrapper) Errorf

func (t *TraceWrapper) Errorf(format string, args ...interface{})

func (*TraceWrapper) Printf

func (t *TraceWrapper) Printf(format string, args ...interface{})

type Tracer

type Tracer interface {
	Logger
	io.Closer
}

Tracer is a generic trace interface, it will close the trace if Close() is called.

type TracerFunc

type TracerFunc func(Family string, Instance string) Tracer

type URLAddr

type URLAddr struct {
	URL *url.URL
}

func (*URLAddr) Network

func (u *URLAddr) Network() string

func (*URLAddr) String

func (u *URLAddr) String() string

Jump to

Keyboard shortcuts

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