fix: don't stop reading the websocket for no reason!

This commit is contained in:
fiatjaf 2023-07-11 15:23:48 -03:00
parent 6e79f72174
commit c03c028142
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -236,6 +236,7 @@ func (r *Relay) Connect(ctx context.Context) error {
message, err := conn.ReadMessage(r.connectionContext) message, err := conn.ReadMessage(r.connectionContext)
if err != nil { if err != nil {
r.ConnectionError = err r.ConnectionError = err
r.Close()
break break
} }
@ -256,7 +257,7 @@ func (r *Relay) Connect(ctx context.Context) error {
} }
case *AuthEnvelope: case *AuthEnvelope:
if env.Challenge == nil { if env.Challenge == nil {
return continue
} }
// see WithAuthHandler // see WithAuthHandler
if r.challenges != nil { if r.challenges != nil {
@ -264,16 +265,16 @@ func (r *Relay) Connect(ctx context.Context) error {
} }
case *EventEnvelope: case *EventEnvelope:
if env.SubscriptionID == nil { if env.SubscriptionID == nil {
return continue
} }
if subscription, ok := r.Subscriptions.Load(*env.SubscriptionID); !ok { if subscription, ok := r.Subscriptions.Load(*env.SubscriptionID); !ok {
// InfoLogger.Printf("{%s} no subscription with id '%s'\n", r.URL, *env.SubscriptionID) // InfoLogger.Printf("{%s} no subscription with id '%s'\n", r.URL, *env.SubscriptionID)
return continue
} else { } else {
// check if the event matches the desired filter, ignore otherwise // check if the event matches the desired filter, ignore otherwise
if !subscription.Filters.Match(&env.Event) { if !subscription.Filters.Match(&env.Event) {
InfoLogger.Printf("{%s} filter does not match: %v ~ %v\n", r.URL, subscription.Filters, env.Event) InfoLogger.Printf("{%s} filter does not match: %v ~ %v\n", r.URL, subscription.Filters, env.Event)
return continue
} }
// check signature, ignore invalid, except from trusted (AssumeValid) relays // check signature, ignore invalid, except from trusted (AssumeValid) relays
@ -284,7 +285,7 @@ func (r *Relay) Connect(ctx context.Context) error {
errmsg = err.Error() errmsg = err.Error()
} }
InfoLogger.Printf("{%s} bad signature: %s\n", r.URL, errmsg) InfoLogger.Printf("{%s} bad signature: %s\n", r.URL, errmsg)
return continue
} }
} }