sync

package
v0.37.3 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Unlicense Imports: 25 Imported by: 0

Documentation

Overview

Package sync provides NIP-11 relay information document fetching and caching

Package sync provides relay group configuration management

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterManager added in v0.24.2

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

func NewClusterManager added in v0.24.2

func NewClusterManager(ctx context.Context, db *database.D, adminNpubs []string, propagatePrivilegedEvents bool, publisher interface{ Deliver(*event.E) }) *ClusterManager

func (*ClusterManager) HandleEventsRange added in v0.24.2

func (cm *ClusterManager) HandleEventsRange(w http.ResponseWriter, r *http.Request)

func (*ClusterManager) HandleLatestSerial added in v0.24.2

func (cm *ClusterManager) HandleLatestSerial(w http.ResponseWriter, r *http.Request)

func (*ClusterManager) HandleMembershipEvent added in v0.24.2

func (cm *ClusterManager) HandleMembershipEvent(event *event.E) error

HandleMembershipEvent processes a cluster membership event (Kind 39108)

func (*ClusterManager) Start added in v0.24.2

func (cm *ClusterManager) Start()

func (*ClusterManager) Stop added in v0.24.2

func (cm *ClusterManager) Stop()

func (*ClusterManager) UpdateMembership added in v0.24.2

func (cm *ClusterManager) UpdateMembership(relayURLs []string)

type ClusterMember added in v0.24.2

type ClusterMember struct {
	HTTPURL      string
	WebSocketURL string
	LastSerial   uint64
	LastPoll     time.Time
	Status       string // "active", "error", "unknown"
	ErrorCount   int
}

type CurrentRequest

type CurrentRequest struct {
	NodeID   string `json:"node_id"`
	RelayURL string `json:"relay_url"`
}

CurrentRequest represents a request for the current serial number

type CurrentResponse

type CurrentResponse struct {
	NodeID   string `json:"node_id"`
	RelayURL string `json:"relay_url"`
	Serial   uint64 `json:"serial"`
}

CurrentResponse returns the current serial number

type EventIDsRequest added in v0.24.1

type EventIDsRequest struct {
	NodeID   string `json:"node_id"`
	RelayURL string `json:"relay_url"`
	From     uint64 `json:"from"`
	To       uint64 `json:"to"`
}

EventIDsRequest represents a request for event IDs with serials

type EventIDsResponse added in v0.24.1

type EventIDsResponse struct {
	EventMap map[string]uint64 `json:"event_map"` // event_id -> serial
}

EventIDsResponse contains event IDs mapped to their serial numbers

type EventInfo added in v0.24.2

type EventInfo struct {
	Serial    uint64 `json:"serial"`
	ID        string `json:"id"`
	Timestamp int64  `json:"timestamp"`
}

type EventsRangeResponse added in v0.24.2

type EventsRangeResponse struct {
	Events   []EventInfo `json:"events"`
	HasMore  bool        `json:"has_more"`
	NextFrom uint64      `json:"next_from,omitempty"`
}

type LatestSerialResponse added in v0.24.2

type LatestSerialResponse struct {
	Serial    uint64 `json:"serial"`
	Timestamp int64  `json:"timestamp"`
}

type Manager

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

Manager handles distributed synchronization between relay peers using serial numbers as clocks

func NewManager

func NewManager(ctx context.Context, db *database.D, nodeID, relayURL string, peers []string, relayGroupMgr *RelayGroupManager, policyManager interface {
	CheckPolicy(action string, ev *event.E, pubkey []byte, remote string) (bool, error)
}) *Manager

NewManager creates a new sync manager

func (*Manager) GetCurrentSerial

func (m *Manager) GetCurrentSerial() uint64

GetCurrentSerial returns the current serial number

func (*Manager) GetPeerPubkey added in v0.24.1

func (m *Manager) GetPeerPubkey(peerURL string) (string, error)

GetPeerPubkey fetches and caches the pubkey for a peer relay

func (*Manager) GetPeers added in v0.24.1

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

GetPeers returns a copy of the current peer list

func (*Manager) HandleCurrentRequest

func (m *Manager) HandleCurrentRequest(w http.ResponseWriter, r *http.Request)

HandleCurrentRequest handles requests for current serial number

func (*Manager) HandleEventIDsRequest added in v0.24.1

func (m *Manager) HandleEventIDsRequest(w http.ResponseWriter, r *http.Request)

HandleEventIDsRequest handles requests for event IDs with their serial numbers

func (*Manager) IsAuthorizedPeer added in v0.24.1

func (m *Manager) IsAuthorizedPeer(peerURL string, expectedPubkey string) bool

IsAuthorizedPeer checks if a peer is authorized by validating its NIP-11 pubkey

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the sync manager

func (*Manager) UpdatePeers added in v0.24.1

func (m *Manager) UpdatePeers(newPeers []string)

UpdatePeers updates the peer list from relay group configuration

func (*Manager) UpdateSerial

func (m *Manager) UpdateSerial()

UpdateSerial updates the current serial number when a new event is stored

type NIP11Cache added in v0.24.1

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

NIP11Cache caches relay information documents with TTL

func NewNIP11Cache added in v0.24.1

func NewNIP11Cache(ttl time.Duration) *NIP11Cache

NewNIP11Cache creates a new NIP-11 cache with the specified TTL

func (*NIP11Cache) Get added in v0.24.1

func (c *NIP11Cache) Get(ctx context.Context, relayURL string) (*relayinfo.T, error)

Get fetches relay information for a given URL, using cache if available

func (*NIP11Cache) GetPubkey added in v0.24.1

func (c *NIP11Cache) GetPubkey(ctx context.Context, relayURL string) (string, error)

GetPubkey fetches the relay's identity pubkey from its NIP-11 document

type RelayGroupConfig added in v0.24.1

type RelayGroupConfig struct {
	Relays []string `json:"relays"`
}

RelayGroupConfig represents a relay group configuration event

type RelayGroupManager added in v0.24.1

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

RelayGroupManager handles relay group configuration

func NewRelayGroupManager added in v0.24.1

func NewRelayGroupManager(db *database.D, adminNpubs []string) *RelayGroupManager

NewRelayGroupManager creates a new relay group manager

func (*RelayGroupManager) FindAuthoritativeConfig added in v0.24.1

func (rgm *RelayGroupManager) FindAuthoritativeConfig(ctx context.Context) (*RelayGroupConfig, error)

FindAuthoritativeConfig finds the authoritative relay group configuration by selecting the latest event by timestamp, with hash tie-breaking

func (*RelayGroupManager) HandleRelayGroupEvent added in v0.24.1

func (rgm *RelayGroupManager) HandleRelayGroupEvent(ev *event.E, syncManager *Manager)

HandleRelayGroupEvent processes a relay group configuration event and updates peer lists

func (*RelayGroupManager) IsAuthorizedPublisher added in v0.24.1

func (rgm *RelayGroupManager) IsAuthorizedPublisher(pubkey []byte) bool

IsAuthorizedPublisher checks if a pubkey is authorized to publish relay group configs

func (*RelayGroupManager) ValidateRelayGroupEvent added in v0.24.1

func (rgm *RelayGroupManager) ValidateRelayGroupEvent(ev *event.E) error

ValidateRelayGroupEvent validates a relay group configuration event

Source Files

  • cluster.go
  • manager.go
  • nip11.go
  • relaygroup.go

Jump to

Keyboard shortcuts

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