Documentation
¶
Index ¶
- Variables
- type ClientConn
- type ClientMetadata
- type ConnectionPool
- func (p *ConnectionPool) Add(clientID string, conn *ClientConn) error
- func (p *ConnectionPool) Count() int
- func (p *ConnectionPool) Get(clientID string) (*ClientConn, bool)
- func (p *ConnectionPool) HealthyCount() int
- func (p *ConnectionPool) List() []*ClientConn
- func (p *ConnectionPool) MarkHealthy(clientID string)
- func (p *ConnectionPool) MarkUnhealthy(clientID string)
- func (p *ConnectionPool) Remove(clientID string)
- func (p *ConnectionPool) Select() (*ClientConn, error)
- func (p *ConnectionPool) Stop()
- func (p *ConnectionPool) UpdateLastSeen(clientID string)
- type LeastConnectionsBalancer
- type LoadBalancer
- type RoundRobinBalancer
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoClientsAvailable = fmt.Errorf("no clients available in pool") ErrNoHealthyClients = fmt.Errorf("no healthy clients available") )
Errors
Functions ¶
This section is empty.
Types ¶
type ClientConn ¶
type ClientConn struct {
ID string
Conn *quic.Conn
ControlStream *quic.Stream
RegisteredAt time.Time
LastSeen time.Time
Metadata ClientMetadata
// Connection tracking
ActiveConns atomic.Int64
TotalConns atomic.Uint64
// contains filtered or unexported fields
}
ClientConn represents a connected client
type ClientMetadata ¶
type ClientMetadata struct {
Version string
Capabilities []string
Labels map[string]string // For future filtering
}
ClientMetadata contains client information
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool manages client connections for a QUIC listener
func New ¶
func New(quicAddr string, balancer LoadBalancer, logger zerolog.Logger) *ConnectionPool
New creates a new connection pool
func (*ConnectionPool) Add ¶
func (p *ConnectionPool) Add(clientID string, conn *ClientConn) error
Add registers a new client connection
func (*ConnectionPool) Count ¶
func (p *ConnectionPool) Count() int
Count returns the number of clients in the pool
func (*ConnectionPool) Get ¶
func (p *ConnectionPool) Get(clientID string) (*ClientConn, bool)
Get retrieves a specific client by ID
func (*ConnectionPool) HealthyCount ¶
func (p *ConnectionPool) HealthyCount() int
HealthyCount returns the number of healthy clients
func (*ConnectionPool) List ¶
func (p *ConnectionPool) List() []*ClientConn
List returns all clients in the pool
func (*ConnectionPool) MarkHealthy ¶
func (p *ConnectionPool) MarkHealthy(clientID string)
MarkHealthy marks a client as healthy
func (*ConnectionPool) MarkUnhealthy ¶
func (p *ConnectionPool) MarkUnhealthy(clientID string)
MarkUnhealthy marks a client as unhealthy
func (*ConnectionPool) Remove ¶
func (p *ConnectionPool) Remove(clientID string)
Remove removes a client from the pool
func (*ConnectionPool) Select ¶
func (p *ConnectionPool) Select() (*ClientConn, error)
Select chooses a client using the load balancer
func (*ConnectionPool) UpdateLastSeen ¶
func (p *ConnectionPool) UpdateLastSeen(clientID string)
UpdateLastSeen updates the last seen timestamp for a client
type LeastConnectionsBalancer ¶
type LeastConnectionsBalancer struct{}
LeastConnectionsBalancer implements least-connections load balancing
func NewLeastConnectionsBalancer ¶
func NewLeastConnectionsBalancer() *LeastConnectionsBalancer
NewLeastConnectionsBalancer creates a new least-connections balancer
func (*LeastConnectionsBalancer) Name ¶
func (l *LeastConnectionsBalancer) Name() string
Name returns the balancer name
func (*LeastConnectionsBalancer) Select ¶
func (l *LeastConnectionsBalancer) Select(clients []*ClientConn) (*ClientConn, error)
Select chooses the client with fewest active connections Uses linear scan for small pools (≤100 clients) and optimized path for larger pools
type LoadBalancer ¶
type LoadBalancer interface {
// Select chooses a client from the pool
Select(clients []*ClientConn) (*ClientConn, error)
// Name returns the balancer name
Name() string
}
LoadBalancer selects a client from the pool
type RoundRobinBalancer ¶
type RoundRobinBalancer struct {
// contains filtered or unexported fields
}
RoundRobinBalancer implements round-robin load balancing
func NewRoundRobinBalancer ¶
func NewRoundRobinBalancer() *RoundRobinBalancer
NewRoundRobinBalancer creates a new round-robin balancer
func (*RoundRobinBalancer) Name ¶
func (r *RoundRobinBalancer) Name() string
Name returns the balancer name
func (*RoundRobinBalancer) Select ¶
func (r *RoundRobinBalancer) Select(clients []*ClientConn) (*ClientConn, error)
Select chooses a client using round-robin algorithm with O(1) complexity