distributed

package
v0.55.6 Latest Latest
Warning

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

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

Documentation

Overview

Package distributed provides serial-based peer-to-peer synchronization

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	NodeID        string
	RelayURL      string
	Peers         []string
	SyncInterval  time.Duration
	NIP11CacheTTL time.Duration
}

Config holds configuration for the distributed sync manager

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default configuration

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

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

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

EventIDsResponse contains event IDs mapped to their serial numbers

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, cfg *Config, policyManager PolicyChecker) *Manager

NewManager creates a new sync manager

func (*Manager) GetCurrentSerial

func (m *Manager) GetCurrentSerial() uint64

GetCurrentSerial returns the current serial number

func (*Manager) GetEventsWithIDs

func (m *Manager) GetEventsWithIDs(from, to uint64) (map[string]uint64, error)

GetEventsWithIDs retrieves events with their IDs by serial range

func (*Manager) GetNodeID

func (m *Manager) GetNodeID() string

GetNodeID returns the node's identity

func (*Manager) GetPeerPubkey

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

GetPeerPubkey fetches and caches the pubkey for a peer relay

func (*Manager) GetPeerStatus

func (m *Manager) GetPeerStatus() map[string]uint64

GetPeerStatus returns the sync status for all peers

func (*Manager) GetPeers

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

GetPeers returns a copy of the current peer list

func (*Manager) GetRelayURL

func (m *Manager) GetRelayURL() string

GetRelayURL returns the relay's URL

func (*Manager) HandleCurrentRequest

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

HandleCurrentRequest handles requests for current serial number

func (*Manager) HandleEventIDsRequest

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

HandleEventIDsRequest handles requests for event IDs with their serial numbers

func (*Manager) IsAuthorizedPeer

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

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

func (*Manager) IsSelfNodeID

func (m *Manager) IsSelfNodeID(nodeID string) bool

IsSelfNodeID checks if a node ID matches ours

func (*Manager) IsSelfURL

func (m *Manager) IsSelfURL(url string) bool

IsSelfURL checks if a URL is our own relay

func (*Manager) MarkSelfURL

func (m *Manager) MarkSelfURL(url string)

MarkSelfURL marks a URL as belonging to us

func (*Manager) NotifyNewEvent

func (m *Manager) NotifyNewEvent(eventID []byte, serial uint64)

NotifyNewEvent notifies the manager of a new event

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the sync manager

func (*Manager) UpdatePeers

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 PolicyChecker

type PolicyChecker interface {
	CheckPolicy(action string, ev *event.E, pubkey []byte, remote string) (bool, error)
}

PolicyChecker is an interface for checking event policies

type RelayGroupConfigProvider

type RelayGroupConfigProvider interface {
	FindAuthoritativeConfig(ctx context.Context) ([]string, error)
}

RelayGroupConfigProvider provides relay group configuration

Source Files

  • manager.go

Directories

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

Jump to

Keyboard shortcuts

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