engine

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package engine turns captured packets into parser events.

It owns the pieces parsers should not have to think about: decoding link and network layers, routing datagrams to PacketParsers, and running TCP reassembly so StreamParsers see an ordered byte stream instead of segments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Registry *parser.Registry
	Sink     event.Sink
	Logger   *slog.Logger

	// StreamTimeout is how long a TCP connection may sit idle before it is
	// flushed and closed. Too low truncates slow connections; too high holds
	// memory for connections that ended without a FIN.
	StreamTimeout time.Duration
	// FlushInterval is how often, in capture time, idle connections are swept.
	FlushInterval time.Duration
}

Config tunes an Engine. The zero value of each field selects a sensible default, so only the Registry and Sink are required.

type Engine

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

Engine reads from a Source until it is exhausted or the context is done.

func New

func New(cfg Config) (*Engine, error)

New builds an Engine.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, src capture.Source) (Stats, error)

Run processes every packet from src. It returns when the source is exhausted, the context is cancelled, or an unrecoverable read error occurs.

Reaching the end of a capture file is success, not an error.

func (*Engine) Stats

func (e *Engine) Stats() Stats

Stats returns the counters accumulated so far. It is safe to call while Run is in flight.

type Stats

type Stats struct {
	Packets      uint64 `json:"packets"`
	Bytes        uint64 `json:"bytes"`
	Events       uint64 `json:"events"`
	Streams      uint64 `json:"streams"`
	Unhandled    uint64 `json:"unhandled"`
	DecodeErrors uint64 `json:"decode_errors"`
	ParseErrors  uint64 `json:"parse_errors"`
	StreamGaps   uint64 `json:"stream_gaps"`
	// Tunnelled counts packets that arrived inside an encapsulation.
	Tunnelled uint64 `json:"tunnelled,omitzero"`

	// Capture holds libpcap's own counters, and is absent for a capture file.
	// Its Dropped field is the one that matters: a live capture that cannot
	// keep up silently reports less than it saw, and every other number here
	// is an undercount when it is nonzero.
	Capture *capture.Stats `json:"capture,omitempty"`
}

Stats is a snapshot of what an Engine run processed.

Jump to

Keyboard shortcuts

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