Documentation
¶
Overview ¶
Package websockets used for communicating with the server via WebSocket protocol
Package websockets used for communicating with the server via WebSocket protocol ¶
Package websockets provides functions to manage the CookieFarm client submission.
Index ¶
- Variables
- func ConfigHandler(payload json.RawMessage) error
- func GetConnection() (*websocket.Conn, error)
- func Start(flagsChan <-chan models.ClientData) error
- func WSHandleMessage(message []byte) error
- func WSReader(conn *websocket.Conn)
- type CircuitBreaker
- type CircuitState
- type ConnectionMonitor
- func (m *ConnectionMonitor) GetStats() ConnectionStats
- func (m *ConnectionMonitor) GetStatus() ConnectionStatus
- func (m *ConnectionMonitor) MeasureLatency()
- func (m *ConnectionMonitor) RecordDisconnect(err error)
- func (m *ConnectionMonitor) RecordMessageReceived()
- func (m *ConnectionMonitor) RecordMessageSent()
- func (m *ConnectionMonitor) SetConnection(conn *websocket.Conn)
- func (m *ConnectionMonitor) SetStatus(status ConnectionStatus)
- func (m *ConnectionMonitor) StopMonitoring()
- type ConnectionStats
- type ConnectionStatus
- type Event
- type EventWS
- type EventWSFlag
- type NewMessageEvent
Constants ¶
This section is empty.
Variables ¶
var (
ErrCircuitOpen = errors.New("circuit breaker is open")
)
var OnNewConfig func()
Functions ¶
func ConfigHandler ¶
func ConfigHandler(payload json.RawMessage) error
ConfigHandler processes the configuration update received from the WebSocket server
func GetConnection ¶
bad handshake (401) connection refused (503)
func Start ¶
func Start(flagsChan <-chan models.ClientData) error
Start initializes the submission loop to the cookiefarm server.
func WSHandleMessage ¶
WSHandleMessage processes incoming WebSocket messages based on their type
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker is a struct that implements the circuit breaker pattern
func (*CircuitBreaker) IsAllowed ¶
func (cb *CircuitBreaker) IsAllowed() bool
IsAllowed checks if a connection attempt is allowed based on the circuit breaker state
func (*CircuitBreaker) RecordFailure ¶
func (cb *CircuitBreaker) RecordFailure()
RecordFailure registers a failed connection attempt and updates the state
func (*CircuitBreaker) RecordSuccess ¶
func (cb *CircuitBreaker) RecordSuccess()
RecordSuccess registers a successful connection and resets the failure count
type CircuitState ¶
type CircuitState int
CircuitState state of the circuit breaker
const ( FlagEvent = "flag" ConfigEvent = "config" StateClosed CircuitState = iota // Allowed connections StateHalfOpen // Allowed connections with limited retries StateOpen // Blocked connections )
type ConnectionMonitor ¶
type ConnectionMonitor struct {
// contains filtered or unexported fields
}
ConnectionMonitor monitors WebSocket connections and provides statistics
func GetMonitor ¶
func GetMonitor() *ConnectionMonitor
GetMonitor returns the singleton instance of ConnectionMonitor
func (*ConnectionMonitor) GetStats ¶
func (m *ConnectionMonitor) GetStats() ConnectionStats
GetStats returns a copy of the current connection statistics
func (*ConnectionMonitor) GetStatus ¶
func (m *ConnectionMonitor) GetStatus() ConnectionStatus
GetStatus returns the current connection status
func (*ConnectionMonitor) MeasureLatency ¶
func (m *ConnectionMonitor) MeasureLatency()
MeasureLatency sends a ping and measures the time until pong is received
func (*ConnectionMonitor) RecordDisconnect ¶
func (m *ConnectionMonitor) RecordDisconnect(err error)
RecordDisconnect records a disconnection event
func (*ConnectionMonitor) RecordMessageReceived ¶
func (m *ConnectionMonitor) RecordMessageReceived()
RecordMessageReceived records statistics about received messages
func (*ConnectionMonitor) RecordMessageSent ¶
func (m *ConnectionMonitor) RecordMessageSent()
RecordMessageSent records statistics about sent messages
func (*ConnectionMonitor) SetConnection ¶
func (m *ConnectionMonitor) SetConnection(conn *websocket.Conn)
SetConnection registers a WebSocket connection with the monitor
func (*ConnectionMonitor) SetStatus ¶
func (m *ConnectionMonitor) SetStatus(status ConnectionStatus)
SetStatus updates the connection status
func (*ConnectionMonitor) StopMonitoring ¶
func (m *ConnectionMonitor) StopMonitoring()
StopMonitoring stops the monitoring process
type ConnectionStats ¶
type ConnectionStats struct {
// Connection tracking
ConnectionAttempts int
SuccessfulConnects int
FailedConnects int
LastConnectTime time.Time
LastDisconnectTime time.Time
// Message tracking
MessagesSent int
MessagesReceived int
LastSendTime time.Time
LastReceiveTime time.Time
// Error tracking
LastError error
ConsecutiveErrs int
// Status
CurrentStatus ConnectionStatus
// Latency tracking
LastPingTime time.Time
LastPongTime time.Time
CurrentLatency time.Duration
AverageLatency time.Duration
// contains filtered or unexported fields
}
ConnectionStats holds statistics about the WebSocket connection
type ConnectionStatus ¶
type ConnectionStatus int
ConnectionStatus represents the current status of the WebSocket connection
const ( StatusDisconnected ConnectionStatus = iota StatusConnecting StatusConnected StatusReconnecting StatusFailed )
type Event ¶
type Event struct {
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
type EventWSFlag ¶
type EventWSFlag struct {
Type string `json:"type"`
Payload models.ClientData `json:"payload"`
}
type NewMessageEvent ¶
NewMessageEvent represents a new message event