Documentation ¶
Overview ¶
Package base provides common utilities for other stenographer libraries.
Index ¶
- Variables
- func ContextDone(ctx context.Context) bool
- func PacketsToFile(in *PacketChan, out io.Writer, limit Limit) error
- func PathDiskFreePercentage(path string) (int, error)
- func V(level int, fmt string, args ...interface{})
- func Watchdog(d time.Duration, msg string) *time.Timer
- type Context
- type Limit
- type Packet
- type PacketChan
- type Positions
Constants ¶
This section is empty.
Variables ¶
var ( AllPositions = Positions{-1} NoPositions = Positions{} )
var VerboseLogging = flag.Int("v", -1, "log many verbose logs")
Functions ¶
func ContextDone ¶
ContextDone returns true if a context is complete.
func PacketsToFile ¶
func PacketsToFile(in *PacketChan, out io.Writer, limit Limit) error
PacketsToFile writes all packets from 'in' to 'out', writing out all packets in a valid PCAP file format.
func PathDiskFreePercentage ¶
func Watchdog ¶
Watchdog returns a time.Timer which log.Fatals if it goes off. The creator must call Stop before that time (to never die) or Reset (to postpone the inevitable).
Usage:
func couldGetStuck() { defer base.Watchdog(time.Minute * 5, "my description").Stop() ... do stuff ... }
Or:
func couldGetStuckOnManyThings(things []thing) { fido := base.Watchdog(time.Second * 15) defer fido.Stop() initialize() // can take up to 15 secs for _, thing := range things { fido.Reset(time.Second * 5) process(thing) // can take up to 5 seconds each } }
Types ¶
type Context ¶
Context wraps a context.Context with its cancel function.
func NewContext ¶
WrapContext wraps a context.Context in our type of Context. Timeout of zero means never time out. Cancel function should be called when operation is completed.
type Limit ¶
type Limit struct {
Bytes, Packets int64
}
Limit is the amount of data we want to return, or the amount taken by a single upload.
func LimitFromHeaders ¶
LimitFromHeaders returns a Limit based on HTTP headers.
func (*Limit) ShouldStopAfter ¶
ShouldStopAfter returns true if output should stop after the next update, where the next update is of size 'b'.
type Packet ¶
type Packet struct { Data []byte // The actual bytes that make up the packet gopacket.CaptureInfo // Metadata about when/how the packet was captured }
Packet is a single packet with its metadata.
type PacketChan ¶
type PacketChan struct { // C can be used to send packets on this channel in a select. Do NOT // call 'close' on it... instead call the Close function. C chan<- *Packet // contains filtered or unexported fields }
PacketChan provides an async method for passing multiple ordered packets between goroutines.
func ConcatPacketChans ¶
func ConcatPacketChans(ctx context.Context, in <-chan *PacketChan) *PacketChan
ConcatPacketChans concatenates packet chans in order.
func MergePacketChans ¶
func MergePacketChans(ctx context.Context, in []*PacketChan) *PacketChan
MergePacketChans merges an incoming set of packet chans, each sorted by time, returning a new single packet chan that's also sorted by time.
func NewPacketChan ¶
func NewPacketChan(buffer int) *PacketChan
NewPacketChan returns a new PacketChan channel for passing packets around.
func (*PacketChan) Close ¶
func (p *PacketChan) Close(err error)
Close closes the sending channel and sets the PacketChan's error based in its input.
func (*PacketChan) Discard ¶
func (p *PacketChan) Discard()
Discard discards all remaining packets on the receiving end. If you stop using the channel before reading all packets, you must call this function. It's a good idea to defer this regardless.
func (*PacketChan) Done ¶
func (p *PacketChan) Done() <-chan struct{}
Done returns a channel that is closed when this packet channel is complete.
func (*PacketChan) Err ¶
func (p *PacketChan) Err() error
Err gets the current error for the channel, if any exists. This may be called during Next(), but if an error occurs it may only be set after Next() returns false the first time.
func (*PacketChan) Receive ¶
func (p *PacketChan) Receive() <-chan *Packet
Receive provides the channel from which to read packets. It always returns the same channel.
func (*PacketChan) Send ¶
func (p *PacketChan) Send(pkt *Packet)
Send sends a single packet on the channel to the receiver.
type Positions ¶
type Positions []int64
Positions detail the offsets of packets within a blockfile.
func (Positions) Intersect ¶
Intersect returns the intersection of a and b. a and b must be sorted in advance. Returned slice will be sorted. a or b may be returned by Intersect, but neither a nor b will be modified.