util

package
v2.0.0-...-4530641 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAdvertizedPrefixes

func GetAdvertizedPrefixes(wr *pb.WriteRequest) ([]*net.IPNet, error)

GetAdvertizedPrefixes returns the advertized routes from a capture WriteRequest

func GetAsPath

func GetAsPath(wr *pb.WriteRequest) []int

GetAsPath returns an AS path from a capture WriteRequest

func GetIPWrapper

func GetIPWrapper(pip *pbcomm.IPAddressWrapper) (ret net.IP, err error)

GetIPWrapper returns a net.IP from a pbcomm.IPAddressWrapper

func GetNextHop

func GetNextHop(wr *pb.WriteRequest) (net.IP, error)

GetNextHop returns the IP of the next hop from a capture WriteRequest

func GetNodeTableNameDates

func GetNodeTableNameDates(name string, stime time.Time, durmin int) (string, time.Time, time.Time)

GetNodeTableNameDates this function gets the date for a new collector table to be added with the desired duration minutes and returns a string that should be the table name, the truncated time, and the end time.

func GetOriginAs

func GetOriginAs(wr *pb.WriteRequest) int

GetOriginAs Returns the AS at index 0 of the ASPath from a capture WriteRequest

func GetPeerIP

func GetPeerIP(wr *pb.WriteRequest) (net.IP, error)

GetPeerIP Returns a PeerIP from a capture WriteRequest

func GetProtoMsg

func GetProtoMsg(wr *pb.WriteRequest) []byte

GetProtoMsg Returns a byte array representing the capture from a WritRequest

func GetTimeColIP

func GetTimeColIP(pb *pb.WriteRequest) (time.Time, net.IP, error)

GetTimeColIP Returns the time and collector IP from a capture WriteRequest

func GetWithdrawnPrefixes

func GetWithdrawnPrefixes(wr *pb.WriteRequest) ([]*net.IPNet, error)

GetWithdrawnPrefixes returns the withdrawn routes from a captured WriteRequest

func NBContextClosed

func NBContextClosed(ctx context.Context) bool

NBContextClosed Returns true if a context has been closed, false otherwise and doesn't block

func PrefixesToPQArray

func PrefixesToPQArray(n []*net.IPNet) interface {
	driver.Valuer
	sql.Scanner
}

PrefixesToPQArray handles a strange case where protobuf deserialize an array element of nil as "<nil>" and that kills the db insert statement cause it can't make it into a cidr.

func SumNodeConfs

func SumNodeConfs(confnodes, dbnodes map[string]config.NodeConfig) map[string]config.NodeConfig

SumNodeConfs Combines two maps of NodeConfigs, preferring the first in case of overlap

Types

type CollectorsByNameDate

type CollectorsByNameDate []collectorDateString

CollectorsByNameDate collector-date strings ordered by their starting date.

func (CollectorsByNameDate) Add

Add will return a new copy of the sorted array with the new collector date added. the time should be the truncated time according to the the duration provided in the arguments of a GetNodeTableNameDates() call, as well as the end time to be stime+duration the caller should try to insert that new name to the nodes table and if succesful, change his collectorsByNameDate reference to the new updated one. there is a helper func in schemamgr for this called AddNodeAndTableInCache

func (CollectorsByNameDate) ColNameDateInSlice

func (c CollectorsByNameDate) ColNameDateInSlice(colname string, date time.Time) (int, bool)

ColNameDateInSlice this will return the index and if the name and date are in the slice. caller has to check existence.

func (CollectorsByNameDate) Len

func (c CollectorsByNameDate) Len() int

Len implementation for sort interface

func (CollectorsByNameDate) Less

func (c CollectorsByNameDate) Less(i, j int) bool

Less implementation for sort interface. uses the stable sort attribute to do two keys. first by name then by date.

func (CollectorsByNameDate) String

func (c CollectorsByNameDate) String() string

func (CollectorsByNameDate) Swap

func (c CollectorsByNameDate) Swap(i, j int)

Swap implementation for sort interface

type InsertBuffer

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

InsertBuffer Represents the VALUES() array for an insert statement Helps to optimize the amount of inserted values on a single query

func (*InsertBuffer) Add

func (ib *InsertBuffer) Add(arg ...interface{}) error

Add Satisfies the SQLBuffer interface

func (*InsertBuffer) Clear

func (ib *InsertBuffer) Clear()

Clear Satisfies the SQLBuffer interface

func (*InsertBuffer) Flush

func (ib *InsertBuffer) Flush() error

Flush Satisfies the SQLBuffer interface

type Logger

type Logger interface {
	Infof(string, ...interface{})
	Errorf(string, ...interface{}) error
	Fatalf(string, ...interface{})
}

Logger is a wrapper on a logrus.FieldLogger, meant to ease use

func NewLogger

func NewLogger(fields ...string) Logger

NewLogger returns a util.Logger, with pairs of strings matched for fields

type SQLBuffer

type SQLBuffer interface {
	Add(arg ...interface{}) error
	Flush() error
	Clear()
}

SQLBuffer is an interface used to describe anything that can buffer sql values to be flushed later

func NewInsertBuffer

func NewInsertBuffer(ex SQLErrorExecutor, stmt string, max int, batchSize int, usePositional bool) SQLBuffer

NewInsertBuffer Returns a SQLBuffer which buffers values for an insert statement

type SQLErrorExecutor

type SQLErrorExecutor interface {
	SQLExecutor
	SetError(error)
}

SQLErrorExecutor is a SQLExecutor with a persistent error, useful in tx

type SQLExecutor

type SQLExecutor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

SQLExecutor is a wrapper around sql.Tx, sql.Db, and others we implement

type TimedBuffer

type TimedBuffer struct {
	SQLBuffer
	// contains filtered or unexported fields
}

TimedBuffer is a SQLBuffer that wraps another SQLBuffer, flushing it after a certain amount of time

func NewTimedBuffer

func NewTimedBuffer(parent SQLBuffer, d time.Duration) *TimedBuffer

NewTimedBuffer returns a TimedBuffer

func (*TimedBuffer) Add

func (t *TimedBuffer) Add(args ...interface{}) error

Add Satisfies the SQLBuffer interface

func (*TimedBuffer) Stop

func (t *TimedBuffer) Stop()

Stop is unique to the TimedBuffer, it stops the timer and closes the waiting goroutine

type WorkerPool

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

WorkerPool is a struct that manages the amount of goroutines by blocking on and add

func NewWorkerPool

func NewWorkerPool(ct int) *WorkerPool

NewWorkerPool returns a worker pool with ct as the maximum number of goroutines

func (*WorkerPool) Add

func (wp *WorkerPool) Add()

Add adds a worker to the pool

func (*WorkerPool) Close

func (wp *WorkerPool) Close() bool

Close waits for all workers to be finished and closes the daemon goroutine

func (*WorkerPool) Done

func (wp *WorkerPool) Done()

Done signifies a worker is finished

Jump to

Keyboard shortcuts

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