global

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Unlicense Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	S struct {
		Port          string `envconfig:"PORT" default:"3334"`
		SFTPPort      string `envconvig:"SFTP_PORT" default:"2222"`
		Host          string `envconfig:"HOST" default:"localhost"`
		DataPath      string `envconfig:"DATA_PATH" default:"./data"`
		NoAutoUpdates bool   `envconfig:"NO_AUTO_UPDATES"`
	}
	Nostr    *sdk.System
	MMMM     *mmm.MultiMmapManager
	Settings UserSettings
)
View Source
var FiveSecondsDebouncer = debounce.New(time.Second * 5)
View Source
var IL struct {
	// for usage with the sdk
	System *mmm.IndexingLayer

	// main relay
	Main *mmm.IndexingLayer

	// specific
	Favorites *mmm.IndexingLayer
	Internal  *mmm.IndexingLayer
	Invites   *mmm.IndexingLayer
	Personal  *mmm.IndexingLayer
	Groups    *mmm.IndexingLayer
	Inbox     *mmm.IndexingLayer

	// only nip44-encrypted DMs for now
	Secret *mmm.IndexingLayer

	// moderated relay
	ModerationQueue *mmm.IndexingLayer
	Moderated       *mmm.IndexingLayer

	// algo
	Popular   *mmm.IndexingLayer
	Uppermost *mmm.IndexingLayer

	// scheduled events
	Scheduled *mmm.IndexingLayer

	// blossom blob index
	Blossom *mmm.IndexingLayer
}
View Source
var KindIsAllowed func(nostr.Kind) bool
View Source
var Log = zerolog.New(zerolog.MultiLevelWriter(
	zerolog.ConsoleWriter{Out: os.Stdout},
	zerolog.ConsoleWriter{Out: logSink, NoColor: true},
)).With().Timestamp().Logger()
View Source
var LogFilePath string
View Source
var PinnedCache struct {
	Main      *nostr.Event
	Internal  *nostr.Event
	Favorites *nostr.Event
	Popular   *nostr.Event
	Uppermost *nostr.Event
	Moderated *nostr.Event
}
View Source
var SupportedKindsDefault = []nostr.Kind{
	0, 1, 3, 5, 6, 7, 8, 9,
	11, 16, 20, 21, 22, 24, 777, 818, 1040,
	1063, 1111, 1222, 1227, 1244, 1617, 1618, 1619, 1621,
	1630, 1631, 1632, 1633, 1984, 1985, 7375, 7376,
	9321, 9735, 9802, 10000, 10001, 10002, 10003, 10004,
	10005, 10006, 10007, 10009, 10012, 10013, 10015, 10019, 10027, 10030, 10050,
	10063, 10777, 10101, 10102, 10317, 15128, 17375,
	23194, 23195, 24133,
	30000, 30002, 30003, 30004, 30008, 30009, 30015, 30023, 30024, 30030,
	30078, 30311, 30617, 30618, 30818, 30819, 31922, 31923,
	31924, 31925, 35128, 39701,
}

this must be sorted, which we do on main()

Functions

func BuildKindIsAllowedFunction added in v1.2.0

func BuildKindIsAllowedFunction(
	spec string,
	defaultKinds []nostr.Kind,
) (isAllowed func(nostr.Kind) bool, err error)

func CachePinnedEvent added in v1.0.18

func CachePinnedEvent(relayId RelayID)

func CleanupRelay added in v1.0.20

func CleanupRelay(relay *khatru.Relay)

func End

func End()

func GetFilterCost added in v1.2.8

func GetFilterCost(filter nostr.Filter) int

func GetLoggedUser

func GetLoggedUser(r *http.Request) (nostr.PubKey, bool)

func Init

func Init() error

func InitLogging added in v1.2.0

func InitLogging(dataPath string) error

func JSONString added in v1.0.18

func JSONString(v any) string

func NewRelay added in v1.2.7

func NewRelay() *khatru.Relay

func ParseKinds added in v1.2.0

func ParseKinds(spec string, defaultKinds []nostr.Kind) ([]nostr.Kind, error)

func PreparedPinned added in v1.0.20

func PreparedPinned(pinned *nostr.Event, filter nostr.Filter) (nostr.Event, bool)

if the query allows, we'll wrap the pinned event in a kind:6 repost with "-" tag otherwise we will return it naked. or not return it at all

func PubKeyFromInput added in v1.0.10

func PubKeyFromInput(input string) nostr.PubKey

func QueryStoredWithPinned added in v1.0.18

func QueryStoredWithPinned(relayId RelayID) func(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event]

QueryStoredWithPinned is a custom QueryStored function that returns pinned events first when that makes sense

func RandomString added in v1.2.4

func RandomString(size int) string

func RejectTooManyOpenSubscriptions added in v1.2.7

func RejectTooManyOpenSubscriptions(ctx context.Context, _ nostr.Filter) (bool, string)

func SaveUserSettings

func SaveUserSettings() error

func SubscribeLogStream added in v1.2.0

func SubscribeLogStream(buffer int) (<-chan []byte, func())

Types

type Limits added in v1.2.7

type Limits struct {
	MaxEventSize           int `json:"max_event_size"`
	MaxSubscriptionsOpen   int `json:"max_subscriptions_open"`
	MaxTotalCostOpen       int `json:"max_total_cost_open"`
	MaxIndexableTags       int `json:"max_indexable_tags"`
	MaxEntriesInFollowList int `json:"max_entries_in_follow_list"`
	MaxQueryLimit          int `json:"max_query_limit"`
}

type RelayID added in v1.0.20

type RelayID string
const (
	RelayMain      RelayID = "main"
	RelayInternal  RelayID = "internal"
	RelayPersonal  RelayID = "personal"
	RelayFavorites RelayID = "favorites"
	RelayGroups    RelayID = "groups"
	RelayInbox     RelayID = "inbox"
	RelayModerated RelayID = "moderated"
	RelayPopular   RelayID = "popular"
	RelayUppermost RelayID = "uppermost"
)

func (RelayID) String added in v1.0.20

func (r RelayID) String() string

String returns the string representation of RelayID

type RelayMetadata added in v1.0.1

type RelayMetadata struct {
	Enabled      bool     `json:"enabled"`
	Name         string   `json:"name"`
	Description  string   `json:"description"`
	Icon         string   `json:"icon"`
	HTTPBasePath string   `json:"path"`
	HTTPDomain   string   `json:"domain,omitempty"`
	Pinned       nostr.ID `json:"pinned,omitempty"`
	// contains filtered or unexported fields
}

func (RelayMetadata) GetDescription added in v1.0.1

func (rm RelayMetadata) GetDescription() string

func (RelayMetadata) GetIcon added in v1.0.1

func (rm RelayMetadata) GetIcon() string

func (RelayMetadata) GetName added in v1.0.1

func (rm RelayMetadata) GetName() string

func (RelayMetadata) GetPageURL added in v1.2.6

func (rm RelayMetadata) GetPageURL() string

func (RelayMetadata) GetServiceURL added in v1.2.6

func (rm RelayMetadata) GetServiceURL() string

func (RelayMetadata) IsIconDefault added in v1.0.1

func (rm RelayMetadata) IsIconDefault() bool

func (RelayMetadata) IsNameDefault added in v1.0.1

func (rm RelayMetadata) IsNameDefault() bool

type UserSettings

type UserSettings struct {
	// relay metadata
	Domain           string   `json:"domain"`
	RelayName        string   `json:"relay_name"`
	RelayDescription string   `json:"relay_description"`
	RelayContact     string   `json:"relay_contact"`
	RelayIcon        string   `json:"relay_icon"`
	Pinned           nostr.ID `json:"pinned,omitempty"`

	// theme
	Theme struct {
		BackgroundColor          string `json:"background_color"`
		TextColor                string `json:"text_color"`
		AccentColor              string `json:"accent_color"`
		SecondaryBackgroundColor string `json:"secondary_background_color"`
		ExtraColor               string `json:"extra_color"`
		BaseColor                string `json:"base_color"`
		HeaderTransparency       string `json:"header_transparency"`
		PrimaryFont              string `json:"primary_font"`
		SecondaryFont            string `json:"secondary_font"`
	} `json:"theme"`

	// general
	BrowseURI                string `json:"browse_uri"`
	LinkURL                  string `json:"link_url"`
	MaxInvitesPerPerson      int    `json:"max_invites_per_person,omitempty"`
	MaxInvitesAtEachLevel    []int  `json:"max_invites_at_each_level,omitempty"`
	RequireCurrentTimestamp  bool   `json:"require_current_timestamp"`
	AcceptScheduledEvents    bool   `json:"accept_scheduled_events"`
	AllowEphemeralFromAnyone bool   `json:"allow_ephemeral_from_anyone"`
	ValidateSchema           bool   `json:"validate_schema"`
	Search                   struct {
		Enable    bool     `json:"enable"`
		Languages []string `json:"languages"`
	} `json:"search"`

	Paywall struct {
		Enabled bool `json:"enable"`
	} `json:"paywall"`

	NIP05 struct {
		Enabled bool                    `json:"enabled"`
		Names   map[string]nostr.PubKey `json:"names"`
	} `json:"nip05"`

	RelayInternalSecretKey nostr.SecretKey `json:"relay_internal_secret_key"`

	BlockedIPs       []string `json:"blocked_ips"`
	AllowedKindsSpec string   `json:"allowed_kinds_spec,omitempty"`
	Limits           Limits   `json:"limits"`

	// Deprecated: remove this after people have migrated
	AllowedKindsLegacy []nostr.Kind `json:"allowed_kinds,omitempty"`

	// Deprecated: remove this after people have migrated
	MaxEventSize int `json:"max_event_size,omitempty"`

	// per-relay
	Internal struct {
		RelayMetadata
	} `json:"internal"`

	Personal struct {
		RelayMetadata
	} `json:"personal"`

	Favorites struct {
		RelayMetadata
	} `json:"favorites"`

	Inbox struct {
		RelayMetadata
		SpecificallyBlocked []nostr.PubKey `json:"specifically_blocked"`
		AllowedKindsSpec    string         `json:"allowed_kinds_spec,omitempty"`

		// Deprecated: remove this after people have migrated
		AllowedKindsLegacy []nostr.Kind `json:"allowed_kinds,omitempty"`

		HellthreadLimit  int    `json:"hellthread_limit"`
		MinDMPoW         int    `json:"min_dm_pow"`
		RequireAuthForDM string `json:"require_auth_for_dm,omitempty"` // "", "always", "when_no_pow"
	} `json:"inbox"`

	Groups struct {
		Enabled                bool   `json:"enabled"`
		EmbeddedLiveKitEnabled bool   `json:"embedded_livekit_enabled"`
		LiveKitServerURL       string `json:"livekit_server_url"`
		LiveKitAPIKey          string `json:"livekit_apikey"`
		LiveKitAPISecret       string `json:"livekit_apisecret"`
	} `json:"groups"`

	Grasp struct {
		Enabled bool `json:"enabled"`
	} `json:"grasp"`

	Blossom struct {
		Enabled                      bool  `json:"enabled"`
		MaxUserUploadSize            int   `json:"max_user_upload_size,omitempty"` // in megabytes, 0 means unlimited
		MaxUserUploadSizeAtEachLevel []int `json:"max_user_upload_size_at_each_level,omitempty"`
	} `json:"blossom"`

	Stream struct {
		Enabled bool   `json:"enabled"`
		Salt    string `json:"salt"`
	} `json:"stream"`

	Popular struct {
		RelayMetadata
		PercentThreshold int `json:"percent_threshold"`
	} `json:"popular"`

	Uppermost struct {
		RelayMetadata
		PercentThreshold int `json:"percent_threshold"`
	} `json:"uppermost"`

	Moderated struct {
		RelayMetadata
		MinPoW uint `json:"min_pow"`
	} `json:"moderated"`

	FTP struct {
		Enabled  bool   `json:"enabled"`
		Password string `json:"password"`
	} `json:"ftp"`
}
func (us UserSettings) GetExternalLink(pointer nostr.Pointer) string

func (UserSettings) GetMaxInvitesDisplay added in v1.0.22

func (us UserSettings) GetMaxInvitesDisplay() string

func (UserSettings) GetMaxUserUploadSizeDisplay added in v1.1.0

func (us UserSettings) GetMaxUserUploadSizeDisplay() string

func (UserSettings) HTTPScheme

func (us UserSettings) HTTPScheme() string

func (UserSettings) HasThemeColors

func (us UserSettings) HasThemeColors() bool

func (UserSettings) WSScheme

func (us UserSettings) WSScheme() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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