back to the original way now the FJ fixed his mistakes

This commit is contained in:
Barry Deen 2024-09-12 22:09:21 -04:00
parent 6cef35e0f1
commit 7232b14a29
3 changed files with 21 additions and 44 deletions

4
go.mod
View File

@ -17,8 +17,8 @@ require (
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fasthttp/websocket v1.5.7 // indirect
github.com/fiatjaf/eventstore v0.8.2 // indirect
github.com/fiatjaf/khatru v0.8.2-0.20240912020201-6d827ac89ae6 // indirect
github.com/fiatjaf/eventstore v0.8.3-0.20240913011328-1196fabb86f2 // indirect
github.com/fiatjaf/khatru v0.8.2-0.20240913013357-18fc0dc1dd58 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.4.0 // indirect

4
go.sum
View File

@ -51,12 +51,16 @@ github.com/fiatjaf/eventstore v0.8.1 h1:51LchQNy0Hpb0YQHwqYR5pKBpfDs/KjySlWCbbz2
github.com/fiatjaf/eventstore v0.8.1/go.mod h1:bsp0Ibv0CIcVuFcoM2AEerMWmXRhF8uWXMf+dClhuow=
github.com/fiatjaf/eventstore v0.8.2 h1:nCa3UuJNV5Y5t+SDoPQe7PBmKJ6dhm9TQ/WyR4SCbIM=
github.com/fiatjaf/eventstore v0.8.2/go.mod h1:ck3RxufitHUBjID1RLcRxfX+NMywQzMsdfNpSt6m+9U=
github.com/fiatjaf/eventstore v0.8.3-0.20240913011328-1196fabb86f2 h1:eb4kt20dn2bQFGIUFNlF9O+nWO37s89gz2PTa/o40kk=
github.com/fiatjaf/eventstore v0.8.3-0.20240913011328-1196fabb86f2/go.mod h1:ck3RxufitHUBjID1RLcRxfX+NMywQzMsdfNpSt6m+9U=
github.com/fiatjaf/khatru v0.8.0 h1:hofUi4qbSqkJiKD4rC9EyNdi9obzBvp3ykJOBxuu/h8=
github.com/fiatjaf/khatru v0.8.0/go.mod h1:jRmqbbIbEH+y0unt3wMUBwqY/btVussqx5SmBoGhXtg=
github.com/fiatjaf/khatru v0.8.1 h1:BWAZqwuT0272ZlyzPkuqAA0eGBOs5G3u0Dn1tlWrm6Q=
github.com/fiatjaf/khatru v0.8.1/go.mod h1:jRmqbbIbEH+y0unt3wMUBwqY/btVussqx5SmBoGhXtg=
github.com/fiatjaf/khatru v0.8.2-0.20240912020201-6d827ac89ae6 h1:Ad1Z2+CM0zbp405rcZDaaXMemLDKZkm/Z+f+RrjmXdU=
github.com/fiatjaf/khatru v0.8.2-0.20240912020201-6d827ac89ae6/go.mod h1:jRmqbbIbEH+y0unt3wMUBwqY/btVussqx5SmBoGhXtg=
github.com/fiatjaf/khatru v0.8.2-0.20240913013357-18fc0dc1dd58 h1:F5Cy44IzxeIhzY8bf34rnORw0pYn6ZT/pIuyMO02Kjs=
github.com/fiatjaf/khatru v0.8.2-0.20240913013357-18fc0dc1dd58/go.mod h1:jRmqbbIbEH+y0unt3wMUBwqY/btVussqx5SmBoGhXtg=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=

57
main.go
View File

@ -333,7 +333,9 @@ func appendOneHopNetwork(pubkey string) {
}
func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
timeout := time.After(time.Duration(config.RefreshInterval) * time.Hour)
//timeout, cancel := context.WithTimeout(ctx, time.Duration(config.RefreshInterval)*time.Hour)
timeout, cancel := context.WithTimeout(ctx, 2*time.Minute)
defer cancel()
go refreshProfiles(ctx)
filters := []nostr.Filter{{
@ -354,50 +356,21 @@ func archiveTrustedNotes(ctx context.Context, relay *khatru.Relay) {
log.Println("📦 archiving trusted notes...")
eventChan := pool.SubMany(ctx, seedRelays, filters)
for {
select {
case <-timeout:
log.Println("⏰ Archive process terminated due to timeout")
log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes")
trustedNotes = 0
untrustedNotes = 0
return
case <-ctx.Done():
log.Println("⏰ Archive process terminated due to context cancellation")
log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes")
trustedNotes = 0
untrustedNotes = 0
return
case ev, ok := <-eventChan:
if !ok {
log.Println("📦 subscription channel closed")
log.Println("📦 archived", trustedNotes, "trusted notes and discarded", untrustedNotes, "untrusted notes")
trustedNotes = 0
untrustedNotes = 0
return
for ev := range pool.SubMany(timeout, seedRelays, filters) {
if trustNetworkMap[ev.PubKey] {
if len(ev.Tags) > 3000 {
continue
}
go processEvent(ctx, ev.Event, relay)
wdb.Publish(ctx, *ev.Event)
relay.BroadcastEvent(ev.Event)
trustedNotes++
log.Println("📦 archived note: ", ev.ID)
} else {
log.Println("🗑️ discarded note: ", ev.ID)
untrustedNotes++
}
}
}
func processEvent(ctx context.Context, ev *nostr.Event, relay *khatru.Relay) {
if trustNetworkMap[ev.PubKey] {
if len(ev.Tags) > 3000 {
return
}
wdb.Publish(ctx, *ev)
relay.BroadcastEvent(ev)
trustedNotes++
log.Println("📦 archived note: ", ev.ID)
} else {
log.Println("📦 discarded note: ", ev.ID)
untrustedNotes++
}
log.Println("📦 archived", trustedNotes, "trusted notes and discarded ", untrustedNotes, "untrusted notes")
}