usbip

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package usbip is the public facade for the usbip-go library. It re-exports the stable surface (constructors, configuration options, sentinel errors) and wraps the internal application services so that consumers never reach into the `internal/` tree.

Index

Constants

View Source
const (
	KernelModuleUSBIPCore = "usbip_core"
	KernelModuleVHCIHCD   = "vhci_hcd"
	KernelModuleUSBIPHost = "usbip_host"
)

Canonical Linux USB/IP kernel module names used as ProbeKernelModules keys.

View Source
const (
	EventPortAttached           = domain.EventPortAttached
	EventPortDetached           = domain.EventPortDetached
	EventPortErrored            = domain.EventPortErrored
	EventPortReconnectExhausted = domain.EventPortReconnectExhausted
	EventDeviceBound            = domain.EventDeviceBound
	EventDeviceUnbound          = domain.EventDeviceUnbound
	EventSessionStarted         = domain.EventSessionStarted
	EventSessionEnded           = domain.EventSessionEnded
)

EventKind constants re-exported for consumers comparing domain.Event values without importing pkg/domain directly.

Variables

View Source
var (
	// ErrDeviceNotFound indicates the requested busid is not present.
	ErrDeviceNotFound = domain.ErrDeviceNotFound

	// ErrDeviceAlreadyBound indicates the device is already bound to
	// usbip-host and cannot be bound again.
	ErrDeviceAlreadyBound = domain.ErrDeviceAlreadyBound

	// ErrDeviceNotBound indicates the device is not currently bound to
	// usbip-host.
	ErrDeviceNotBound = domain.ErrDeviceNotBound

	// ErrPortInUse indicates a local vhci port is already attached.
	ErrPortInUse = domain.ErrPortInUse

	// ErrNoFreePort indicates no vhci port is available for attach.
	ErrNoFreePort = domain.ErrNoFreePort

	// ErrProtocolMismatch indicates the peer reported a different USBIP
	// protocol version.
	ErrProtocolMismatch = domain.ErrProtocolMismatch

	// ErrProtocolError indicates the peer replied with a protocol error
	// status code (OP_REP_*.status != 0 on a handshake frame).
	ErrProtocolError = domain.ErrProtocolError

	// ErrBusIDInvalid indicates a bus id failed validation.
	ErrBusIDInvalid = domain.ErrBusIDInvalid

	// ErrPermission indicates the caller lacks the privileges needed
	// (typically CAP_SYS_ADMIN or root).
	ErrPermission = domain.ErrPermission

	// ErrKernelModuleMissing indicates a required kernel module
	// (usbip-core/usbip-host/vhci-hcd) is not loaded.
	ErrKernelModuleMissing = domain.ErrKernelModuleMissing

	// ErrAlreadyRunning indicates another exporter instance is holding
	// the shared PID lock.
	ErrAlreadyRunning = domain.ErrAlreadyRunning

	// ErrAlreadyShutdown indicates the exporter has been shut down and
	// cannot accept further requests. Aliased to pkg/domain because the
	// domain package already publishes this lifecycle sentinel on the
	// public surface (public-library-api OpenSpec).
	ErrAlreadyShutdown = domain.ErrAlreadyShutdown

	// ErrAttachInProgress indicates Attach is already running for the
	// same (remote, busid) pair and the dedupe gate rejected a second
	// caller. Aliased to pkg/domain so errors.Is matches against
	// either form.
	ErrAttachInProgress = domain.ErrAttachInProgress

	// ErrUnsupportedDevice indicates the device cannot be exported
	// via usbip — typically a USB hub (bDeviceClass=0x09). Surfaced
	// before any destructive sysfs write so detaching the hub's
	// driver does not cascade-disconnect its downstream devices.
	ErrUnsupportedDevice = domain.ErrUnsupportedDevice

	// ErrDeviceUnavailable indicates the remote daemon reports the
	// device exists but is currently unusable for import (stub-side
	// internal error, ST_DEV_ERR=3 on the wire). Distinct from
	// ErrDeviceAlreadyBound (busy / already attached) and
	// ErrDeviceNotFound (no such device).
	ErrDeviceUnavailable = domain.ErrDeviceUnavailable
)

Sentinel errors re-exported from pkg/domain. Assignment — not wrapping — preserves identity so errors.Is(err, usbip.ErrX) and errors.Is(err, domain.ErrX) match the same underlying value. public-library-api OpenSpec.

View Source
var (
	// ErrImporterClosed indicates a method was called after Close.
	// Close itself is idempotent (returns nil); other operations on a
	// closed Importer surface this sentinel via errors.Is.
	ErrImporterClosed = errors.New("importer closed")

	// ErrEventStreamClosed indicates an established importer event source
	// ended unexpectedly while its caller and Importer remained live.
	ErrEventStreamClosed = errors.New("event stream closed unexpectedly")

	// ErrExporterShutdown indicates Serve (or a Serve-adjacent method)
	// was called after Shutdown completed. Shutdown is terminal: the
	// caller must construct a new Exporter to serve again. Aliased to
	// domain.ErrAlreadyShutdown so errors.Is against either form
	// succeeds.
	ErrExporterShutdown = domain.ErrAlreadyShutdown

	// ErrServeAlreadyRunning indicates Serve was called while another
	// Serve is still active on the same Exporter. Overlapping accept
	// loops would fight over the shared session bookkeeping, so the
	// second call is rejected.
	ErrServeAlreadyRunning = errors.New("exporter: Serve already running")

	// ErrAttachOptionsInvalid indicates Importer.Attach was called with
	// an AttachOptions field carrying a value the reconnect machinery
	// cannot interpret — most commonly a negative MaxAttempts. The
	// facade assigns a distinct identity (not aliased to internal/app)
	// so errors.Is classification is available through the public
	// surface without a cross-package import.
	ErrAttachOptionsInvalid = errors.New("attach options invalid")

	// ErrTransportOptionsInvalid indicates a negative TCP tuning value
	// was passed to NewImporter or NewExporter.
	ErrTransportOptionsInvalid = errors.New("transport options invalid")

	// ErrACLInvalid indicates an exporter allow-list entry is not a
	// valid CIDR prefix.
	ErrACLInvalid = errors.New("acl cidr invalid")

	// ErrExponentialBackoffConfigInvalid indicates an exponential
	// backoff configuration failed validation.
	ErrExponentialBackoffConfigInvalid = errors.New("exponential backoff config invalid")

	// ErrAcceptRateLimitInvalid indicates WithExporterAcceptRateLimit was
	// supplied a non-finite value. Finite zero and negative values disable the
	// limiter and are valid.
	ErrAcceptRateLimitInvalid = errors.New("accept rate limit invalid")
)

Public lifecycle sentinels. ErrImporterClosed and ErrServeAlreadyRunning carry identities distinct from the internal/app sentinels of the same name so downstream callers never need to import internal/app to classify an error; the forwarding methods in usbip.go translate the matching internal identity into these values. ErrExporterShutdown aliases the domain-level ErrAlreadyShutdown so the spec-listed public name stays matchable via errors.Is on either alias.

Functions

func ProbeKernelModules

func ProbeKernelModules(ctx context.Context) (map[string]ModuleState, error)

ProbeKernelModules reports the canonical USB/IP module triple on every platform. The returned map always contains all three keys, including when ctx is cancelled; platform code may replace Unknown values as observations complete.

Types

type AttachOptions

type AttachOptions struct {
	// AutoReconnect enables the reconnect watcher. When true, Attach
	// spawns a watcher goroutine that re-establishes the attach after
	// uevent- or poll-detected detach.
	AutoReconnect bool

	// Backoff computes delays between reconnect attempts. nil selects
	// the library default of ExponentialBackoff{Min:1s, Max:60s, Jitter:0.2}.
	Backoff BackoffStrategy

	// MaxAttempts caps the number of reconnect retries. Zero means
	// infinite.
	MaxAttempts int

	// OnReconnect receives retry notifications with the 1-indexed attempt
	// number and the error that triggered the retry. nil disables the
	// callback. Notifications run serially outside the retry goroutine; when
	// attempts outpace a slow callback, pending notifications are coalesced
	// to the latest attempt. Panics are recovered and logged via the
	// Importer's logger.
	OnReconnect func(attempt int, err error)

	// StatusPollInterval controls the backstop poll period. Zero picks
	// up the library default (5 seconds); a negative value disables
	// polling entirely.
	StatusPollInterval time.Duration

	// ShutdownTimeout bounds how long Detach and Close block on a
	// reconnect watcher's wind-down before proceeding with the
	// kernel-side detach. Zero picks up the library default (5
	// seconds); a negative value disables the bound and waits
	// indefinitely for the watcher to exit.
	ShutdownTimeout time.Duration
}

AttachOptions configures a single Importer.Attach call. All fields are optional; zero values produce the documented defaults.

type BackoffFactory

type BackoffFactory func() BackoffStrategy

BackoffFactory constructs one independent strategy for each top-level auto-reconnecting Attach. The created strategy remains owned by that logical attachment across all of its reconnect generations.

type BackoffStrategy

type BackoffStrategy interface {
	// Next returns the delay to sleep before attempt number `attempt`
	// (0-indexed — attempt 0 is the first retry after the initial
	// failure).
	Next(attempt int) time.Duration

	// Reset returns the strategy to its initial state. Called after a
	// successful reconnect so the next failure starts from the smallest
	// delay again.
	Reset()
}

BackoffStrategy computes delays between reconnect attempts. Concrete types shipped with this package are FixedBackoff and ExponentialBackoff. Consumers can implement their own strategy as long as it satisfies both methods; AttachOptions.Backoff accepts any implementation.

type BusID

type BusID = domain.BusID

BusID is the stable USB topology identifier (e.g. "1-1.2").

type Device

type Device = domain.Device

Device describes a USB device enumerated over USB/IP.

type DeviceBoundEvent

type DeviceBoundEvent = domain.DeviceBoundEvent

DeviceBoundEvent is emitted when a local device becomes exportable.

type DeviceUnboundEvent

type DeviceUnboundEvent = domain.DeviceUnboundEvent

DeviceUnboundEvent is emitted when a local device is unbound.

type Event

type Event = domain.Event

Event is the closed polymorphic union of domain events emitted on Watch / WatchSessions iterators.

type EventKind

type EventKind = domain.EventKind

EventKind is the discriminator of the closed Event union.

type ExponentialBackoff

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

ExponentialBackoff doubles the base delay every attempt, clamps at Max, and optionally jitters by ±Jitter. The zero-value is NOT usable — construct via NewExponentialBackoff which validates the config and seeds a PRNG for jitter.

func MustNewExponentialBackoff

func MustNewExponentialBackoff(cfg ExponentialBackoffConfig) *ExponentialBackoff

MustNewExponentialBackoff constructs a concurrency-safe backoff and panics when cfg is invalid. Call cfg.Validate first for a fallible configuration path.

func NewExponentialBackoff deprecated

func NewExponentialBackoff(cfg ExponentialBackoffConfig) *ExponentialBackoff

NewExponentialBackoff constructs an ExponentialBackoff from cfg.

Deprecated: use MustNewExponentialBackoff, whose name makes the panic contract explicit. Call cfg.Validate first when invalid configuration is a runtime condition.

func (*ExponentialBackoff) Next

func (b *ExponentialBackoff) Next(attempt int) time.Duration

Next returns the delay for the given attempt.

func (*ExponentialBackoff) Reset

func (b *ExponentialBackoff) Reset()

Reset clears attempt-dependent state; a no-op for ExponentialBackoff since its Next is a pure function of attempt.

type ExponentialBackoffConfig

type ExponentialBackoffConfig struct {
	// Min is the non-negative delay for the first attempt (attempt 0). A zero
	// Min keeps every exponential delay at zero for v1 compatibility.
	Min time.Duration

	// Max is the non-negative cap for every returned delay.
	Max time.Duration

	// Jitter is the fractional range applied multiplicatively to the
	// base delay. Must be in [0, 1). A zero Jitter disables jitter
	// entirely and Next returns the deterministic geometric value.
	Jitter float64
}

ExponentialBackoffConfig mirrors the internal config. Zero Min retains the v1 immediate-retry schedule; zero Max is valid when Min is also zero.

func (ExponentialBackoffConfig) Validate

func (cfg ExponentialBackoffConfig) Validate() error

Validate reports whether cfg falls inside the documented acceptance ranges: Min and Max are non-negative, Max is not below Min, and Jitter sits in [0, 1). Construction via NewExponentialBackoff panics when Validate returns a non-nil error — an invalid backoff config is a programmer error comparable to a nil dependency, not a runtime condition to propagate.

type Exporter

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

Exporter is the public wrapper around internalapp.Exporter. Method bodies forward after argument translation. Construct via NewExporter; the zero value is not usable.

transport is the same TCP adapter the inner Exporter was built with. Storing it on the public wrapper lets ListenAndServe call Transport.Listen with the stored TransportOptions so accepted connections inherit the requested tuning. Serve(ctx, listener) retains its caller-supplied-listener semantics; ListenAndServe is the option-honoring counterpart for callers that do not need systemd-activation or other foreign listener wiring.

func NewExporter

func NewExporter(opts ...ExporterOption) (*Exporter, error)

NewExporter constructs an Exporter backed by the default Linux kernel, uevent, transport, and codec adapters. Options apply in declaration order. Non-Linux callers receive ErrKernelModuleMissing.

func (*Exporter) Bind

func (e *Exporter) Bind(ctx context.Context, busID BusID) error

Bind makes a local device exportable (binds usbip-host).

func (*Exporter) ListAvailable

func (e *Exporter) ListAvailable(ctx context.Context) ([]Device, error)

ListAvailable enumerates every USB device on the host regardless of bind state — the CLI's `usbip-go list` view.

func (*Exporter) ListExported

func (e *Exporter) ListExported(ctx context.Context) ([]Device, error)

ListExported returns the currently-bound subset: devices whose driver is usbip-host AND that are not actively claimed by an importer (SDEV_ST_USED excluded). This is what peers see via the OP_REP_DEVLIST wire reply and what the status socket reports as "bound_devices". Distinct from ListAvailable which dumps the full local USB bus.

func (*Exporter) ListenAndServe

func (e *Exporter) ListenAndServe(ctx context.Context, addr string) error

ListenAndServe reserves the Exporter's lifecycle, then binds addr through the transport adapter (so accepted connections inherit the WithExporterTransportOptions tuning) and runs the accept loop. It is the option-honoring counterpart to Serve(ctx, listener) for callers that do not need systemd activation or other foreign listener wiring.

Lifecycle rejection precedes Listen. A Listen failure short-circuits the reserved call and is surfaced wrapped. Any bound listener is closed deterministically before ListenAndServe returns.

func (*Exporter) Serve

func (e *Exporter) Serve(ctx context.Context, listener net.Listener) error

Serve runs the accept loop until ctx is cancelled or the listener returns a permanent error.

func (*Exporter) Sessions

func (e *Exporter) Sessions(ctx context.Context) []Session

Sessions returns a snapshot of currently-accepted sessions, sorted by start time.

func (*Exporter) Shutdown

func (e *Exporter) Shutdown(ctx context.Context) error

Shutdown stops accepting new connections and drains in-flight sessions bounded by the provided ctx deadline.

func (*Exporter) Unbind

func (e *Exporter) Unbind(ctx context.Context, busID BusID) error

Unbind returns a previously-bound device to its original driver.

func (*Exporter) WatchSessions

func (e *Exporter) WatchSessions(ctx context.Context) iter.Seq[Event]

WatchSessions returns an iter.Seq yielding SessionStartedEvent and SessionEndedEvent values while ctx is live.

type ExporterOption

type ExporterOption func(*exporterConfig)

ExporterOption configures an Exporter at construction time. Apply options by passing them to NewExporter; options mutate an internal config struct in declaration order so the last option wins for any field.

func WithExporterAcceptRateLimit

func WithExporterAcceptRateLimit(rps float64) ExporterOption

WithExporterAcceptRateLimit caps new accepts at rps tokens per second via an internal token bucket with a library-default burst size (security-release-quality OpenSpec). Finite rps <= 0 disables rate limiting entirely; NaN or infinity makes NewExporter return ErrAcceptRateLimitInvalid.

func WithExporterAllowCIDR

func WithExporterAllowCIDR(cidrs ...string) ExporterOption

WithExporterAllowCIDR appends CIDR strings to the accept-path allow- list (security-release-quality OpenSpec). Multiple calls accumulate. An empty list means "allow every peer" to match upstream usbip-utils behaviour; at least one CIDR opts the exporter into fail-closed ACL enforcement. Invalid CIDR strings surface as NewExporter construction errors.

func WithExporterHandshakeTimeout

func WithExporterHandshakeTimeout(d time.Duration) ExporterOption

WithExporterHandshakeTimeout bounds how long the exporter waits for a client to complete its OP request (security-release-quality OpenSpec). Zero picks up the library default; a negative value disables the timeout.

func WithExporterLogger

func WithExporterLogger(l *slog.Logger) ExporterOption

WithExporterLogger installs l as the Exporter's structured logger. A nil logger is accepted and selects slog.Default() at construction time.

func WithExporterMaxHandshakeBytes

func WithExporterMaxHandshakeBytes(n int) ExporterOption

WithExporterMaxHandshakeBytes caps bytes read during the handshake phase (security-release-quality OpenSpec). Zero picks up the library default.

func WithExporterMaxSessions

func WithExporterMaxSessions(n int) ExporterOption

WithExporterMaxSessions caps the total concurrent accepted sessions (security-release-quality OpenSpec). Zero picks up the library default; a negative value disables the cap entirely.

func WithExporterMaxSessionsPerPeer

func WithExporterMaxSessionsPerPeer(n int) ExporterOption

WithExporterMaxSessionsPerPeer caps the concurrent sessions per source IP (security-release-quality OpenSpec). Zero picks up the library default; a negative value disables the per-peer cap entirely.

func WithExporterShutdownTimeout

func WithExporterShutdownTimeout(d time.Duration) ExporterOption

WithExporterShutdownTimeout applies a backstop deadline to Exporter.Shutdown(ctx) when the caller passes a ctx without its own deadline. A positive value caps the drain; zero disables the backstop; a caller-supplied ctx deadline always wins when tighter. public-library-api OpenSpec.

func WithExporterTransportOptions

func WithExporterTransportOptions(opts TransportOptions) ExporterOption

WithExporterTransportOptions stores TCP-level tuning that the Exporter hands to the transport adapter on accepted listener connections. Zero-valued fields preserve v1.0.0 behavior. Negative values cause NewExporter to return ErrTransportOptionsInvalid.

IMPORTANT: tuning reaches accepted connections only when the listener was produced by the transport adapter's Listen wrapper. Daemons that pass a pre-built net.Listener (e.g. systemd activation) into Serve must apply socket options to that listener themselves; the option is silently inert in that path.

type FixedBackoff

type FixedBackoff struct {
	Delay time.Duration
}

FixedBackoff returns the same Delay for every attempt. A zero Delay makes every retry fire immediately — correct for deterministic tests but never appropriate for production.

func (FixedBackoff) Next

func (b FixedBackoff) Next(_ int) time.Duration

Next returns b.Delay unchanged.

func (FixedBackoff) Reset

func (FixedBackoff) Reset()

Reset is a no-op for FixedBackoff.

type Importer

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

Importer is the public wrapper around internalapp.Importer. Method bodies forward after argument translation so the internal shape can evolve without breaking consumers. Construct via NewImporter; the zero value is not usable.

func NewImporter

func NewImporter(opts ...ImporterOption) (*Importer, error)

NewImporter constructs an Importer backed by the default Linux kernel, uevent, transport, and codec adapters. Options apply in declaration order; the last option wins for any field. Non-Linux callers receive ErrKernelModuleMissing — adapter injection is deliberately hidden from the public surface (public-library-api OpenSpec).

func (*Importer) Attach

func (i *Importer) Attach(ctx context.Context, r RemoteEndpoint, busID BusID, opts AttachOptions) (Port, error)

Attach runs the USB/IP import handshake for busID at r and returns the attached Port. AttachOptions is merged with the Importer-level defaults (WithImporterBackoff, WithImporterBackoffFactory, and WithImporterStatusPollInterval) then translated to the internal form before forwarding.

func (*Importer) Close

func (i *Importer) Close() error

Close cancels every active port handle, drains background goroutines, and marks the Importer closed. Idempotent via the internal sync.Once.

func (*Importer) Detach

func (i *Importer) Detach(ctx context.Context, id PortID) error

Detach tears down a kernel-owned vhci port. The Port may have been attached by this Importer or inherited from an earlier Importer or process.

func (*Importer) ListPorts

func (i *Importer) ListPorts(ctx context.Context) ([]Port, error)

ListPorts returns the kernel's vhci status rows, including free-capacity rows whose Status is Null or Available and claimed NotAssigned rows that are still waiting for their local USB address.

func (*Importer) ListRemote

func (i *Importer) ListRemote(ctx context.Context, r RemoteEndpoint) ([]Device, error)

ListRemote dials endpoint and returns its device list.

func (*Importer) Watch

func (i *Importer) Watch(ctx context.Context) iter.Seq[Event]

Watch returns an iter.Seq yielding domain events while ctx is live. Iteration terminates when the upstream source closes, ctx is cancelled, or yield returns false.

func (*Importer) WatchWithErrors

func (i *Importer) WatchWithErrors(ctx context.Context) iter.Seq2[Event, error]

WatchWithErrors returns an error-aware event iterator. Ordinary events are paired with nil; subscription failures preserve their wrapped cause; and an unexpectedly closed established source yields ErrEventStreamClosed. Caller cancellation and Importer.Close end the iterator without an error.

type ImporterOption

type ImporterOption func(*importerConfig)

ImporterOption configures an Importer at construction time. Apply options by passing them to NewImporter; options mutate an internal config struct in declaration order so the last option wins for any field.

func WithImporterBackoff

func WithImporterBackoff(b BackoffStrategy) ImporterOption

WithImporterBackoff sets the BackoffStrategy handed to AttachOptions when the caller leaves the per-Attach Backoff field nil. A nil strategy falls back to the library default (exponential, min 1s, max 60s, 20% jitter).

func WithImporterBackoffFactory

func WithImporterBackoffFactory(factory BackoffFactory) ImporterOption

WithImporterBackoffFactory installs a constructor for importer-level reconnect defaults. The factory is invoked once for each top-level auto-reconnecting Attach, and MUST return an independently owned strategy. A nil factory restores the library default exponential strategy.

Prefer this option over WithImporterBackoff for stateful custom strategies. The legacy option remains supported and mutex-safe, but necessarily shares one strategy instance because the v1 BackoffStrategy contract has no Clone method.

func WithImporterLogger

func WithImporterLogger(l *slog.Logger) ImporterOption

WithImporterLogger installs l as the Importer's structured logger. A nil logger is accepted and selects slog.Default() at construction time, matching the internal convention.

func WithImporterStatusPollInterval

func WithImporterStatusPollInterval(d time.Duration) ImporterOption

WithImporterStatusPollInterval sets the reconnect watcher's backstop poll period. Zero picks up the library default (5 seconds); a negative value disables polling entirely. importer-lifecycle OpenSpec.

func WithImporterTransportOptions

func WithImporterTransportOptions(opts TransportOptions) ImporterOption

WithImporterTransportOptions stores TCP-level tuning that the Importer hands to the transport adapter on every outbound Dial. Zero-valued fields preserve v1.0.0 behavior. Negative values cause NewImporter to return ErrTransportOptionsInvalid.

Recommended WAN starting point:

usbip.WithImporterTransportOptions(usbip.TransportOptions{
    DialConnectTimeout:   10 * time.Second,
    TCPKeepAliveIdle:     30 * time.Second,
    TCPKeepAliveInterval: 10 * time.Second,
    TCPKeepAliveProbes:   6,
})

type ModuleState

type ModuleState int

ModuleState is the tri-state classification of a USB/IP kernel module probe result. A two-state "loaded" / "missing" design silently collapses EACCES / EIO / any-other-error into "missing", masking the difference between "probe was blocked" and "probe proved the module is absent"; this tri-state preserves that distinction.

JSON marshaling emits the lowercase string form so the operations-observability and json-contracts OpenSpec status schema retains its stable `{"usbip_core": "loaded"}` shape.

const (
	ModuleStateUnknown ModuleState = iota
	ModuleStateLoaded
	ModuleStateMissing
)

ModuleState constants. Order is public API: the iota placement determines what the zero value means. ModuleStateUnknown is 0 so a forgotten-to-populate map entry flags as Unknown rather than the potentially misleading Loaded or Missing.

func (ModuleState) MarshalJSON

func (s ModuleState) MarshalJSON() ([]byte, error)

MarshalJSON renders the lowercase string form so the status JSON schema stays a stable string mapping. json.Marshaler is the right seam here because the caller's map[string]ModuleState should otherwise marshal as an integer.

func (ModuleState) String

func (s ModuleState) String() string

String returns the lowercase wire form of the state. Invalid (out-of-range) values render as "unknown" for a safe fallback.

type Port

type Port = domain.Port

Port describes one vhci kernel status row on the importer side.

type PortAttachedEvent

type PortAttachedEvent = domain.PortAttachedEvent

PortAttachedEvent is emitted when a remote device attaches.

type PortDetachedEvent

type PortDetachedEvent = domain.PortDetachedEvent

PortDetachedEvent is emitted when a previously-attached port is released.

type PortErroredEvent

type PortErroredEvent = domain.PortErroredEvent

PortErroredEvent is emitted when the vhci port transitions to error.

type PortID

type PortID = domain.PortID

PortID identifies a vhci port numerically.

type PortReconnectExhaustedEvent

type PortReconnectExhaustedEvent = domain.PortReconnectExhaustedEvent

PortReconnectExhaustedEvent is emitted by the importer's reconnect watcher when MaxAttempts is reached without a successful reattach. Carries a snapshot of the last successful Port plus attempt count and stringified last error. See openspec/specs/domain-model/spec.md.

type RemoteEndpoint

type RemoteEndpoint = domain.RemoteEndpoint

RemoteEndpoint identifies a USB/IP peer by host and port.

type Session

type Session = domain.Session

Session describes a single client connection from the daemon's view.

type SessionEndedEvent

type SessionEndedEvent = domain.SessionEndedEvent

SessionEndedEvent is emitted when a Session closes for any reason.

type SessionStartedEvent

type SessionStartedEvent = domain.SessionStartedEvent

SessionStartedEvent is emitted when a client completes the handshake.

type Speed

type Speed = domain.Speed

Speed is the negotiated USB speed.

type Status

type Status = domain.Status

Status is a vhci port state (available/used/error/...).

type TransportOptions

type TransportOptions = netopts.TransportOptions

TransportOptions carries TCP tuning for importer dials and exporter-owned listeners. It remains an alias for compatibility with the v1 API, whose exported type identity is recorded by the API baseline.

Every zero value inherits the Go/kernel default. Negative values are rejected by NewImporter and NewExporter with ErrTransportOptionsInvalid.

Jump to

Keyboard shortcuts

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