2024-09-06 11:16:40 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-09-06 19:25:40 -04:00
|
|
|
"html/template"
|
2024-09-08 10:55:56 -04:00
|
|
|
"io"
|
2024-09-06 11:16:40 -04:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2024-09-07 23:39:23 -04:00
|
|
|
"strconv"
|
2024-09-06 11:16:40 -04:00
|
|
|
"time"
|
|
|
|
|
2024-09-12 20:51:26 -04:00
|
|
|
"github.com/fiatjaf/eventstore"
|
2024-09-06 11:16:40 -04:00
|
|
|
"github.com/fiatjaf/khatru"
|
2024-09-11 22:06:17 -04:00
|
|
|
"github.com/fiatjaf/khatru/policies"
|
2024-09-06 11:16:40 -04:00
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/nbd-wtf/go-nostr"
|
|
|
|
)
|
|
|
|
|
2024-09-18 08:50:28 +01:00
|
|
|
var (
|
2024-09-19 10:59:59 -04:00
|
|
|
version string
|
2024-09-18 08:50:28 +01:00
|
|
|
)
|
|
|
|
|
2024-09-06 11:16:40 -04:00
|
|
|
type Config struct {
|
|
|
|
RelayName string
|
|
|
|
RelayPubkey string
|
|
|
|
RelayDescription string
|
|
|
|
DBPath string
|
2024-09-06 19:25:40 -04:00
|
|
|
RelayURL string
|
2024-09-06 19:33:29 -04:00
|
|
|
IndexPath string
|
|
|
|
StaticPath string
|
2024-09-07 23:39:23 -04:00
|
|
|
RefreshInterval int
|
2024-09-12 15:23:32 -04:00
|
|
|
MinimumFollowers int
|
2024-09-16 21:54:16 -04:00
|
|
|
ArchivalSync bool
|
2024-09-18 12:12:48 +01:00
|
|
|
RelayContact string
|
|
|
|
RelayIcon string
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
var pool *nostr.SimplePool
|
2024-09-12 20:51:26 -04:00
|
|
|
var wdb nostr.RelayStore
|
2024-09-06 11:16:40 -04:00
|
|
|
var relays []string
|
|
|
|
var config Config
|
|
|
|
var trustNetwork []string
|
2024-09-07 20:14:43 -04:00
|
|
|
var seedRelays []string
|
2024-09-07 23:39:23 -04:00
|
|
|
var booted bool
|
|
|
|
var oneHopNetwork []string
|
2024-09-12 14:16:56 -04:00
|
|
|
var trustNetworkMap map[string]bool
|
2024-09-12 15:23:32 -04:00
|
|
|
var pubkeyFollowerCount = make(map[string]int)
|
2024-09-12 20:33:53 -04:00
|
|
|
var trustedNotes uint64
|
|
|
|
var untrustedNotes uint64
|
2024-09-06 11:16:40 -04:00
|
|
|
|
|
|
|
func main() {
|
2024-09-08 10:55:56 -04:00
|
|
|
nostr.InfoLogger = log.New(io.Discard, "", 0)
|
2024-09-07 23:39:23 -04:00
|
|
|
booted = false
|
2024-09-07 20:14:43 -04:00
|
|
|
green := "\033[32m"
|
|
|
|
reset := "\033[0m"
|
|
|
|
|
2024-09-07 23:39:23 -04:00
|
|
|
art := `
|
|
|
|
888 888 88888888888 8888888b. 888
|
|
|
|
888 o 888 888 888 Y88b 888
|
|
|
|
888 d8b 888 888 888 888 888
|
|
|
|
888 d888b 888 .d88b. 888 888 d88P .d88b. 888 8888b. 888 888
|
|
|
|
888d88888b888 d88""88b 888 8888888P" d8P Y8b 888 "88b 888 888
|
|
|
|
88888P Y88888 888 888 888 888 T88b 88888888 888 .d888888 888 888
|
|
|
|
8888P Y8888 Y88..88P 888 888 T88b Y8b. 888 888 888 Y88b 888
|
|
|
|
888P Y888 "Y88P" 888 888 T88b "Y8888 888 "Y888888 "Y88888
|
|
|
|
888
|
|
|
|
Y8b d88P
|
|
|
|
powered by: khatru "Y88P"
|
|
|
|
`
|
2024-09-07 20:14:43 -04:00
|
|
|
|
|
|
|
fmt.Println(green + art + reset)
|
|
|
|
log.Println("🚀 booting up web of trust relay")
|
2024-09-06 11:16:40 -04:00
|
|
|
relay := khatru.NewRelay()
|
|
|
|
ctx := context.Background()
|
2024-09-07 20:14:43 -04:00
|
|
|
pool = nostr.NewSimplePool(ctx)
|
2024-09-06 11:16:40 -04:00
|
|
|
config = LoadConfig()
|
|
|
|
|
|
|
|
relay.Info.Name = config.RelayName
|
|
|
|
relay.Info.PubKey = config.RelayPubkey
|
2024-09-18 12:12:48 +01:00
|
|
|
relay.Info.Icon = config.RelayIcon
|
|
|
|
relay.Info.Contact = config.RelayContact
|
2024-09-06 11:16:40 -04:00
|
|
|
relay.Info.Description = config.RelayDescription
|
2024-09-19 10:59:59 -04:00
|
|
|
relay.Info.Software = "https://github.com/bitvora/wot-relay"
|
2024-09-18 08:50:28 +01:00
|
|
|
relay.Info.Version = version
|
|
|
|
|
2024-09-06 16:26:00 -04:00
|
|
|
appendPubkey(config.RelayPubkey)
|
2024-09-06 11:16:40 -04:00
|
|
|
|
2024-09-07 22:01:13 -03:00
|
|
|
db := getDB()
|
2024-09-06 11:16:40 -04:00
|
|
|
if err := db.Init(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-09-12 20:51:26 -04:00
|
|
|
wdb = eventstore.RelayWrapper{Store: &db}
|
2024-09-06 11:16:40 -04:00
|
|
|
|
2024-09-12 10:04:06 -04:00
|
|
|
relay.RejectEvent = append(relay.RejectEvent,
|
|
|
|
policies.RejectEventsWithBase64Media,
|
2024-09-12 20:33:53 -04:00
|
|
|
policies.EventIPRateLimiter(5, time.Minute*1, 30),
|
2024-09-12 10:04:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
relay.RejectFilter = append(relay.RejectFilter,
|
|
|
|
policies.NoEmptyFilters,
|
|
|
|
policies.NoComplexFilters,
|
|
|
|
)
|
|
|
|
|
|
|
|
relay.RejectConnection = append(relay.RejectConnection,
|
2024-09-12 20:33:53 -04:00
|
|
|
policies.ConnectionRateLimiter(10, time.Minute*2, 30),
|
2024-09-12 10:04:06 -04:00
|
|
|
)
|
2024-09-11 22:06:17 -04:00
|
|
|
|
2024-09-06 11:16:40 -04:00
|
|
|
relay.StoreEvent = append(relay.StoreEvent, db.SaveEvent)
|
|
|
|
relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents)
|
2024-09-07 20:14:43 -04:00
|
|
|
relay.DeleteEvent = append(relay.DeleteEvent, db.DeleteEvent)
|
2024-09-06 11:16:40 -04:00
|
|
|
relay.RejectEvent = append(relay.RejectEvent, func(ctx context.Context, event *nostr.Event) (bool, string) {
|
2024-09-06 17:39:39 -04:00
|
|
|
for _, pk := range trustNetwork {
|
2024-09-06 11:16:40 -04:00
|
|
|
if pk == event.PubKey {
|
|
|
|
return false, ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, "you are not in the web of trust"
|
|
|
|
})
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
seedRelays = []string{
|
2024-09-06 11:16:40 -04:00
|
|
|
"wss://nos.lol",
|
|
|
|
"wss://nostr.mom",
|
|
|
|
"wss://purplepag.es",
|
|
|
|
"wss://purplerelay.com",
|
|
|
|
"wss://relay.damus.io",
|
|
|
|
"wss://relay.nostr.band",
|
|
|
|
"wss://relay.snort.social",
|
|
|
|
"wss://relayable.org",
|
|
|
|
"wss://relay.primal.net",
|
|
|
|
"wss://relay.nostr.bg",
|
|
|
|
"wss://no.str.cr",
|
|
|
|
"wss://nostr21.com",
|
|
|
|
"wss://nostrue.com",
|
|
|
|
"wss://relay.siamstr.com",
|
|
|
|
}
|
|
|
|
|
2024-09-12 20:51:26 -04:00
|
|
|
go refreshTrustNetwork(ctx, relay)
|
2024-09-06 11:16:40 -04:00
|
|
|
|
2024-09-06 19:25:40 -04:00
|
|
|
mux := relay.Router()
|
2024-09-10 17:17:03 -04:00
|
|
|
static := http.FileServer(http.Dir(config.StaticPath))
|
|
|
|
|
|
|
|
mux.Handle("GET /static/", http.StripPrefix("/static/", static))
|
|
|
|
mux.Handle("GET /favicon.ico", http.StripPrefix("/", static))
|
|
|
|
|
2024-09-06 19:25:40 -04:00
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
tmpl := template.Must(template.ParseFiles(os.Getenv("INDEX_PATH")))
|
|
|
|
data := struct {
|
|
|
|
RelayName string
|
|
|
|
RelayPubkey string
|
|
|
|
RelayDescription string
|
|
|
|
RelayURL string
|
|
|
|
}{
|
|
|
|
RelayName: config.RelayName,
|
|
|
|
RelayPubkey: config.RelayPubkey,
|
|
|
|
RelayDescription: config.RelayDescription,
|
|
|
|
RelayURL: config.RelayURL,
|
|
|
|
}
|
|
|
|
err := tmpl.Execute(w, data)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
log.Println("🎉 relay running on port :3334")
|
2024-09-06 19:38:39 -04:00
|
|
|
err := http.ListenAndServe(":3334", relay)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig() Config {
|
2024-09-07 07:10:01 -03:00
|
|
|
godotenv.Load(".env")
|
2024-09-06 11:16:40 -04:00
|
|
|
|
2024-09-07 23:39:23 -04:00
|
|
|
if os.Getenv("REFRESH_INTERVAL_HOURS") == "" {
|
2024-09-11 12:55:40 -04:00
|
|
|
os.Setenv("REFRESH_INTERVAL_HOURS", "3")
|
2024-09-07 23:39:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshInterval, _ := strconv.Atoi(os.Getenv("REFRESH_INTERVAL_HOURS"))
|
|
|
|
log.Println("🔄 refresh interval set to", refreshInterval, "hours")
|
|
|
|
|
2024-09-12 15:23:32 -04:00
|
|
|
if os.Getenv("MINIMUM_FOLLOWERS") == "" {
|
|
|
|
os.Setenv("MINIMUM_FOLLOWERS", "1")
|
|
|
|
}
|
|
|
|
|
2024-09-16 21:54:16 -04:00
|
|
|
if os.Getenv("ARCHIVAL_SYNC") == "" {
|
|
|
|
os.Setenv("ARCHIVAL_SYNC", "TRUE")
|
|
|
|
}
|
|
|
|
|
2024-09-19 11:04:47 -04:00
|
|
|
if os.Getenv("RELAY_ICON") == "" {
|
|
|
|
os.Setenv("RELAY_ICON", "https://pfp.nostr.build/56306a93a88d4c657d8a3dfa57b55a4ed65b709eee927b5dafaab4d5330db21f.png")
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.Getenv("RELAY_CONTACT") == "" {
|
|
|
|
os.Setenv("RELAY_CONTACT", getEnv("RELAY_PUBKEY"))
|
|
|
|
}
|
|
|
|
|
2024-09-12 15:23:32 -04:00
|
|
|
minimumFollowers, _ := strconv.Atoi(os.Getenv("MINIMUM_FOLLOWERS"))
|
|
|
|
|
2024-09-06 11:16:40 -04:00
|
|
|
config := Config{
|
|
|
|
RelayName: getEnv("RELAY_NAME"),
|
|
|
|
RelayPubkey: getEnv("RELAY_PUBKEY"),
|
|
|
|
RelayDescription: getEnv("RELAY_DESCRIPTION"),
|
2024-09-18 12:12:48 +01:00
|
|
|
RelayContact: getEnv("RELAY_CONTACT"),
|
|
|
|
RelayIcon: getEnv("RELAY_ICON"),
|
2024-09-06 11:16:40 -04:00
|
|
|
DBPath: getEnv("DB_PATH"),
|
2024-09-06 19:25:40 -04:00
|
|
|
RelayURL: getEnv("RELAY_URL"),
|
2024-09-06 19:33:29 -04:00
|
|
|
IndexPath: getEnv("INDEX_PATH"),
|
|
|
|
StaticPath: getEnv("STATIC_PATH"),
|
2024-09-07 23:39:23 -04:00
|
|
|
RefreshInterval: refreshInterval,
|
2024-09-12 15:23:32 -04:00
|
|
|
MinimumFollowers: minimumFollowers,
|
2024-09-16 21:54:16 -04:00
|
|
|
ArchivalSync: getEnv("ARCHIVAL_SYNC") == "TRUE",
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
func getEnv(key string) string {
|
|
|
|
value, exists := os.LookupEnv(key)
|
|
|
|
if !exists {
|
|
|
|
log.Fatalf("Environment variable %s not set", key)
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
func updateTrustNetworkFilter() {
|
2024-09-12 14:16:56 -04:00
|
|
|
trustNetworkMap = make(map[string]bool)
|
|
|
|
|
2024-09-12 15:23:32 -04:00
|
|
|
log.Println("🌐 updating trust network map")
|
|
|
|
for pubkey, count := range pubkeyFollowerCount {
|
|
|
|
if count >= config.MinimumFollowers {
|
|
|
|
trustNetworkMap[pubkey] = true
|
|
|
|
appendPubkey(pubkey)
|
|
|
|
}
|
2024-09-07 20:14:43 -04:00
|
|
|
}
|
2024-09-12 15:23:32 -04:00
|
|
|
|
|
|
|
log.Println("🌐 trust network map updated with", len(trustNetwork), "keys")
|
2024-09-07 20:14:43 -04:00
|
|
|
}
|
|
|
|
|
2024-09-12 20:51:26 -04:00
|
|
|
func refreshProfiles(ctx context.Context) {
|
2024-09-12 11:06:57 -04:00
|
|
|
for i := 0; i < len(trustNetwork); i += 200 {
|
|
|
|
timeout, cancel := context.WithTimeout(ctx, 4*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
end := i + 200
|
|
|
|
if end > len(trustNetwork) {
|
|
|
|
end = len(trustNetwork)
|
|
|
|
}
|
|
|
|
|
|
|
|
filters := []nostr.Filter{{
|
|
|
|
Authors: trustNetwork[i:end],
|
|
|
|
Kinds: []int{nostr.KindProfileMetadata},
|
|
|
|
}}
|
|
|
|
|
|
|
|
for ev := range pool.SubManyEose(timeout, seedRelays, filters) {
|
2024-09-12 20:51:26 -04:00
|
|
|
wdb.Publish(ctx, *ev.Event)
|
2024-09-12 11:06:57 -04:00
|
|
|
}
|
|
|
|
}
|
2024-09-12 12:40:45 -04:00
|
|
|
log.Println("👤 profiles refreshed: ", len(trustNetwork))
|
2024-09-12 11:06:57 -04:00
|
|
|
}
|
|
|
|
|
2024-09-12 20:51:26 -04:00
|
|
|
func refreshTrustNetwork(ctx context.Context, relay *khatru.Relay) {
|
2024-09-06 11:16:40 -04:00
|
|
|
|
2024-09-06 16:26:00 -04:00
|
|
|
runTrustNetworkRefresh := func() {
|
2024-09-11 12:55:40 -04:00
|
|
|
timeoutCtx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
2024-09-06 11:16:40 -04:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
filters := []nostr.Filter{{
|
|
|
|
Authors: []string{config.RelayPubkey},
|
|
|
|
Kinds: []int{nostr.KindContactList},
|
|
|
|
}}
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
log.Println("🔍 fetching owner's follows")
|
|
|
|
for ev := range pool.SubManyEose(timeoutCtx, seedRelays, filters) {
|
2024-09-06 11:16:40 -04:00
|
|
|
for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) {
|
2024-09-12 15:23:32 -04:00
|
|
|
pubkeyFollowerCount[contact[1]]++ // Increment follower count for the pubkey
|
2024-09-07 23:39:23 -04:00
|
|
|
appendOneHopNetwork(contact[1])
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
log.Println("🌐 building web of trust graph")
|
2024-09-07 23:39:23 -04:00
|
|
|
for i := 0; i < len(oneHopNetwork); i += 100 {
|
2024-09-11 12:55:40 -04:00
|
|
|
timeout, cancel := context.WithTimeout(ctx, 4*time.Second)
|
2024-09-07 20:14:43 -04:00
|
|
|
defer cancel()
|
|
|
|
|
2024-09-07 23:39:23 -04:00
|
|
|
end := i + 100
|
|
|
|
if end > len(oneHopNetwork) {
|
|
|
|
end = len(oneHopNetwork)
|
2024-09-07 20:14:43 -04:00
|
|
|
}
|
2024-09-06 11:16:40 -04:00
|
|
|
|
|
|
|
filters = []nostr.Filter{{
|
2024-09-07 23:39:23 -04:00
|
|
|
Authors: oneHopNetwork[i:end],
|
2024-09-07 20:14:43 -04:00
|
|
|
Kinds: []int{nostr.KindContactList, nostr.KindRelayListMetadata, nostr.KindProfileMetadata},
|
2024-09-06 11:16:40 -04:00
|
|
|
}}
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
for ev := range pool.SubManyEose(timeout, seedRelays, filters) {
|
2024-09-06 11:16:40 -04:00
|
|
|
for _, contact := range ev.Event.Tags.GetAll([]string{"p"}) {
|
2024-09-12 15:41:00 -04:00
|
|
|
if len(contact) > 1 {
|
|
|
|
pubkeyFollowerCount[contact[1]]++ // Increment follower count for the pubkey
|
|
|
|
}
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
2024-09-07 20:14:43 -04:00
|
|
|
|
|
|
|
for _, relay := range ev.Event.Tags.GetAll([]string{"r"}) {
|
|
|
|
appendRelay(relay[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
if ev.Event.Kind == nostr.KindProfileMetadata {
|
2024-09-12 20:51:26 -04:00
|
|
|
wdb.Publish(ctx, *ev.Event)
|
2024-09-07 20:14:43 -04:00
|
|
|
}
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
2024-09-07 20:14:43 -04:00
|
|
|
}
|
2024-09-12 15:23:32 -04:00
|
|
|
log.Println("🫂 total network size:", len(pubkeyFollowerCount))
|
2024-09-07 20:14:43 -04:00
|
|
|
log.Println("🔗 relays discovered:", len(relays))
|
2024-09-06 16:26:00 -04:00
|
|
|
}
|
|
|
|
|
2024-09-07 23:39:23 -04:00
|
|
|
for {
|
2024-09-06 16:26:00 -04:00
|
|
|
runTrustNetworkRefresh()
|
2024-09-07 20:14:43 -04:00
|
|
|
updateTrustNetworkFilter()
|
2024-09-12 20:51:26 -04:00
|
|
|
archiveTrustedNotes(ctx, relay)
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
func appendRelay(relay string) {
|
2024-09-06 13:24:33 -04:00
|
|
|
|
2024-09-07 20:14:43 -04:00
|
|
|
for _, r := range relays {
|
|
|
|
if r == relay {
|
|
|
|
return
|
2024-09-06 13:24:33 -04:00
|
|
|
}
|
|
|
|
}
|
2024-09-07 20:14:43 -04:00
|
|
|
relays = append(relays, relay)
|
2024-09-06 13:24:33 -04:00
|
|
|
}
|
|
|
|
|
2024-09-06 11:16:40 -04:00
|
|
|
func appendPubkey(pubkey string) {
|
|
|
|
for _, pk := range trustNetwork {
|
|
|
|
if pk == pubkey {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2024-09-07 20:14:43 -04:00
|
|
|
|
|
|
|
if len(pubkey) != 64 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-09-06 11:16:40 -04:00
|
|
|
trustNetwork = append(trustNetwork, pubkey)
|
|
|
|
}
|
|
|
|
|
2024-09-07 23:39:23 -04:00
|
|
|
func appendOneHopNetwork(pubkey string) {
|
|
|
|
for _, pk := range oneHopNetwork {
|
|
|
|
if pk == pubkey {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(pubkey) != 64 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
oneHopNetwork = append(oneHopNetwork, pubkey)
|
|
|
|
}
|
|
|
|
|
2024-09-12 20:51:26 -04:00
|
|
|
func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
|
2024-09-12 22:10:16 -04:00
|
|
|
timeout, cancel := context.WithTimeout(ctx, time.Duration(config.RefreshInterval)*time.Hour)
|
2024-09-12 22:09:21 -04:00
|
|
|
defer cancel()
|
2024-09-12 20:33:53 -04:00
|
|
|
|
2024-09-16 21:54:16 -04:00
|
|
|
done := make(chan struct{})
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
if config.ArchivalSync {
|
|
|
|
go refreshProfiles(ctx)
|
|
|
|
|
|
|
|
filters := []nostr.Filter{{
|
|
|
|
Kinds: []int{
|
|
|
|
nostr.KindArticle,
|
|
|
|
nostr.KindDeletion,
|
|
|
|
nostr.KindContactList,
|
|
|
|
nostr.KindEncryptedDirectMessage,
|
|
|
|
nostr.KindMuteList,
|
|
|
|
nostr.KindReaction,
|
|
|
|
nostr.KindRelayListMetadata,
|
|
|
|
nostr.KindRepost,
|
|
|
|
nostr.KindZapRequest,
|
|
|
|
nostr.KindZap,
|
|
|
|
nostr.KindTextNote,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
log.Println("📦 archiving trusted notes...")
|
|
|
|
|
|
|
|
for ev := range pool.SubMany(timeout, seedRelays, filters) {
|
|
|
|
go archiveEvent(ctx, relay, *ev.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes")
|
|
|
|
} else {
|
|
|
|
log.Println("🔄 web of trust will refresh in", config.RefreshInterval, "hours")
|
|
|
|
select {
|
|
|
|
case <-timeout.Done():
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(done)
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-timeout.Done():
|
|
|
|
log.Println("restarting process")
|
|
|
|
case <-done:
|
|
|
|
log.Println("📦 archiving process completed")
|
|
|
|
}
|
2024-09-06 11:16:40 -04:00
|
|
|
}
|
2024-09-13 08:04:45 -04:00
|
|
|
|
2024-09-13 08:11:57 -04:00
|
|
|
func archiveEvent(ctx context.Context, relay *khatru.Relay, ev nostr.Event) {
|
2024-09-13 08:04:45 -04:00
|
|
|
if trustNetworkMap[ev.PubKey] {
|
2024-09-13 08:11:57 -04:00
|
|
|
wdb.Publish(ctx, ev)
|
2024-09-13 08:04:45 -04:00
|
|
|
relay.BroadcastEvent(&ev)
|
|
|
|
trustedNotes++
|
|
|
|
} else {
|
|
|
|
untrustedNotes++
|
|
|
|
}
|
|
|
|
}
|