negentropy

package
v0.55.4 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: Unlicense Imports: 16 Imported by: 0

Documentation

Overview

Package negentropy provides NIP-77 negentropy-based set reconciliation for both relay-to-relay sync and client-facing WebSocket operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientSession

type ClientSession struct {
	SubscriptionID string
	ConnectionID   string
	CreatedAt      time.Time
	LastActivity   time.Time
	RoundCount     int32
	// contains filtered or unexported fields
}

ClientSession represents an active client negentropy session.

func (*ClientSession) GetNegentropy

func (s *ClientSession) GetNegentropy() *negentropy.Negentropy

GetNegentropy returns the negentropy instance for this session.

func (*ClientSession) SetNegentropy

func (s *ClientSession) SetNegentropy(neg *negentropy.Negentropy, storage *negentropy.Vector)

SetNegentropy sets the negentropy instance and storage for this session.

type Config

type Config struct {
	Peers                []string
	SyncInterval         time.Duration
	FrameSize            int
	IDSize               int
	ClientSessionTimeout time.Duration
	Filter               *filter.F // Optional filter for selective sync
}

Config holds configuration for the negentropy manager.

type Manager

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

Manager handles negentropy sync operations.

func NewManager

func NewManager(db database.Database, cfg *Config) *Manager

NewManager creates a new negentropy manager.

func (*Manager) AddPeer

func (m *Manager) AddPeer(peerURL string)

AddPeer adds a peer for negentropy sync.

func (*Manager) CleanupExpiredSessions

func (m *Manager) CleanupExpiredSessions() int

CleanupExpiredSessions removes sessions that have been inactive beyond timeout.

func (*Manager) CloseSession

func (m *Manager) CloseSession(connectionID, subscriptionID string)

CloseSession closes a client session.

func (*Manager) CloseSessionsByConnection

func (m *Manager) CloseSessionsByConnection(connectionID string)

CloseSessionsByConnection closes all sessions for a connection.

func (*Manager) GetPeerState

func (m *Manager) GetPeerState(peerURL string) (*PeerState, bool)

GetPeerState returns the sync state for a specific peer.

func (*Manager) GetPeerStates

func (m *Manager) GetPeerStates() []*PeerState

GetPeerStates returns the sync state for all peers.

func (*Manager) GetPeers

func (m *Manager) GetPeers() []string

GetPeers returns the list of peer URLs.

func (*Manager) GetSession

func (m *Manager) GetSession(connectionID, subscriptionID string) (*ClientSession, bool)

GetSession retrieves an existing session.

func (*Manager) IsActive

func (m *Manager) IsActive() bool

IsActive returns whether background sync is running.

func (*Manager) LastSync

func (m *Manager) LastSync() time.Time

LastSync returns the timestamp of the last sync cycle.

func (*Manager) ListSessions

func (m *Manager) ListSessions() []*ClientSession

ListSessions returns all active sessions.

func (*Manager) OpenSession

func (m *Manager) OpenSession(connectionID, subscriptionID string) *ClientSession

OpenSession opens a new client negentropy session.

func (*Manager) RemovePeer

func (m *Manager) RemovePeer(peerURL string)

RemovePeer removes a peer from negentropy sync.

func (*Manager) Start

func (m *Manager) Start()

Start starts the background sync loop.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the background sync loop.

func (*Manager) TriggerSync

func (m *Manager) TriggerSync(ctx context.Context, peerURL string)

TriggerSync manually triggers sync with a specific peer or all peers.

func (*Manager) UpdateSessionActivity

func (m *Manager) UpdateSessionActivity(connectionID, subscriptionID string)

UpdateSessionActivity updates the last activity time for a session.

type PeerState

type PeerState struct {
	URL                 string
	LastSync            time.Time
	EventsSynced        int64
	Status              string // "idle", "syncing", "error"
	LastError           string
	ConsecutiveFailures int32
}

PeerState represents the sync state for a peer relay.

Source Files

  • manager.go

Directories

Path Synopsis
Package grpc provides a gRPC client for the negentropy sync service.
Package grpc provides a gRPC client for the negentropy sync service.
Package server provides the gRPC server implementation for negentropy sync.
Package server provides the gRPC server implementation for negentropy sync.

Jump to

Keyboard shortcuts

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