mtrsession

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mtrsession stores explicitly recorded MTR sessions for offline replay.

Index

Constants

View Source
const (
	FormatName    = "nexttrace-mtr-session"
	SchemaVersion = 1
	// MaxLineBytes includes the terminating newline written by Writer.
	MaxLineBytes = 1 << 20
	StartEvent   = "start"
	EndEvent     = "end"
)

Variables

View Source
var (
	ErrLineTooLarge = errors.New("MTR session record exceeds 1 MiB")
	ErrClosed       = errors.New("MTR session file is closed")
)

Functions

This section is empty.

Types

type DisplayParameters

type DisplayParameters struct {
	HostMode     int    `json:"host_mode"`
	HostNameMode int    `json:"host_name_mode"`
	ShowIPs      bool   `json:"show_ips"`
	ShowMPLS     bool   `json:"show_mpls"`
	Wide         bool   `json:"wide"`
	Columns      string `json:"columns,omitempty"`
}

type End

type End struct {
	EndedAt   time.Time         `json:"ended_at"`
	EndReason string            `json:"end_reason"`
	PathEnd   *trace.StopReason `json:"path_end"`
	Error     *Error            `json:"error,omitempty"`
	Signal    string            `json:"signal,omitempty"`
}

type Error

type Error struct {
	Stage   string `json:"stage"`
	Message string `json:"message"`
}

type Parameters

type Parameters struct {
	FWMark           *uint32 `json:"fwmark,omitempty"`
	MaxPerHop        int     `json:"max_per_hop"`
	HopIntervalMs    int     `json:"hop_interval_ms"`
	TimeoutMs        int64   `json:"timeout_ms"`
	BeginHop         int     `json:"begin_hop"`
	MaxHops          int     `json:"max_hops"`
	ParallelRequests int     `json:"parallel_requests"`
	SourceAddress    string  `json:"source_address"`
	SourceDevice     string  `json:"source_device,omitempty"`
	SourcePort       *int    `json:"source_port,omitempty"`
	Port             *int    `json:"port,omitempty"`
	PacketSize       int     `json:"packet_size"`
	RandomPacketSize bool    `json:"random_packet_size"`
	TOS              int     `json:"tos"`
	ICMPMode         *int    `json:"icmp_mode,omitempty"`
	DataProvider     string  `json:"data_provider"`
	Language         string  `json:"language"`
	DotServer        string  `json:"dot_server,omitempty"`
	RDNS             bool    `json:"rdns"`
	AlwaysWaitRDNS   bool    `json:"always_wait_rdns"`
	DisableMPLS      bool    `json:"disable_mpls"`
	DN42             bool    `json:"dn42"`
}

Parameters contains effective probe settings, never provider credentials.

type Reader

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

Reader holds an open regular file and a fixed byte limit. New data appended while replaying is not followed, including after Rewind.

func OpenReader

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

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Incomplete

func (r *Reader) Incomplete() bool

func (*Reader) Next

func (r *Reader) Next() (Record, error)

Next returns io.EOF at the fixed end, including a recoverable partial tail. Call Incomplete after EOF to distinguish a complete session from a prefix. Invalid complete records are errors and are never silently skipped.

func (*Reader) Offset

func (r *Reader) Offset() int64

func (*Reader) Rewind

func (r *Reader) Rewind() error

Rewind starts a new pass over the same original file extent.

func (*Reader) Size

func (r *Reader) Size() int64

type Record

type Record struct {
	Format        string    `json:"format"`
	SchemaVersion int       `json:"schema_version"`
	Seq           uint64    `json:"seq"`
	ElapsedNS     int64     `json:"elapsed_ns"`
	Timestamp     time.Time `json:"timestamp"`
	ProbeAgeNS    *int64    `json:"probe_age_ns,omitempty"`
	trace.MTRSessionEvent
	Session *Session `json:"session,omitempty"`
	End     *End     `json:"end,omitempty"`
}

Record keeps event occurrence time separate from the ordered playback clock. Sequence and ElapsedNS are monotonic, even if the wall clock moves backwards.

type Session

type Session struct {
	Version             string            `json:"version"`
	Target              string            `json:"target"`
	ResolvedIP          string            `json:"resolved_ip"`
	Protocol            string            `json:"protocol"`
	StartedAt           time.Time         `json:"started_at"`
	EffectiveParameters *Parameters       `json:"effective_parameters"`
	SourceHost          string            `json:"source_host"`
	SourceIP            string            `json:"source_ip,omitempty"`
	Display             DisplayParameters `json:"display"`
}

type Writer

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

Writer writes each complete event before returning. Finish syncs and closes the file. A failed write is sticky: later calls never append to a bad tail.

func Open

func Open(path string) (*Writer, error)

Open exclusively creates a private file. Existing files, including symlinks, are never overwritten or appended to.

func (*Writer) Close

func (w *Writer) Close() error

Close preserves an unfinished file for recovery without inventing an end.

func (*Writer) Event

func (w *Writer) Event(event trace.MTRSessionEvent) error

func (*Writer) Finish

func (w *Writer) Finish(end End) error

Finish is idempotent and checks both Sync and Close, including after a write failure. The first failed record is never retried.

func (*Writer) Start

func (w *Writer) Start(session Session) error

Jump to

Keyboard shortcuts

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