view

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package view maintains an ordered, filtered flow store and frontend focus. All access, including subscriptions and snapshots, must run inside hooks, commands or master.Do; the addon dispatch lock serializes its state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Kind  string
	Flow  flow.Flow
	Index int
}

Event describes a view, store or focus change. Kind is view_add, view_remove, view_update, view_refresh, store_add, store_remove, store_refresh or focus. Index is the ascending index before removal, matching upstream's signal. Flow is nil for refresh and focus events. Subscribe delivers dispatch-owned flows that require master.Do before inspection. Observe delivers detached, independently owned copies with the original flow identity and live flag.

type Focus

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

Focus tracks one selected visible flow. Its methods require the dispatch lock.

func (*Focus) Flow

func (f *Focus) Flow() flow.Flow

Flow returns the selected flow, or nil for an empty view.

func (*Focus) Index

func (f *Focus) Index() int

Index returns the selection's display index, or -1 without a selection.

func (*Focus) Set

func (f *Focus) Set(selected flow.Flow) error

Set selects a visible flow or clears the selection with nil.

func (*Focus) SetIndex

func (f *Focus) SetIndex(index int) error

SetIndex selects a flow at a nonnegative display index.

type Settings

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

Settings holds transient string settings that expire when a flow is removed.

func (*Settings) IDs

func (s *Settings) IDs() []string

IDs returns the IDs with settings in unspecified order.

func (*Settings) Values

func (s *Settings) Values(f flow.Flow) (map[string]string, error)

Values returns the flow's mutable settings, or an error for an unknown flow. The returned map may only be used while the dispatch lock is held.

type View

type View struct {
	// Focus tracks the selected flow.
	Focus *Focus
	// Settings holds transient per-flow frontend values.
	Settings *Settings
	// contains filtered or unexported fields
}

View stores flows in insertion order and exposes a separately ordered view. Construct it with New; the zero value is not usable.

func New

func New(manager *addon.Manager) *View

New constructs a View. A nil manager permits standalone store use; commands that notify other addons require a manager.

func (*View) Add

func (v *View) Add(_ context.Context, flows []flow.Flow)

Add stores previously unseen flows and adds those matching the filter to the view. Like upstream, marked-only mode affects refiltering, not this path.

func (*View) At

func (v *View) At(index int) (flow.Flow, error)

At returns a visible flow by index. Negative indices count from the end.

func (*View) Configure

func (v *View) Configure(ctx context.Context, updated map[string]struct{}) error

Configure applies view filtering, ordering, reversal and follow options.

func (*View) Contains

func (v *View) Contains(f flow.Flow) bool

Contains reports whether the flow is visible.

func (*View) DNSError

func (v *View) DNSError(ctx context.Context, f *flow.DNSFlow) error

DNSError refreshes a DNS flow after an error.

func (*View) DNSRequest

func (v *View) DNSRequest(ctx context.Context, f *flow.DNSFlow) error

DNSRequest adds a DNS query flow.

func (*View) DNSResponse

func (v *View) DNSResponse(ctx context.Context, f *flow.DNSFlow) error

DNSResponse refreshes a DNS response flow.

func (*View) Done

func (v *View) Done(context.Context) error

Done releases synchronous observers without changing the bounded Subscribe API.

func (*View) Error

func (v *View) Error(ctx context.Context, f *flow.HTTPFlow) error

Error refreshes an HTTP flow after an error.

func (*View) Flows

func (v *View) Flows() []flow.Flow

Flows returns a snapshot of visible flows in display order.

func (*View) GetByID

func (v *View) GetByID(id string) flow.Flow

GetByID returns the stored flow, or nil when the ID is absent.

func (*View) Index

func (v *View) Index(f flow.Flow) int

Index returns a visible flow's display index, or -1 when it is absent.

func (*View) Intercept

func (v *View) Intercept(ctx context.Context, f flow.Flow) error

Intercept refreshes an intercepted flow. The core addon uses Update at runtime.

func (*View) Kill

func (v *View) Kill(ctx context.Context, f flow.Flow) error

Kill refreshes a killed flow. The core addon uses Update at runtime.

func (*View) Len

func (v *View) Len() int

Len returns the number of visible flows.

func (*View) Load

func (v *View) Load(ctx context.Context, loader *addon.Loader) error

Load registers the four upstream options and all view commands.

func (*View) Notify

func (v *View) Notify(fn func()) func()

Notify registers a synchronous payload-free callback for the same event sequence as Observe, without copying flows. Callbacks may only mark dirty or wake a consumer nonblocking; they must not mutate the view, perform I/O or wait for another dispatch. Registration, notification and the idempotent unsubscribe require addon dispatch. Unsubscribe affects later emissions, not the captured callback set of an in-flight emission. A nil callback is ignored. Notify starts no goroutines. Use Observe when the consumer needs detached event payloads.

func (*View) Observe

func (v *View) Observe(fn func(Event)) func()

Observe registers a synchronous observer of the existing event sequence. Registration, notification and the idempotent unsubscribe require addon dispatch. Each callback receives its own detached Flow copy, safe to retain or mutate without changing the store or other observers. Copying preserves the original ID and Live flag. The callback must not mutate the view, perform I/O or wait for another dispatch; it may only copy/serialize and enqueue nonblocking data. Unsubscribe affects later emissions, not the captured callback set of an in-flight emission. A nil callback is ignored. Observe starts no goroutines.

func (*View) RequestHeaders

func (v *View) RequestHeaders(ctx context.Context, f *flow.HTTPFlow) error

RequestHeaders adds the HTTP flow when its headers arrive.

func (*View) Response

func (v *View) Response(ctx context.Context, f *flow.HTTPFlow) error

Response refreshes an HTTP flow after its response.

func (*View) Resume

func (v *View) Resume(ctx context.Context, f flow.Flow) error

Resume refreshes a resumed flow. The core addon uses Update at runtime.

func (*View) SetFilter

func (v *View) SetFilter(expression filter.Expr)

SetFilter replaces the filter and rebuilds the visible view. Nil matches all flows.

func (*View) StoreCount

func (v *View) StoreCount() int

StoreCount returns the number of stored flows, including hidden flows.

func (*View) Subscribe

func (v *View) Subscribe(capacity int) (<-chan Event, func())

Subscribe returns a bounded event channel and cancellation function. The capacity is at least one. Sends never block: overflow closes and removes that subscriber, leaving queued events readable. The consumer must resnapshot after closure. Subscribe and cancel, like all View access, require the dispatch lock. No goroutine is started and consumers must not wait under that lock.

func (*View) TCPEnd

func (v *View) TCPEnd(ctx context.Context, f *flow.TCPFlow) error

TCPEnd refreshes an ended TCP flow.

func (*View) TCPError

func (v *View) TCPError(ctx context.Context, f *flow.TCPFlow) error

TCPError refreshes a TCP flow after an error.

func (*View) TCPMessage

func (v *View) TCPMessage(ctx context.Context, f *flow.TCPFlow) error

TCPMessage refreshes a TCP flow after a message.

func (*View) TCPStart

func (v *View) TCPStart(ctx context.Context, f *flow.TCPFlow) error

TCPStart adds a new TCP flow.

func (*View) UDPEnd

func (v *View) UDPEnd(ctx context.Context, f *flow.UDPFlow) error

UDPEnd refreshes an ended UDP flow.

func (*View) UDPError

func (v *View) UDPError(ctx context.Context, f *flow.UDPFlow) error

UDPError refreshes a UDP flow after an error.

func (*View) UDPMessage

func (v *View) UDPMessage(ctx context.Context, f *flow.UDPFlow) error

UDPMessage refreshes a UDP flow after a datagram.

func (*View) UDPStart

func (v *View) UDPStart(ctx context.Context, f *flow.UDPFlow) error

UDPStart adds a new UDP flow.

func (*View) Update

func (v *View) Update(_ context.Context, flows []flow.Flow) error

Update refreshes the order and visibility of stored flows; unknown flows are ignored.

Jump to

Keyboard shortcuts

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