connection

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseCoreClient

func CloseCoreClient() error

CloseCoreClient closes the core client connections

func EnsureRelayConnections

func EnsureRelayConnections() error

EnsureRelayConnections is the demand-side guard used by API/data callers that need at least one usable relay connection before issuing a query. It returns nil as soon as any relay is connected; if none are it forces a reconnect attempt against the full index-relay list. This is *not* the right primitive for filling a partial pool — see TopUpRelayConnections for that, and #68 for the production bug where confusing the two semantics let the upstream pool sit at 1/5 indefinitely.

func GetCoreClient

func GetCoreClient() *core.Client

GetCoreClient returns the core client instance

func GetCoreClientStatus

func GetCoreClientStatus() map[string]interface{}

GetCoreClientStatus returns status information about the core client

func GetIndexRelays added in v0.5.0

func GetIndexRelays() []string

GetIndexRelays returns the configured index/seed relays

func InitializeCoreClient

func InitializeCoreClient(serverCfg *cfgType.ServerConfig) error

InitializeCoreClient sets up the global core client with server configuration

func IsCoreClientInitialized

func IsCoreClientInitialized() bool

IsCoreClientInitialized checks if the core client is properly initialized

func ReleaseUser added in v0.8.1

func ReleaseUser(pubkey string)

ReleaseUser closes pubkey's UserContext, releasing their relay holds and ending their NIP-42 sessions. Called when their last session ends.

func SetIndexRelays added in v0.5.0

func SetIndexRelays(relays []string)

SetIndexRelays sets the index/seed relays used for discovery

func StartLiveSync added in v0.8.0

func StartLiveSync(pubkey string)

StartLiveSync opens a subscription to a user's own replaceable events created from now on; for each, it drops the cached resolution that event supersedes and pushes a live update to the user's open pages. Wired to the SSE hub's first-connection hook, so it runs only while a page is open.

func StartRelayDiscoveryRoll added in v0.8.0

func StartRelayDiscoveryRoll(ctx context.Context, interval time.Duration)

StartRelayDiscoveryRoll starts the core client's periodic NIP-66 discovery roll (#104 Phase 3): re-discover relay monitors, refresh their published relay sets, and evict monitors whose data has gone stale — keeping the known-relays browser a live, self-healing set. Bounded to ctx like the other background services. The initial bootstrap pass is kicked at connect time.

func StartRelayEvictionSweeper added in v0.8.0

func StartRelayEvictionSweeper(ctx context.Context, interval time.Duration)

StartRelayEvictionSweeper starts the core client's idle-connection sweeper, bounded to ctx so it doesn't outlive the server instance (#93). Companion to StartRelayHealthCheck: the health check keeps the pinned index relays up, while the sweeper reclaims the per-user connections the outbox pool dials on demand once they go idle.

func StartRelayHealthCheck added in v0.5.0

func StartRelayHealthCheck(ctx context.Context, interval time.Duration)

StartRelayHealthCheck starts a background goroutine to maintain relay connections. It exits when ctx is cancelled so it doesn't outlive the server instance that started it (#93).

func StopLiveSync added in v0.8.0

func StopLiveSync(pubkey string)

StopLiveSync closes a user's live-sync subscription — wired to the SSE hub's last-connection hook.

func TopUpRelayConnections added in v0.5.4

func TopUpRelayConnections() (before, after int, err error)

TopUpRelayConnections attempts to bring the index-relay pool up to its configured target by dialing every relay that isn't currently connected. Already-connected relays are left alone (the pool's Connect is a no-op for them). Returns the (before, after) connection counts so the caller can log meaningfully — this exists because the health check previously logged "reconnection successful" whenever EnsureRelayConnections returned nil, which it does on any-connection-exists, regardless of whether the deficit was actually closed (#68).

func UserFor added in v0.8.1

func UserFor(pubkey string) *core.UserContext

UserFor returns pubkey's UserContext on the current core client, creating it on first use. It returns nil when there is no core client or no pubkey.

Types

This section is empty.

Jump to

Keyboard shortcuts

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