dump

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirClientToServer byte = 0x00
	DirServerToClient byte = 0x01
)

Packet direction constants.

View Source
const (
	ProtocolOracle     = "oracle"
	ProtocolPostgreSQL = "postgresql"
	ProtocolMySQL      = "mysql"
)

Protocol identifiers.

View Source
const (
	FileExt = ".dbbat-dump"
)

File format constants.

Variables

View Source
var (
	ErrInvalidMagic       = errors.New("invalid dump file magic")
	ErrUnsupportedVersion = errors.New("unsupported dump format version")
)

Errors.

Functions

func Anonymise

func Anonymise(inputPath, outputPath string) error

Anonymise reads a dump file and writes an anonymised copy. The anonymised dump preserves packet data but strips connection metadata from the header, keeping only the session ID and protocol.

func CleanupOldFiles

func CleanupOldFiles(dir string, retention time.Duration) (int, error)

CleanupOldFiles deletes .dbbat-dump files older than the retention period. Returns the number of files deleted.

Types

type Header struct {
	SessionID  string         `json:"session_id"`
	Protocol   string         `json:"protocol"`
	StartTime  time.Time      `json:"start_time"`
	Connection map[string]any `json:"connection"`
}

Header holds the JSON-serializable session metadata.

type Packet

type Packet struct {
	RelativeNs int64  // Nanoseconds since session start
	Direction  byte   // DirClientToServer or DirServerToClient
	Data       []byte // Raw protocol bytes
}

Packet represents a single captured packet.

type Reader

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

Reader reads packets from a dump file.

func OpenReader

func OpenReader(path string) (*Reader, error)

OpenReader opens a dump file and parses the header.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the underlying file.

func (*Reader) Header

func (r *Reader) Header() Header

Header returns the parsed JSON header.

func (*Reader) ReadPacket

func (r *Reader) ReadPacket() (*Packet, error)

ReadPacket reads the next packet from the dump. Returns io.EOF after the EOF marker.

type TapConn

type TapConn struct {
	net.Conn
	// contains filtered or unexported fields
}

TapConn wraps a net.Conn and captures all read/written bytes to a Writer. Reads are tagged with one direction, writes with the other.

func NewTapConn

func NewTapConn(conn net.Conn, w *Writer, readDir, writeDir byte) *TapConn

NewTapConn creates a connection wrapper that captures traffic to a dump Writer.

func (*TapConn) Read

func (t *TapConn) Read(b []byte) (int, error)

Read reads from the underlying connection and records the data.

func (*TapConn) Write

func (t *TapConn) Write(b []byte) (int, error)

Write writes to the underlying connection and records the data.

type Writer

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

Writer writes packet dumps to a binary file.

func NewWriter

func NewWriter(path string, header Header, maxSize int64) (*Writer, error)

NewWriter creates a new dump file and writes the file header + JSON header.

func (*Writer) Close

func (w *Writer) Close() error

Close writes the EOF marker and closes the file.

func (*Writer) WritePacket

func (w *Writer) WritePacket(direction byte, data []byte) error

WritePacket appends a single packet to the dump file. Thread-safe. Silently skips if maxSize would be exceeded.

Jump to

Keyboard shortcuts

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