capture

package
v0.0.0-...-36fb464 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDualTapFactory

func NewDualTapFactory(svc *Service, baseTunnelID string, username string, maxEvents int, portToIndex map[string]int) tunnel.TapFactory

NewDualTapFactory emits capture to both base session ID and per-remote IDs

func NewPerRemoteTapFactory

func NewPerRemoteTapFactory(svc *Service, baseTunnelID string, username string, maxEvents int, portToIndex map[string]int) tunnel.TapFactory

NewPerRemoteTapFactory creates a TapFactory which assigns events to per-remote IDs (baseID-r{index}) portToIndex maps remote.LocalPort -> index used in the ID suffix

func NewTapFactory

func NewTapFactory(svc *Service, tunnelID string, username string, maxEvents int) tunnel.TapFactory

NewTapFactory creates a tunnel TapFactory bound to this capture Service and a tunnel id/user

func NewTripleTapFactoryWithCanonical

func NewTripleTapFactoryWithCanonical(svc *Service, baseTunnelID string, username string, maxEvents int, portToIndex map[string]int, unameEnc string) tunnel.TapFactory

NewTripleTapFactoryWithCanonical emits capture to: - base session ID (sess-...) - per-remote session IDs (sess-...-rN) - canonical per-user+ports tunnel ID (tun-<b64user>-<lp>-<rp>)

Types

type Event

type Event struct {
	Time      time.Time `json:"time"`
	TunnelID  string    `json:"tunnel_id"`
	User      string    `json:"user"`
	ConnID    string    `json:"conn_id"`
	Type      EventType `json:"type"`
	Meta      any       `json:"meta,omitempty"`
	Data      []byte    `json:"data,omitempty"`
	Truncated bool      `json:"truncated,omitempty"`
}

Event represents a captured event for a tunnel/connection.

type EventType

type EventType string

EventType represents the type of capture event.

const (
	ConnOpen   EventType = "conn_open"
	ConnClose  EventType = "conn_close"
	ReqHeaders EventType = "req_headers"
	ReqBody    EventType = "req_body"
	ResHeaders EventType = "res_headers"
	ResBody    EventType = "res_body"
	Metric     EventType = "metric"
)

type Meta

type Meta struct {
	Username string
	Remote   settings.Remote
	ConnID   string
}

type Ring

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

Ring is a fixed-size ring buffer of events.

func NewRing

func NewRing(cap int) *Ring

func (*Ring) Add

func (r *Ring) Add(e Event)

func (*Ring) Snapshot

func (r *Ring) Snapshot() []Event

type Service

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

Service manages capture buffers per tunnel and persistence.

func NewService

func NewService(maxEvents, maxBytes int) *Service

func (*Service) AddEvent

func (s *Service) AddEvent(tunnelID string, e Event, maxEvents int)

AddEvent adds to ring and optionally persists

func (*Service) GetRecent

func (s *Service) GetRecent(tunnelID string, maxEvents int) []Event

func (*Service) LatestLogFile

func (s *Service) LatestLogFile(tunnelID, connID string) (string, error)

LatestLogFile returns the latest file path for a given connection (base or highest rotated)

func (*Service) ListConnections

func (s *Service) ListConnections(tunnelID string) ([]string, error)

ListConnections returns known connection IDs for a tunnel based on persisted files

func (*Service) SetOnConnDelta

func (s *Service) SetOnConnDelta(fn func(tunnelID string, delta int))

SetOnConnDelta sets a hook to be called when a connection opens (+1) or closes (-1).

func (*Service) SetOnMetric

func (s *Service) SetOnMetric(fn func(tunnelID string, sent, received int64))

SetOnMetric sets a hook to be called when a connection closes with byte counts.

func (*Service) Subscribe

func (s *Service) Subscribe(tunnelID string) chan Event

Subscribe returns a channel that will receive future events for a tunnel.

func (*Service) Unsubscribe

func (s *Service) Unsubscribe(tunnelID string, ch chan Event)

Unsubscribe removes a subscriber channel.

type TapImpl

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

func (*TapImpl) DstWriter

func (t *TapImpl) DstWriter() io.Writer

DstWriter receives bytes from upstream -> client

func (*TapImpl) OnClose

func (t *TapImpl) OnClose(sent, received int64)

func (*TapImpl) OnOpen

func (t *TapImpl) OnOpen()

func (*TapImpl) SrcWriter

func (t *TapImpl) SrcWriter() io.Writer

SrcWriter receives bytes from client -> upstream

Jump to

Keyboard shortcuts

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