protocol

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersionV1 = "1.0.0"
	ProtocolVersionV2 = "2.0"
)

Protocol version constants

View Source
const (
	FeatureTLS         = "tls"
	FeatureHeartbeat   = "heartbeat"
	FeatureTunnelInfo  = "tunnel_info"
	FeatureMultiTenant = "multi_tenant"
	FeatureProxy       = "proxy"
	FeatureQUIC        = "quic"
	FeatureMetrics     = "metrics"
	FeatureJWT         = "jwt"
	FeatureTunneling   = "tunneling"
	FeatureHTTP2       = "http2"
)

Protocol features

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMessage

type AuthMessage struct {
	Type       string                 `json:"type"`
	Token      string                 `json:"token"`
	TenantID   string                 `json:"tenant_id,omitempty"`
	Version    string                 `json:"version,omitempty"`
	ClientInfo map[string]interface{} `json:"client_info,omitempty"`
}

AuthMessage represents the authentication message

func NewAuthMessage

func NewAuthMessage(token, tenantID string) *AuthMessage

NewAuthMessage creates a new auth message for v2.0

func NewAuthMessageV1

func NewAuthMessageV1(token string, clientInfo map[string]interface{}) *AuthMessage

NewAuthMessageV1 creates a new auth message for v1.0.0 (backward compatibility)

type HTTP2Client

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

HTTP2Client represents an HTTP/2 connection client

func NewHTTP2Client

func NewHTTP2Client(config *HTTP2Config) *HTTP2Client

NewHTTP2Client creates a new HTTP/2 client

func (*HTTP2Client) Close

func (hc *HTTP2Client) Close() error

Close closes the HTTP/2 client

func (*HTTP2Client) Connect

func (hc *HTTP2Client) Connect(ctx context.Context, address string) error

Connect establishes an HTTP/2 connection (validates connectivity)

func (*HTTP2Client) GetConnectionState

func (hc *HTTP2Client) GetConnectionState() tls.ConnectionState

GetConnectionState returns the TLS connection state

func (*HTTP2Client) GetStats

func (hc *HTTP2Client) GetStats() map[string]interface{}

GetStats returns HTTP/2 connection statistics

func (*HTTP2Client) IsConnected

func (hc *HTTP2Client) IsConnected() bool

IsConnected returns true if the client can make requests

func (*HTTP2Client) Ping

func (hc *HTTP2Client) Ping() error

Ping sends a ping request to test connectivity

func (*HTTP2Client) Receive

func (hc *HTTP2Client) Receive(buffer []byte) (int, error)

Receive receives data via HTTP/2 GET request

func (*HTTP2Client) Send

func (hc *HTTP2Client) Send(data []byte) error

Send sends data via HTTP/2 POST request

func (*HTTP2Client) SetKeepAlive

func (hc *HTTP2Client) SetKeepAlive(enabled bool, period time.Duration)

SetKeepAlive enables or disables keep-alive

type HTTP2Config

type HTTP2Config struct {
	TLSConfig       *tls.Config
	Timeout         time.Duration
	KeepAlive       bool
	KeepAlivePeriod time.Duration
	MaxIdleConns    int
	IdleConnTimeout time.Duration
}

HTTP2Config holds HTTP/2-specific configuration

func DefaultHTTP2Config

func DefaultHTTP2Config() *HTTP2Config

DefaultHTTP2Config returns default HTTP/2 configuration

type HelloMessage

type HelloMessage struct {
	Type     string   `json:"type"`
	Version  string   `json:"version"`
	Features []string `json:"features"`
}

HelloMessage represents the hello handshake message

func NewHelloMessage

func NewHelloMessage() *HelloMessage

NewHelloMessage creates a new hello message for v2.0

func NewHelloMessageV1

func NewHelloMessageV1() *HelloMessage

NewHelloMessageV1 creates a new hello message for v1.0.0 (backward compatibility)

type Protocol

type Protocol int

Protocol represents supported protocols

const (
	QUIC Protocol = iota
	HTTP2
	HTTP1
)

func GetProtocolHTTP1

func GetProtocolHTTP1() Protocol

GetProtocolHTTP1 returns HTTP1 protocol

func GetProtocolHTTP2

func GetProtocolHTTP2() Protocol

GetProtocolHTTP2 returns HTTP2 protocol

func GetProtocolQUIC

func GetProtocolQUIC() Protocol

GetProtocolQUIC returns QUIC protocol

func (Protocol) GetProtocolDescription

func (p Protocol) GetProtocolDescription() string

GetProtocolDescription returns a human-readable description of the protocol

func (Protocol) String

func (p Protocol) String() string

type ProtocolEngine

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

ProtocolEngine manages protocol selection and switching

func NewProtocolEngine

func NewProtocolEngine() *ProtocolEngine

NewProtocolEngine creates a new protocol engine

func NewProtocolEngineV1

func NewProtocolEngineV1() *ProtocolEngine

NewProtocolEngineV1 creates a new protocol engine for v1.0.0 (backward compatibility)

func (*ProtocolEngine) DisableAutoSwitch

func (pe *ProtocolEngine) DisableAutoSwitch()

DisableAutoSwitch disables automatic protocol switching

func (*ProtocolEngine) EnableAutoSwitch

func (pe *ProtocolEngine) EnableAutoSwitch()

EnableAutoSwitch enables automatic protocol switching

func (*ProtocolEngine) GetBestProtocol

func (pe *ProtocolEngine) GetBestProtocol() Protocol

GetBestProtocol returns the best available protocol based on performance and availability

func (*ProtocolEngine) GetFeatures

func (pe *ProtocolEngine) GetFeatures() []string

GetFeatures returns the supported features

func (*ProtocolEngine) GetNextProtocol

func (pe *ProtocolEngine) GetNextProtocol(current Protocol) Protocol

GetNextProtocol returns the next protocol to try

func (*ProtocolEngine) GetOptimalProtocolForConnection

func (pe *ProtocolEngine) GetOptimalProtocolForConnection(ctx context.Context, address string) Protocol

GetOptimalProtocolForConnection returns the optimal protocol for a new connection

func (*ProtocolEngine) GetPreferredOrder

func (pe *ProtocolEngine) GetPreferredOrder() []Protocol

GetPreferredOrder returns the current preferred protocol order

func (*ProtocolEngine) GetProtocolRecommendation

func (pe *ProtocolEngine) GetProtocolRecommendation() map[string]interface{}

GetProtocolRecommendation returns a recommendation for protocol selection

func (*ProtocolEngine) GetStats

func (pe *ProtocolEngine) GetStats() map[string]interface{}

GetStats returns protocol statistics

func (*ProtocolEngine) GetVersion

func (pe *ProtocolEngine) GetVersion() string

GetVersion returns the protocol version

func (*ProtocolEngine) IsAutoSwitchEnabled

func (pe *ProtocolEngine) IsAutoSwitchEnabled() bool

IsAutoSwitchEnabled returns true if auto switching is enabled

func (*ProtocolEngine) MarkProtocolAvailable

func (pe *ProtocolEngine) MarkProtocolAvailable(protocol Protocol)

MarkProtocolAvailable marks a protocol as available

func (*ProtocolEngine) MarkProtocolUnavailable

func (pe *ProtocolEngine) MarkProtocolUnavailable(protocol Protocol)

MarkProtocolUnavailable marks a protocol as unavailable

func (*ProtocolEngine) RecordFailure

func (pe *ProtocolEngine) RecordFailure(protocol Protocol, reason string)

RecordFailure records a failed operation for a protocol

func (*ProtocolEngine) RecordSuccess

func (pe *ProtocolEngine) RecordSuccess(protocol Protocol, latency time.Duration)

RecordSuccess records a successful operation for a protocol

func (*ProtocolEngine) ResetStats

func (pe *ProtocolEngine) ResetStats()

ResetStats resets all protocol statistics

func (*ProtocolEngine) SetPreferredOrder

func (pe *ProtocolEngine) SetPreferredOrder(order []Protocol)

SetPreferredOrder sets the preferred protocol order

func (*ProtocolEngine) ShouldSwitchProtocol

func (pe *ProtocolEngine) ShouldSwitchProtocol(current Protocol) bool

ShouldSwitchProtocol determines if we should switch protocols

type ProtocolStats

type ProtocolStats struct {
	SuccessCount   int64
	FailureCount   int64
	TotalLatency   time.Duration
	LastUsed       time.Time
	IsAvailable    bool
	LastFailure    time.Time
	FailureReason  string
	AverageLatency time.Duration
	ConnectionTime time.Duration
}

ProtocolStats tracks performance metrics for each protocol

type QUICClient

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

QUICClient represents a QUIC connection client

func NewQUICClient

func NewQUICClient(config *QUICConfig) *QUICClient

NewQUICClient creates a new QUIC client

func (*QUICClient) Close

func (qc *QUICClient) Close() error

Close closes the QUIC connection

func (*QUICClient) Connect

func (qc *QUICClient) Connect(ctx context.Context, address string) error

Connect establishes a QUIC connection

func (*QUICClient) GetConnectionState

func (qc *QUICClient) GetConnectionState() tls.ConnectionState

GetConnectionState returns the connection state

func (*QUICClient) GetStats

func (qc *QUICClient) GetStats() map[string]interface{}

GetStats returns QUIC connection statistics

func (*QUICClient) IsConnected

func (qc *QUICClient) IsConnected() bool

IsConnected returns true if the client is connected

func (*QUICClient) Ping

func (qc *QUICClient) Ping() error

Ping sends a ping to test connectivity

func (*QUICClient) Receive

func (qc *QUICClient) Receive(buffer []byte) (int, error)

Receive receives data from QUIC stream

func (*QUICClient) Send

func (qc *QUICClient) Send(data []byte) error

Send sends data over QUIC stream

func (*QUICClient) SetKeepAlive

func (qc *QUICClient) SetKeepAlive(enabled bool, period time.Duration)

SetKeepAlive enables or disables keep-alive

type QUICConfig

type QUICConfig struct {
	TLSConfig        *tls.Config
	KeepAlive        bool
	KeepAlivePeriod  time.Duration
	IdleTimeout      time.Duration
	HandshakeTimeout time.Duration
	MaxStreams       int
}

QUICConfig holds QUIC-specific configuration

func DefaultQUICConfig

func DefaultQUICConfig() *QUICConfig

DefaultQUICConfig returns default QUIC configuration

Jump to

Keyboard shortcuts

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