federation

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashToken

func HashToken(token string) string

HashToken computes sha256 hex string for the peer auth token.

Types

type Config

type Config struct {
	Store        *Store
	Relays       RelaySource
	Version      string
	SyncInterval time.Duration
	Log          *slog.Logger
	HTTPClient   *http.Client
}

Config configures the federation service.

type CreatePeerInput

type CreatePeerInput struct {
	Name       string
	APIURL     string
	AuthToken  string
	SyncRelays bool
}

CreatePeerInput is input for registering a new peer panel.

type FederatedRelay

type FederatedRelay struct {
	ID         int64     `json:"id"`
	PeerID     int64     `json:"peer_id"`
	PeerName   string    `json:"peer_name,omitempty"`
	RemoteName string    `json:"remote_name"`
	PublicHost string    `json:"public_host"`
	Region     string    `json:"region,omitempty"`
	Health     string    `json:"health"`
	LastSyncAt time.Time `json:"last_sync_at"`
}

FederatedRelay represents a relay announced by a peered RD Panel.

type HealthDTO

type HealthDTO struct {
	Status        string `json:"status"`
	Version       string `json:"version"`
	ActiveRelays  int    `json:"active_relays"`
	TimestampNano int64  `json:"timestamp_nano"`
}

HealthDTO is the response to /api/v1/federation/health.

type Peer

type Peer struct {
	ID         int64      `json:"id"`
	Name       string     `json:"name"`
	APIURL     string     `json:"api_url"`
	TokenHash  string     `json:"-"`
	SyncRelays bool       `json:"sync_relays"`
	Status     PeerStatus `json:"status"`
	LastSyncAt *time.Time `json:"last_sync_at,omitempty"`
	LastError  *string    `json:"last_error,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

Peer represents an external peered RD Panel instance.

type PeerStatus

type PeerStatus string

PeerStatus is the connection status of a peered RD Panel.

const (
	StatusUnknown     PeerStatus = "unknown"
	StatusActive      PeerStatus = "active"
	StatusUnreachable PeerStatus = "unreachable"
)

type PublicRelayDTO

type PublicRelayDTO struct {
	Name       string `json:"name"`
	PublicHost string `json:"public_host"`
	Region     string `json:"region,omitempty"`
	Health     string `json:"health"`
}

PublicRelayDTO is what a panel announces to peers.

type RelaySource

type RelaySource interface {
	List(ctx context.Context) ([]relays.View, relays.Rotation, error)
}

RelaySource provides active local relays to announce.

type Service

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

Service manages federation peering, relay synchronization and public federation endpoints.

func NewService

func NewService(cfg Config) *Service

NewService creates a new federation service.

func (*Service) PublicHealth

func (s *Service) PublicHealth(ctx context.Context) HealthDTO

PublicHealth returns local health for peering verification.

func (*Service) PublicRelays

func (s *Service) PublicRelays(ctx context.Context) ([]PublicRelayDTO, error)

PublicRelays returns local active relays for peering peers.

func (*Service) RegisterPeerToken

func (s *Service) RegisterPeerToken(peerID int64, token string)

RegisterPeerToken caches the plaintext token in-memory for outgoing sync requests.

func (*Service) Start

func (s *Service) Start(ctx context.Context)

Start begins the background sync loop.

func (*Service) Store

func (s *Service) Store() *Store

Store returns the underlying store.

func (*Service) SyncAll

func (s *Service) SyncAll(ctx context.Context)

SyncAll passes through all peers and attempts sync.

func (*Service) SyncPeer

func (s *Service) SyncPeer(ctx context.Context, id int64) error

SyncPeer synchronizes announced relays from a single peer.

type Store

type Store struct {
	DB  *db.DB
	Now func() time.Time
}

Store persists federation peers and announced relays.

func (*Store) Create

func (s *Store) Create(ctx context.Context, in CreatePeerInput) (Peer, error)

Create registers a new peered panel.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id int64) error

Delete removes a peer and its announced relays (via CASCADE).

func (*Store) Get

func (s *Store) Get(ctx context.Context, id int64) (Peer, error)

Get returns one peer by ID.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]Peer, error)

List returns all registered peers.

func (*Store) ListFederatedRelays

func (s *Store) ListFederatedRelays(ctx context.Context) ([]FederatedRelay, error)

ListFederatedRelays returns all federated relays from all active peers.

func (*Store) ReplaceFederatedRelays

func (s *Store) ReplaceFederatedRelays(ctx context.Context, peerID int64, relays []FederatedRelay) error

ReplaceFederatedRelays atomically replaces the relays associated with a peer.

func (*Store) UpdateStatus

func (s *Store) UpdateStatus(ctx context.Context, id int64, status PeerStatus, errMsg *string) error

UpdateStatus records a peer's sync attempt and current connectivity status.

Jump to

Keyboard shortcuts

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