server

package
v0.5.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "dev"
	BuildTime = "unknown"
	GitCommit = "unknown"
)

Version information - these will be set during build via main package

Functions

func BroadcastEvent added in v0.5.0

func BroadcastEvent(evt nostr.Event)

BroadcastEvent sends an event to all connected clients whose active subscriptions match the event. This is the real-time delivery mechanism required by NIP-01: after EOSE, new matching events are pushed to subscribers.

func ClientHandler

func ClientHandler(ws *websocket.Conn)

func DeleteEvents added in v0.5.0

func DeleteEvents(ids []string) error

DeleteEvents is the admin-takedown entry point invoked from `grain --delete <id>` / `grain --delete-file <path>`. It opens nostrdb with the same settings as normal startup, enqueues a physical delete for every supplied hex event id, and waits for the writer queue to drain on Close.

Authorization model: there is none. Shell access to the grain binary and data directory is the authorization boundary — identical to the existing `--import` flow. This is the moderator / legal-takedown path, not a protocol-level feature, and deliberately has no signature check.

Each call logs one line per id: "deleted <id>" on success, "not found" isn't observable from the Go side (the C delete is a no-op on missing ids and returns success), so every well-formed id that enqueues cleanly is reported as deleted. Malformed ids report an error and continue.

func HandleArgs added in v0.4.1

func HandleArgs() bool

HandleArgs processes command-line arguments and returns true if the program should exit

func ImportEvents added in v0.5.0

func ImportEvents(filename string) error

ImportEvents reads a JSONL file of Nostr events and stores them in nostrdb. It processes the entire file in a single run with an in-place progress bar.

func InitStatsMonitoring

func InitStatsMonitoring()

Start stats monitoring

func PrintStats

func PrintStats()

PrintStats periodically logs messaging and connection statistics

func ReadDeleteFile added in v0.5.0

func ReadDeleteFile(path string) ([]string, error)

ReadDeleteFile loads a newline-delimited file of hex event ids, stripping blank lines and comments (lines beginning with '#'). Used by `grain --delete-file <path>`.

func Run added in v0.4.1

func Run() error

Run starts the GRAIN relay server with configuration management and graceful shutdown

func SetVersionInfo added in v0.4.1

func SetVersionInfo(version, buildTime, gitCommit string)

SetVersionInfo allows main package to set version information. The version is also forwarded to server/utils so the NIP-11 relay info document always advertises the running binary's version.

Types

type Client

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

Client implements ClientInterface

func (*Client) AllowEvent added in v0.5.0

func (c *Client) AllowEvent(kind int, category string) (bool, string)

AllowEvent checks this client's per-connection event rate limiter.

func (*Client) AllowReq added in v0.5.0

func (c *Client) AllowReq() (bool, string)

AllowReq checks this client's per-connection REQ rate limiter.

func (*Client) ClientInfo

func (c *Client) ClientInfo() string

func (*Client) CloseClient

func (c *Client) CloseClient()

CloseClient closes the client connection and cleans up resources

func (*Client) DeleteSubscription added in v0.5.0

func (c *Client) DeleteSubscription(subID string)

func (*Client) ForEachSubscription added in v0.5.0

func (c *Client) ForEachSubscription(fn func(subID string, filters []nostr.Filter))

func (*Client) GetSubscriptions

func (c *Client) GetSubscriptions() map[string][]nostr.Filter

func (*Client) GetWS

func (c *Client) GetWS() *websocket.Conn

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client connection is still active

func (*Client) SendMessage

func (c *Client) SendMessage(msg interface{})

Implement `ClientInterface` methods SendMessage sends a message with write timeout and proper error handling

func (*Client) SetSubscription added in v0.5.0

func (c *Client) SetSubscription(subID string, filters []nostr.Filter)

func (*Client) SubscriptionCount added in v0.5.0

func (c *Client) SubscriptionCount() int

type ConnectionManager

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

ConnectionManager tracks connections and memory usage

func (*ConnectionManager) GetConnectionCount

func (cm *ConnectionManager) GetConnectionCount() int

GetConnectionCount returns the current number of connections

func (*ConnectionManager) GetMemoryStats

func (cm *ConnectionManager) GetMemoryStats() map[string]interface{}

GetMemoryStats returns memory statistics for monitoring

func (*ConnectionManager) RegisterConnection

func (cm *ConnectionManager) RegisterConnection(client *Client)

RegisterConnection adds a connection to the manager

func (*ConnectionManager) RemoveConnection

func (cm *ConnectionManager) RemoveConnection(client *Client)

RemoveConnection removes a connection from tracking

Directories

Path Synopsis
db
log

Jump to

Keyboard shortcuts

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