core

package
v0.0.0-...-d92f398 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright (c) 2024 RethinkDNS and its authors.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Index

Constants

View Source
const (
	// Anew is the value returned by Barrier.Do when the function was
	// executed and its results are stored in the Barrier.
	Anew = iota
	// Shared is the value returned by Barrier.Do when the function's
	// results are already stored in the Barrier.
	Shared
)
View Source
const (
	// BMAX is slab of size 64k; also the max
	BMAX = 64 * 1024
	// B65536 is slab of size 64k
	B65536 = BMAX
	// B32768 is slab of size 32k
	B32768 = 32 * 1024
	// B16384 is slab of size 16k
	B16384 = 16 * 1024
	// B8192 is slab of size 8k
	B8192 = 8 * 1024
	// B4096 is slab of size 4k
	B4096 = 4 * 1024
	// B2048 is slab of size 2k; also the min
	B2048 = 2 * 1024
)

Variables

This section is empty.

Functions

func Alloc

func Alloc() *[]byte

Alloc returns a truncated byte slice of size 4096

func AllocRegion

func AllocRegion(size int) *[]byte

AllocRegion returns a truncated byte slice at least size big

func NewConnMap

func NewConnMap() *cm

func Recycle

func Recycle(b *[]byte) bool

Recycle returns the byte slices to the pool

Types

type Barrier

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

Barrier represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.

func NewBarrier

func NewBarrier[T any](ttl time.Duration) *Barrier[T]

NewBarrier returns a new Barrier with the given time-to-live for completed Vs.

func (*Barrier[T]) Do

func (ba *Barrier[T]) Do(k string, once Work[T]) (*V[T], int)

Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.

type ConnMapper

type ConnMapper interface {
	Clear() []string
	Track(t ConnTuple, x ...net.Conn) int
	TrackDest(t ConnTuple, x netip.AddrPort) int
	Find(dst string) (t []ConnTuple)
	FindAll(csvips, port string) (t []ConnTuple)
	Get(cid string) []net.Conn
	Untrack(cid string) int
	UntrackBatch(cids []string) []string
}

type ConnTuple

type ConnTuple struct {
	CID string // conn id
	UID string // proc id
}

func (ConnTuple) String

func (t ConnTuple) String() string

type ExpMap

type ExpMap struct {
	sync.Mutex // guards ExpMap.
	// contains filtered or unexported fields
}

ExpMap holds expiring keys and read hits.

func NewExpiringMap

func NewExpiringMap() *ExpMap

NewExpiringMap returns a new ExpMap.

func (*ExpMap) Clear

func (m *ExpMap) Clear() int

Clear deletes all keys and returns the number of keys deleted.

func (*ExpMap) Delete

func (m *ExpMap) Delete(key string)

Delete deletes the given key.

func (*ExpMap) Get

func (m *ExpMap) Get(key string) uint32

Get returns the number of hits for the given key.

func (*ExpMap) Len

func (m *ExpMap) Len() int

Len returns the number of keys, which may or may not have expired.

func (*ExpMap) Set

func (m *ExpMap) Set(key string, expiry time.Duration) uint32

Set sets the expiry for the given key and returns the number of hits.

type Hangover

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

func NewHangover

func NewHangover() *Hangover

func (*Hangover) Break

func (h *Hangover) Break()

func (*Hangover) Exceeds

func (h *Hangover) Exceeds(d time.Duration) bool

func (*Hangover) Note

func (h *Hangover) Note()

func (*Hangover) Within

func (h *Hangover) Within(d time.Duration) bool

type P2QuantileEstimator

type P2QuantileEstimator interface {
	// Add a sample to the estimator.
	Add(float64)
	// Get the estimation for p.
	Get() int64
	// Get the percentile, p.
	P() float64
}

P2QuantileEstimator is an interface for the P2 quantile estimator.

func NewP2QuantileEstimator

func NewP2QuantileEstimator(samples int, probability float64) P2QuantileEstimator

NewP90Estimator returns a new estimator with percentile p.

func NewP50Estimator

func NewP50Estimator() P2QuantileEstimator

NewP50Estimator returns a new P50 (median) estimator.

type PcapHeader

type PcapHeader struct {
	MagicNumber  uint32
	VersionMajor uint16
	VersionMinor uint16
	Thiszone     int32
	Sigfigs      uint32
	Snaplen      uint32
	Network      uint32
}

from: github.com/google/gvisor/blob/596e8d22/pkg/tcpip/link/sniffer/pcap.go#L26

type TCPConn

type TCPConn interface {
	// RemoteAddr returns the destination network address.
	RemoteAddr() net.Addr

	// LocalAddr returns the local client network address.
	LocalAddr() net.Addr

	// confirms to protect.Conn
	Write(data []byte) (int, error)
	Read(data []byte) (int, error)
	Close() error

	// CloseWrite closes the writing side by sending a FIN
	// segment to local peer. That means we can write no further
	// data to TUN.
	CloseWrite() error

	// CloseRead closes the reading side. That means we can no longer
	// read more from TUN.
	CloseRead() error

	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

TCPConn abstracts a TCP connection comming from TUN. This connection should be handled by a registered TCP proxy handler.

type UDPConn

type UDPConn interface {
	// LocalAddr returns the local client network address.
	LocalAddr() net.Addr
	RemoteAddr() net.Addr

	// confirms to protect.Conn
	Write(data []byte) (int, error)
	Read(data []byte) (int, error)

	// confirms to net.PacketConn
	WriteTo(data []byte, addr net.Addr) (int, error)
	ReadFrom(data []byte) (int, net.Addr, error)

	// Close closes the connection.
	Close() error

	// Implements net.Conn
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

UDPConn abstracts a UDP connection comming from TUN. This connection should be handled by a registered UDP proxy handler.

type V

type V[T any] struct {
	Val T
	Err error
	N   atomic.Uint32
	// contains filtered or unexported fields
}

V is an in-flight or completed Barrier.Do V

func (*V[t]) String

func (v *V[t]) String() string

type Volatile

type Volatile[T any] atomic.Value

func NewVolatile

func NewVolatile[T any](t T) *Volatile[T]

NewVolatile returns a new Volatile with the value t. Panics if t is nil.

func (*Volatile[T]) Cas

func (a *Volatile[T]) Cas(old, new T) bool

Cas compares and swaps the value of a with new, returns true if the value was swapped. Panics if new is nil.

func (*Volatile[T]) Load

func (a *Volatile[T]) Load() (t T)

Load returns the value of a. May return nil.

func (*Volatile[T]) Store

func (a *Volatile[T]) Store(t T)

Store stores the value t, panics if t is nil.

func (*Volatile[T]) Swap

func (a *Volatile[T]) Swap(new T) (old T)

Swap swaps the value of a with new, returns the old value. Panics if new is nil.

type Work

type Work[T any] func() (T, error)

Work is the type of the function to memoize.

Directories

Path Synopsis
Package blindrsa implements the RSA Blind Signature Protocol as defined in [RFC9474].
Package blindrsa implements the RSA Blind Signature Protocol as defined in [RFC9474].

Jump to

Keyboard shortcuts

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