util

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcPadding

func CalcPadding(length, blkSize int) int

CalcPadding returns the number of padding bytes needed to round length bytes to a multiple of blkSize

func Checksum

func Checksum(srcs ...common.RawBytes) uint16

Calculate RFC1071 checksum of supplied data chunks. If a chunk has an odd length, it is padded with a 0 during checksum computation.

func FillPadding

func FillPadding(b common.RawBytes, length, blkSize int) int

func FmtDuration

func FmtDuration(dur time.Duration) string

func ParseDuration

func ParseDuration(durationStr string) (time.Duration, error)

ParseDuration parses a string into a time.Duration, assuming that a year always has 365d, a week always has 7d, and a day always has 24h.

It is similar to time.ParseDuration, but differs in the following ways: - It adds support for the following units: "y", "w", "d" - It requires a unit suffix - It does not support mixed unit durations (e.g. `1h10m10s` is not supported). - It does not support negative durations.

func SecsToTime

func SecsToTime(t uint32) time.Time

SecsToTime takes seconds stored in a uint32.

func TimeToSecs added in v0.2.0

func TimeToSecs(t time.Time) uint32

TimeToSecs returns seconds stored as uint32.

func TimeToString

func TimeToString(t time.Time) string

Types

type ASList

type ASList struct {
	Core    []addr.IA
	NonCore []addr.IA
}

func LoadASList

func LoadASList(fileName string) (*ASList, error)

LoadASList parses the yaml file fileName and returns a structure with non-core and core ASes.

func (*ASList) AllASes added in v0.1.1

func (al *ASList) AllASes() []addr.IA

AllASes returns all ASes in the ASList as a slice.

type B64Bytes

type B64Bytes []byte

func (B64Bytes) MarshalYAML

func (b B64Bytes) MarshalYAML() (interface{}, error)

func (B64Bytes) String

func (b B64Bytes) String() string

func (*B64Bytes) UnmarshalYAML

func (b *B64Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error

type ChannelLock

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

ChannelLock implements a sync.Mutex-like API that uses a 1-value channel behind the scenes. This makes it usable in selects that also need to meet context deadlines.

func NewChannelLock

func NewChannelLock() *ChannelLock

func (*ChannelLock) Lock

func (l *ChannelLock) Lock() <-chan struct{}

Lock returns a channel that can be drained to acquire the lock.

func (*ChannelLock) Unlock

func (l *ChannelLock) Unlock()

type DebugID added in v0.2.0

type DebugID uint32

DebugID is used to correlate behavior in logs. A DebugID is allocated for each outgoing request/response or notify message exchange, and for each handler executed during ListenAndServe.

func GetDebugID added in v0.2.0

func GetDebugID() DebugID

func (DebugID) String added in v0.2.0

func (id DebugID) String() string

type Raw

type Raw struct {
	B      common.RawBytes
	Offset int
}

func (*Raw) Peek

func (r *Raw) Peek(p []byte) (int, error)

func (*Raw) Read

func (r *Raw) Read(p []byte) (int, error)

func (*Raw) Write

func (r *Raw) Write(p []byte) (int, error)

type Trigger

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

Trigger represents a timer with delayed arming. Once Arm is called, the channel return by Done() will be closed after d time. If d is 0, the channel is never closed.

func NewTrigger

func NewTrigger(d time.Duration) *Trigger

func (*Trigger) Arm

func (t *Trigger) Arm() *time.Timer

Arm starts the trigger's preset timer, and returns the corresponding timer object. If the trigger is not configured with a timer, nil is returned.

Calling Arm multiple times on the same object is a no-op. Every successive call will return nil.

func (*Trigger) Done

func (t *Trigger) Done() <-chan struct{}

func (*Trigger) Triggered

func (t *Trigger) Triggered() bool

Directories

Path Synopsis
Package bufpool initializes an elastic pool of free buffers.
Package bufpool initializes an elastic pool of free buffers.

Jump to

Keyboard shortcuts

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