1 // Package messages is a collection of example/common messages and
2 // machine-readable prefixes to use with OK and CLOSED envelopes.
3 package messages
4 5 import (
6 "lukechampine.com/frand"
7 )
8 9 const (
10 // Duplicate is a machine readable prefix for OK envelopes indicating that the
11 // submitted event is already in the relay,s event store.
12 Duplicate = "duplicate"
13 14 // Pow is a machine readable prefix for OK envelopes indicating that the
15 // eventid.T lacks sufficient zeros at the front.
16 Pow = "pow"
17 18 // Blocked is a machine readable prefix for OK envelopes indicating the event
19 // submission or REQ has been rejected.
20 Blocked = "blocked"
21 22 // RateLimited is a machine readable prefix for CLOSED and OK envelopes
23 // indicating the relay is now slowing down processing of requests from the
24 // client.
25 RateLimited = "rate-limited"
26 27 // Invalid is a machine readable prefix for OK envelopes indicating
28 // that the submitted event or other request is not correctly formatted, and may
29 // mean a signature does not verify.
30 Invalid = "invalid"
31 32 // Error is a machine readable prefix for CLOSED and OK envelopes indicating
33 // there was some kind of error in processing the request.
34 Error = "error"
35 )
36 37 // Examples are some examples of the use of the prefixes above with appropriate
38 // human-readable suffixes.
39 var Examples = [][]byte{
40 []byte("pow: difficulty 25>=24"),
41 []byte("duplicate: already have this event"),
42 []byte("blocked: you are banned from posting here"),
43 []byte("blocked: please register your pubkey at " +
44 "https://my-expensive-relay.example.com"),
45 []byte("rate-limited: slow down there chief"),
46 []byte("invalid: event creation date is too far off from the current time"),
47 []byte("pow: difficulty 26 is less than 30"),
48 []byte("error: could not connect to the database"),
49 }
50 51 // RandomMessage generates a random message out of the above list of Examples.
52 func RandomMessage() []byte {
53 return Examples[frand.Intn(len(Examples)-1)]
54 }
55