mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-16 03:42:34 +02:00
protect against faulty relays that send more than one EOSE halting us
using sync.Once{} to only emit to the EndOfStoredEvents channel once (it has capacity 1 so anything over that would halt).
This commit is contained in:
parent
7538f1108d
commit
69ccfbaa08
2
relay.go
2
relay.go
@ -140,7 +140,9 @@ func (r *Relay) Connect() error {
|
|||||||
var channel string
|
var channel string
|
||||||
json.Unmarshal(jsonMessage[1], &channel)
|
json.Unmarshal(jsonMessage[1], &channel)
|
||||||
if subscription, ok := r.subscriptions.Load(channel); ok {
|
if subscription, ok := r.subscriptions.Load(channel); ok {
|
||||||
|
subscription.emitEose.Do(func() {
|
||||||
subscription.EndOfStoredEvents <- struct{}{}
|
subscription.EndOfStoredEvents <- struct{}{}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
case "OK":
|
case "OK":
|
||||||
if len(jsonMessage) < 3 {
|
if len(jsonMessage) < 3 {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package nostr
|
package nostr
|
||||||
|
|
||||||
|
import "sync"
|
||||||
|
|
||||||
type Subscription struct {
|
type Subscription struct {
|
||||||
id string
|
id string
|
||||||
conn *Connection
|
conn *Connection
|
||||||
@ -9,6 +11,7 @@ type Subscription struct {
|
|||||||
EndOfStoredEvents chan struct{}
|
EndOfStoredEvents chan struct{}
|
||||||
|
|
||||||
stopped bool
|
stopped bool
|
||||||
|
emitEose sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventMessage struct {
|
type EventMessage struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user