sdk: track query attempts automatically and other small tweaks to replaceable fetching and stuff.

This commit is contained in:
fiatjaf
2024-12-24 00:15:10 -03:00
parent 3b3d5cce7b
commit 95ddacb9f3
4 changed files with 74 additions and 15 deletions

View File

@ -124,15 +124,19 @@ func (sys *System) determineRelaysToQuery(ctx context.Context, pubkey string, ki
if kind == 10002 {
// prevent infinite loops by jumping directly to this
relays = sys.Hints.TopN(pubkey, 3)
} else if kind == 0 {
// leave room for one hardcoded relay because people are stupid
relays = sys.FetchOutboxRelays(ctx, pubkey, 2)
if len(relays) == 0 {
relays = []string{"wss://relay.damus.io", "wss://nos.lol"}
}
} else if kind == 0 || kind == 3 {
// leave room for two hardcoded relays because people are stupid
relays = sys.FetchOutboxRelays(ctx, pubkey, 1)
} else {
relays = sys.FetchOutboxRelays(ctx, pubkey, 3)
}
// use a different set of extra relays depending on the kind
for i := 0; i < 3-len(relays); i++ {
needed := 3 - len(relays)
for range needed {
var next string
switch kind {
case 0: