ipc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ipc provides a cross-platform inter-process communication layer for SENTINEL SOC Process Isolation (SEC-001).

On Linux: Unix Domain Sockets with SO_PEERCRED validation. On Windows: Named Pipes (\\.\pipe\sentinel-soc-*).

Protocol: newline-delimited JSON messages over the pipe. Each message has a Type field for routing (event, incident, ack, heartbeat).

Package ipc provides localhost IPC transport for Virtual Swarm peer synchronization using Named Pipes (Windows) or Unix Domain Sockets. Zero external dependencies — uses Go standard `net` package.

Index

Constants

View Source
const (
	SOCMsgEvent     SOCMsgType = "soc_event"     // Persisted event → correlate
	SOCMsgIncident  SOCMsgType = "soc_incident"  // Created incident → respond
	SOCMsgAck       SOCMsgType = "soc_ack"       // Acknowledgement
	SOCMsgHeartbeat SOCMsgType = "soc_heartbeat" // Keepalive

	// DefaultTimeout for IPC operations.
	DefaultTimeout = 5 * time.Second

	// MaxRetries for message delivery.
	MaxRetries = 3

	// BufferSize for pending messages when downstream is slow.
	BufferSize = 4096
)
View Source
const (
	MsgHandshake    = "handshake"
	MsgHandshakeAck = "handshake_ack"
	MsgSyncRequest  = "sync_request"
	MsgSyncPayload  = "sync_payload"
)

Message types for the IPC protocol.

Variables

This section is empty.

Functions

func Dial

func Dial(name string) (net.Conn, error)

Dial connects to an existing named pipe.

func DialWithRetry

func DialWithRetry(ctx context.Context, name string, maxRetries int) (net.Conn, error)

DialWithRetry attempts to connect to a named pipe with retries. Useful during startup when the downstream process may not be ready.

Types

type BufferedSender

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

BufferedSender wraps a Sender with an async buffer for non-blocking sends. If the downstream pipe is slow, messages are buffered up to BufferSize.

func NewBufferedSender

func NewBufferedSender(conn net.Conn, name string) *BufferedSender

NewBufferedSender creates a buffered async sender.

func (*BufferedSender) Close

func (bs *BufferedSender) Close() error

Close flushes remaining messages and shuts down.

func (*BufferedSender) Pending

func (bs *BufferedSender) Pending() int

Pending returns the number of messages waiting in the buffer.

func (*BufferedSender) Send

func (bs *BufferedSender) Send(msg *SOCMessage) error

Send enqueues a message for async delivery. Non-blocking if buffer isn't full.

type Listener

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

Listener accepts incoming IPC connections on a named pipe.

func Listen

func Listen(name string) (*Listener, error)

Listen creates a platform-specific named pipe listener. On Linux: Unix Domain Socket at /tmp/sentinel-<name>.sock On Windows: Named Pipe at \\.\pipe\sentinel-<name>

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept waits for and returns the next connection.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's address.

func (*Listener) Close

func (l *Listener) Close() error

Close shuts down the listener.

type Message

type Message struct {
	Type    string          `json:"type"`
	Payload json.RawMessage `json:"payload"`
}

Message is the wire format for IPC communication.

type Receiver

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

Receiver reads messages from an upstream IPC pipe.

func NewReceiver

func NewReceiver(conn net.Conn, name string) *Receiver

NewReceiver wraps a net.Conn for reading JSON messages.

func (*Receiver) Close

func (r *Receiver) Close() error

Close shuts down the receiver connection.

func (*Receiver) Next

func (r *Receiver) Next() (*SOCMessage, error)

Next reads the next message, blocking until available. Returns io.EOF when the connection is closed.

type SOCMessage

type SOCMessage struct {
	Type      SOCMsgType      `json:"type"`
	ID        string          `json:"id,omitempty"`
	Timestamp int64           `json:"ts"`
	Payload   json.RawMessage `json:"payload,omitempty"`
}

SOCMessage is the wire format for SOC process isolation IPC.

func NewSOCMessage

func NewSOCMessage(t SOCMsgType, payload any) (*SOCMessage, error)

NewSOCMessage creates a new SOC IPC message with the given type and payload.

type SOCMsgType

type SOCMsgType string

SOCMsgType identifies the SOC IPC message kind. Named differently from the Swarm transport Message to avoid conflicts.

type Sender

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

Sender writes messages to a downstream IPC pipe.

func NewSender

func NewSender(conn net.Conn, name string) *Sender

NewSender wraps a net.Conn for sending JSON messages.

func (*Sender) Close

func (s *Sender) Close() error

Close shuts down the sender connection.

func (*Sender) Send

func (s *Sender) Send(msg *SOCMessage) error

Send writes a message to the downstream pipe. Thread-safe.

func (*Sender) SendWithRetry

func (s *Sender) SendWithRetry(msg *SOCMessage) error

SendWithRetry attempts to send a message with retries.

type SwarmTransport

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

SwarmTransport manages localhost IPC for peer synchronization.

func NewSwarmTransport

func NewSwarmTransport(rlmDir string, reg *peer.Registry, store memory.FactStore, bus *alert.Bus) *SwarmTransport

NewSwarmTransport creates a new IPC transport.

func (*SwarmTransport) Dial

func (t *SwarmTransport) Dial(ctx context.Context) (bool, error)

Dial connects to a listening peer and performs handshake + sync. Returns true if sync was successful.

func (*SwarmTransport) IsListening

func (t *SwarmTransport) IsListening() bool

IsListening returns true if this transport is the active listener.

func (*SwarmTransport) Listen

func (t *SwarmTransport) Listen(ctx context.Context) error

Listen starts the IPC server. Blocks until context is cancelled. Only one instance can listen at a time — the first one wins.

Jump to

Keyboard shortcuts

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