Documentation ¶
Overview ¶
Package util contains helper functions for processes, IP addresses, env variables, etc.
Index ¶
- Variables
- func ChunkPayloadsBySizeAndWeight[T any, P any](l *PayloadList[P], a *ChunkAllocator[T, P], maxChunkSize int, ...)
- func GetDockerSocketPath() (string, error)
- func HandleSignals(exit chan struct{})
- func NetIPFromAddress(addr Address, buf []byte) net.IP
- func ToLowHigh(addr Address) (l, h uint64)
- func ToLowHighIP(a netip.Addr) (l, h uint64)
- type Address
- type AppendToChunk
- type ChunkAllocator
- func (c *ChunkAllocator[T, P]) Accept(ps []P, weight int)
- func (c *ChunkAllocator[T, P]) Append()
- func (c *ChunkAllocator[T, P]) GetChunks() *[]T
- func (c *ChunkAllocator[T, P]) Next()
- func (c *ChunkAllocator[T, P]) SetActiveChunk(i int)
- func (c *ChunkAllocator[T, P]) SetLastChunk()
- func (c *ChunkAllocator[T, P]) TakenSize() int
- func (c *ChunkAllocator[T, P]) TakenWeight() int
- type OnAccept
- type PayloadList
- type SSBytes
- type WeightAt
Constants ¶
This section is empty.
Variables ¶
var IPBufferPool = ddsync.NewSlicePool[byte](net.IPv6len, net.IPv6len)
IPBufferPool is meant to be used in conjunction with `NetIPFromAddress`
Functions ¶
func ChunkPayloadsBySizeAndWeight ¶
func ChunkPayloadsBySizeAndWeight[T any, P any](l *PayloadList[P], a *ChunkAllocator[T, P], maxChunkSize int, maxChunkWeight int)
ChunkPayloadsBySizeAndWeight allocates chunks of payloads taking max allowed size and max allowed weight algorithm in the nutshell: - iterate through payloads in the `payloadList` - keep track of size and weight available for allocation (`TakenSize` and `TakenWeight`) - create a new chunk once we exceed these limits - consider case when the current item exceeds the max allowed weight and create a new chunk at the end (`Append`) this implementation allows for multiple passes through the chunks, which can be useful in cases with different payload types being allocated within chunks See PayloadList and ChunkAllocator for a description of the type params.
func GetDockerSocketPath ¶
GetDockerSocketPath is only for exposing the sockpath out of the module
func HandleSignals ¶
func HandleSignals(exit chan struct{})
HandleSignals tells us whether we should exit.
func NetIPFromAddress ¶
NetIPFromAddress returns a net.IP from an Address Warning: the returned `net.IP` will share the same underlying memory as the given `buf` argument.
func ToLowHighIP ¶
ToLowHighIP converts a netaddr.IP into a pair of uint64 numbers
Types ¶
type Address ¶
Address is an IP abstraction that is family (v4/v6) agnostic
func AddressFromNetIP ¶
AddressFromNetIP returns an Address from a provided net.IP
func AddressFromString ¶
AddressFromString creates an Address using the string representation of an IP
func FromLowHigh ¶
FromLowHigh creates an address from a pair of uint64 numbers
type AppendToChunk ¶
type ChunkAllocator ¶
type ChunkAllocator[T any, P any] struct { // A function which adds the group of payloads to the chunk AppendToChunk AppendToChunk[T, P] // An optional callback that allows for manipulation the chunk when a payload is added OnAccept OnAccept[T] // contains filtered or unexported fields }
ChunkAllocator manages operations for chunk allocation. The type T is the type of the chunk, and the type P is the type of the payload.
func (*ChunkAllocator[T, P]) Accept ¶
func (c *ChunkAllocator[T, P]) Accept(ps []P, weight int)
Accept accepts a group of payloads into the current chunk
func (*ChunkAllocator[T, P]) Append ¶
func (c *ChunkAllocator[T, P]) Append()
Append creates a new chunk at the end (cases when it is known any previously allocated chunks cannot fit the payload)
func (*ChunkAllocator[T, P]) GetChunks ¶
func (c *ChunkAllocator[T, P]) GetChunks() *[]T
func (*ChunkAllocator[T, P]) Next ¶
func (c *ChunkAllocator[T, P]) Next()
Next moves to the next chunk or allocates a new chunk if the current chunk is the last
func (*ChunkAllocator[T, P]) SetActiveChunk ¶
func (c *ChunkAllocator[T, P]) SetActiveChunk(i int)
SetActiveChunk allows for rewinding in the case of multiple runs
func (*ChunkAllocator[T, P]) SetLastChunk ¶
func (c *ChunkAllocator[T, P]) SetLastChunk()
SetLastChunk sets the last chunk in case there is space at end across multiple runs
func (*ChunkAllocator[T, P]) TakenSize ¶
func (c *ChunkAllocator[T, P]) TakenSize() int
TakenSize returns the size allocated to the current chunk
func (*ChunkAllocator[T, P]) TakenWeight ¶
func (c *ChunkAllocator[T, P]) TakenWeight() int
TakenWeight returns the weight allocated to the current chunk
type PayloadList ¶
type PayloadList[T any] struct { // The items to chunk Items []T // A function which returns the weight of an item at the given index WeightAt WeightAt }
PayloadList is a wrapper for payloads subject to chunking
func (*PayloadList[T]) Len ¶
func (l *PayloadList[T]) Len() int
Len returns the number of items in the list