mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-18 14:39:58 +02:00
fix OK handling.
This commit is contained in:
parent
1bccebbf2a
commit
3e1749a01d
6
pool.go
6
pool.go
@ -256,13 +256,13 @@ func (pool *SimplePool) subManyEose(ctx context.Context, urls []string, filters
|
||||
case reason := <-sub.ClosedReason:
|
||||
if strings.HasPrefix(reason, "auth-required:") && pool.authHandler != nil && !hasAuthed {
|
||||
// relay is requesting auth. if we can we will perform auth and try again
|
||||
if err := relay.Auth(ctx, pool.authHandler); err == nil {
|
||||
err := relay.Auth(ctx, pool.authHandler)
|
||||
if err == nil {
|
||||
hasAuthed = true // so we don't keep doing AUTH again and again
|
||||
goto subscribe
|
||||
}
|
||||
} else {
|
||||
log.Printf("CLOSED from %s: '%s'\n", nm, reason)
|
||||
}
|
||||
log.Printf("CLOSED from %s: '%s'\n", nm, reason)
|
||||
return
|
||||
case evt, more := <-sub.Events:
|
||||
if !more {
|
||||
|
5
relay.go
5
relay.go
@ -319,7 +319,9 @@ func (r *Relay) publish(ctx context.Context, id string, env Envelope) error {
|
||||
}
|
||||
|
||||
// listen for an OK callback
|
||||
gotOk := false
|
||||
r.okCallbacks.Store(id, func(ok bool, reason string) {
|
||||
gotOk = true
|
||||
if !ok {
|
||||
err = fmt.Errorf("msg: %s", reason)
|
||||
}
|
||||
@ -338,6 +340,9 @@ func (r *Relay) publish(ctx context.Context, id string, env Envelope) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// this will be called when we get an OK or when the context has been canceled
|
||||
if gotOk {
|
||||
return err
|
||||
}
|
||||
return ctx.Err()
|
||||
case <-r.connectionContext.Done():
|
||||
// this is caused when we lose connectivity
|
||||
|
Loading…
x
Reference in New Issue
Block a user