-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (66 loc) · 1.91 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/fiatjaf/eventstore/bolt"
"github.com/fiatjaf/khatru/policies"
"github.com/fiatjaf/relay29"
"github.com/joho/godotenv"
"github.com/nbd-wtf/go-nostr"
"golang.org/x/exp/slices"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
relayPrivateKey := os.Getenv("RELAY_PRIVATE_KEY")
relayName := os.Getenv("RELAY_NAME")
relayDescription := os.Getenv("RELAY_DESCRIPTION")
relayContact := os.Getenv("RELAY_CONTACT")
relayIconUrl := os.Getenv("RELAY_ICON_URL")
relayPublicKey, err := nostr.GetPublicKey(relayPrivateKey)
if err != nil {
panic(err)
}
db := bolt.BoltBackend{Path: "./db"}
err = db.Init()
if err != nil {
panic(err)
}
state := relay29.Init(relay29.Options{
Domain: "localhost:5577",
DB: &db,
SecretKey: relayPrivateKey,
})
// init relay
state.Relay.Info.Name = relayName
state.Relay.Info.Description = relayDescription
state.Relay.Info.Contact = relayContact
state.Relay.Info.Icon = relayIconUrl
state.Relay.Info.PubKey = relayPublicKey
state.Relay.Info.SupportedNIPs = append(state.Relay.Info.SupportedNIPs, 29)
// extra policies
state.Relay.RejectEvent = slices.Insert(state.Relay.RejectEvent, 0,
policies.PreventLargeTags(64),
policies.PreventTooManyIndexableTags(6, []int{9005}, nil),
policies.RestrictToSpecifiedKinds(
0, 9, 10, 11, 12, 10009,
30023, 31922, 31923, 9802,
9000, 9001, 9002, 9003, 9004, 9005, 9006, 9007,
9021,
),
policies.PreventTimestampsInThePast(60),
policies.PreventTimestampsInTheFuture(30),
)
// http routes
state.Relay.Router().HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "nothing to see here, you must use a nip-29 powered client")
})
fmt.Println("running on http://0.0.0.0:5577")
if err := http.ListenAndServe(":5577", state.Relay); err != nil {
log.Fatal("failed to serve")
}
}