Documentation
¶
Overview ¶
Package networker manages resource and static port-forward sessions. Resource forwards preserve caller cancellation through readiness and retain their admitted connection-generation lease for the accepted session lifetime.
Index ¶
- Constants
- Variables
- func CanTransition(from, to SessionState) bool
- func FindFreeTCPPort() (int32, error)
- func IsPortUnavailable(port int32) bool
- func LocalHostOf(addrs ...net.Addr) string
- func RegisterNetworkerPluginServer(registrar grpc.ServiceRegistrar, server networkerpb.NetworkerPluginServer)
- func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error
- type Connection
- type FindPortForwardSessionRequest
- type ForwarderResult
- type Manager
- func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
- func (m *Manager) ClosePortForwardSession(_ *types.PluginContext, sessionID string) (*PortForwardSession, error)
- func (m *Manager) FindPortForwardSessions(_ *types.PluginContext, req FindPortForwardSessionRequest) ([]*PortForwardSession, error)
- func (m *Manager) GetPortForwardSession(_ *types.PluginContext, sessionID string) (*PortForwardSession, error)
- func (m *Manager) GetSupportedPortForwardTargets(_ *types.PluginContext) ([]string, error)
- func (m *Manager) ListPortForwardSessions(_ *types.PluginContext) ([]*PortForwardSession, error)
- func (m *Manager) StartPortForwardSession(pluginctx *types.PluginContext, opts PortForwardSessionOptions) (*PortForwardSession, error)
- func (m *Manager) StartResourcePortForwardSession(pluginctx *types.PluginContext, opts PortForwardSessionOptions) (*PortForwardSession, error)
- func (m *Manager) StopAll()
- type ManagerConfig
- type NetworkerError
- func NewForwarderFailedError(sessionID string, err error) *NetworkerError
- func NewInvalidConnectionTypeError(connectionType string) *NetworkerError
- func NewInvalidStateTransitionError(sessionID string, from, to SessionState) *NetworkerError
- func NewManagerShuttingDownError(sessionID string) *NetworkerError
- func NewNoHandlerFoundError(resourceKey string) *NetworkerError
- func NewPortUnavailableError(port int32) *NetworkerError
- func NewSessionNotFoundError(sessionID string) *NetworkerError
- type NetworkerErrorCode
- type Plugin
- type PluginClient
- func (p *PluginClient) ClosePortForwardSession(ctx *types.PluginContext, sessionID string) (*PortForwardSession, error)
- func (p *PluginClient) FindPortForwardSessions(ctx *types.PluginContext, req FindPortForwardSessionRequest) ([]*PortForwardSession, error)
- func (p *PluginClient) GetPortForwardSession(ctx *types.PluginContext, sessionID string) (*PortForwardSession, error)
- func (p *PluginClient) GetSupportedPortForwardTargets(ctx *types.PluginContext) ([]string, error)
- func (p *PluginClient) ListPortForwardSessions(ctx *types.PluginContext) ([]*PortForwardSession, error)
- func (p *PluginClient) StartPortForwardSession(ctx *types.PluginContext, opts PortForwardSessionOptions) (*PortForwardSession, error)
- func (p *PluginClient) StartResourcePortForwardSession(ctx *types.PluginContext, opts PortForwardSessionOptions) (*PortForwardSession, error)
- func (p *PluginClient) StopAll()
- type PluginOpts
- type PluginServer
- func (s *PluginServer) ClosePortForwardSession(ctx context.Context, in *networkerpb.PortForwardSessionByIdRequest) (*networkerpb.PortForwardSessionByIdResponse, error)
- func (s *PluginServer) FindPortForwardSessions(ctx context.Context, in *networkerpb.FindPortForwardSessionRequest) (*networkerpb.PortForwardSessionListResponse, error)
- func (s *PluginServer) GetPortForwardSession(ctx context.Context, in *networkerpb.PortForwardSessionByIdRequest) (*networkerpb.PortForwardSessionByIdResponse, error)
- func (s *PluginServer) GetSupportedPortForwardTargets(ctx context.Context, _ *emptypb.Empty) (*networkerpb.GetSupportedPortForwardTargetsResponse, error)
- func (s *PluginServer) ListPortForwardSessions(ctx context.Context, _ *emptypb.Empty) (*networkerpb.PortForwardSessionListResponse, error)
- func (s *PluginServer) StartPortForwardSession(ctx context.Context, in *networkerpb.PortForwardSessionOptions) (*networkerpb.PortForwardSessionByIdResponse, error)
- func (s *PluginServer) StartResourcePortForwardSession(ctx context.Context, in *networkerpb.PortForwardSessionOptions) (*networkerpb.ResourcePortForwardSessionResponse, error)
- type PortChecker
- type PortForwardConnectionType
- type PortForwardProtocol
- type PortForwardProvider
- type PortForwardResourceConnection
- type PortForwardSession
- type PortForwardSessionEncryption
- type PortForwardSessionOptions
- type PortForwardStaticConnection
- func (c *PortForwardStaticConnection) ToProto() *networkerpb.PortForwardStaticConnection
- func (c *PortForwardStaticConnection) ToSessionOptionsProto() *networkerpb.PortForwardSessionOptions_StaticConnection
- func (c *PortForwardStaticConnection) ToSessionProto() *networkerpb.PortForwardSession_StaticConnection
- type Provider
- type RealPortChecker
- type ResourceForwarder
- type ResourceForwarderFunc
- type ResourcePortForwardHandlerOpts
- type ResourcePortForwardProvider
- type SessionState
- type StaticForwarder
- type StaticForwarderFunc
- type StaticPortForwardHandlerOpts
Constants ¶
const (
// PluginID is the capability name used to register and discover networker plugins.
PluginID = "networker"
)
Variables ¶
var ( ErrNetSessionNotFound = &NetworkerError{Code: ErrCodeSessionNotFound} ErrNetNoHandlerFound = &NetworkerError{Code: ErrCodeNoHandlerFound} ErrNetForwarderFailed = &NetworkerError{Code: ErrCodeForwarderFailed} ErrNetManagerShuttingDown = &NetworkerError{Code: ErrCodeManagerShuttingDown} ErrNetInvalidStateTransition = &NetworkerError{Code: ErrCodeInvalidStateTransition} ErrNetInvalidConnectionType = &NetworkerError{Code: ErrCodeInvalidConnectionType} )
Sentinel errors support code-based matching with errors.Is.
var ( ErrSessionClosed = errors.New("session closed") ErrManagerStopped = errors.New("manager stopped") )
Sentinel causes for context cancellation — forwarders can inspect these via context.Cause to distinguish intentional stops from failures.
Functions ¶
func CanTransition ¶
func CanTransition(from, to SessionState) bool
CanTransition reports whether a nonterminal state permits the requested change.
func FindFreeTCPPort ¶
FindFreeTCPPort finds an available port by letting the OS pick a free port. The port is not reserved after this function returns.
func IsPortUnavailable ¶
IsPortUnavailable reports whether a TCP connection to the local port succeeds. A failed probe returns false but does not guarantee that a listener can bind.
func LocalHostOf ¶ added in v0.23.0
LocalHostOf names the host a forwarder's listeners are bound to, from the addresses they really bound (net.Listener.Addr), for ForwarderResult.LocalHost.
It states what the addresses say and nothing else: one address gives its host ("127.0.0.1", "::1", "0.0.0.0", "::", or an address with a zone); addresses that share a host give that host; loopback addresses of different hosts, as 127.0.0.1 and ::1 (which is what a listener on "localhost" binds), give "localhost". It returns "" (the forwarder does not say) for no address, for an address that is not a TCP or UDP address or has no IP, for an address whose zone is not an interface name of the kinds a session states (letters, digits, '.', '_' and '-', at most 64 bytes), and for addresses on different hosts that are not all loopback: a forward that listens on a loopback address and on a wildcard one is reachable beyond this computer, which no single host states.
func RegisterNetworkerPluginServer ¶ added in v0.9.0
func RegisterNetworkerPluginServer(registrar grpc.ServiceRegistrar, server networkerpb.NetworkerPluginServer)
RegisterNetworkerPluginServer admits resource requests before generated decoding.
func RegisterPlugin ¶
func RegisterPlugin( p *sdk.Plugin, opts PluginOpts, ) error
RegisterPlugin constructs a manager and registers the networker capability.
Types ¶
type Connection ¶
type Connection interface {
// contains filtered or unexported methods
}
Connection is implemented by PortForwardResourceConnection and PortForwardStaticConnection. The unexported method seals the interface.
type FindPortForwardSessionRequest ¶
type FindPortForwardSessionRequest struct {
ResourceID string `json:"resource_id"`
ConnectionID string `json:"connection_id"`
}
FindPortForwardSessionRequest filters sessions by opaque resource and connection selectors. Empty selectors do not restrict that dimension.
func NewFindPortForwardSessionRequestFromProto ¶
func NewFindPortForwardSessionRequestFromProto( p *networkerpb.FindPortForwardSessionRequest, ) FindPortForwardSessionRequest
NewFindPortForwardSessionRequestFromProto copies selectors; nil matches all sessions.
func (FindPortForwardSessionRequest) ToProto ¶
func (p FindPortForwardSessionRequest) ToProto() *networkerpb.FindPortForwardSessionRequest
ToProto copies the filter selectors into a wire request.
type ForwarderResult ¶
type ForwarderResult struct {
SessionID string
LocalHost string
Ready <-chan struct{} // closed when tunnel established
ErrCh <-chan error // receives fatal error; closed on clean exit
}
ForwarderResult carries the outcome of starting a port forward. The Ready channel is closed once the tunnel is established. The ErrCh channel receives a fatal error or is closed on clean exit. The manager monitors ErrCh to detect post-start failures.
LocalHost is the host the forwarder's listener is bound to, as the forwarder states it: an IP address ("127.0.0.1", "::1", "0.0.0.0", "::"; an IPv6 address may carry a zone of letters, digits, '.', '_' and '-') or "localhost" in any case. A forwarder that opens its own listeners reads it from their addresses with LocalHostOf; one that hands listening to a library states the address it asked the library to bind. Empty means the forwarder does not say. The manager copies it into the session's local_host and never fills it in itself: the port it chose before starting the forwarder says nothing about where the forwarder listens. A value that cannot be stated (not UTF-8, longer than 255 bytes, a zone of other bytes, anything that is not an IP address or "localhost") is dropped, the session states none, and the log says how long the value was and which of these it was, never the value.
A consumer takes the forward as reachable only from this computer if and only if the host is not empty and is "localhost" (ASCII, any case) or an IP address that is loopback once an IPv4-mapped IPv6 address is unmapped: 127.0.0.0/8, ::1 or ::ffff:127.x.y.z. Any other host (0.0.0.0 and :: for every interface, a LAN or a link-local address) is reachable from other computers, and empty is unknown and never loopback.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the lifecycle of networker actions, such as port forwarding sessions.
func NewManager ¶
func NewManager(cfg ManagerConfig, opts PluginOpts) *Manager
NewManager creates a new Manager with the given config and plugin opts.
func (*Manager) BindConnectionContextProvider ¶ added in v0.9.0
func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
BindConnectionContextProvider binds resource forwarding to the active registry.
func (*Manager) ClosePortForwardSession ¶
func (m *Manager) ClosePortForwardSession( _ *types.PluginContext, sessionID string, ) (*PortForwardSession, error)
ClosePortForwardSession cancels a tunnel and waits for its monitor up to the configured close timeout. Unknown IDs return a session-not-found error.
func (*Manager) FindPortForwardSessions ¶
func (m *Manager) FindPortForwardSessions( _ *types.PluginContext, req FindPortForwardSessionRequest, ) ([]*PortForwardSession, error)
FindPortForwardSessions returns owned snapshots matching both nonempty selectors.
func (*Manager) GetPortForwardSession ¶
func (m *Manager) GetPortForwardSession( _ *types.PluginContext, sessionID string, ) (*PortForwardSession, error)
GetPortForwardSession returns an owned snapshot or a session-not-found error.
func (*Manager) GetSupportedPortForwardTargets ¶
func (m *Manager) GetSupportedPortForwardTargets(_ *types.PluginContext) ([]string, error)
GetSupportedPortForwardTargets returns registered opaque resource keys.
func (*Manager) ListPortForwardSessions ¶
func (m *Manager) ListPortForwardSessions(_ *types.PluginContext) ([]*PortForwardSession, error)
ListPortForwardSessions returns owned snapshots, including terminal sessions.
func (*Manager) StartPortForwardSession ¶
func (m *Manager) StartPortForwardSession( pluginctx *types.PluginContext, opts PortForwardSessionOptions, ) (*PortForwardSession, error)
StartPortForwardSession creates a static tunnel. Creation observes request cancellation; accepted tunnels survive the initiating request's completion. Resource targets require StartResourcePortForwardSession.
func (*Manager) StartResourcePortForwardSession ¶ added in v0.9.0
func (m *Manager) StartResourcePortForwardSession( pluginctx *types.PluginContext, opts PortForwardSessionOptions, ) (*PortForwardSession, error)
StartResourcePortForwardSession admits a resource target against the configured registry and retains its generation lease until tunnel closure or retirement. Cancellation remains attached throughout creation, readiness, and admission.
type ManagerConfig ¶
type ManagerConfig struct {
Logger logging.Logger
Settings settings.Provider
PortChecker PortChecker // nil → RealPortChecker
Clock timeutil.Clock // nil → timeutil.RealClock
CloseTimeout time.Duration // default 10s
}
ManagerConfig configures the Manager.
type NetworkerError ¶
type NetworkerError struct {
Code NetworkerErrorCode
SessionID string
Message string
Err error // optional wrapped error
}
NetworkerError is a structured error for networker operations.
func NewForwarderFailedError ¶
func NewForwarderFailedError(sessionID string, err error) *NetworkerError
NewForwarderFailedError wraps a native failure and associates it with a session.
func NewInvalidConnectionTypeError ¶
func NewInvalidConnectionTypeError(connectionType string) *NetworkerError
NewInvalidConnectionTypeError identifies an unsupported connection kind.
func NewInvalidStateTransitionError ¶
func NewInvalidStateTransitionError(sessionID string, from, to SessionState) *NetworkerError
NewInvalidStateTransitionError describes the rejected session state change.
func NewManagerShuttingDownError ¶
func NewManagerShuttingDownError(sessionID string) *NetworkerError
NewManagerShuttingDownError reports that shutdown prevents work on the session.
func NewNoHandlerFoundError ¶
func NewNoHandlerFoundError(resourceKey string) *NetworkerError
NewNoHandlerFoundError identifies a resource key without a registered forwarder.
func NewPortUnavailableError ¶
func NewPortUnavailableError(port int32) *NetworkerError
NewPortUnavailableError identifies the local port that cannot be used.
func NewSessionNotFoundError ¶
func NewSessionNotFoundError(sessionID string) *NetworkerError
NewSessionNotFoundError identifies the session that could not be found.
func (*NetworkerError) Error ¶
func (e *NetworkerError) Error() string
Error formats the code, optional session ID, and diagnostic message.
func (*NetworkerError) Is ¶
func (e *NetworkerError) Is(target error) bool
Is reports whether target matches this error's code.
func (*NetworkerError) Unwrap ¶
func (e *NetworkerError) Unwrap() error
Unwrap returns the underlying forwarder error, if present.
type NetworkerErrorCode ¶
type NetworkerErrorCode int
NetworkerErrorCode classifies networker errors for programmatic handling.
const ( // ErrCodeSessionNotFound identifies an unknown session ID. ErrCodeSessionNotFound NetworkerErrorCode = iota + 1 // ErrCodeNoHandlerFound identifies a resource without a registered forwarder. ErrCodeNoHandlerFound ErrCodePortUnavailable // ErrCodeForwarderFailed identifies a native tunnel startup or runtime failure. ErrCodeForwarderFailed // ErrCodeManagerShuttingDown rejects work after manager shutdown begins. ErrCodeManagerShuttingDown // ErrCodeInvalidStateTransition identifies an unsupported session state change. ErrCodeInvalidStateTransition // ErrCodeInvalidConnectionType identifies an unsupported connection kind. ErrCodeInvalidConnectionType )
func (NetworkerErrorCode) String ¶
func (c NetworkerErrorCode) String() string
String returns the stable uppercase error code, or UNKNOWN for an unrecognized code.
type Plugin ¶
Plugin connects a forwarding provider to the HashiCorp gRPC plugin protocol.
func (*Plugin) BindConnectionContextProvider ¶ added in v0.9.0
func (p *Plugin) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
BindConnectionContextProvider delegates registry binding to capable providers.
func (*Plugin) GRPCClient ¶
func (p *Plugin) GRPCClient( _ context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn, ) (any, error)
GRPCClient creates a forwarding client for the supplied plugin connection.
func (*Plugin) GRPCServer ¶
GRPCServer registers the provider with resource-aware request admission.
type PluginClient ¶
type PluginClient struct {
// contains filtered or unexported fields
}
PluginClient manages remote forwarding sessions through resource-aware gRPC calls.
func (*PluginClient) ClosePortForwardSession ¶
func (p *PluginClient) ClosePortForwardSession( ctx *types.PluginContext, sessionID string, ) (*PortForwardSession, error)
ClosePortForwardSession closes the remote session and returns its final snapshot.
func (*PluginClient) FindPortForwardSessions ¶
func (p *PluginClient) FindPortForwardSessions( ctx *types.PluginContext, req FindPortForwardSessionRequest, ) ([]*PortForwardSession, error)
FindPortForwardSessions returns all of the port forward sessions that match the given request.
func (*PluginClient) GetPortForwardSession ¶
func (p *PluginClient) GetPortForwardSession( ctx *types.PluginContext, sessionID string, ) (*PortForwardSession, error)
GetPortForwardSession returns a port forward session by ID.
func (*PluginClient) GetSupportedPortForwardTargets ¶
func (p *PluginClient) GetSupportedPortForwardTargets(ctx *types.PluginContext) ([]string, error)
GetSupportedPortForwardTargets returns the list of targets that are supported by this plugin for port forwarding.
func (*PluginClient) ListPortForwardSessions ¶
func (p *PluginClient) ListPortForwardSessions( ctx *types.PluginContext, ) ([]*PortForwardSession, error)
ListPortForwardSessions returns all of the port forward sessions.
func (*PluginClient) StartPortForwardSession ¶
func (p *PluginClient) StartPortForwardSession( ctx *types.PluginContext, opts PortForwardSessionOptions, ) (*PortForwardSession, error)
StartPortForwardSession starts a static forward or dispatches resource options through the lossless resource RPC without falling back to the legacy RPC.
func (*PluginClient) StartResourcePortForwardSession ¶ added in v0.9.0
func (p *PluginClient) StartResourcePortForwardSession( ctx *types.PluginContext, opts PortForwardSessionOptions, ) (*PortForwardSession, error)
StartResourcePortForwardSession requires resource-v2 support and carries the caller's admission observations and cancellation through native readiness. An accepted session remains open after this RPC completes.
func (*PluginClient) StopAll ¶
func (p *PluginClient) StopAll()
StopAll performs a best-effort shutdown of all remote sessions by listing them and closing each individually. Per-session close errors are logged but do not stop the loop.
type PluginOpts ¶
type PluginOpts struct {
// ResourceForwarders maps resource key → ResourceForwarder.
ResourceForwarders map[string]ResourceForwarder
// StaticForwarders maps key → StaticForwarder.
StaticForwarders map[string]StaticForwarder
}
PluginOpts contains the options for the networker plugin, passed to RegisterPlugin.
type PluginServer ¶
type PluginServer struct {
networkerpb.UnimplementedNetworkerPluginServer
Impl Provider
}
PluginServer exposes a forwarding provider over gRPC with resource wire admission.
func (*PluginServer) ClosePortForwardSession ¶
func (s *PluginServer) ClosePortForwardSession( ctx context.Context, in *networkerpb.PortForwardSessionByIdRequest, ) (*networkerpb.PortForwardSessionByIdResponse, error)
ClosePortForwardSession closes the requested forward and returns its final snapshot.
func (*PluginServer) FindPortForwardSessions ¶
func (s *PluginServer) FindPortForwardSessions( ctx context.Context, in *networkerpb.FindPortForwardSessionRequest, ) (*networkerpb.PortForwardSessionListResponse, error)
FindPortForwardSessions returns bounded snapshots matching the supplied filters.
func (*PluginServer) GetPortForwardSession ¶
func (s *PluginServer) GetPortForwardSession( ctx context.Context, in *networkerpb.PortForwardSessionByIdRequest, ) (*networkerpb.PortForwardSessionByIdResponse, error)
GetPortForwardSession returns a bounded wire snapshot for the requested session.
func (*PluginServer) GetSupportedPortForwardTargets ¶
func (s *PluginServer) GetSupportedPortForwardTargets( ctx context.Context, _ *emptypb.Empty, ) (*networkerpb.GetSupportedPortForwardTargetsResponse, error)
GetSupportedPortForwardTargets lists resource keys with registered forwarders.
func (*PluginServer) ListPortForwardSessions ¶
func (s *PluginServer) ListPortForwardSessions( ctx context.Context, _ *emptypb.Empty, ) (*networkerpb.PortForwardSessionListResponse, error)
ListPortForwardSessions returns session snapshots within the aggregate wire limit.
func (*PluginServer) StartPortForwardSession ¶
func (s *PluginServer) StartPortForwardSession( ctx context.Context, in *networkerpb.PortForwardSessionOptions, ) (*networkerpb.PortForwardSessionByIdResponse, error)
StartPortForwardSession starts a legacy static forward and rejects resource payloads.
func (*PluginServer) StartResourcePortForwardSession ¶ added in v0.9.0
func (s *PluginServer) StartResourcePortForwardSession( ctx context.Context, in *networkerpb.PortForwardSessionOptions, ) (*networkerpb.ResourcePortForwardSessionResponse, error)
StartResourcePortForwardSession admits resource-v2 context and starts a forward. Caller cancellation remains attached through readiness; accepted session lifetime and its retained connection-generation lease belong to the forwarding provider.
type PortChecker ¶
type PortChecker interface {
// FindFreePort returns a free TCP port.
FindFreePort() (int32, error)
IsPortUnavailable(port int32) bool
}
PortChecker abstracts port availability operations so tests can inject fakes.
type PortForwardConnectionType ¶
type PortForwardConnectionType string
PortForwardConnectionType distinguishes resource and static forwarding targets.
const ( // PortForwardConnectionTypeResource selects a registered resource forwarder. PortForwardConnectionTypeResource PortForwardConnectionType = "RESOURCE" // PortForwardConnectionTypeStatic selects a registered address forwarder. PortForwardConnectionTypeStatic PortForwardConnectionType = "STATIC" )
type PortForwardProtocol ¶
type PortForwardProtocol string
PortForwardProtocol selects the native transport protocol.
const ( // PortForwardProtocolTCP requests a TCP tunnel. PortForwardProtocolTCP PortForwardProtocol = "TCP" // PortForwardProtocolUDP requests a UDP tunnel. PortForwardProtocolUDP PortForwardProtocol = "UDP" )
func PortForwardProtocolFromProto ¶
func PortForwardProtocolFromProto( p networkerpb.PortForwardProtocol, ) PortForwardProtocol
PortForwardProtocolFromProto converts from the protobuf enum. Unknown proto values map to an invalid internal protocol (empty string), which callers can detect via Valid().
func (PortForwardProtocol) String ¶
func (p PortForwardProtocol) String() string
String returns the protocol label.
func (PortForwardProtocol) ToProto ¶
func (p PortForwardProtocol) ToProto() networkerpb.PortForwardProtocol
ToProto converts to the protobuf enum. Unknown values are encoded as an unknown enum value (-1), so callers should validate with Valid() upstream.
func (PortForwardProtocol) Valid ¶
func (p PortForwardProtocol) Valid() bool
Valid returns true if the protocol is a known value (TCP or UDP).
type PortForwardProvider ¶
type PortForwardProvider interface {
GetSupportedPortForwardTargets(*types.PluginContext) ([]string, error)
GetPortForwardSession(*types.PluginContext, string) (*PortForwardSession, error)
ListPortForwardSessions(*types.PluginContext) ([]*PortForwardSession, error)
FindPortForwardSessions(
*types.PluginContext,
FindPortForwardSessionRequest,
) ([]*PortForwardSession, error)
StartPortForwardSession(
*types.PluginContext,
PortForwardSessionOptions,
) (*PortForwardSession, error)
ClosePortForwardSession(*types.PluginContext, string) (*PortForwardSession, error)
StopAll()
}
PortForwardProvider manages forwarding sessions and reports supported resource targets.
type PortForwardResourceConnection ¶
type PortForwardResourceConnection struct {
ResourceData *resourcev2.Value `json:"resource_data,omitempty"`
Reference *resourcev2.ResourceReference `json:"reference,omitempty"`
Route *resourcev2.AccessRoute `json:"route,omitempty"`
ConnectionID string `json:"connection_id"`
PluginID string `json:"plugin_id"`
ResourceID string `json:"resource_id"`
ResourceKey string `json:"resource_key"`
}
PortForwardResourceConnection carries exact tagged resource data and only the reference and route supplied by the caller. Opaque legacy selectors retain their original spelling; no identity or resource acquisition is inferred.
func PortForwardResourceConnectionFromProto ¶
func PortForwardResourceConnectionFromProto( o *networkerpb.PortForwardResourceConnection, ) (PortForwardResourceConnection, error)
PortForwardResourceConnectionFromProto validates version, unknown fields, and tagged values before decoding. The result owns its decoded resource data.
func (*PortForwardResourceConnection) ToProto ¶
func (c *PortForwardResourceConnection) ToProto() (*networkerpb.PortForwardResourceConnection, error)
ToProto validates exact tagged data and returns an independently owned wire value. Nil receivers and oversized frames return classified resource errors.
func (*PortForwardResourceConnection) UnmarshalJSON ¶ added in v0.9.0
func (c *PortForwardResourceConnection) UnmarshalJSON(data []byte) error
UnmarshalJSON rejects unknown fields and invalid resource references, routes, or lossless values before replacing the receiver.
type PortForwardSession ¶
type PortForwardSession struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Connection Connection `json:"connection"`
Labels map[string]string `json:"labels"`
ID string `json:"id"`
Protocol PortForwardProtocol `json:"protocol"`
State SessionState `json:"state"`
ConnectionType PortForwardConnectionType `json:"connection_type"`
Encryption PortForwardSessionEncryption `json:"encryption"`
LocalHost string `json:"local_host,omitempty"`
LocalPort int32 `json:"local_port"`
RemotePort int32 `json:"remote_port"`
}
PortForwardSession represents a session between a forwarding target and the host.
LocalHost is the host the forwarder's listener is bound to, as the forwarder stated it (see ForwarderResult.LocalHost): an IP address or "localhost" in any case, and empty when the forwarder did not say. It is never defaulted, so LocalPort alone is not an address, and empty is unknown, never loopback. A reader takes the forward as reachable only from this computer if and only if the host is not empty and is "localhost" or an IP address that is loopback once an IPv4-mapped IPv6 address is unmapped (127.0.0.0/8, ::1, ::ffff:127.x.y.z); 0.0.0.0, ::, a LAN or a link-local address are reachable from other computers. A session from a plugin that predates the field decodes with it empty.
func NewPortForwardSessionFromProto ¶
func NewPortForwardSessionFromProto(s *networkerpb.PortForwardSession) (*PortForwardSession, error)
NewPortForwardSessionFromProto validates and decodes a bounded session frame. Nil input stays absent; invalid resource states, timestamps, and versions fail.
func (*PortForwardSession) ToProto ¶
func (s *PortForwardSession) ToProto() (*networkerpb.PortForwardSession, error)
ToProto validates and copies the session into a bounded wire frame. A nil receiver represents an absent session and returns nil without error.
type PortForwardSessionEncryption ¶
type PortForwardSessionEncryption struct {
Algorithm string `json:"algorithm"`
Key string `json:"key"`
Enabled bool `json:"enabled"`
}
PortForwardSessionEncryption carries forwarder-specific encryption settings. The manager transports these settings; the native forwarder enforces support.
func PortForwardSessionEncryptionFromProto ¶
func PortForwardSessionEncryptionFromProto( o *networkerpb.PortForwardSessionEncryption, ) PortForwardSessionEncryption
PortForwardSessionEncryptionFromProto copies settings; nil produces disabled encryption.
func (*PortForwardSessionEncryption) ToProto ¶
func (o *PortForwardSessionEncryption) ToProto() *networkerpb.PortForwardSessionEncryption
ToProto copies encryption settings; nil stays absent.
type PortForwardSessionOptions ¶
type PortForwardSessionOptions struct {
Connection Connection `json:"connection"`
Labels map[string]string `json:"labels"`
Params map[string]string `json:"params"`
Protocol PortForwardProtocol `json:"protocol"`
ConnectionType PortForwardConnectionType `json:"connection_type"`
Encryption PortForwardSessionEncryption `json:"encryption"`
LocalPort int32 `json:"local_port"`
RemotePort int32 `json:"remote_port"`
}
PortForwardSessionOptions configures a new tunnel. LocalPort zero requests an available port. The manager copies labels and connection data on acceptance.
func NewPortForwardSessionOptionsFromProto ¶
func NewPortForwardSessionOptionsFromProto( o *networkerpb.PortForwardSessionOptions, ) (*PortForwardSessionOptions, error)
NewPortForwardSessionOptionsFromProto validates the wire frame and resource version before decoding. Nil options return INVALID_REQUEST.
func (*PortForwardSessionOptions) ToProto ¶
func (o *PortForwardSessionOptions) ToProto() (*networkerpb.PortForwardSessionOptions, error)
ToProto validates metadata and resource payloads before allocating a bounded frame. Nil options return INVALID_REQUEST.
func (*PortForwardSessionOptions) UnmarshalJSON ¶ added in v0.2.1
func (o *PortForwardSessionOptions) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a strict options envelope and validates resource targets without inferring identity from legacy selectors.
type PortForwardStaticConnection ¶
type PortForwardStaticConnection struct {
Address string `json:"address"`
}
PortForwardStaticConnection identifies a native address without resource identity.
func PortForwardStaticConnectionFromJson ¶
func PortForwardStaticConnectionFromJson(o map[string]any) *PortForwardStaticConnection
PortForwardStaticConnectionFromJson reads a string address; absent or nonstring addresses remain empty, matching the static target's zero value.
func PortForwardStaticConnectionFromProto ¶
func PortForwardStaticConnectionFromProto( o *networkerpb.PortForwardStaticConnection, ) PortForwardStaticConnection
PortForwardStaticConnectionFromProto copies the address; nil produces the zero value.
func (*PortForwardStaticConnection) ToProto ¶
func (c *PortForwardStaticConnection) ToProto() *networkerpb.PortForwardStaticConnection
ToProto copies the address; a nil receiver stays absent.
func (*PortForwardStaticConnection) ToSessionOptionsProto ¶
func (c *PortForwardStaticConnection) ToSessionOptionsProto() *networkerpb.PortForwardSessionOptions_StaticConnection
ToSessionOptionsProto wraps the address in the options connection oneof.
func (*PortForwardStaticConnection) ToSessionProto ¶
func (c *PortForwardStaticConnection) ToSessionProto() *networkerpb.PortForwardSession_StaticConnection
ToSessionProto wraps the address in the session connection oneof.
type Provider ¶
type Provider interface {
PortForwardProvider
}
Provider embeds the session-management contract shared by local managers and remote clients. Resource forwarding is an optional ResourcePortForwardProvider.
type RealPortChecker ¶
type RealPortChecker struct{}
RealPortChecker performs actual network checks.
func (RealPortChecker) FindFreePort ¶
func (RealPortChecker) FindFreePort() (int32, error)
FindFreePort returns an available TCP port selected by the operating system.
func (RealPortChecker) IsPortUnavailable ¶
func (RealPortChecker) IsPortUnavailable(port int32) bool
IsPortUnavailable reports whether a TCP connection to the local port succeeds.
type ResourceForwarder ¶
type ResourceForwarder interface {
ForwardResource(
ctx context.Context,
pctx *types.PluginContext,
opts ResourcePortForwardHandlerOpts,
) (*ForwarderResult, error)
}
ResourceForwarder initiates a port forward for a resource.
type ResourceForwarderFunc ¶
type ResourceForwarderFunc func(ctx context.Context, pctx *types.PluginContext, opts ResourcePortForwardHandlerOpts) (*ForwarderResult, error)
ResourceForwarderFunc adapts a plain function to the ResourceForwarder interface.
func (ResourceForwarderFunc) ForwardResource ¶
func (f ResourceForwarderFunc) ForwardResource( ctx context.Context, pctx *types.PluginContext, opts ResourcePortForwardHandlerOpts, ) (*ForwarderResult, error)
ForwardResource calls f with the resource forwarding request.
type ResourcePortForwardHandlerOpts ¶
type ResourcePortForwardHandlerOpts struct {
Resource PortForwardResourceConnection `json:"resource"`
Options PortForwardSessionOptions `json:"options"`
}
ResourcePortForwardHandlerOpts pairs resource identity with forwarding options.
type ResourcePortForwardProvider ¶ added in v0.9.0
type ResourcePortForwardProvider interface {
StartResourcePortForwardSession(*types.PluginContext, PortForwardSessionOptions) (*PortForwardSession, error)
}
ResourcePortForwardProvider opts into lossless resource forwarding through the existing forwarding engine. Resource connections use this method even when ResourceData is nil. Older peers return UNSUPPORTED; clients never retry the legacy static-only StartPortForwardSession RPC.
type SessionState ¶
type SessionState string
SessionState describes tunnel availability; stopped and failed states are terminal.
const ( // SessionStateActive means the forwarder has reported readiness. SessionStateActive SessionState = "ACTIVE" // SessionStatePaused permits resumption or termination. SessionStatePaused SessionState = "PAUSED" // SessionStateStopped marks intentional termination. SessionStateStopped SessionState = "STOPPED" // SessionStateFailed marks unexpected termination. SessionStateFailed SessionState = "FAILED" )
func (SessionState) String ¶
func (s SessionState) String() string
String returns the stable state label.
func (SessionState) ToProto ¶
func (s SessionState) ToProto() networkerpb.PortForwardSession_SessionState
ToProto encodes the state; unknown states map to stopped.
type StaticForwarder ¶
type StaticForwarder interface {
ForwardStatic(
ctx context.Context,
pctx *types.PluginContext,
opts StaticPortForwardHandlerOpts,
) (*ForwarderResult, error)
}
StaticForwarder initiates a port forward for a static address.
type StaticForwarderFunc ¶
type StaticForwarderFunc func(ctx context.Context, pctx *types.PluginContext, opts StaticPortForwardHandlerOpts) (*ForwarderResult, error)
StaticForwarderFunc adapts a plain function to the StaticForwarder interface.
func (StaticForwarderFunc) ForwardStatic ¶
func (f StaticForwarderFunc) ForwardStatic( ctx context.Context, pctx *types.PluginContext, opts StaticPortForwardHandlerOpts, ) (*ForwarderResult, error)
ForwardStatic calls f with the static forwarding request.
type StaticPortForwardHandlerOpts ¶
type StaticPortForwardHandlerOpts struct {
Static PortForwardStaticConnection `json:"static"`
Options PortForwardSessionOptions `json:"options"`
}
StaticPortForwardHandlerOpts pairs a native address with forwarding options.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package networktest provides forwarding fakes, session harnesses, and state observers for tests that exercise the real networker session manager.
|
Package networktest provides forwarding fakes, session harnesses, and state observers for tests that exercise the real networker session manager. |