Files
realy/envelopes/messages/messages.go
mleku bbebbe2b02 Add tracing with lol.Tracer in multiple functions.
Introduced `lol.Tracer` for function entry/exit logging across various packages. This improves traceability and debugging of function executions while preserving existing behavior. Removed unused files `doc.go` and `nothing.go` to clean up the repository.
2025-06-29 07:32:24 +01:00

59 lines
2.0 KiB
Go

// Package messages is a collection of example/common messages and
// machine-readable prefixes to use with OK and CLOSED envelopes.
package messages
import (
"lukechampine.com/frand"
"realy.lol/lol"
)
const (
// Duplicate is a machine readable prefix for OK envelopes indicating that the
// submitted event is already in the relay,s event store.
Duplicate = "duplicate"
// Pow is a machine readable prefix for OK envelopes indicating that the
// eventid.T lacks sufficient zeros at the front.
Pow = "pow"
// Blocked is a machine readable prefix for OK envelopes indicating the event
// submission or REQ has been rejected.
Blocked = "blocked"
// RateLimited is a machine readable prefix for CLOSED and OK envelopes
// indicating the relay is now slowing down processing of requests from the
// client.
RateLimited = "rate-limited"
// Invalid is a machine readable prefix for OK envelopes indicating
// that the submitted event or other request is not correctly formatted, and may
// mean a signature does not verify.
Invalid = "invalid"
// Error is a machine readable prefix for CLOSED and OK envelopes indicating
// there was some kind of error in processing the request.
Error = "error"
)
// Examples are some examples of the use of the prefixes above with appropriate
// human-readable suffixes.
var Examples = [][]byte{
[]byte("pow: difficulty 25>=24"),
[]byte("duplicate: already have this event"),
[]byte("blocked: you are banned from posting here"),
[]byte("blocked: please register your pubkey at " +
"https://my-expensive-relay.example.com"),
[]byte("rate-limited: slow down there chief"),
[]byte("invalid: event creation date is too far off from the current time"),
[]byte("pow: difficulty 26 is less than 30"),
[]byte("error: could not connect to the database"),
}
// RandomMessage generates a random message out of the above list of Examples.
func RandomMessage() (msg []byte) {
lol.Tracer("RandomMessage")
defer func() { lol.Tracer("end RandomMessage", msg) }()
msg = Examples[frand.Intn(len(Examples))]
return
}