Documentation
ΒΆ
Index ΒΆ
- type AdaptiveTimeoutStats
- type AdaptiveTimeouts
- func (at *AdaptiveTimeouts) Close() error
- func (at *AdaptiveTimeouts) GetMetrics() metrics.MetricsSnapshot
- func (at *AdaptiveTimeouts) GetStats() AdaptiveTimeoutStats
- func (at *AdaptiveTimeouts) GetTimeout(peerID peer.ID, operation string) time.Duration
- func (at *AdaptiveTimeouts) RecordRTT(peerID peer.ID, rtt time.Duration)
- func (at *AdaptiveTimeouts) RecordSuccess(peerID peer.ID, duration time.Duration)
- func (at *AdaptiveTimeouts) RecordTimeout(peerID peer.ID, timeoutValue time.Duration)
- func (at *AdaptiveTimeouts) SetStrategy(peerID peer.ID, strategy TimeoutStrategy)
- type BandwidthConfig
- type BandwidthManager
- type BandwidthStats
- type BatchedMessage
- type BatchingConfig
- type BatchingStats
- type ConnectionPool
- func (cp *ConnectionPool) Close() error
- func (cp *ConnectionPool) ConnectToPeer(ctx context.Context, addrs ...multiaddr.Multiaddr) error
- func (cp *ConnectionPool) GetConnection(ctx context.Context, peerID peer.ID) (network.Conn, error)
- func (cp *ConnectionPool) GetMetrics() metrics.MetricsSnapshot
- func (cp *ConnectionPool) GetStats() ConnectionPoolStats
- func (cp *ConnectionPool) GetStream(ctx context.Context, peerID peer.ID, proto protocol.ID) (network.Stream, error)
- func (cp *ConnectionPool) ReleaseConnection(peerID peer.ID)
- type ConnectionPoolConfig
- type ConnectionPoolStats
- type Direction
- type MessageBatcher
- func (mb *MessageBatcher) Close() error
- func (mb *MessageBatcher) DeserializeBatch(data []byte) ([]BatchedMessage, error)
- func (mb *MessageBatcher) Flush()
- func (mb *MessageBatcher) GetMetrics() metrics.MetricsSnapshot
- func (mb *MessageBatcher) GetStats() BatchingStats
- func (mb *MessageBatcher) QueueMessage(peerID peer.ID, msg BatchedMessage) error
- func (mb *MessageBatcher) SendImmediately(peerID peer.ID)
- type MessagePriority
- type OptimizationConfig
- type OptimizationStats
- type OptimizationStatus
- type OptimizedNetwork
- func (on *OptimizedNetwork) Addrs() []multiaddr.Multiaddr
- func (on *OptimizedNetwork) Close() error
- func (on *OptimizedNetwork) ConnectToPeer(ctx context.Context, addrs ...multiaddr.Multiaddr) error
- func (on *OptimizedNetwork) Flush()
- func (on *OptimizedNetwork) GetMetrics() map[string]metrics.MetricsSnapshot
- func (on *OptimizedNetwork) GetOptimizationStats() OptimizationStats
- func (on *OptimizedNetwork) GetStream(ctx context.Context, peerID peer.ID, proto protocol.ID) (network.Stream, error)
- func (on *OptimizedNetwork) ID() peer.ID
- func (on *OptimizedNetwork) Peers() []peer.ID
- func (on *OptimizedNetwork) Send(ctx context.Context, peerID peer.ID, data []byte) error
- func (on *OptimizedNetwork) UpdateConfiguration(config *OptimizationConfig) error
- type PeerTimeoutSummary
- type QoSQueueStats
- type TimeoutConfig
- type TimeoutStrategy
- type TrafficClass
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type AdaptiveTimeoutStats ΒΆ
type AdaptiveTimeoutStats struct {
TrackedPeers int
GlobalAverageRTT time.Duration
TotalRequests int64
TotalTimeouts int64
TimeoutRate float64
PeerStats map[peer.ID]PeerTimeoutSummary
}
AdaptiveTimeoutStats provides timeout statistics
type AdaptiveTimeouts ΒΆ
type AdaptiveTimeouts struct {
// contains filtered or unexported fields
}
AdaptiveTimeouts dynamically adjusts timeout values based on network conditions
func NewAdaptiveTimeouts ΒΆ
func NewAdaptiveTimeouts(config TimeoutConfig) *AdaptiveTimeouts
NewAdaptiveTimeouts creates a new adaptive timeout manager
func (*AdaptiveTimeouts) Close ΒΆ
func (at *AdaptiveTimeouts) Close() error
Close shuts down the adaptive timeout manager
func (*AdaptiveTimeouts) GetMetrics ΒΆ
func (at *AdaptiveTimeouts) GetMetrics() metrics.MetricsSnapshot
GetMetrics returns the current metrics for this adaptive timeout manager
func (*AdaptiveTimeouts) GetStats ΒΆ
func (at *AdaptiveTimeouts) GetStats() AdaptiveTimeoutStats
GetStats returns current adaptive timeout statistics
func (*AdaptiveTimeouts) GetTimeout ΒΆ
GetTimeout returns the appropriate timeout for a peer and operation
func (*AdaptiveTimeouts) RecordRTT ΒΆ
func (at *AdaptiveTimeouts) RecordRTT(peerID peer.ID, rtt time.Duration)
RecordRTT records a round-trip time measurement for a peer
func (*AdaptiveTimeouts) RecordSuccess ΒΆ
func (at *AdaptiveTimeouts) RecordSuccess(peerID peer.ID, duration time.Duration)
RecordSuccess records a successful operation for a peer
func (*AdaptiveTimeouts) RecordTimeout ΒΆ
func (at *AdaptiveTimeouts) RecordTimeout(peerID peer.ID, timeoutValue time.Duration)
RecordTimeout records a timeout for a peer
func (*AdaptiveTimeouts) SetStrategy ΒΆ
func (at *AdaptiveTimeouts) SetStrategy(peerID peer.ID, strategy TimeoutStrategy)
SetStrategy sets the timeout strategy for a specific peer
type BandwidthConfig ΒΆ
type BandwidthConfig struct {
MaxUpload int64 // bytes per second
MaxDownload int64 // bytes per second
QoSEnabled bool // Enable Quality of Service
TokenRefillRate time.Duration // How often to refill token buckets
BurstSize int64 // Maximum burst size in bytes
PeerLimitRatio float64 // Max bandwidth per peer as ratio of total
// QoS class configurations
HighPriorityRatio float64 // Bandwidth reserved for high priority traffic
NormalPriorityRatio float64 // Bandwidth reserved for normal priority traffic
LowPriorityRatio float64 // Bandwidth reserved for low priority traffic
}
BandwidthConfig defines bandwidth management parameters
func DefaultBandwidthConfig ΒΆ
func DefaultBandwidthConfig() BandwidthConfig
DefaultBandwidthConfig returns sensible defaults
type BandwidthManager ΒΆ
type BandwidthManager struct {
// contains filtered or unexported fields
}
BandwidthManager controls and monitors network bandwidth usage
func NewBandwidthManager ΒΆ
func NewBandwidthManager(config BandwidthConfig) *BandwidthManager
NewBandwidthManager creates a new bandwidth manager
func (*BandwidthManager) Close ΒΆ
func (bm *BandwidthManager) Close() error
Close shuts down the bandwidth manager
func (*BandwidthManager) GetMetrics ΒΆ
func (bm *BandwidthManager) GetMetrics() metrics.MetricsSnapshot
GetMetrics returns the current metrics for this bandwidth manager
func (*BandwidthManager) GetStats ΒΆ
func (bm *BandwidthManager) GetStats() BandwidthStats
GetStats returns current bandwidth statistics
func (*BandwidthManager) RequestBandwidth ΒΆ
func (bm *BandwidthManager) RequestBandwidth(peerID peer.ID, class TrafficClass, direction Direction, bytes int64) bool
RequestBandwidth attempts to allocate bandwidth for a transfer
type BandwidthStats ΒΆ
type BandwidthStats struct {
UploadUsed int64
DownloadUsed int64
UploadLimit int64
DownloadLimit int64
ActivePeers int
QoSEnabled bool
QoSQueues map[TrafficClass]QoSQueueStats
}
BandwidthStats provides bandwidth usage statistics
type BatchedMessage ΒΆ
type BatchedMessage struct {
ID string
Data []byte
Priority MessagePriority
Callback func(error) // Called when message is sent
}
BatchedMessage represents a message to be batched
type BatchingConfig ΒΆ
type BatchingConfig struct {
MaxBatchSize int // Maximum messages per batch
MaxBatchBytes int // Maximum bytes per batch
BatchTimeout time.Duration // Maximum time to wait for batch completion
CompressionLevel int // Gzip compression level (1-9, 0=disabled)
EnablePriority bool // Enable priority message handling
WorkerCount int // Number of batch processing workers
}
BatchingConfig defines message batching parameters
func DefaultBatchingConfig ΒΆ
func DefaultBatchingConfig() BatchingConfig
DefaultBatchingConfig returns sensible defaults
type BatchingStats ΒΆ
BatchingStats provides batching statistics
type ConnectionPool ΒΆ
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool manages a pool of reusable connections to peers
func NewConnectionPool ΒΆ
func NewConnectionPool(h host.Host, config ConnectionPoolConfig) *ConnectionPool
NewConnectionPool creates a new connection pool
func (*ConnectionPool) Close ΒΆ
func (cp *ConnectionPool) Close() error
Close shuts down the connection pool
func (*ConnectionPool) ConnectToPeer ΒΆ
ConnectToPeer establishes a connection to a peer given their addresses
func (*ConnectionPool) GetConnection ΒΆ
GetConnection returns a connection to the specified peer
func (*ConnectionPool) GetMetrics ΒΆ
func (cp *ConnectionPool) GetMetrics() metrics.MetricsSnapshot
GetMetrics returns the current metrics for this connection pool
func (*ConnectionPool) GetStats ΒΆ
func (cp *ConnectionPool) GetStats() ConnectionPoolStats
GetStats returns current pool statistics
func (*ConnectionPool) GetStream ΒΆ
func (cp *ConnectionPool) GetStream(ctx context.Context, peerID peer.ID, proto protocol.ID) (network.Stream, error)
GetStream returns a stream to the specified peer using the given protocol
func (*ConnectionPool) ReleaseConnection ΒΆ
func (cp *ConnectionPool) ReleaseConnection(peerID peer.ID)
ReleaseConnection marks a connection as no longer in use
type ConnectionPoolConfig ΒΆ
type ConnectionPoolConfig struct {
MaxConnections int // Maximum total connections
MaxPerPeer int // Maximum connections per peer
IdleTimeout time.Duration // Time before closing idle connections
HealthCheckInterval time.Duration // How often to check connection health
ConnectTimeout time.Duration // Timeout for new connections
RetryAttempts int // Number of retry attempts for failed connections
RetryBackoff time.Duration // Backoff between retry attempts
}
ConnectionPoolConfig defines connection pool parameters
func DefaultConnectionPoolConfig ΒΆ
func DefaultConnectionPoolConfig() ConnectionPoolConfig
DefaultConnectionPoolConfig returns sensible defaults
type ConnectionPoolStats ΒΆ
ConnectionPoolStats provides pool statistics
type MessageBatcher ΒΆ
type MessageBatcher struct {
// contains filtered or unexported fields
}
MessageBatcher groups multiple small messages into larger batches to reduce protocol overhead and improve network efficiency
func NewMessageBatcher ΒΆ
func NewMessageBatcher(config BatchingConfig) *MessageBatcher
NewMessageBatcher creates a new message batcher
func (*MessageBatcher) Close ΒΆ
func (mb *MessageBatcher) Close() error
Close shuts down the message batcher
func (*MessageBatcher) DeserializeBatch ΒΆ
func (mb *MessageBatcher) DeserializeBatch(data []byte) ([]BatchedMessage, error)
DeserializeBatch parses a received batch
func (*MessageBatcher) Flush ΒΆ
func (mb *MessageBatcher) Flush()
Flush forces all pending batches to be sent immediately
func (*MessageBatcher) GetMetrics ΒΆ
func (mb *MessageBatcher) GetMetrics() metrics.MetricsSnapshot
GetMetrics returns the current metrics for this message batcher
func (*MessageBatcher) GetStats ΒΆ
func (mb *MessageBatcher) GetStats() BatchingStats
GetStats returns current batching statistics
func (*MessageBatcher) QueueMessage ΒΆ
func (mb *MessageBatcher) QueueMessage(peerID peer.ID, msg BatchedMessage) error
QueueMessage adds a message to the batching queue
func (*MessageBatcher) SendImmediately ΒΆ
func (mb *MessageBatcher) SendImmediately(peerID peer.ID)
SendImmediately forces immediate sending of any pending batch for a peer
type MessagePriority ΒΆ
type MessagePriority int
MessagePriority defines message priority levels
const ( PriorityLow MessagePriority = iota PriorityNormal PriorityHigh PriorityUrgent )
type OptimizationConfig ΒΆ
type OptimizationConfig struct {
EnableConnectionPool bool
EnableMessageBatching bool
EnableBandwidthManager bool
EnableAdaptiveTimeouts bool
// Component configurations
ConnectionPool ConnectionPoolConfig
MessageBatching BatchingConfig
BandwidthManager BandwidthConfig
AdaptiveTimeouts TimeoutConfig
}
OptimizationConfig defines which optimizations to enable
func DefaultOptimizationConfig ΒΆ
func DefaultOptimizationConfig() *OptimizationConfig
DefaultOptimizationConfig returns sensible defaults for all optimizations
type OptimizationStats ΒΆ
type OptimizationStats struct {
Enabled OptimizationStatus
ConnectionPool ConnectionPoolStats
MessageBatching BatchingStats
BandwidthManager BandwidthStats
AdaptiveTimeouts AdaptiveTimeoutStats
}
OptimizationStats provides comprehensive optimization statistics
type OptimizationStatus ΒΆ
type OptimizationStatus struct {
ConnectionPool bool
MessageBatching bool
BandwidthManager bool
AdaptiveTimeouts bool
}
OptimizationStatus shows which optimizations are enabled
type OptimizedNetwork ΒΆ
type OptimizedNetwork struct {
// contains filtered or unexported fields
}
OptimizedNetwork wraps the basic network wrapper with advanced optimizations
func NewOptimizedNetwork ΒΆ
func NewOptimizedNetwork(baseNetwork *networkpkg.HostWrapper, config *OptimizationConfig) (*OptimizedNetwork, error)
NewOptimizedNetwork creates a new optimized network wrapper
func (*OptimizedNetwork) Addrs ΒΆ
func (on *OptimizedNetwork) Addrs() []multiaddr.Multiaddr
Addrs returns the addresses of the underlying host
func (*OptimizedNetwork) Close ΒΆ
func (on *OptimizedNetwork) Close() error
Close shuts down the optimized network and all its components
func (*OptimizedNetwork) ConnectToPeer ΒΆ
ConnectToPeer connects to a peer with optimizations
func (*OptimizedNetwork) Flush ΒΆ
func (on *OptimizedNetwork) Flush()
Flush forces all pending optimizations to complete
func (*OptimizedNetwork) GetMetrics ΒΆ
func (on *OptimizedNetwork) GetMetrics() map[string]metrics.MetricsSnapshot
GetMetrics returns combined metrics from all components
func (*OptimizedNetwork) GetOptimizationStats ΒΆ
func (on *OptimizedNetwork) GetOptimizationStats() OptimizationStats
GetOptimizationStats returns statistics for all optimization components
func (*OptimizedNetwork) GetStream ΒΆ
func (on *OptimizedNetwork) GetStream(ctx context.Context, peerID peer.ID, proto protocol.ID) (network.Stream, error)
GetStream returns an optimized stream to a peer
func (*OptimizedNetwork) ID ΒΆ
func (on *OptimizedNetwork) ID() peer.ID
ID returns the peer ID of the underlying host
func (*OptimizedNetwork) Peers ΒΆ
func (on *OptimizedNetwork) Peers() []peer.ID
Peers returns the connected peers
func (*OptimizedNetwork) UpdateConfiguration ΒΆ
func (on *OptimizedNetwork) UpdateConfiguration(config *OptimizationConfig) error
UpdateConfiguration updates the optimization configuration
type PeerTimeoutSummary ΒΆ
type PeerTimeoutSummary struct {
CurrentRTT time.Duration
RTTVariance time.Duration
SuccessCount int64
FailureCount int64
SuccessRate float64
Strategy TimeoutStrategy
LastSeen time.Time
}
PeerTimeoutSummary provides per-peer timeout statistics
type QoSQueueStats ΒΆ
QoSQueueStats provides per-queue statistics
type TimeoutConfig ΒΆ
type TimeoutConfig struct {
MinTimeout time.Duration // Minimum timeout value
MaxTimeout time.Duration // Maximum timeout value
InitialTimeout time.Duration // Initial timeout for new peers
RTTMultiplier float64 // Multiplier for RTT-based timeout calculation
VarianceMultiplier float64 // Multiplier for RTT variance
AdaptationRate float64 // How quickly to adapt (0-1)
DecayRate float64 // How quickly old samples decay (0-1)
SampleWindowSize int // Number of samples to keep for calculation
CleanupInterval time.Duration // How often to clean up old peer stats
PeerTimeoutTTL time.Duration // How long to keep peer stats
}
TimeoutConfig defines adaptive timeout parameters
func DefaultTimeoutConfig ΒΆ
func DefaultTimeoutConfig() TimeoutConfig
DefaultTimeoutConfig returns sensible defaults
type TimeoutStrategy ΒΆ
type TimeoutStrategy int
TimeoutStrategy defines different timeout calculation strategies
const ( StrategyFixed TimeoutStrategy = iota StrategyRTTBased StrategyAdaptive StrategyAggressive StrategyConservative )
type TrafficClass ΒΆ
type TrafficClass int
TrafficClass defines different classes of network traffic
const ( TrafficClassLow TrafficClass = iota TrafficClassNormal TrafficClassHigh TrafficClassSystem // For critical system messages )