Documentation
¶
Overview ¶
Package strfrui provides foundations for building strfry's event-sifters plugins in Go.
If you want to explore built-in event-sifter implementations and combinators, which can be used to make complex sifter logics from small parts, see the doc of github.com/jiftechnify/strfrui/sifters package.
Index ¶
Examples ¶
Constants ¶
const ( RejectReasonPrefixBlocked = "blocked" RejectReasonPrefixRateLimited = "rate-limited" RejectReasonPrefixInvalid = "invalid" RejectReasonPrefixPoW = "pow" RejectReasonPrefixError = "error" )
"Machine-readable prefixes" for rejection messages. Use them with BuildRejectMessage.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
type Action string
Action represents a type of action by event sifter, in other words, how to process an event.
type Input ¶
type Input struct { // A type of input. As of strfry 0.9.6, it is always "new". Type string `json:"type"` // An event data sent by a client or imported from file / another relay. Event *nostr.Event `json:"event"` // Unix timestamp (in second) of when the event was received by the relay. ReceivedAt uint64 `json:"receivedAt"` // The source type, or where the event came from. SourceType SourceType `json:"sourceType"` // Information about event source. If SourceType is... // // - SourceTypeIP4 or SourceTypeIP6, it's a string representation of client's IP address. // - SourceTypeStream or SourceTypeSync, it's a URL of a source relay. // - SourceTypeImport, it's an empty string. SourceInfo string `json:"sourceInfo"` }
Input is a data structure of event sifter's input.
func (*Input) Reject ¶
Reject rejects the event in the input with a rejection message to the client.
As per NIP-01, the message should be prefixed with a machine-readable word followed by ":" (e.g. "blocked: you are not allowed to write events"). You can use BuildRejectMessage to build a rejection message in that format.
func (*Input) ShadowReject ¶
ShadowReject silently rejects the event in the input, that is, makes it look accepted to the client, but actually reject it.
type Result ¶
type Result struct { // The ID of the target event, taken from the ID field of Input. ID string `json:"id"` // An action to take on the target event. Action Action `json:"action"` // A message to be sent to a client (included in an OK message) if event is rejected. Msg string `json:"msg"` }
Result is a data structure of event sifter's output. It can be generated from methods of an Input.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner implements the main routine of a event sifter as Run() method. You may want to use strfrui.New to initialize a Runner and set a Sifter at the same time.
The zero value for Runner is a valid Runner that accepts all events.
Example ¶
package main import ( "github.com/jiftechnify/strfrui" "github.com/jiftechnify/strfrui/sifters" ) func main() { strfrui.New(sifters.KindList([]int{1}, sifters.Allow)).Run() }
Output:
func NewWithSifterFunc ¶
NewWithSifterFunc initializes a new Runner and set the passed event sifting function as a Sifter at the same time.
type Sifter ¶
A Sifter decides whether accept or reject an event based on Input, the event data itself with context information.
Sift should return either Result with an action to take on the event, or error if it couldn't process the input. If error is returned from Sift, the event is rejected by default.
type SifterFunc ¶
SifterFunc is an adapter to allow the use of functions which takes a sifter Input and returns a sifter Result as a Sifter.
type SourceType ¶
type SourceType string
SourceType represents a source type of a Nostr event, in other words, where an event came from.
const ( // SourceTypeIP4 shows that an event was sent from a client which has an IPv4 address. SourceTypeIP4 SourceType = "IP4" // SourceTypeIP6 shows that an event was sent from a client which has an IPv6 address. SourceTypeIP6 SourceType = "IP6" // SourceTypeImport shows that an event was imported via "strfry import" command. SourceTypeImport SourceType = "Import" // SourceTypeStream shows that an event was imported from another relay via "strfry stream" or "strfry router" command. SourceTypeStream SourceType = "Stream" // SourceTypeSync shows that an event was imported from another relay via "strfry sync" command. SourceTypeSync SourceType = "Sync" )
func (SourceType) IsEndUser ¶
func (st SourceType) IsEndUser() bool
IsEndUser checks whether the source is an "end-user" (or, a "user-facing client").