utils

package
v1.4.11 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const NormalBufferSize = 65536

NormalBufferSize is the size of buffers used by various processes when copying data between sockets.

Variables

View Source
var (
	// OIDSubjectAltName is the OID for subjectAltName.
	OIDSubjectAltName = asn1.ObjectIdentifier{2, 5, 29, 17}
	// OIDReceptorName is the OID for a Receptor node ID.
	OIDReceptorName = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 2312, 19, 1}
)
View Source
var ErrLocked = fmt.Errorf("fslock is already locked")

ErrLocked is returned when the flock is already held.

Functions

func BridgeConns

func BridgeConns(c1 io.ReadWriteCloser, c1Name string, c2 io.ReadWriteCloser, c2Name string, logger *logger.ReceptorLogger)

BridgeConns bridges two connections, like netcat.

func ErrorIsKind

func ErrorIsKind(err error, kind string) bool

ErrorIsKind returns true if err is an ErrorWithKind of the specified kind, or false otherwise (including if nil).

func GetSysCPUCount

func GetSysCPUCount() int

GetSysCPUCount returns number of logical CPU cores on the system.

func GetSysMemoryMiB

func GetSysMemoryMiB() uint64

GetSysMemoryMiB returns the capacity (in mebibytes) of the physical memory installed on the system.

func MakeReceptorSAN

func MakeReceptorSAN(dnsNames []string, ipAddresses []net.IP, nodeIDs []string) (*pkix.Extension, error)

MakeReceptorSAN generates a subjectAltName extension, optionally containing Receptor names.

func ParseReceptorNamesFromCert added in v1.3.0

func ParseReceptorNamesFromCert(cert *x509.Certificate, expectedHostname string, logger *logger.ReceptorLogger) (bool, []string, error)

func ReadStringContext

func ReadStringContext(ctx context.Context, reader *bufio.Reader, delim byte) (string, error)

ReadStringContext calls bufio.Reader.ReadString() but uses a context. Note that if the ctx.Done() fires, the ReadString() call is still active, and bufio is not re-entrant, so it is important for callers to error out of further use of the bufio. Also, the goroutine will not exit until the bufio's underlying connection is closed.

func ReceptorNames

func ReceptorNames(extensions []pkix.Extension) ([]string, error)

ReceptorNames returns a list of Receptor node IDs found in the subjectAltName field of an x.509 certificate.

Types

type Broker

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

Broker implements a simple pub-sub broadcast system.

func NewBroker

func NewBroker(ctx context.Context, msgType reflect.Type) *Broker

NewBroker allocates a new Broker object.

func (*Broker) Publish

func (b *Broker) Publish(msg interface{}) error

Publish sends a message to all subscribers.

func (*Broker) Subscribe

func (b *Broker) Subscribe() chan interface{}

Subscribe registers to receive messages from the broker.

func (*Broker) Unsubscribe

func (b *Broker) Unsubscribe(msgCh chan interface{})

Unsubscribe de-registers a message receiver.

type DNSNameEncode

type DNSNameEncode struct {
	Value string `asn1:"tag:2"`
}

DNSNameEncode is used for encoding the OtherName field of an x.509 subjectAltName.

type ErrorWithKind

type ErrorWithKind struct {
	Err  error
	Kind string
}

ErrorWithKind represents an error wrapped with a designation of what kind of error it is.

func WrapErrorWithKind

func WrapErrorWithKind(err error, kind string) ErrorWithKind

WrapErrorWithKind creates an ErrorWithKind that wraps an underlying error.

func (ErrorWithKind) Error

func (ek ErrorWithKind) Error() string

Error returns the error text as a string.

type FLock

type FLock struct {
	Fd int
}

FLock represents a file lock.

func TryFLock

func TryFLock(filename string) (*FLock, error)

TryFLock non-blockingly attempts to acquire a lock on the file.

func UnixSocketListen

func UnixSocketListen(filename string, permissions os.FileMode) (net.Listener, *FLock, error)

UnixSocketListen listens on a Unix socket, handling file locking and permissions.

func (*FLock) Unlock

func (lock *FLock) Unlock() error

Unlock unlocks the file lock.

type GeneralNameEncode

type GeneralNameEncode struct {
	Names []interface{} `asn1:"tag:0"`
}

GeneralNameEncode is used for encoding a GeneralName in an x.509 certificate.

type IPAddressEncode

type IPAddressEncode struct {
	Value []byte `asn1:"tag:7"`
}

IPAddressEncode is used for encoding the OtherName field of an x.509 subjectAltName.

type IncrementalDuration

type IncrementalDuration struct {
	Duration        time.Duration
	InitialDuration time.Duration
	MaxDuration     time.Duration
	// contains filtered or unexported fields
}

IncrementalDuration handles a time.Duration with max limits.

func NewIncrementalDuration

func NewIncrementalDuration(duration, maxDuration time.Duration, multiplier float64) *IncrementalDuration

NewIncrementalDuration returns an IncrementalDuration object with initialized values.

func (*IncrementalDuration) IncreaseDuration added in v1.4.9

func (id *IncrementalDuration) IncreaseDuration()

func (*IncrementalDuration) NextTimeout

func (id *IncrementalDuration) NextTimeout() <-chan time.Time

NextTimeout returns a timeout channel based on current duration.

func (*IncrementalDuration) Reset

func (id *IncrementalDuration) Reset()

Reset sets current duration to initial duration.

type JobContext

type JobContext struct {
	Ctx         context.Context
	JcCancel    context.CancelFunc
	Wg          *sync.WaitGroup
	JcRunning   bool
	RunningLock *sync.Mutex
}

JobContext is a synchronization object that combines the functions of a Context and a WaitGroup. The expected lifecycle is:

  • Caller calls JobContext.NewJob() with a parent context and a count of workers expected.
  • Caller launches the given number of workers, passing the JobContext to them.
  • Workers can check for termination by using the JobContext as a context.Context.
  • Workers can cancel the overall job by calling JobContext.Cancel().
  • Workers must call JobContext.WorkerDone() when they complete, like sync.WaitGroup.Done().
  • The caller, or other goroutines. can call JobContext.Wait() to wait for job completion.

A single JobContext can only run one job at a time. If JobContext.NewJob() is called while a job is already running, that job will be cancelled and waited on prior to starting the new job.

func (*JobContext) Cancel

func (mw *JobContext) Cancel()

Cancel cancels the JobContext's context. If no job has been started, this does nothing.

func (*JobContext) Deadline

func (mw *JobContext) Deadline() (time time.Time, ok bool)

Deadline implements Context.Deadline().

func (*JobContext) Done

func (mw *JobContext) Done() <-chan struct{}

Done implements Context.Done().

func (*JobContext) Err

func (mw *JobContext) Err() error

Err implements Context.Err().

func (*JobContext) NewJob

func (mw *JobContext) NewJob(ctx context.Context, workers int, returnIfRunning bool) bool

NewJob starts a new job with a defined number of workers. If a prior job is running, it is cancelled.

func (*JobContext) Running

func (mw *JobContext) Running() bool

Running returns true if a job is currently running.

func (*JobContext) Value

func (mw *JobContext) Value(key interface{}) interface{}

Value implements Context.Value().

func (*JobContext) Wait

func (mw *JobContext) Wait()

Wait waits for the current job to complete, like sync.WaitGroup.Wait(). If no job has been started, always just returns.

func (*JobContext) WorkerDone

func (mw *JobContext) WorkerDone()

WorkerDone signals that a worker is finished, like sync.WaitGroup.Done().

type OtherNameDecode

type OtherNameDecode struct {
	ID    asn1.ObjectIdentifier
	Value asn1.RawValue
}

OtherNameDecode is used for decoding the OtherName field type of an x.509 subjectAltName.

type OtherNameEncode

type OtherNameEncode struct {
	OID   asn1.ObjectIdentifier
	Value UTFString `asn1:"tag:0"`
}

OtherNameEncode is used for encoding the OtherName field of an x.509 subjectAltName.

type UTFString

type UTFString struct {
	A string `asn1:"utf8"`
}

UTFString is used for encoding a UTF-8 string.

Jump to

Keyboard shortcuts

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