Documentation
¶
Overview ¶
Package client implements the DNS tunneling client. It provides TCP proxy functionality that tunnels traffic through DNS queries to multiple resolvers using QUIC multipath.
Index ¶
- Constants
- Variables
- type CallbackEvent
- type CallbackHandler
- type CallbackRegistry
- func (r *CallbackRegistry) HasHandlers(callbackType CallbackType) bool
- func (r *CallbackRegistry) Register(callbackType CallbackType, handler CallbackHandler)
- func (r *CallbackRegistry) Trigger(event *CallbackEvent)
- func (r *CallbackRegistry) TriggerAsync(event *CallbackEvent)
- func (r *CallbackRegistry) Unregister(callbackType CallbackType)
- type CallbackType
- type Client
- func (c *Client) AcceptorStats() TCPAcceptorStats
- func (c *Client) Close() error
- func (c *Client) Config() *Config
- func (c *Client) Context() context.Context
- func (c *Client) IsRunning() bool
- func (c *Client) ListenAddr() string
- func (c *Client) PathStats() []ResolverPathStats
- func (c *Client) RegisterCallback(callbackType CallbackType, handler CallbackHandler)
- func (c *Client) Start() error
- func (c *Client) State() ClientState
- func (c *Client) Stats() ClientStats
- func (c *Client) Stop() error
- func (c *Client) StreamStats() StreamManagerStats
- func (c *Client) WaitForShutdown()
- type ClientCallbacks
- type ClientState
- type ClientStats
- type Config
- func (c *Config) Clone() *Config
- func (c *Config) GetListenAddress() string
- func (c *Config) IsIPv6() (bool, error)
- func (c *Config) ParseResolvers() ([]ResolverAddress, error)
- func (c *Config) Validate() error
- func (c *Config) WithCongestionControl(cc CongestionControlAlgorithm) *Config
- func (c *Config) WithDomain(domain string) *Config
- func (c *Config) WithGSO(enable bool) *Config
- func (c *Config) WithKeepAlive(interval time.Duration) *Config
- func (c *Config) WithListenAddr(addr string) *Config
- func (c *Config) WithListenPort(port int) *Config
- func (c *Config) WithResolvers(resolvers ...string) *Config
- type CongestionControlAlgorithm
- type DataQueue
- type DataQueueItem
- type MinRTTPathScheduler
- type PathManager
- func (m *PathManager) AddPath(addr *net.UDPAddr) (*ResolverPath, error)
- func (m *PathManager) AddPathsFromConfig(resolvers []ResolverAddress) error
- func (m *PathManager) Close() error
- func (m *PathManager) GetAllPaths() []*ResolverPath
- func (m *PathManager) GetAvailablePaths() []*ResolverPath
- func (m *PathManager) GetPath(pathID int) *ResolverPath
- func (m *PathManager) PathCount() (total, available int)
- func (m *PathManager) ProbeAllPaths(ctx context.Context, codec *dns.ClientCodec) []error
- func (m *PathManager) ProbePath(ctx context.Context, pathID int, codec *dns.ClientCodec) error
- func (m *PathManager) RemovePath(pathID int) error
- func (m *PathManager) SelectAllPaths() []*ResolverPath
- func (m *PathManager) SelectPath() *ResolverPath
- func (m *PathManager) SetCallbacks(onAdded, onRemoved, onFailed func(int))
- func (m *PathManager) Stats() []ResolverPathStats
- type PathManagerConfig
- type PathScheduler
- type PathState
- type PollEvent
- type Poller
- type PollerConfig
- type ResolverAddress
- type ResolverPath
- func (p *ResolverPath) Close() error
- func (p *ResolverPath) Connect() error
- func (p *ResolverPath) IsAvailable() bool
- func (p *ResolverPath) RTT() time.Duration
- func (p *ResolverPath) Receive(buffer []byte, timeout time.Duration) (int, error)
- func (p *ResolverPath) Send(data []byte) error
- func (p *ResolverPath) SetState(state PathState)
- func (p *ResolverPath) State() PathState
- func (p *ResolverPath) Stats() ResolverPathStats
- func (p *ResolverPath) UpdateRTT(rtt time.Duration)
- type ResolverPathStats
- type RoundRobinPathScheduler
- type Stream
- func (s *Stream) Activate(streamID int64) bool
- func (s *Stream) Age() time.Duration
- func (s *Stream) Close() error
- func (s *Stream) CompareAndSwapState(expected, new StreamState) bool
- func (s *Stream) Context() context.Context
- func (s *Stream) IdleDuration() time.Duration
- func (s *Stream) IsActive() bool
- func (s *Stream) IsClosed() bool
- func (s *Stream) LastActivity() time.Time
- func (s *Stream) LocalAddr() net.Addr
- func (s *Stream) Read(p []byte) (int, error)
- func (s *Stream) ReadFromTCP() ([]byte, int, error)
- func (s *Stream) RemoteAddr() net.Addr
- func (s *Stream) SetOnClose(callback func(*Stream))
- func (s *Stream) SetState(state StreamState)
- func (s *Stream) State() StreamState
- func (s *Stream) Stats() StreamStats
- func (s *Stream) Write(p []byte) (int, error)
- func (s *Stream) WriteToTCP(data []byte) (int, error)
- type StreamCallback
- type StreamCallbackHandler
- type StreamCallbackRegistry
- func (r *StreamCallbackRegistry) Get(streamID int64) *StreamCallbackHandler
- func (r *StreamCallbackRegistry) Register(streamID int64, callback *StreamCallback)
- func (r *StreamCallbackRegistry) TriggerClose(streamID int64)
- func (r *StreamCallbackRegistry) TriggerData(streamID int64, data []byte)
- func (r *StreamCallbackRegistry) TriggerError(streamID int64, err error)
- func (r *StreamCallbackRegistry) Unregister(streamID int64)
- type StreamConfig
- type StreamManager
- func (m *StreamManager) ActivateStream(localID uint64, streamID int64) (*Stream, error)
- func (m *StreamManager) AddPendingStream(tcpConn net.Conn, config *StreamConfig) (*Stream, error)
- func (m *StreamManager) Close() error
- func (m *StreamManager) Count() (active, pending int)
- func (m *StreamManager) FindIdleStreams(maxIdle time.Duration) []*Stream
- func (m *StreamManager) ForEachStream(fn func(*Stream) bool)
- func (m *StreamManager) GetAllStreams() []*Stream
- func (m *StreamManager) GetPendingStream(localID uint64) *Stream
- func (m *StreamManager) GetPendingStreams() []*Stream
- func (m *StreamManager) GetStream(streamID int64) *Stream
- func (m *StreamManager) IsClosed() bool
- func (m *StreamManager) RemoveStream(streamID int64)
- func (m *StreamManager) SetOnStreamClosed(callback func(*Stream))
- func (m *StreamManager) Stats() StreamManagerStats
- type StreamManagerStats
- type StreamState
- type StreamStats
- type TCPAcceptor
- type TCPAcceptorConfig
- type TCPAcceptorStats
- type WeightedPathScheduler
Constants ¶
const ( CongestionControlBBR = quic.CongestionControlBBR CongestionControlDCUBIC = quic.CongestionControlDCUBIC )
Congestion control algorithm constants
Variables ¶
var ( ErrNoResolvers = errors.New("at least one resolver address is required") ErrInvalidListenPort = errors.New("listen port must be between 1 and 65535") ErrInvalidDomain = errors.New("domain must not be empty") ErrMixedAddressFamilies = errors.New("cannot mix IPv4 and IPv6 resolver addresses") ErrInvalidResolverAddr = errors.New("invalid resolver address") ErrClientClosed = errors.New("client is closed") ErrClientNotRunning = errors.New("client is not running") ErrConnectionFailed = errors.New("connection failed") ErrStreamCreationFailed = errors.New("stream creation failed") ErrNoActiveConnection = errors.New("no active connection") )
Common errors for client configuration
Functions ¶
This section is empty.
Types ¶
type CallbackEvent ¶
type CallbackEvent struct {
// Type is the type of callback event
Type CallbackType
// StreamID is the QUIC stream ID (if applicable)
StreamID int64
// PathID is the path ID (if applicable)
PathID int
// Data is the event data (if applicable)
Data []byte
// Error is the error (if applicable)
Error error
// Context provides additional context
Context context.Context
}
CallbackEvent represents an event passed to callback handlers
type CallbackHandler ¶
type CallbackHandler func(event *CallbackEvent)
CallbackHandler is a function that handles callback events
type CallbackRegistry ¶
type CallbackRegistry struct {
// contains filtered or unexported fields
}
CallbackRegistry manages callback registrations
func NewCallbackRegistry ¶
func NewCallbackRegistry() *CallbackRegistry
NewCallbackRegistry creates a new callback registry
func (*CallbackRegistry) HasHandlers ¶
func (r *CallbackRegistry) HasHandlers(callbackType CallbackType) bool
HasHandlers returns true if there are handlers registered for a callback type
func (*CallbackRegistry) Register ¶
func (r *CallbackRegistry) Register(callbackType CallbackType, handler CallbackHandler)
Register registers a handler for a callback type
func (*CallbackRegistry) Trigger ¶
func (r *CallbackRegistry) Trigger(event *CallbackEvent)
Trigger triggers all handlers for a callback event
func (*CallbackRegistry) TriggerAsync ¶
func (r *CallbackRegistry) TriggerAsync(event *CallbackEvent)
TriggerAsync triggers all handlers asynchronously
func (*CallbackRegistry) Unregister ¶
func (r *CallbackRegistry) Unregister(callbackType CallbackType)
Unregister removes all handlers for a callback type
type CallbackType ¶
type CallbackType int
CallbackType identifies the type of callback event
const ( // CallbackTypeConnected is called when the QUIC connection is established CallbackTypeConnected CallbackType = iota // CallbackTypeConnectionClosed is called when the QUIC connection is closed CallbackTypeConnectionClosed // CallbackTypeStreamData is called when data is received on a stream CallbackTypeStreamData // CallbackTypeStreamOpened is called when a new stream is opened CallbackTypeStreamOpened // CallbackTypeStreamClosed is called when a stream is closed CallbackTypeStreamClosed // CallbackTypeStreamReset is called when a stream is reset CallbackTypeStreamReset // CallbackTypePollResponse is called when a poll response is received CallbackTypePollResponse // CallbackTypePathAdded is called when a new path is added CallbackTypePathAdded // CallbackTypePathRemoved is called when a path is removed CallbackTypePathRemoved // CallbackTypeError is called when an error occurs CallbackTypeError )
func (CallbackType) String ¶
func (t CallbackType) String() string
String returns the string representation of the callback type
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the DNS tunneling client
func (*Client) AcceptorStats ¶
func (c *Client) AcceptorStats() TCPAcceptorStats
AcceptorStats returns the TCP acceptor statistics
func (*Client) ListenAddr ¶
ListenAddr returns the TCP listen address
func (*Client) PathStats ¶
func (c *Client) PathStats() []ResolverPathStats
PathStats returns all path statistics
func (*Client) RegisterCallback ¶
func (c *Client) RegisterCallback(callbackType CallbackType, handler CallbackHandler)
RegisterCallback registers a callback handler
func (*Client) StreamStats ¶
func (c *Client) StreamStats() StreamManagerStats
StreamStats returns the stream manager statistics
func (*Client) WaitForShutdown ¶
func (c *Client) WaitForShutdown()
WaitForShutdown waits for the client to shut down
type ClientCallbacks ¶
type ClientCallbacks struct {
// OnConnected is called when the QUIC connection is established
OnConnected func()
// OnConnectionClosed is called when the QUIC connection is closed
OnConnectionClosed func(error)
// OnStreamData is called when data is received on a stream
OnStreamData func(streamID int64, data []byte)
// OnStreamOpened is called when a new stream is opened
OnStreamOpened func(streamID int64)
// OnStreamClosed is called when a stream is closed
OnStreamClosed func(streamID int64)
// OnStreamReset is called when a stream is reset by the server
OnStreamReset func(streamID int64, errorCode uint64)
// OnPollResponse is called when a poll response is received
OnPollResponse func(pathID int, data []byte)
// OnPathAdded is called when a new path is added
OnPathAdded func(pathID int)
// OnPathRemoved is called when a path is removed
OnPathRemoved func(pathID int)
// OnError is called when an error occurs
OnError func(error)
}
ClientCallbacks holds callback functions for client events
func DefaultClientCallbacks ¶
func DefaultClientCallbacks() *ClientCallbacks
DefaultClientCallbacks returns a ClientCallbacks with no-op handlers
func (*ClientCallbacks) ToRegistry ¶
func (c *ClientCallbacks) ToRegistry() *CallbackRegistry
ToRegistry converts ClientCallbacks to a CallbackRegistry
type ClientState ¶
type ClientState int32
ClientState represents the state of the client
const ( // ClientStateInitial indicates the client is initialized but not started ClientStateInitial ClientState = iota // ClientStateConnecting indicates the client is connecting ClientStateConnecting // ClientStateConnected indicates the client is connected and running ClientStateConnected // ClientStateClosing indicates the client is closing ClientStateClosing // ClientStateClosed indicates the client is closed ClientStateClosed )
func (ClientState) String ¶
func (s ClientState) String() string
String returns the string representation of the client state
type ClientStats ¶
type ClientStats struct {
// Connection stats
ConnectionAttempts uint64
ConnectionFailures uint64
ConnectionTime time.Time
// Data stats
BytesSent uint64
BytesReceived uint64
QueriesSent uint64
ResponsesReceived uint64
// Stream stats
StreamsOpened uint64
StreamsClosed uint64
// Error stats
Errors uint64
}
ClientStats holds statistics for the client
type Config ¶
type Config struct {
// ListenPort is the TCP port to listen on for incoming connections
// Default: 5201
ListenPort int
// ListenAddr is the address to bind the TCP listener to
// Default: "127.0.0.1" (localhost only)
ListenAddr string
// Resolvers is the list of DNS resolver addresses
// At least one resolver is required
Resolvers []string
// Domain is the base domain used for DNS tunneling
Domain string
// CongestionControl specifies the congestion control algorithm
// Default: BBR
CongestionControl CongestionControlAlgorithm
// EnableGSO enables Generic Segmentation Offload
// Default: false
EnableGSO bool
// KeepAliveInterval is the interval between keep-alive packets
// Default: 400ms
KeepAliveInterval time.Duration
// ConnectTimeout is the timeout for establishing the QUIC connection
// Default: 10s
ConnectTimeout time.Duration
// MaxStreams is the maximum number of concurrent TCP streams
// Default: 100
MaxStreams int
// BufferSize is the buffer size for TCP connections
// Default: 32KB
BufferSize int
// DNSTimeout is the timeout for DNS queries
// Default: 2s
DNSTimeout time.Duration
// PollInterval is the interval between poll messages when no data
// Default: 50ms
PollInterval time.Duration
// MaxRetries is the maximum number of retries for failed operations
// Default: 3
MaxRetries int
}
Config holds the client configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with sensible defaults
func (*Config) GetListenAddress ¶
GetListenAddress returns the full TCP listen address
func (*Config) ParseResolvers ¶
func (c *Config) ParseResolvers() ([]ResolverAddress, error)
ParseResolvers parses all resolver addresses and returns ResolverAddress structs
func (*Config) WithCongestionControl ¶
func (c *Config) WithCongestionControl(cc CongestionControlAlgorithm) *Config
WithCongestionControl returns a new Config with the given congestion control
func (*Config) WithDomain ¶
WithDomain returns a new Config with the given domain
func (*Config) WithKeepAlive ¶
WithKeepAlive returns a new Config with the given keep-alive interval
func (*Config) WithListenAddr ¶
WithListenAddr returns a new Config with the given listen address
func (*Config) WithListenPort ¶
WithListenPort returns a new Config with the given listen port
func (*Config) WithResolvers ¶
WithResolvers returns a new Config with the given resolvers
type CongestionControlAlgorithm ¶
type CongestionControlAlgorithm = quic.CongestionControlAlgorithm
CongestionControlAlgorithm re-exports the QUIC congestion control type.
type DataQueue ¶
type DataQueue struct {
// contains filtered or unexported fields
}
DataQueue manages outgoing data from TCP streams to be sent over DNS
func (*DataQueue) Dequeue ¶
func (q *DataQueue) Dequeue() *DataQueueItem
Dequeue removes and returns the next item from the queue
func (*DataQueue) DequeueBlocking ¶
func (q *DataQueue) DequeueBlocking(ctx context.Context) *DataQueueItem
DequeueBlocking blocks until an item is available
func (*DataQueue) Items ¶
func (q *DataQueue) Items() <-chan *DataQueueItem
Items returns the channel for receiving items (for select)
type DataQueueItem ¶
type DataQueueItem struct {
// Stream is the source stream
Stream *Stream
// Data is the data to send
Data []byte
// Timestamp is when the item was queued
Timestamp time.Time
}
DataQueueItem represents an item in the data queue
type MinRTTPathScheduler ¶
type MinRTTPathScheduler struct {
// contains filtered or unexported fields
}
MinRTTPathScheduler selects the path with the lowest RTT
func NewMinRTTPathScheduler ¶
func NewMinRTTPathScheduler() *MinRTTPathScheduler
NewMinRTTPathScheduler creates a new min-RTT scheduler
func (*MinRTTPathScheduler) AddPath ¶
func (s *MinRTTPathScheduler) AddPath(pathID int)
AddPath adds a path with default metrics
func (*MinRTTPathScheduler) RemovePath ¶
func (s *MinRTTPathScheduler) RemovePath(pathID int)
RemovePath removes a path
func (*MinRTTPathScheduler) SelectPath ¶
func (s *MinRTTPathScheduler) SelectPath() int
SelectPath returns the path with the lowest RTT
func (*MinRTTPathScheduler) UpdatePathMetrics ¶
func (s *MinRTTPathScheduler) UpdatePathMetrics(pathID int, rtt time.Duration, loss float64)
UpdatePathMetrics updates the metrics for a path
type PathManager ¶
type PathManager struct {
// contains filtered or unexported fields
}
PathManager manages multiple resolver paths
func NewPathManager ¶
func NewPathManager(config *PathManagerConfig) *PathManager
NewPathManager creates a new path manager
func (*PathManager) AddPath ¶
func (m *PathManager) AddPath(addr *net.UDPAddr) (*ResolverPath, error)
AddPath adds a new resolver path
func (*PathManager) AddPathsFromConfig ¶
func (m *PathManager) AddPathsFromConfig(resolvers []ResolverAddress) error
AddPathsFromConfig adds paths from resolver addresses
func (*PathManager) Close ¶
func (m *PathManager) Close() error
Close closes all paths and the manager
func (*PathManager) GetAllPaths ¶
func (m *PathManager) GetAllPaths() []*ResolverPath
GetAllPaths returns all paths
func (*PathManager) GetAvailablePaths ¶
func (m *PathManager) GetAvailablePaths() []*ResolverPath
GetAvailablePaths returns all available paths
func (*PathManager) GetPath ¶
func (m *PathManager) GetPath(pathID int) *ResolverPath
GetPath returns a path by ID
func (*PathManager) PathCount ¶
func (m *PathManager) PathCount() (total, available int)
PathCount returns the number of paths (total and available)
func (*PathManager) ProbeAllPaths ¶
func (m *PathManager) ProbeAllPaths(ctx context.Context, codec *dns.ClientCodec) []error
ProbeAllPaths probes all paths concurrently
func (*PathManager) ProbePath ¶
func (m *PathManager) ProbePath(ctx context.Context, pathID int, codec *dns.ClientCodec) error
ProbePath sends a probe query to verify path connectivity
func (*PathManager) RemovePath ¶
func (m *PathManager) RemovePath(pathID int) error
RemovePath removes a path by ID
func (*PathManager) SelectAllPaths ¶
func (m *PathManager) SelectAllPaths() []*ResolverPath
SelectAllPaths returns all available paths for broadcast
func (*PathManager) SelectPath ¶
func (m *PathManager) SelectPath() *ResolverPath
SelectPath selects a path for sending using the scheduler
func (*PathManager) SetCallbacks ¶
func (m *PathManager) SetCallbacks(onAdded, onRemoved, onFailed func(int))
SetCallbacks sets the path event callbacks
func (*PathManager) Stats ¶
func (m *PathManager) Stats() []ResolverPathStats
Stats returns statistics for all paths
type PathManagerConfig ¶
type PathManagerConfig struct {
// MaxPaths is the maximum number of paths
MaxPaths int
// Scheduler is the path selection scheduler
Scheduler PathScheduler
// ProbeTimeout is the timeout for path probing
ProbeTimeout time.Duration
}
PathManagerConfig holds configuration for the path manager
func DefaultPathManagerConfig ¶
func DefaultPathManagerConfig() *PathManagerConfig
DefaultPathManagerConfig returns default path manager configuration
type PathScheduler ¶
type PathScheduler interface {
// SelectPath returns the next path ID to use, or -1 if none available
SelectPath() int
// AddPath adds a path to the scheduler
AddPath(pathID int)
// RemovePath removes a path from the scheduler
RemovePath(pathID int)
// UpdatePathMetrics updates metrics for a path
UpdatePathMetrics(pathID int, rtt time.Duration, loss float64)
}
PathScheduler selects paths for sending
type PathState ¶
type PathState int32
PathState represents the state of a resolver path
const ( // PathStateProbing indicates the path is being probed PathStateProbing PathState = iota // PathStateActive indicates an active, healthy path PathStateActive // PathStateDegraded indicates a degraded path (high latency or packet loss) PathStateDegraded // PathStateFailed indicates a failed path PathStateFailed // PathStateDisabled indicates a disabled path PathStateDisabled )
type PollEvent ¶
type PollEvent struct {
// Stream is the stream with data ready
Stream *Stream
// Data is the data read from the stream (if any)
Data []byte
// Error is any error that occurred
Error error
// IsClosed indicates the stream was closed
IsClosed bool
}
PollEvent represents an event from the poller
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller monitors streams for readability and notifies when data is available
func NewPoller ¶
func NewPoller(streams *StreamManager, config *PollerConfig) *Poller
NewPoller creates a new poller
func (*Poller) SetCallbacks ¶
func (p *Poller) SetCallbacks(onDataReady func(*Stream, []byte), onStreamClosed func(*Stream, error))
SetCallbacks sets the data ready and stream closed callbacks
func (*Poller) StopStreamPoller ¶
StopStreamPoller stops polling a specific stream
type PollerConfig ¶
type PollerConfig struct {
// PollInterval is the interval between poll cycles for idle streams
PollInterval time.Duration
// ReadTimeout is the timeout for read operations
ReadTimeout time.Duration
// BufferSize is the size of read buffers
BufferSize int
// EventBufferSize is the size of the event channel buffer
EventBufferSize int
}
PollerConfig holds configuration for the poller
func DefaultPollerConfig ¶
func DefaultPollerConfig() *PollerConfig
DefaultPollerConfig returns default poller configuration
type ResolverAddress ¶
type ResolverAddress struct {
// Address is the resolver address (IP:port or hostname:port)
Address string
// ParsedAddr is the parsed network address
ParsedAddr *net.UDPAddr
// PathID is the unique identifier for this path
PathID int
}
ResolverAddress represents a DNS resolver endpoint
type ResolverPath ¶
type ResolverPath struct {
// ID is the unique path identifier
ID int
// Address is the resolver address
Address *net.UDPAddr
// contains filtered or unexported fields
}
ResolverPath represents a path to a DNS resolver
func NewResolverPath ¶
func NewResolverPath(id int, addr *net.UDPAddr) *ResolverPath
NewResolverPath creates a new resolver path
func (*ResolverPath) Connect ¶
func (p *ResolverPath) Connect() error
Connect establishes a UDP connection to the resolver
func (*ResolverPath) IsAvailable ¶
func (p *ResolverPath) IsAvailable() bool
IsAvailable returns true if the path can be used for sending
func (*ResolverPath) RTT ¶
func (p *ResolverPath) RTT() time.Duration
RTT returns the current RTT estimate
func (*ResolverPath) Send ¶
func (p *ResolverPath) Send(data []byte) error
Send sends a DNS query to the resolver
func (*ResolverPath) SetState ¶
func (p *ResolverPath) SetState(state PathState)
SetState sets the path state
func (*ResolverPath) State ¶
func (p *ResolverPath) State() PathState
State returns the current path state
func (*ResolverPath) Stats ¶
func (p *ResolverPath) Stats() ResolverPathStats
Stats returns the path statistics
func (*ResolverPath) UpdateRTT ¶
func (p *ResolverPath) UpdateRTT(rtt time.Duration)
UpdateRTT updates the RTT estimate with a new sample
type ResolverPathStats ¶
type ResolverPathStats struct {
ID int
Address string
State PathState
RTT time.Duration
QueriesSent uint64
ResponsesRecv uint64
BytesSent uint64
BytesRecv uint64
Timeouts uint64
Errors uint64
LastResponseTime time.Time
}
ResolverPathStats holds statistics for a resolver path
type RoundRobinPathScheduler ¶
type RoundRobinPathScheduler struct {
// contains filtered or unexported fields
}
RoundRobinPathScheduler selects paths in round-robin order
func NewRoundRobinPathScheduler ¶
func NewRoundRobinPathScheduler() *RoundRobinPathScheduler
NewRoundRobinPathScheduler creates a new round-robin scheduler
func (*RoundRobinPathScheduler) AddPath ¶
func (s *RoundRobinPathScheduler) AddPath(pathID int)
AddPath adds a path to the scheduler
func (*RoundRobinPathScheduler) RemovePath ¶
func (s *RoundRobinPathScheduler) RemovePath(pathID int)
RemovePath removes a path from the scheduler
func (*RoundRobinPathScheduler) SelectPath ¶
func (s *RoundRobinPathScheduler) SelectPath() int
SelectPath returns the next path in round-robin order
func (*RoundRobinPathScheduler) UpdatePathMetrics ¶
func (s *RoundRobinPathScheduler) UpdatePathMetrics(pathID int, rtt time.Duration, loss float64)
UpdatePathMetrics is a no-op for round-robin
type Stream ¶
type Stream struct {
// ID is the unique stream identifier (assigned by QUIC)
ID int64
// LocalID is a local identifier for tracking
LocalID uint64
// TCPConn is the local TCP connection from the client
TCPConn net.Conn
// contains filtered or unexported fields
}
Stream represents a TCP connection being tunneled through QUIC
func NewStream ¶
func NewStream(tcpConn net.Conn, config *StreamConfig) *Stream
NewStream creates a new stream for a TCP connection
func (*Stream) CompareAndSwapState ¶
func (s *Stream) CompareAndSwapState(expected, new StreamState) bool
CompareAndSwapState atomically updates state if it matches expected
func (*Stream) IdleDuration ¶
IdleDuration returns how long the stream has been idle
func (*Stream) LastActivity ¶
LastActivity returns the time of the last activity
func (*Stream) ReadFromTCP ¶
ReadFromTCP reads data from the TCP connection into the read buffer
func (*Stream) RemoteAddr ¶
RemoteAddr returns the remote address of the TCP connection
func (*Stream) SetOnClose ¶
SetOnClose sets a callback to be called when the stream is closed
func (*Stream) SetState ¶
func (s *Stream) SetState(state StreamState)
SetState sets the stream state
type StreamCallback ¶
type StreamCallback struct {
// OnData is called when data is received
OnData func([]byte)
// OnClose is called when the stream is closed
OnClose func()
// OnError is called when an error occurs
OnError func(error)
}
StreamCallback represents a callback for stream events
type StreamCallbackHandler ¶
type StreamCallbackHandler struct {
// contains filtered or unexported fields
}
StreamCallbackHandler wraps StreamCallback to implement handling
func NewStreamCallbackHandler ¶
func NewStreamCallbackHandler(streamID int64, callback *StreamCallback) *StreamCallbackHandler
NewStreamCallbackHandler creates a new stream callback handler
func (*StreamCallbackHandler) HandleClose ¶
func (h *StreamCallbackHandler) HandleClose()
HandleClose handles stream close
func (*StreamCallbackHandler) HandleData ¶
func (h *StreamCallbackHandler) HandleData(data []byte)
HandleData handles data received on the stream
func (*StreamCallbackHandler) HandleError ¶
func (h *StreamCallbackHandler) HandleError(err error)
HandleError handles stream error
type StreamCallbackRegistry ¶
type StreamCallbackRegistry struct {
// contains filtered or unexported fields
}
StreamCallbackRegistry manages per-stream callbacks
func NewStreamCallbackRegistry ¶
func NewStreamCallbackRegistry() *StreamCallbackRegistry
NewStreamCallbackRegistry creates a new stream callback registry
func (*StreamCallbackRegistry) Get ¶
func (r *StreamCallbackRegistry) Get(streamID int64) *StreamCallbackHandler
Get returns the callback handler for a stream
func (*StreamCallbackRegistry) Register ¶
func (r *StreamCallbackRegistry) Register(streamID int64, callback *StreamCallback)
Register registers callbacks for a stream
func (*StreamCallbackRegistry) TriggerClose ¶
func (r *StreamCallbackRegistry) TriggerClose(streamID int64)
TriggerClose triggers the close callback for a stream
func (*StreamCallbackRegistry) TriggerData ¶
func (r *StreamCallbackRegistry) TriggerData(streamID int64, data []byte)
TriggerData triggers the data callback for a stream
func (*StreamCallbackRegistry) TriggerError ¶
func (r *StreamCallbackRegistry) TriggerError(streamID int64, err error)
TriggerError triggers the error callback for a stream
func (*StreamCallbackRegistry) Unregister ¶
func (r *StreamCallbackRegistry) Unregister(streamID int64)
Unregister removes callbacks for a stream
type StreamConfig ¶
type StreamConfig struct {
// BufferSize is the size of read/write buffers
BufferSize int
// ReadTimeout is the timeout for TCP read operations
ReadTimeout time.Duration
// WriteTimeout is the timeout for TCP write operations
WriteTimeout time.Duration
}
StreamConfig holds configuration for stream creation
func DefaultStreamConfig ¶
func DefaultStreamConfig() *StreamConfig
DefaultStreamConfig returns default stream configuration
type StreamManager ¶
type StreamManager struct {
// contains filtered or unexported fields
}
StreamManager manages multiple streams
func NewStreamManager ¶
func NewStreamManager(maxStreams int) *StreamManager
NewStreamManager creates a new stream manager
func (*StreamManager) ActivateStream ¶
func (m *StreamManager) ActivateStream(localID uint64, streamID int64) (*Stream, error)
ActivateStream activates a pending stream with the given QUIC stream ID
func (*StreamManager) AddPendingStream ¶
func (m *StreamManager) AddPendingStream(tcpConn net.Conn, config *StreamConfig) (*Stream, error)
AddPendingStream adds a new pending stream and returns its local ID
func (*StreamManager) Close ¶
func (m *StreamManager) Close() error
Close closes all streams and the manager
func (*StreamManager) Count ¶
func (m *StreamManager) Count() (active, pending int)
Count returns the number of active and pending streams
func (*StreamManager) FindIdleStreams ¶
func (m *StreamManager) FindIdleStreams(maxIdle time.Duration) []*Stream
FindIdleStreams returns streams that have been idle longer than the given duration
func (*StreamManager) ForEachStream ¶
func (m *StreamManager) ForEachStream(fn func(*Stream) bool)
ForEachStream calls the given function for each active stream
func (*StreamManager) GetAllStreams ¶
func (m *StreamManager) GetAllStreams() []*Stream
GetAllStreams returns all active streams
func (*StreamManager) GetPendingStream ¶
func (m *StreamManager) GetPendingStream(localID uint64) *Stream
GetPendingStream returns a pending stream by its local ID
func (*StreamManager) GetPendingStreams ¶
func (m *StreamManager) GetPendingStreams() []*Stream
GetPendingStreams returns all pending streams
func (*StreamManager) GetStream ¶
func (m *StreamManager) GetStream(streamID int64) *Stream
GetStream returns a stream by its QUIC stream ID
func (*StreamManager) IsClosed ¶
func (m *StreamManager) IsClosed() bool
IsClosed returns true if the manager is closed
func (*StreamManager) RemoveStream ¶
func (m *StreamManager) RemoveStream(streamID int64)
RemoveStream removes a stream by its QUIC stream ID
func (*StreamManager) SetOnStreamClosed ¶
func (m *StreamManager) SetOnStreamClosed(callback func(*Stream))
SetOnStreamClosed sets a callback for when streams are closed
func (*StreamManager) Stats ¶
func (m *StreamManager) Stats() StreamManagerStats
Stats returns the stream manager statistics
type StreamManagerStats ¶
type StreamManagerStats struct {
TotalStreams uint64
ActiveStreams uint64
ClosedStreams uint64
TotalBytesSent uint64
TotalBytesRecv uint64
}
StreamManagerStats holds statistics for the stream manager
type StreamState ¶
type StreamState int32
StreamState represents the current state of a stream
const ( // StreamStateNew indicates a newly created stream StreamStateNew StreamState = iota // StreamStateActive indicates an active, tunneling stream StreamStateActive // StreamStateClosing indicates a stream that is being closed StreamStateClosing // StreamStateClosed indicates a fully closed stream StreamStateClosed )
func (StreamState) String ¶
func (s StreamState) String() string
String returns the string representation of the stream state
type StreamStats ¶
type StreamStats struct {
ID int64
LocalID uint64
State StreamState
CreatedAt time.Time
LastActivity time.Time
BytesReceived uint64
BytesSent uint64
}
StreamStats holds statistics for a stream
type TCPAcceptor ¶
type TCPAcceptor struct {
// contains filtered or unexported fields
}
TCPAcceptor accepts incoming TCP connections and adds them to the stream manager
func NewTCPAcceptor ¶
func NewTCPAcceptor(streams *StreamManager, config *TCPAcceptorConfig) (*TCPAcceptor, error)
NewTCPAcceptor creates a new TCP acceptor
func (*TCPAcceptor) IsRunning ¶
func (a *TCPAcceptor) IsRunning() bool
IsRunning returns true if the acceptor is running
func (*TCPAcceptor) SetOnNewStream ¶
func (a *TCPAcceptor) SetOnNewStream(callback func(*Stream))
SetOnNewStream sets the callback for new streams
func (*TCPAcceptor) Stats ¶
func (a *TCPAcceptor) Stats() TCPAcceptorStats
Stats returns acceptor statistics
type TCPAcceptorConfig ¶
type TCPAcceptorConfig struct {
// ListenAddr is the address to listen on
ListenAddr string
// StreamConfig is the configuration for new streams
StreamConfig *StreamConfig
// AcceptTimeout is the timeout for accepting connections
AcceptTimeout time.Duration
}
TCPAcceptorConfig holds configuration for the TCP acceptor
func DefaultTCPAcceptorConfig ¶
func DefaultTCPAcceptorConfig() *TCPAcceptorConfig
DefaultTCPAcceptorConfig returns default TCP acceptor configuration
type TCPAcceptorStats ¶
TCPAcceptorStats holds statistics for the TCP acceptor
type WeightedPathScheduler ¶
type WeightedPathScheduler struct {
// contains filtered or unexported fields
}
WeightedPathScheduler selects paths based on weighted probability
func NewWeightedPathScheduler ¶
func NewWeightedPathScheduler() *WeightedPathScheduler
NewWeightedPathScheduler creates a new weighted scheduler
func (*WeightedPathScheduler) AddPath ¶
func (s *WeightedPathScheduler) AddPath(pathID int)
AddPath adds a path with default metrics
func (*WeightedPathScheduler) RemovePath ¶
func (s *WeightedPathScheduler) RemovePath(pathID int)
RemovePath removes a path
func (*WeightedPathScheduler) SelectPath ¶
func (s *WeightedPathScheduler) SelectPath() int
SelectPath returns a path based on weighted probability (inverse RTT)
func (*WeightedPathScheduler) UpdatePathMetrics ¶
func (s *WeightedPathScheduler) UpdatePathMetrics(pathID int, rtt time.Duration, loss float64)
UpdatePathMetrics updates the metrics for a path