Documentation ¶
Index ¶
- Constants
- Variables
- func AntiSyncBots(c context.T, f *filter.T) (rej bool, msg string)
- func DecryptDM(ev *event.T, meSec, youPub string) (decryptedStr string, err error)
- func EncryptDM(ev *event.T, meSec, youPub string) (evo *event.T, err error)
- func GetAuthed(c context.T) string
- func GetConnection(c context.T) *relayws.WebSocket
- func GetIP(c context.T) string
- func GetListeningFilters() (respFilters filters.T)
- func GetOpenSubscriptions(c context.T) filters.T
- func GetSubscriptionID(c context.T) string
- func MakeReply(ev *event.T, content string) (evo *event.T)
- func NoComplexFilters(c context.T, f *filter.T) (rej bool, msg string)
- func NoEmptyFilters(c context.T, f *filter.T) (reject bool, msg string)
- func NoSearchQueries(c context.T, f *filter.T) (reject bool, msg string)
- func PointerHasher[V any](_ maphash.Seed, k *V) uint64
- func RemoveListener(ws *relayws.WebSocket)
- func RemoveListenerId(ws *relayws.WebSocket, id string)
- func RemoveSearchQueries(c context.T, f *filter.T)
- func RequestAuth(c context.T)
- func SetListener(id string, ws *relayws.WebSocket, f filters.T, c context.C)
- type Command
- type Config
- type CountEvents
- type Events
- type ExportCmd
- type Hook
- type ImportCmd
- type InitCfg
- type Listener
- type ListenerMap
- type OnEventSaved
- type OverrideDeletionOutcome
- type OverwriteFilter
- type OverwriteRelayInformation
- type OverwriteResponseEvent
- type QueryEvents
- type RejectEvent
- func PreventExcessTags(max int, ign kinds.T, only kinds.T) RejectEvent
- func PreventLargeTags(maxTagValueLen int) RejectEvent
- func PreventTimestampsInTheFuture(thresholdSeconds timestamp.T) RejectEvent
- func PreventTimestampsInThePast(thresholdSeconds timestamp.T) RejectEvent
- func RestrictToSpecifiedKinds(kinds ...kind.T) RejectEvent
- type RejectFilter
- type Relay
- func (rl *Relay) AddEvent(c context.T, ev *event.T) (err error)
- func (rl *Relay) AuthCheck(c context.T)
- func (rl *Relay) BroadcastEvent(evt *event.T)
- func (rl *Relay) Chat(c context.T, ev *event.T) (err error)
- func (rl *Relay) Export(db *badger.Backend, filename string)
- func (rl *Relay) FilterPrivileged(c context.T, id subscriptionid.T, f *filter.T) (reject bool, msg string)
- func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request)
- func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request)
- func (rl *Relay) Import(db *badger.Backend, files []string)
- func (rl *Relay) Init()
- func (rl *Relay) OverrideDelete(c context.T, tgt, del *event.T) (ok bool, msg string)
- func (rl *Relay) Router() *http.ServeMux
- func (rl *Relay) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (rl *Relay) Shutdown(c context.T)
- func (rl *Relay) Start(host string, port int, started ...chan bool) (err error)
- type Spam
- type Spammer
Constants ¶
const ( WriteWait = 10 * time.Second PongWait = 60 * time.Second PingPeriod = 30 * time.Second ReadBufferSize = 4096 WriteBufferSize = 4096 MaxMessageSize int = 512000 // ??? )
const IgnoreAfter = 16
Variables ¶
var Commands []*Command
var Software = "https://github.com/Hubmakerlabs/replicatr"
var Version = "v0.0.1"
Functions ¶
func AntiSyncBots ¶
AntiSyncBots tries to prevent people from syncing kind:1s from this relay to else by always requiring an author parameter at least.
func GetListeningFilters ¶
func GetSubscriptionID ¶
func MakeReply ¶
MakeReply creates an appropriate reply event from a provided event that is being replied to (not quoting, just the right tags, timestamps and kind).
func NoComplexFilters ¶
NoComplexFilters disallows filters with more than 2 tags.
func NoEmptyFilters ¶
NoEmptyFilters disallows filters that don't have at least a tag, a kind, an author or an id.
func RemoveListener ¶
RemoveListener removes WebSocket conn from listeners (no need to cancel contexts as they are all inherited from the main connection context)
func RemoveListenerId ¶
RemoveListenerId removes a specific subscription id from listeners for a given ws client and cancel its specific context
func RequestAuth ¶
Types ¶
type Config ¶ added in v1.1.0
type Config struct { ExportCmd *ExportCmd `arg:"subcommand:export" json:"-" help:"export database as line structured JSON"` ImportCmd *ImportCmd `arg:"subcommand:import" json:"-" help:"import data from line structured JSON"` InitCfgCmd *InitCfg `arg:"subcommand:initcfg" json:"-" help:"initialize relay configuration files"` Listen string `arg:"-l,--listen" default:"0.0.0.0:3334" json:"listen" help:"network address to listen on"` EventStore string `arg:"-e,--eventstore" default:"ic" json:"eventstore" help:"select event store backend [ic,badger]"` CanisterAddr string `arg:"-C,--canisteraddr" default:"127.0.0.1:46847" json:"canister_addr" help:"IC canister address to use"` CanisterID string `arg:"-I,--canisterid" json:"canister_id" help:"IC canister ID to use"` Profile string `arg:"-p,--profile" json:"-" default:"replicatr" help:"profile name to use for storage"` Name string `arg:"-n,--name" json:"name" default:"replicatr relay" help:"name of relay for NIP-11"` Description string `arg:"-d,--description" json:"description" help:"description of relay for NIP-11"` Pubkey string `arg:"--pubkey" json:"pubkey" help:"public key of relay operator"` Contact string `arg:"-c,--contact" json:"contact,omitempty" help:"non-nostr relay operator contact details"` Icon string `arg:"-i,--icon" json:"icon" default:"https://i.nostr.build/n8vM.png" help:"icon to show on relay information pages"` // Whitelist permits ONLY inbound connections from specified IP addresses. Whitelist []string `arg:"-w,--whitelist,separate" json:"ip_whitelist" help:"IP addresses that are only allowed to access"` // AllowIPs is for bypassing authentication required for clients based on IP // addresses... primarily for testing with wireguard VPN clients run by the // developer, as these are stable, non-routeable addresses, this skips the // requirement enforced by AuthRequired. AllowIPs []string `arg:"-A,--allow,separate" json:"allow_ip" help:"IP addresses that are always allowed to access"` AuthRequired bool `arg:"-a,--auth" json:"auth_required" default:"false" help:"NIP-42 authentication required for all access"` Public bool `arg:"--public" json:"public" default:"true" help:"allow public read access to users not on ACL"` Owners []string `arg:"-o,--owner,separate" json:"owners" help:"specify public keys of users with owner level permissions on relay"` SecKey string `arg:"-s" json:"seckey" help:"identity key of relay, used to sign 30066 and 30166 events and for message control interface"` MaxProcs int `args:"-m" json:"max_procs" default:"128" help:"maximum number of goroutines to use"` }
type CountEvents ¶
function types used in the relay state
type ExportCmd ¶ added in v1.1.0
type ExportCmd struct {
ToFile string `arg:"-f,--tofile" help:"write to file instead of stdout"`
}
type ImportCmd ¶ added in v1.1.0
type ImportCmd struct {
FromFile []string `arg:"-f,--fromfile,separate" help:"read from files instead of stdin (can use flag repeatedly for multiple files)"`
}
type ListenerMap ¶
type OnEventSaved ¶
function types used in the relay state
type OverrideDeletionOutcome ¶
function types used in the relay state
type OverwriteFilter ¶
function types used in the relay state
func RemoveAllButKinds ¶
func RemoveAllButKinds(k ...kind.T) OverwriteFilter
func RemoveAllButTags ¶
func RemoveAllButTags(tagNames ...string) OverwriteFilter
type OverwriteRelayInformation ¶
function types used in the relay state
type OverwriteResponseEvent ¶
function types used in the relay state
type QueryEvents ¶
function types used in the relay state
type RejectEvent ¶
function types used in the relay state
func PreventExcessTags ¶
PreventExcessTags returns a function that can be used as a RejectFilter that will reject events with more indexable (single-character) tags than the specified number.
If ignoreKinds is given this restriction will not apply to these kinds (useful for allowing a bigger). If onlyKinds is given then all other kinds will be ignored.
func PreventLargeTags ¶
func PreventLargeTags(maxTagValueLen int) RejectEvent
PreventLargeTags rejects events that have indexable tag values greater than maxTagValueLen.
func PreventTimestampsInTheFuture ¶
func PreventTimestampsInTheFuture(thresholdSeconds timestamp.T) RejectEvent
func PreventTimestampsInThePast ¶
func PreventTimestampsInThePast(thresholdSeconds timestamp.T) RejectEvent
func RestrictToSpecifiedKinds ¶
func RestrictToSpecifiedKinds(kinds ...kind.T) RejectEvent
RestrictToSpecifiedKinds returns a function that can be used as a RejectFilter that will reject any events with kinds different than the specified ones.
type RejectFilter ¶
function types used in the relay state
type Relay ¶
type Relay struct { ServiceURL atomic.String RejectEvent []RejectEvent RejectFilter []RejectFilter RejectCountFilter []RejectFilter OverrideDeletion []OverrideDeletionOutcome OverwriteResponseEvent []OverwriteResponseEvent OverwriteFilter []OverwriteFilter OverwriteCountFilter []OverwriteFilter OverwriteRelayInfo []OverwriteRelayInformation StoreEvent []Events DeleteEvent []Events QueryEvents []QueryEvents CountEvents []CountEvents OnConnect []Hook OnDisconnect []Hook OnEventSaved []OnEventSaved Config *Config Info *relayinfo.T // in case you call Server.Start Addr string // websocket options // WriteWait is the time allowed to write a message to the peer. WriteWait time.Duration // PongWait is the time allowed to read the next pong message from the peer. PongWait time.Duration // PingPeriod is the tend pings to peer with this period. Must be less than // pongWait. PingPeriod time.Duration MaxMessageSize int64 // Maximum message size allowed from peer. Whitelist []string // whitelist of allowed IPs for access RelayPubHex string RelayNpub string // ACL is the list of users and privileges on this relay ACL *acl.T // contains filtered or unexported fields }
func (*Relay) AddEvent ¶
AddEvent sends an event through then normal add pipeline, as if it was received from a websocket.
func (*Relay) AuthCheck ¶
AuthCheck sends out a request if auth is required (this is an OnConnect method).
func (*Relay) BroadcastEvent ¶
BroadcastEvent emits an event to all listeners whose filters' match, skipping all filters and actions it also doesn't attempt to store the event or trigger any reactions or callbacks
func (*Relay) Chat ¶
Chat implements the control interface, intercepting kind 4 encrypted direct messages and processing them if they are for the relay's pubkey
func (*Relay) FilterPrivileged ¶
func (rl *Relay) FilterPrivileged(c context.T, id subscriptionid.T, f *filter.T) (reject bool, msg string)
FilterPrivileged interacts between filters and the privileges of the users according to the access control settings of the relay, checking whether the request is authorised, if not, requesting authorisation.
If there is an ACL configured, it acts as a whitelist, no access without being on the ACL.
If the message is a private message, only authenticated users may get these events who also match one of the parties in the conversation.
func (*Relay) HandleNIP11 ¶
func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request)
func (*Relay) HandleWebsocket ¶
func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request)
func (*Relay) Import ¶
Import a collection of JSON events from stdin or from one or more files, line structured JSON.
func (*Relay) OverrideDelete ¶
OverrideDelete decides whether to veto a delete event.
Temporarily removing delete functionality until a proper tombstone/indexing strategy is devised to filter out these events from database results.
func (*Relay) ServeHTTP ¶
func (rl *Relay) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface.