nip46: client call to switch_relays must not wait forever (as it may be ignored).
This commit is contained in:
+5
-2
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
@@ -56,6 +57,7 @@ func ConnectBunker(
|
|||||||
pool,
|
pool,
|
||||||
onAuth,
|
onAuth,
|
||||||
)
|
)
|
||||||
|
|
||||||
_, err = bunker.RPC(ctx, "connect", []string{nostr.HexEncodeToString(parsed.HostPubKey[:]), parsed.Secret})
|
_, err = bunker.RPC(ctx, "connect", []string{nostr.HexEncodeToString(parsed.HostPubKey[:]), parsed.Secret})
|
||||||
return bunker, err
|
return bunker, err
|
||||||
}
|
}
|
||||||
@@ -175,10 +177,11 @@ func NewBunker(
|
|||||||
|
|
||||||
// attempt switch_relays once every 10 times
|
// attempt switch_relays once every 10 times
|
||||||
if now%10 == 0 {
|
if now%10 == 0 {
|
||||||
if newRelays, _ := bunker.SwitchRelays(ctx); newRelays != nil {
|
swctx, cancel := context.WithTimeout(ctx, time.Second*3)
|
||||||
cancel()
|
if newRelays, _ := bunker.SwitchRelays(swctx); newRelays != nil {
|
||||||
bunker = NewBunker(ctx, clientSecretKey, targetPublicKey, newRelays, pool, func(string) {})
|
bunker = NewBunker(ctx, clientSecretKey, targetPublicKey, newRelays, pool, func(string) {})
|
||||||
}
|
}
|
||||||
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
<-eosed
|
<-eosed
|
||||||
|
|||||||
Reference in New Issue
Block a user