Documentation
¶
Index ¶
- func NewNamespacedJSONRPCClient(url string, namespace string, opts *JSONRPCClientOptions) (jsonrpc.RPCClient, error)
- func RunInNamespace[T any](nsName string, fn func() (T, error)) (T, error)
- func WaitForNamespace(log *slog.Logger, namespace string, timeout time.Duration) (*netns.NsHandle, error)
- type JSONRPCClientOptions
- type SingleThreadTransport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNamespacedJSONRPCClient ¶
func NewNamespacedJSONRPCClient(url string, namespace string, opts *JSONRPCClientOptions) (jsonrpc.RPCClient, error)
NewNamespacedJSONRPCClient returns a JSON-RPC client that performs network operations within the context of a given network namespace. It constructs a custom HTTP transport using a single-threaded dialer wrapped in RunInNamespace, allowing requests to be issued from inside the specified namespace.
func RunInNamespace ¶
RunInNamespace executes the given function within the context of the specified Linux network namespace. It locks the current OS thread, switches to the target namespace using setns, invokes the function, and then restores the original namespace. This allows thread-local operations like dialing sockets to be scoped to a namespace without affecting the rest of the program.
This is safe for use in single-threaded, short-lived operations; not safe for concurrent use.
Types ¶
type JSONRPCClientOptions ¶
type SingleThreadTransport ¶
type SingleThreadTransport struct {
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
TLSConfig *tls.Config
}
SingleThreadTransport is a minimal, non-concurrent HTTP transport that uses a manually specified DialContext to establish TCP connections. It is designed for environments like network namespaces where custom dialing logic is required. It does not support connection reuse or pipelining and is intended for low-level, single-request usage patterns where full-featured HTTP transport is unnecessary.