server

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitAlertBuffer added in v0.12.0

func InitAlertBuffer(capacity int)

InitAlertBuffer creates the package-level alert ring buffer. Must be called once before RunForever.

func Run

func Run(ctx context.Context, startTime time.Time, plugins []string) error

Run performs a single connection lifecycle: dial → register → ack → loops. Returns nil only when ctx is cancelled (clean shutdown).

func RunForever

func RunForever(ctx context.Context, startTime time.Time, plugins []string)

RunForever wraps Run with reconnect logic. It blocks until ctx is cancelled. Backoff strategy per proto.md §7:

  • Normal disconnect: 1s → 2s → ... → 300s, ±25% jitter
  • Auth failure (401): 60s → 120s → ... → 1800s, ±25% jitter

func SendAlertEvent added in v0.12.0

func SendAlertEvent(event *types.Event)

SendAlertEvent enqueues an alert event into the ring buffer. Safe to call even when the WebSocket connection is down. NOTE: the event pointer is stored as-is; callers must not reuse/mutate the Event after this call. The current engine always creates fresh Events.

Types

type Conn

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

Conn manages one WebSocket connection to catpaw-server.

type Message

type Message struct {
	Type    string          `json:"type"`
	ID      string          `json:"id"`
	RefID   string          `json:"ref_id,omitempty"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Message is the protocol envelope for all Agent <-> Server communication.

type RingBuffer added in v0.12.0

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

RingBuffer is a fixed-capacity circular buffer for alert events. When full, the oldest event is overwritten (best-effort semantics). It is safe for concurrent use.

func NewRingBuffer added in v0.12.0

func NewRingBuffer(capacity int) *RingBuffer

func (*RingBuffer) Drain added in v0.12.0

func (r *RingBuffer) Drain(maxItems int) []*types.Event

Drain removes and returns up to maxItems events from the buffer in FIFO order. Returns nil if the buffer is empty.

func (*RingBuffer) Len added in v0.12.0

func (r *RingBuffer) Len() int

Len returns the current number of events in the buffer.

func (*RingBuffer) Push added in v0.12.0

func (r *RingBuffer) Push(event *types.Event)

Push adds an event to the ring buffer. If the buffer is full, the oldest event is overwritten.

Jump to

Keyboard shortcuts

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