transport

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package transport provides a transport abstraction layer supporting both gRPC and WebSocket fallback for Mandau core-agent communication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Connect establishes the connection
	Connect(ctx context.Context) error
	// Close closes the connection
	Close() error
	// GRPCConn returns the underlying gRPC connection (nil for WebSocket)
	GRPCConn() *grpc.ClientConn
	// IsConnected returns true if the connection is active
	IsConnected() bool
	// Type returns the transport type
	Type() Type
}

Client is the transport-agnostic client interface

func NewGRPCClient

func NewGRPCClient(config Config) Client

NewGRPCClient creates a new gRPC client

func NewWSClient

func NewWSClient(config Config) Client

NewWSClient creates a new WebSocket client

type Config

type Config struct {
	// Type is the preferred transport type
	Type Type
	// ServerAddr is the address to connect to
	ServerAddr string
	// TLS holds TLS configuration
	TLS TLSConfig
	// WebSocket holds WebSocket-specific config
	WebSocket WSConfig
}

Config holds transport configuration

type Manager

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

Manager handles transport with automatic fallback

func NewManager

func NewManager(config Config) *Manager

NewManager creates a new transport manager with fallback support

func (*Manager) Active

func (m *Manager) Active() Client

Active returns the currently active transport

func (*Manager) ActiveType

func (m *Manager) ActiveType() Type

ActiveType returns the type of the active transport

func (*Manager) Close

func (m *Manager) Close() error

Close closes all transport connections

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context) error

Connect attempts to connect with primary, falls back to secondary on failure

func (*Manager) ConnectWithRetry

func (m *Manager) ConnectWithRetry(ctx context.Context, maxRetries int, baseDelay time.Duration) error

ConnectWithRetry attempts to connect with exponential backoff

func (*Manager) Failover

func (m *Manager) Failover(ctx context.Context) error

Failover switches to the fallback transport if available

func (*Manager) GRPCConn

func (m *Manager) GRPCConn() *grpc.ClientConn

GRPCConn returns the active gRPC connection (may be nil if using WebSocket)

func (*Manager) IsConnected

func (m *Manager) IsConnected() bool

IsConnected returns true if any transport is connected

func (*Manager) Reconnect

func (m *Manager) Reconnect(ctx context.Context) error

Reconnect attempts to reconnect to the preferred transport

type TLSConfig

type TLSConfig struct {
	CertPath   string
	KeyPath    string
	CAPath     string
	MinVersion string
	ServerName string
}

TLSConfig holds TLS configuration

type Type

type Type string

Type defines the transport mechanism

const (
	// GRPC is the primary transport
	GRPC Type = "grpc"
	// WebSocket is the fallback transport
	WebSocket Type = "websocket"
)

type WSConfig

type WSConfig struct {
	// Path is the WebSocket endpoint path
	Path string
	// PingInterval is how often to send ping frames
	PingInterval time.Duration
	// ReadDeadline is the read deadline for WebSocket connections
	ReadDeadline time.Duration
}

WSConfig holds WebSocket configuration

Jump to

Keyboard shortcuts

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